Annotation of loncom/interface/lonfeedback.pm, revision 1.169
1.1 www 1: # The LearningOnline Network
2: # Feedback
3: #
1.169 ! albertel 4: # $Id: lonfeedback.pm,v 1.168 2005/09/20 07:52:03 albertel Exp $
1.19 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.77 www 28: ###
1.7 albertel 29:
1.1 www 30: package Apache::lonfeedback;
31:
32: use strict;
33: use Apache::Constants qw(:common);
1.3 www 34: use Apache::lonmsg();
1.9 albertel 35: use Apache::loncommon();
1.33 www 36: use Apache::lontexconvert();
1.86 www 37: use Apache::lonlocal; # must not have ()
1.157 albertel 38: use Apache::lonnet;
1.86 www 39: use Apache::lonhtmlcommon();
1.128 raeburn 40: use Apache::lonnavmaps;
1.130 albertel 41: use Apache::lonenc();
1.112 raeburn 42: use HTML::LCParser();
1.106 www 43: use Apache::lonspeller();
1.116 raeburn 44: use Cwd;
1.54 www 45:
1.92 albertel 46: sub discussion_open {
1.122 raeburn 47: my ($status,$symb)=@_;
1.92 albertel 48: if (defined($status) &&
49: !($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER'
1.77 www 50: || $status eq 'OPEN')) {
1.92 albertel 51: return 0;
1.75 albertel 52: }
1.122 raeburn 53: my $close=&Apache::lonnet::EXT('resource.0.discussend',$symb);
1.89 albertel 54: if (defined($close) && $close ne '' && $close < time) {
1.92 albertel 55: return 0;
1.89 albertel 56: }
1.92 albertel 57: return 1;
58: }
59:
60: sub discussion_visible {
61: my ($status)=@_;
62: if (not &discussion_open($status)) {
63: my $hidden=&Apache::lonnet::EXT('resource.0.discusshide');
64: if (lc($hidden) eq 'yes' or $hidden eq '' or !defined($hidden)) {
1.157 albertel 65: if (!$env{'request.role.adv'}) { return 0; }
1.92 albertel 66: }
67: }
68: return 1;
1.90 albertel 69: }
1.84 raeburn 70:
1.90 albertel 71: sub list_discussion {
1.147 raeburn 72: my ($mode,$status,$ressymb,$imsextras)=@_;
1.157 albertel 73: my $outputtarget=$env{'form.grade_target'};
74: if (defined($env{'form.export'})) {
75: if($env{'form.export'}) {
1.116 raeburn 76: $outputtarget = 'export';
77: }
1.140 raeburn 78: }
1.147 raeburn 79: if (defined($imsextras)) {
80: if ($$imsextras{'caller'} eq 'imsexport') {
81: $outputtarget = 'export';
82: }
83: }
1.92 albertel 84: if (not &discussion_visible($status)) { return ''; }
1.84 raeburn 85: my @bgcols = ("#cccccc","#eeeeee");
1.57 www 86: my $discussiononly=0;
87: if ($mode eq 'board') { $discussiononly=1; }
1.157 albertel 88: unless ($env{'request.course.id'}) { return ''; }
89: my $crs='/'.$env{'request.course.id'};
90: my $cid=$env{'request.course.id'};
91: if ($env{'request.course.sec'}) {
92: $crs.='_'.$env{'request.course.sec'};
1.143 raeburn 93: }
1.55 www 94: $crs=~s/\_/\//g;
1.133 albertel 95: unless ($ressymb) { $ressymb=&Apache::lonnet::symbread(); }
96: unless ($ressymb) { return ''; }
97: $ressymb=&wrap_symb($ressymb);
98: my $encsymb=&Apache::lonenc::check_encrypt($ressymb);
99: my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
1.168 albertel 100: && ($ressymb=~/\.(problem|exam|quiz|assess|survey|form|task)$/));
1.133 albertel 101:
1.100 raeburn 102: my %usernamesort = ();
103: my %namesort =();
104: my %subjectsort = ();
1.133 albertel 105:
1.80 raeburn 106: # Get discussion display settings for this discussion
107: my $lastkey = $ressymb.'_lastread';
108: my $showkey = $ressymb.'_showonlyunread';
1.111 raeburn 109: my $markkey = $ressymb.'_showonlyunmark',
1.80 raeburn 110: my $visitkey = $ressymb.'_visit';
1.84 raeburn 111: my $ondispkey = $ressymb.'_markondisp';
1.101 raeburn 112: my $userpickkey = $ressymb.'_userpick';
1.111 raeburn 113: my $toggkey = $ressymb.'_readtoggle';
114: my $readkey = $ressymb.'_read';
1.139 albertel 115: $ressymb=$encsymb;
1.169 ! albertel 116: my %dischash = &Apache::lonnet::get('nohist_'.$cid.'_discuss',[$lastkey,$showkey,$markkey,$visitkey,$ondispkey,$userpickkey,$toggkey,$readkey],$env{'user.domain'},$env{'user.name'});
1.84 raeburn 117: my %discinfo = ();
1.80 raeburn 118: my $showonlyunread = 0;
1.111 raeburn 119: my $showunmark = 0;
1.84 raeburn 120: my $markondisp = 0;
1.79 raeburn 121: my $prevread = 0;
1.81 raeburn 122: my $previous = 0;
1.80 raeburn 123: my $visit = 0;
124: my $newpostsflag = 0;
1.101 raeburn 125: my @posters = split/\&/,$dischash{$userpickkey};
1.80 raeburn 126:
1.81 raeburn 127: # Retain identification of "NEW" posts identified in last display, if continuing 'previous' browsing of posts.
1.101 raeburn 128: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous','sortposts','rolefilter','statusfilter','sectionpick','totposters']);
1.157 albertel 129: my $sortposts = $env{'form.sortposts'};
130: my $statusfilter = $env{'form.statusfilter'};
1.143 raeburn 131: my @sectionpick = ();
1.157 albertel 132: if ($env{'form.sectionpick'} =~ /,/) {
133: @sectionpick = split/,/,$env{'form.sectionpick'};
1.143 raeburn 134: } else {
1.157 albertel 135: $sectionpick[0] = $env{'form.sectionpick'};
1.143 raeburn 136: }
137: my @rolefilter = ();
1.157 albertel 138: if ($env{'form.rolefilter'} =~ /,/) {
139: @rolefilter = split/,/,$env{'form.rolefilter'};
1.143 raeburn 140: } else {
1.157 albertel 141: $rolefilter[0] = $env{'form.rolefilter'};
1.143 raeburn 142: }
1.157 albertel 143: my $totposters = $env{'form.totposters'};
144: $previous = $env{'form.previous'};
1.80 raeburn 145: if ($previous > 0) {
146: $prevread = $previous;
147: } elsif (defined($dischash{$lastkey})) {
1.84 raeburn 148: unless ($dischash{$lastkey} eq '') {
149: $prevread = $dischash{$lastkey};
150: }
1.80 raeburn 151: }
1.79 raeburn 152:
1.108 raeburn 153: # Get information about students and non-students in course for filtering display of posts
1.101 raeburn 154: my %roleshash = ();
155: my %roleinfo = ();
1.157 albertel 156: if ($env{'form.rolefilter'}) {
1.169 ! albertel 157: %roleshash = &Apache::lonnet::dump('nohist_userroles',
! 158: $env{'course.'.$cid.'.domain'},
! 159: $env{'course.'.$cid.'.num'});
1.101 raeburn 160: foreach (keys %roleshash) {
161: my ($role,$uname,$udom,$sec) = split/:/,$_;
1.144 raeburn 162: if ($role =~ /^cr/) {
163: $role = 'cr';
164: }
1.101 raeburn 165: my ($end,$start) = split/:/,$roleshash{$_};
166: my $now = time;
167: my $status = 'Active';
168: if (($now < $start) || ($end > 0 && $now > $end)) {
169: $status = 'Expired';
170: }
1.144 raeburn 171: if ($uname && $udom) {
172: push @{$roleinfo{$uname.':'.$udom}}, $role.':'.$sec.':'.$status;
173: }
1.101 raeburn 174: }
175: my ($classlist) = &Apache::loncoursedata::get_classlist(
1.169 ! albertel 176: $env{'course.'.$cid.'.domain'},
! 177: $env{'course.'.$cid.'.num'});
1.101 raeburn 178: my $sec_index = &Apache::loncoursedata::CL_SECTION();
179: my $status_index = &Apache::loncoursedata::CL_STATUS();
180: while (my ($student,$data) = each %$classlist) {
181: my ($section,$status) = ($data->[$sec_index],
182: $data->[$status_index]);
183: push @{$roleinfo{$student}}, 'st:'.$section.':'.$status;
184: }
185: }
186:
1.84 raeburn 187: # Get discussion display default settings for user
1.157 albertel 188: if ($env{'environment.discdisplay'} eq 'unread') {
1.83 raeburn 189: $showonlyunread = 1;
190: }
1.157 albertel 191: if ($env{'environment.discmarkread'} eq 'ondisp') {
1.84 raeburn 192: $markondisp = 1;
193: }
194:
195: # Override user's default if user specified display setting for this discussion
196: if (defined($dischash{$ondispkey})) {
1.123 raeburn 197: unless ($dischash{$ondispkey} eq '') {
198: $markondisp = $dischash{$ondispkey};
199: }
1.84 raeburn 200: }
201: if ($markondisp) {
202: $discinfo{$lastkey} = time;
203: }
1.83 raeburn 204:
1.80 raeburn 205: if (defined($dischash{$showkey})) {
1.123 raeburn 206: unless ($dischash{$showkey} eq '') {
207: $showonlyunread = $dischash{$showkey};
208: }
1.80 raeburn 209: }
210:
1.111 raeburn 211: if (defined($dischash{$markkey})) {
1.123 raeburn 212: unless ($dischash{$markkey} eq '') {
213: $showunmark = $dischash{$markkey};
214: }
1.111 raeburn 215: }
216:
1.80 raeburn 217: if (defined($dischash{$visitkey})) {
1.123 raeburn 218: unless ($dischash{$visitkey} eq '') {
219: $visit = $dischash{$visitkey};
220: }
1.78 raeburn 221: }
1.80 raeburn 222: $visit ++;
1.78 raeburn 223:
1.54 www 224: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.68 www 225: my @discussionitems=();
1.101 raeburn 226: my %shown = ();
227: my @posteridentity=();
1.116 raeburn 228:
229: my $current=0;
1.67 www 230: my $visible=0;
1.68 www 231: my @depth=();
1.116 raeburn 232: my @replies = ();
1.68 www 233: my %alldiscussion=();
1.116 raeburn 234: my %imsitems=();
235: my %imsfiles=();
1.80 raeburn 236: my %notshown = ();
1.84 raeburn 237: my %newitem = ();
1.68 www 238: my $maxdepth=0;
239:
1.69 www 240: my $target='';
1.157 albertel 241: unless ($env{'browser.interface'} eq 'textual' ||
242: $env{'environment.remote'} eq 'off' ) {
1.69 www 243: $target='target="LONcom"';
244: }
1.111 raeburn 245:
1.79 raeburn 246: my $now = time;
1.80 raeburn 247: $discinfo{$visitkey} = $visit;
248:
1.169 ! albertel 249: &Apache::lonnet::put('nohist_'.$cid.'_discuss',\%discinfo,$env{'user.domain'},$env{'user.name'});
1.143 raeburn 250: &build_posting_display(\%usernamesort,\%subjectsort,\%namesort,\%notshown,\%newitem,\%dischash,\%shown,\%alldiscussion,\%imsitems,\%imsfiles,\%roleinfo,\@discussionitems,\@replies,\@depth,\@posters,\$maxdepth,\$visible,\$newpostsflag,\$current,$status,$viewgrades,$seeid,$prevread,$sortposts,$encsymb,$target,$readkey,$showunmark,$showonlyunread,$totposters,\@rolefilter,\@sectionpick,$statusfilter,$toggkey,$outputtarget);
1.80 raeburn 251:
1.67 www 252: my $discussion='';
1.116 raeburn 253: my $manifestfile;
254: my $manifestok=0;
255: my $tempexport;
256: my $imsresources;
257: my $copyresult;
1.84 raeburn 258:
259: my $function = &Apache::loncommon::get_users_function();
260: my $color = &Apache::loncommon::designparm($function.'.tabbg',
1.157 albertel 261: $env{'user.domain'});
1.84 raeburn 262: my %lt = &Apache::lonlocal::texthash(
1.97 raeburn 263: 'cuse' => 'Current discussion settings',
1.84 raeburn 264: 'allposts' => 'All posts',
265: 'unread' => 'New posts only',
1.111 raeburn 266: 'unmark' => 'Unread only',
1.84 raeburn 267: 'ondisp' => 'Once displayed',
1.111 raeburn 268: 'onmark' => 'Once marked not NEW',
269: 'toggoff' => 'Off',
270: 'toggon' => 'On',
1.84 raeburn 271: 'disa' => 'Posts to be displayed',
272: 'npce' => 'Posts cease to be marked "NEW"',
1.111 raeburn 273: 'epcb' => 'Each post can be toggled read/unread',
1.97 raeburn 274: 'chgt' => 'Change',
275: 'disp' => 'Display',
276: 'nolo' => 'Not new',
1.111 raeburn 277: 'togg' => 'Toggle read/unread',
1.84 raeburn 278: );
279:
280: my $currdisp = $lt{'allposts'};
281: my $currmark = $lt{'onmark'};
1.111 raeburn 282: my $currtogg = $lt{'toggoff'};
1.84 raeburn 283: my $dispchange = $lt{'unread'};
284: my $markchange = $lt{'ondisp'};
1.111 raeburn 285: my $toggchange = $lt{'toggon'};
1.97 raeburn 286: my $chglink = '/adm/feedback?modifydisp='.$ressymb;
1.111 raeburn 287: my $displinkA = 'onlyunread';
288: my $displinkB = 'onlyunmark';
1.97 raeburn 289: my $marklink = 'markondisp';
1.111 raeburn 290: my $togglink = 'toggon';
1.84 raeburn 291:
292: if ($markondisp) {
293: $currmark = $lt{'ondisp'};
294: $markchange = $lt{'onmark'};
1.97 raeburn 295: $marklink = 'markonread';
1.84 raeburn 296: }
297:
298: if ($showonlyunread) {
299: $currdisp = $lt{'unread'};
300: $dispchange = $lt{'allposts'};
1.111 raeburn 301: $displinkA = 'allposts';
1.84 raeburn 302: }
1.111 raeburn 303:
304: if ($showunmark) {
305: $currdisp = $lt{'unmark'};
306: $dispchange = $lt{'unmark'};
307: $displinkA='allposts';
308: $displinkB='onlyunread';
309: $showonlyunread = 0;
310: }
311:
312: if ($dischash{$toggkey}) {
313: $currtogg = $lt{'toggon'};
314: $toggchange = $lt{'toggoff'};
315: $togglink = 'toggoff';
316: }
1.97 raeburn 317:
1.111 raeburn 318: $chglink .= '&changes='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink;
1.84 raeburn 319:
320: if ($newpostsflag) {
1.97 raeburn 321: $chglink .= '&previous='.$prevread;
1.84 raeburn 322: }
323:
1.67 www 324: if ($visible) {
1.80 raeburn 325: # Print the discusssion
1.116 raeburn 326: if ($outputtarget eq 'tex') {
1.156 albertel 327: $discussion.='<tex>{\tiny \vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.
1.116 raeburn 328: '\textbf{DISCUSSIONS}\makebox[2 cm][b]{\hrulefill}'.
329: '\vskip 0 mm\noindent\textbf{'.$lt{'cuse'}.'}:\vskip 0 mm'.
330: '\noindent\textbf{'.$lt{'disa'}.'}: \textit{'.$currdisp.'}\vskip 0 mm'.
1.156 albertel 331: '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}}</tex>';
1.116 raeburn 332: } elsif ($outputtarget eq 'export') {
333: # Create temporary directory if this is an export
334: my $now = time;
1.147 raeburn 335: if ((defined($imsextras)) && ($$imsextras{'caller'} eq 'imsexport')) {
336: $tempexport = $$imsextras{'tempexport'};
337: if (!-e $tempexport) {
338: mkdir($tempexport,0700);
339: }
340: $tempexport .= '/'.$$imsextras{'count'};
341: if (!-e $tempexport) {
342: mkdir($tempexport,0700);
343: }
344: } else {
345: $tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
346: if (!-e $tempexport) {
347: mkdir($tempexport,0700);
348: }
349: $tempexport .= '/'.$now;
350: if (!-e $tempexport) {
351: mkdir($tempexport,0700);
352: }
1.157 albertel 353: $tempexport .= '/'.$env{'user.domain'}.'_'.$env{'user.name'};
1.116 raeburn 354: }
355: if (!-e $tempexport) {
356: mkdir($tempexport,0700);
357: }
358: # open manifest file
359: my $manifest = '/imsmanifest.xml';
360: my $manifestfilename = $tempexport.$manifest;
361: if ($manifestfile = Apache::File->new('>'.$manifestfilename)) {
362: $manifestok=1;
363: print $manifestfile qq|
364: <?xml version="1.0" encoding="UTF-8"?>
365: <manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1" xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
366: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
367: identifier="MANIFEST-$ressymb" xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1
368: imscp_v1p1.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">
369: <organizations default="$ressymb">
370: <organization identifier="$ressymb">
371: <title>Discussion for $ressymb</title>\n|;
372: } else {
373: $discussion .= 'An error occurred opening the manifest file.<br />';
374: }
375: } else {
1.97 raeburn 376: my $colspan=$maxdepth+1;
1.102 raeburn 377: $discussion.= qq|
378: <script>
379: function studentdelete (symb,idx,newflag,previous) {
380: var symbparm = symb+':::'+idx
381: var prevparm = ""
382: if (newflag == 1) {
383: prevparm = "&previous="+previous
384: }
385: 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")) {
386: document.location.href = "/adm/feedback?hide="+symbparm+prevparm
387: }
388: }
389: </script>
390: |;
1.134 albertel 391: $discussion.='<form name="readchoices" method="post" action="/adm/feedback?chgreads='.$ressymb.'" ><table bgcolor="#AAAAAA" cellpadding="2" cellspacing="2" border="0">';
1.97 raeburn 392: $discussion .='<tr><td bgcolor="#DDDDBB" colspan="'.$colspan.'">'.
1.95 sakharuk 393: '<table border="0" width="100%" bgcolor="#DDDDBB"><tr>';
394: if ($visible>2) {
395: $discussion.='<td align="left">'.
1.137 albertel 396: '<a href="/adm/feedback?cmd=threadedon&symb='.$ressymb;
1.95 sakharuk 397: if ($newpostsflag) {
398: $discussion .= '&previous='.$prevread;
399: }
400: $discussion .='">'.&mt('Threaded View').'</a> '.
1.137 albertel 401: '<a href="/adm/feedback?cmd=threadedoff&symb='.$ressymb;
1.95 sakharuk 402: if ($newpostsflag) {
403: $discussion .= '&previous='.$prevread;
404: }
1.100 raeburn 405: $discussion .='">'.&mt('Chronological View').'</a>
1.137 albertel 406: <a href= "/adm/feedback?cmd=sortfilter&symb='.$ressymb;
1.100 raeburn 407: if ($newpostsflag) {
408: $discussion .= '&previous='.$prevread;
409: }
410: $discussion .='">'.&mt('Sorting/Filtering options').'</a>  ';
411: } else {
412: $discussion .= '<td align="left">';
413: }
414: $discussion .='<a href= "/adm/feedback?export='.$ressymb;
415: if ($newpostsflag) {
416: $discussion .= '&previous='.$prevread;
417: }
418: $discussion .= '">'.&mt('Export').'?</a> </td>';
1.95 sakharuk 419: if ($newpostsflag) {
420: if (!$markondisp) {
1.137 albertel 421: $discussion .='<td align="right"><a href="/adm/feedback?markread=1&symb='.$ressymb.'">'.&mt('Mark NEW posts no longer new').'</a> ';
1.95 sakharuk 422: } else {
423: $discussion .= '<td> </td>';
424: }
425: } else {
426: $discussion .= '<td> </td>';
427: }
428: $discussion .= '</tr></table></td></tr>';
1.116 raeburn 429:
430: my $numhidden = keys %notshown;
431: if ($numhidden > 0) {
432: my $colspan = $maxdepth+1;
433: $discussion.="\n".'<tr><td bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
1.145 raeburn 434: '<a href="/adm/feedback?allposts=1&symb='.$ressymb;
1.116 raeburn 435: if ($newpostsflag) {
436: $discussion .= '&previous='.$prevread;
437: }
438: $discussion .= '">'.&mt('Show all posts').'</a> '.&mt('to display').' '.
1.111 raeburn 439: $numhidden.' ';
1.116 raeburn 440: if ($showunmark) {
441: $discussion .= &mt('posts previously marked read');
442: } else {
443: $discussion .= &mt('previously viewed posts');
444: }
445: $discussion .= '<br/></td></tr>';
1.111 raeburn 446: }
1.80 raeburn 447: }
1.100 raeburn 448:
449: # Choose sort mechanism
450: my @showposts = ();
451: if ($sortposts eq 'descdate') {
452: @showposts = (sort { $b <=> $a } keys %alldiscussion);
453: } elsif ($sortposts eq 'thread') {
454: @showposts = (sort { $a <=> $b } keys %alldiscussion);
455: } elsif ($sortposts eq 'subject') {
456: foreach (sort keys %subjectsort) {
457: push @showposts, @{$subjectsort{$_}};
458: }
459: } elsif ($sortposts eq 'username') {
460: foreach my $domain (sort keys %usernamesort) {
461: foreach (sort keys %{$usernamesort{$domain}}) {
462: push @showposts, @{$usernamesort{$domain}{$_}};
463: }
464: }
465: } elsif ($sortposts eq 'lastfirst') {
466: foreach my $last (sort keys %namesort) {
467: foreach (sort keys %{$namesort{$last}}) {
468: push @showposts, @{$namesort{$last}{$_}};
469: }
470: }
471: } else {
472: @showposts = (sort { $a <=> $b } keys %alldiscussion);
473: }
1.116 raeburn 474: my $currdepth = 0;
475: my $firstidx = $alldiscussion{$showposts[0]};
1.100 raeburn 476: foreach (@showposts) {
1.157 albertel 477: unless (($sortposts eq 'thread') || (($sortposts eq '') && ($env{'environment.threadeddiscussion'})) || ($outputtarget eq 'export')) {
1.100 raeburn 478: $alldiscussion{$_} = $_;
479: }
1.101 raeburn 480: unless ( ($notshown{$alldiscussion{$_}} eq '1') || ($shown{$alldiscussion{$_}} == 0) ) {
1.117 albertel 481: if ($outputtarget ne 'tex' && $outputtarget ne 'export') {
1.95 sakharuk 482: $discussion.="\n<tr>";
483: }
1.80 raeburn 484: my $thisdepth=$depth[$alldiscussion{$_}];
1.117 albertel 485: if ($outputtarget ne 'tex' && $outputtarget ne 'export') {
1.95 sakharuk 486: for (1..$thisdepth) {
487: $discussion.='<td> </td>';
488: }
489: }
1.80 raeburn 490: my $colspan=$maxdepth-$thisdepth+1;
1.116 raeburn 491: if ($outputtarget eq 'tex') {
1.95 sakharuk 492: #cleanup block
493: $discussionitems[$alldiscussion{$_}]=~s/<table([^>]*)>/<table TeXwidth="90 mm">/;
494: $discussionitems[$alldiscussion{$_}]=~s/<tr([^>]*)><td([^>]*)>/<tr><td TeXwidth="20 mm" align="left">/;
495: my $threadinsert='';
496: if ($thisdepth > 0) {
497: $threadinsert='<br /><strong>Reply: '.$thisdepth.'</strong>';
498: }
499: $discussionitems[$alldiscussion{$_}]=~s/<\/td><td([^>]*)>/$threadinsert<\/td><td TeXwidth="65 mm" align="left">/;
1.102 raeburn 500: $discussionitems[$alldiscussion{$_}]=~s/<a([^>]+)>(Edit|Hide|Delete|Reply|Submissions)<\/a>//g;
1.95 sakharuk 501: $discussionitems[$alldiscussion{$_}]=~s/(<b>|<\/b>|<\/a>|<a([^>]+)>)//g;
1.114 sakharuk 502:
503: $discussionitems[$alldiscussion{$_}]='<tex>\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}</tex>'.$discussionitems[$alldiscussion{$_}];
504: $discussion.=$discussionitems[$alldiscussion{$_}];
1.116 raeburn 505: } elsif ($outputtarget eq 'export') {
506: my $postfilename = $alldiscussion{$_}.'-'.$imsitems{$alldiscussion{$_}}{'timestamp'}.'.html';
507: if ($manifestok) {
508: if (($depth[$alldiscussion{$_}] <= $currdepth) && ($alldiscussion{$_} != $firstidx)) {
509: print $manifestfile ' </item>'."\n";
510: }
511: $currdepth = $depth[$alldiscussion{$_}];
512: print $manifestfile "\n".
513: '<item identifier="ITEM-'.$ressymb.'-'.$alldiscussion{$_}.'" isvisible="'.
514: $imsitems{$alldiscussion{$_}}{'isvisible'}.'" identifieref="RES-'.$ressymb.'-'.$alldiscussion{$_}.'">'.
515: '<title>'.$imsitems{$alldiscussion{$_}}{'title'}.'</title>';
516: $imsresources .= "\n".
1.146 raeburn 517: '<resource identifier="RES-'.$ressymb.'-'.$alldiscussion{$_}.'" type="webcontent" href="'.$postfilename.'">'."\n".
518: '<file href="'.$postfilename.'">'."\n".
1.116 raeburn 519: $imsfiles{$alldiscussion{$_}}{$imsitems{$alldiscussion{$_}}{'currversion'}}."\n".
520: '</resource>';
521: }
522: my $postingfile;
523: my $postingfilename = $tempexport.'/'.$postfilename;
524: if ($postingfile = Apache::File->new('>'.$postingfilename)) {
525: print $postingfile '<html><head><title>Discussion Post</title></head><body>'.
526: $imsitems{$alldiscussion{$_}}{'title'}.' '.
527: $imsitems{$alldiscussion{$_}}{'sender'}.
528: $imsitems{$alldiscussion{$_}}{'timestamp'}.'<br /><br />'.
529: $imsitems{$alldiscussion{$_}}{'message'}.'<br />'.
530: $imsitems{$alldiscussion{$_}}{'attach'}.'</body></html>'."\n";
531: close($postingfile);
532: } else {
533: $discussion .= 'An error occurred opening the export file for posting '.$alldiscussion{$_}.'<br />';
534: }
535: $copyresult.=&replicate_attachments($imsitems{$alldiscussion{$_}}{'allattachments'},$tempexport);
536: } else {
537: $discussion.='<td bgcolor="'.$bgcols[$newitem{$alldiscussion{$_}}].
538: '" colspan="'.$colspan.'">'. $discussionitems[$alldiscussion{$_}].
539: '</td></tr>';
540: }
1.69 www 541: }
1.80 raeburn 542: }
1.116 raeburn 543: unless ($outputtarget eq 'tex' || $outputtarget eq 'export') {
1.97 raeburn 544: my $colspan=$maxdepth+1;
1.111 raeburn 545: $discussion .= <<END;
1.97 raeburn 546: <tr bgcolor="#FFFFFF">
1.98 raeburn 547: <td colspan="$colspan" valign="top">
1.97 raeburn 548: <table border="0" bgcolor="#FFFFFF" width="100%" cellspacing="2" cellpadding="2">
549: <tr>
550: <td align="left">
551: <table border="0" cellpadding="0" cellspacing="4">
552: <tr>
553: <td>
554: <font size="-1"><b>$lt{'cuse'}</b>:</td>
555: <td> </td>
1.111 raeburn 556: <td><font size="-1">
1.97 raeburn 557: END
558: if ($newpostsflag) {
559: $discussion .=
1.111 raeburn 560: '1. '.$lt{'disp'}.' - <i>'.$currdisp.'</i> 2. '.$lt{'nolo'}.' - <i>'.$currmark.'</i>';
561: if ($dischash{$toggkey}) {
562: $discussion .= ' 3. '.$lt{'togg'}.' - <i>'.$currtogg.'</i>';
563: }
1.97 raeburn 564: } else {
1.111 raeburn 565: if ($dischash{$toggkey}) {
566: $discussion .= '1. '.$lt{'disp'}.' - <i>'.$currdisp.'</i> 2. '.$lt{'togg'}.' - <i>'.$currtogg.'</i>';
567: } else {
568: $discussion .=
569: $lt{'disp'}.' - <i>'.$currdisp.'</i>';
570: }
1.97 raeburn 571: }
572: $discussion .= <<END;
1.111 raeburn 573: </font></td>
1.97 raeburn 574: <td> </td>
1.144 raeburn 575: <td align="left">
1.111 raeburn 576: <font size="-1"><b><a href="$chglink">$lt{'chgt'}</a>?</font></b>
577: </td>
1.97 raeburn 578: </tr>
579: </table>
580: </td>
1.111 raeburn 581: END
1.143 raeburn 582: if ($sortposts) {
583: my %sort_types = ();
584: my %role_types = ();
585: my %status_types = ();
586: &sort_filter_names(\%sort_types,\%role_types,\%status_types);
587:
588: $discussion .= '<td><font size="-1"><b>'.&mt('Sorted by').'</b>: '.$sort_types{$sortposts}.'<br />';
1.157 albertel 589: if (defined($env{'form.totposters'})) {
1.144 raeburn 590: $discussion .= &mt('Posts by').':';
1.143 raeburn 591: if ($totposters > 0) {
592: foreach my $poster (@posters) {
593: $poster =~ s/:/\@/;
1.144 raeburn 594: $discussion .= ' '.$poster.',';
1.143 raeburn 595: }
1.144 raeburn 596: $discussion =~ s/,$//;
1.143 raeburn 597: } else {
598: $discussion .= &mt('None selected');
599: }
600: } else {
601: my $filterchoice ='';
602: if (@sectionpick > 0) {
1.157 albertel 603: $filterchoice = '<i>'.&mt('sections').'</i>- '.$env{'form.sectionpick'};
1.143 raeburn 604: $filterchoice .= ' ';
605: }
606: if (@rolefilter > 0) {
1.144 raeburn 607: $filterchoice .= '<i>'.&mt('roles').'</i>-';
1.143 raeburn 608: foreach (@rolefilter) {
1.144 raeburn 609: $filterchoice .= ' '.$role_types{$_}.',';
1.143 raeburn 610: }
1.144 raeburn 611: $filterchoice =~ s/,$//;
612: $filterchoice .= '<br />     ';
1.143 raeburn 613: }
614: if ($statusfilter) {
615: $filterchoice .= '<i>'.&mt('status').'</i>- '.$status_types{$statusfilter};
616: }
617: if ($filterchoice) {
618: $discussion .= '<b>'.&mt('Filters').'</b>: '.$filterchoice;
619: }
620: $discussion .= '</font></td>';
621: }
622: }
1.111 raeburn 623: if ($dischash{$toggkey}) {
624: my $storebutton = &mt('Store read/unread changes');
625: $discussion.='<td align="right">'.
626: '<input type="hidden" name="discsymb" value="'.$ressymb.'">'."\n".
627: '<input type="button" name="readoptions" value="'.$storebutton.'"'.
628: ' onClick="this.form.submit();">'."\n".
629: '</td>';
630: }
631: $discussion .= (<<END);
1.97 raeburn 632: </tr>
633: </table>
634: </td>
635: </tr>
636: </table>
1.134 albertel 637: <br /><br /></form>
1.97 raeburn 638: END
1.114 sakharuk 639: }
1.116 raeburn 640: if ($outputtarget eq 'export') {
641: if ($manifestok) {
642: while ($currdepth > 0) {
643: print $manifestfile " </item>\n";
644: $currdepth --;
645: }
646: print $manifestfile qq|
647: </organization>
648: </organizations>
649: <resources>
650: $imsresources
651: </resources>
652: </manifest>
653: |;
654: close($manifestfile);
1.147 raeburn 655: if ((defined($imsextras)) && ($$imsextras{'caller'} eq 'imsexport')) {
656: $discussion = $copyresult;
657: } else {
1.116 raeburn 658:
659: #Create zip file in prtspool
660:
1.147 raeburn 661: my $imszipfile = '/prtspool/'.
1.157 albertel 662: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.147 raeburn 663: time.'_'.rand(1000000000).'.zip';
664: my $cwd = &getcwd();
665: my $imszip = '/home/httpd/'.$imszipfile;
666: chdir $tempexport;
667: open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
668: close(OUTPUT);
669: chdir $cwd;
670: $discussion .= 'Download the zip file from <a href="'.$imszipfile.'">Discussion Posting Archive</a><br />';
671: if ($copyresult) {
672: $discussion .= 'The following errors occurred during export - <br />'.$copyresult;
673: }
1.116 raeburn 674: }
675: } else {
676: $discussion .= '<br />Unfortunately you will not be able to retrieve an archive of the discussion posts at this time, because there was a problem creating a manifest file.<br />';
677: }
678: return $discussion;
679: }
1.54 www 680: }
681: if ($discussiononly) {
1.108 raeburn 682: my $now = time;
683: my $attachnum = 0;
684: my $newattachmsg = '';
685: my @currnewattach = ();
686: my @currdelold = ();
687: my $comment = '';
688: my $subject = '';
1.157 albertel 689: if ($env{'form.origpage'}) {
1.108 raeburn 690: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['addnewattach','deloldattach','delnewattach','timestamp','idx','subject','comment']);
1.157 albertel 691: $subject = &Apache::lonnet::unescape($env{'form.subject'});
692: $comment = &Apache::lonnet::unescape($env{'form.comment'});
1.108 raeburn 693: my @keepold = ();
694: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
695: if (@currnewattach > 0) {
696: $attachnum += @currnewattach;
697: }
698: }
1.122 raeburn 699: if (&discussion_open($status)) {
700: $discussion.=(<<ENDDISCUSS);
1.54 www 701: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">
702: <input type="submit" name="discuss" value="Post Discussion" />
703: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
1.73 albertel 704: <input type="hidden" name="symb" value="$ressymb" />
1.54 www 705: <input type="hidden" name="sendit" value="true" />
1.108 raeburn 706: <input type="hidden" name="timestamp" value="$now" />
707: <br /><a name="newpost"></a>
708: <font size="1">Note: in anonymous discussion, your name is visible only
709: to course faculty</font><br />
710: <b>Title:</b> <input type="text" name="subject" value="$subject" size="30" /><br /><br />
711: <textarea name="comment" cols="80" rows="14" wrap="hard">$comment</textarea>
1.54 www 712: ENDDISCUSS
1.157 albertel 713: if ($env{'form.origpage'}) {
714: $discussion.='<input type="hidden" name="origpage" value="'.$env{'form.origpage'}.'" />'."\n";
1.140 raeburn 715: foreach (@currnewattach) {
716: $discussion.='<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
717: }
718: }
719: $discussion.="</form>\n";
720: if ($outputtarget ne 'tex') {
721: $discussion.=&generate_attachments_button('',$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,'',$mode);
722: if (@currnewattach > 0) {
723: $newattachmsg .= '<b>New attachments</b><br />';
724: if (@currnewattach > 1) {
725: $newattachmsg .= '<ol>';
726: foreach my $item (@currnewattach) {
727: $item =~ m#.*/([^/]+)$#;
728: $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
729: }
730: $newattachmsg .= '</ol>'."\n";
731: } else {
732: $currnewattach[0] =~ m#.*/([^/]+)$#;
733: $newattachmsg .= '<a href="'.$currnewattach[0].'">'.$1.'</a><br />'."\n";
1.108 raeburn 734: }
735: }
1.140 raeburn 736: $discussion.=$newattachmsg;
737: $discussion.=&generate_preview_button();
738: }
1.95 sakharuk 739: }
1.140 raeburn 740: } else {
741: if (&discussion_open($status) &&
742: &Apache::lonnet::allowed('pch',
1.157 albertel 743: $env{'request.course.id'}.
744: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
1.95 sakharuk 745: if ($outputtarget ne 'tex') {
746: $discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
1.129 albertel 747: $ressymb.':::" '.$target.'>'.
1.148 albertel 748: '<img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/chat.gif').'" border="0" />'.
1.95 sakharuk 749: &mt('Post Discussion').'</a></td></tr></table>';
750: }
1.100 raeburn 751: }
1.74 www 752: }
1.114 sakharuk 753: return $discussion;
1.54 www 754: }
1.1 www 755:
1.116 raeburn 756: sub build_posting_display {
757: my ($usernamesort,$subjectsort,$namesort,$notshown,$newitem,$dischash,$shown,$alldiscussion,$imsitems,$imsfiles,$roleinfo,$discussionitems,$replies,$depth,$posters,$maxdepth,$visible,$newpostsflag,$current,$status,$viewgrades,$seeid,$prevread,$sortposts,$ressymb,$target,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$statusfilter,$toggkey,$outputtarget) = @_;
758: my @original=();
759: my @index=();
1.133 albertel 760: my $symb=&Apache::lonenc::check_decrypt($ressymb);
1.157 albertel 761: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
762: $env{'course.'.$env{'request.course.id'}.'.domain'},
763: $env{'course.'.$env{'request.course.id'}.'.num'});
1.116 raeburn 764:
765: if ($contrib{'version'}) {
766: my $oldest = $contrib{'1:timestamp'};
767: if ($prevread eq '0') {
768: $prevread = $oldest-1;
769: }
1.143 raeburn 770: my ($skiptest,$rolematch,$roleregexp,$secregexp,$statusregexp);
771: if ($sortposts) {
772: ($skiptest,$roleregexp,$secregexp,$statusregexp) = &filter_regexp($rolefilter,$sectionpick,$statusfilter);
773: $rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp;
774: }
1.116 raeburn 775: for (my $id=1;$id<=$contrib{'version'};$id++) {
776: my $idx=$id;
777: my $posttime = $contrib{$idx.':timestamp'};
778: if ($prevread <= $posttime) {
779: $$newpostsflag = 1;
780: }
781: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
782: my $studenthidden=($contrib{'studenthidden'}=~/\.$idx\./);
783: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
784: my $origindex='0.';
785: my $numoldver=0;
786: if ($contrib{$idx.':replyto'}) {
1.157 albertel 787: if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
1.116 raeburn 788: # this is a follow-up message
789: $original[$idx]=$original[$contrib{$idx.':replyto'}];
790: $$depth[$idx]=$$depth[$contrib{$idx.':replyto'}]+1;
791: $origindex=$index[$contrib{$idx.':replyto'}];
792: if ($$depth[$idx]>$$maxdepth) { $$maxdepth=$$depth[$idx]; }
793: } else {
794: $original[$idx]=0;
795: $$depth[$idx]=0;
796: }
797: } else {
798: # this is an original message
799: $original[$idx]=0;
800: $$depth[$idx]=0;
801: }
802: if ($$replies[$$depth[$idx]]) {
803: $$replies[$$depth[$idx]]++;
804: } else {
805: $$replies[$$depth[$idx]]=1;
806: }
807: unless ((($hidden) && (!$seeid)) || ($deleted)) {
808: $$visible++;
809: if ($contrib{$idx.':history'}) {
810: if ($contrib{$idx.':history'} =~ /:/) {
811: my @oldversions = split/:/,$contrib{$idx.':history'};
812: $numoldver = @oldversions;
813: } else {
814: $numoldver = 1;
815: }
816: }
817: $$current = $numoldver;
818: my %messages = ();
819: my %subjects = ();
820: my %attachtxt = ();
821: my %allattachments = ();
822: my ($screenname,$plainname);
823: my $sender = &mt('Anonymous');
824: my ($message,$subject,$vgrlink,$ctlink);
825: &get_post_contents(\%contrib,$idx,$seeid,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,$numoldver);
826:
827:
828: # Set up for sorting by subject
829: unless ($outputtarget eq 'export') {
830: $message=$messages{$numoldver};
831: $message.=$attachtxt{$numoldver};
832: $subject=$subjects{$numoldver};
833: if ($message) {
834: if ($hidden) {
835: $message='<font color="#888888">'.$message.'</font>';
836: if ($studenthidden) {
837: $message .='<br /><br />Deleted by poster (student).';
838: }
839: }
840:
841: if ($subject eq '') {
842: if (defined($$subjectsort{'__No subject'})) {
843: push @{$$subjectsort{'__No subject'}}, $idx;
844: } else {
845: @{$$subjectsort{'__No subject'}} = ("$idx");
846: }
847: } else {
848: if (defined($$subjectsort{$subject})) {
849: push @{$$subjectsort{$subject}}, $idx;
850: } else {
851: @{$$subjectsort{$subject}} = ("$idx");
852: }
853: }
854: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
855: $sender=&Apache::loncommon::aboutmewrapper(
856: $plainname,
857: $contrib{$idx.':sendername'},
858: $contrib{$idx.':senderdomain'}).' ('.
859: $contrib{$idx.':sendername'}.' at '.
860: $contrib{$idx.':senderdomain'}.')';
861: if ($contrib{$idx.':anonymous'}) {
1.166 www 862: $sender.=' <font color="red"><b>['.&mt('anonymous').']</b></font> '.
1.116 raeburn 863: $screenname;
864: }
865:
866: # Set up for sorting by domain, then username
867: unless (defined($$usernamesort{$contrib{$idx.':senderdomain'}})) {
868: %{$$usernamesort{$contrib{$idx.':senderdomain'}}} = ();
869: }
870: if (defined($$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}})) {
871: push @{$$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}}, $idx;
872: } else {
873: @{$$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}} = ("$idx");
874: }
875: # Set up for sorting by last name, then first name
876: my %names = &Apache::lonnet::get('environment',
877: ['firstname','lastname'],$contrib{$idx.':senderdomain'},
878: ,$contrib{$idx.':sendername'});
879: my $lastname = $names{'lastname'};
880: my $firstname = $names{'firstname'};
881: if ($lastname eq '') {
882: $lastname = '_';
883: }
884: if ($firstname eq '') {
885: $firstname = '_';
886: }
887: unless (defined($$namesort{$lastname})) {
888: %{$$namesort{$lastname}} = ();
889: }
890: if (defined($$namesort{$lastname}{$firstname})) {
891: push @{$$namesort{$lastname}{$firstname}}, $idx;
892: } else {
893: @{$$namesort{$lastname}{$firstname}} = ("$idx");
894: }
1.157 albertel 895: if ($env{'course.'.$env{'request.course.id'}.'.allow_discussion_post_editing'} =~ m/yes/i) {
896: if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) {
1.116 raeburn 897: $sender.=' <a href="/adm/feedback?editdisc='.
898: $ressymb.':::'.$idx;
899: if ($newpostsflag) {
900: $sender .= '&previous='.$prevread;
901: }
902: $sender .= '" '.$target.'>'.&mt('Edit').'</a>';
903: unless ($seeid) {
904: $sender.=" <a href=\"javascript:studentdelete('$ressymb','$idx','$newpostsflag','$prevread')";
905: $sender .= '">'.&mt('Delete').'</a>';
906: }
907: }
908: }
909: if ($seeid) {
910: if ($hidden) {
911: unless ($studenthidden) {
912: $sender.=' <a href="/adm/feedback?unhide='.
913: $ressymb.':::'.$idx;
914: if ($newpostsflag) {
915: $sender .= '&previous='.$prevread;
916: }
917: $sender .= '">'.&mt('Make Visible').'</a>';
918: }
919: } else {
920: $sender.=' <a href="/adm/feedback?hide='.
921: $ressymb.':::'.$idx;
922: if ($newpostsflag) {
923: $sender .= '&previous='.$prevread;
924: }
925: $sender .= '">'.&mt('Hide').'</a>';
926: }
927: $sender.=' <a href="/adm/feedback?deldisc='.
928: $ressymb.':::'.$idx;
929: if ($newpostsflag) {
930: $sender .= '&previous='.$prevread;
931: }
932: $sender .= '">'.&mt('Delete').'</a>';
933: }
934: } else {
935: if ($screenname) {
936: $sender='<i>'.$screenname.'</i>';
937: }
938: # Set up for sorting by domain, then username for anonymous
939: unless (defined($$usernamesort{'__anon'})) {
940: %{$$usernamesort{'__anon'}} = ();
941: }
942: if (defined($$usernamesort{'__anon'}{'__anon'})) {
943: push @{$$usernamesort{'__anon'}{'__anon'}}, $idx;
944: } else {
945: @{$$usernamesort{'__anon'}{'__anon'}} = ("$idx");
946: }
947: # Set up for sorting by last name, then first name for anonymous
948: unless (defined($$namesort{'__anon'})) {
949: %{$$namesort{'__anon'}} = ();
950: }
951: if (defined($$namesort{'__anon'}{'__anon'})) {
952: push @{$$namesort{'__anon'}{'__anon'}}, $idx;
953: } else {
954: @{$$namesort{'__anon'}{'__anon'}} = ("$idx");
955: }
956: }
957: if (&discussion_open($status) &&
958: &Apache::lonnet::allowed('pch',
1.157 albertel 959: $env{'request.course.id'}.
960: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
1.116 raeburn 961: $sender.=' <a href="/adm/feedback?replydisc='.
962: $ressymb.':::'.$idx;
963: if ($newpostsflag) {
964: $sender .= '&previous='.$prevread;
965: }
966: $sender .= '" '.$target.'>'.&mt('Reply').'</a>';
967: }
968: if ($viewgrades) {
969: $vgrlink=&Apache::loncommon::submlink('Submissions',
970: $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$ressymb);
971: }
972: if ($$dischash{$readkey}=~/\.$idx\./) {
1.151 albertel 973: $ctlink = '<label><b>'.&mt('Mark unread').'?</b> <input type="checkbox" name="postunread_'.$idx.'" /></label>';
1.116 raeburn 974: } else {
1.151 albertel 975: $ctlink = '<label><b>'.&mt('Mark read').'?</b> <input type="checkbox" name="postread_'.$idx.'" /></label>';
1.116 raeburn 976: }
977: }
978: #figure out at what position this needs to print
979: }
980: if ($outputtarget eq 'export' || $message) {
981: my $thisindex=$idx;
1.157 albertel 982: if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
1.116 raeburn 983: $thisindex=$origindex.substr('00'.$$replies[$$depth[$idx]],-2,2);
984: }
985: $$alldiscussion{$thisindex}=$idx;
986: $$shown{$idx} = 0;
987: $index[$idx]=$thisindex;
988: }
989: if ($outputtarget eq 'export') {
990: %{$$imsitems{$idx}} = ();
991: $$imsitems{$idx}{'isvisible'}='true';
992: if ($hidden) {
993: $$imsitems{$idx}{'isvisible'}='false';
994: }
995: $$imsitems{$idx}{'title'}=$subjects{$numoldver};
996: $$imsitems{$idx}{'message'}=$messages{$numoldver};
997: $$imsitems{$idx}{'attach'}=$attachtxt{$numoldver};
998: $$imsitems{$idx}{'timestamp'}=$contrib{$idx.':timestamp'};
999: $$imsitems{$idx}{'sender'}=$plainname.' ('.
1000: $contrib{$idx.':sendername'}.' at '.
1001: $contrib{$idx.':senderdomain'}.')';
1002: $$imsitems{$idx}{'isanonymous'}='false';
1003: if ($contrib{$idx.':anonymous'}) {
1004: $$imsitems{$idx}{'isanonymous'}='true';
1005: }
1006: $$imsitems{$idx}{'currversion'}=$numoldver;
1007: %{$$imsitems{$idx}{'allattachments'}}=%allattachments;
1008: unless ($messages{$numoldver} eq '' && $attachtxt{$numoldver} eq '') {
1009: $$shown{$idx} = 1;
1010: }
1011: } else {
1012: if ($message) {
1013: my $spansize = 2;
1014: if ($showonlyunread && $prevread > $posttime) {
1015: $$notshown{$idx} = 1;
1016: } elsif ($showunmark && $$dischash{$readkey}=~/\.$idx\./) {
1017: $$notshown{$idx} = 1;
1018: } else {
1019: # apply filters
1020: my $uname = $contrib{$idx.':sendername'};
1021: my $udom = $contrib{$idx.':senderdomain'};
1022: my $poster = $uname.':'.$udom;
1.157 albertel 1023: if (defined($env{'form.totposters'})) {
1.143 raeburn 1024: if ($totposters == 0) {
1025: $$shown{$idx} = 0;
1026: } elsif ($totposters > 0) {
1027: if (grep/^$poster$/,@{$posters}) {
1028: $$shown{$idx} = 1;
1.116 raeburn 1029: }
1030: }
1.143 raeburn 1031: } elsif ($sortposts) {
1.116 raeburn 1032: if ($skiptest) {
1033: $$shown{$idx} = 1;
1034: } else {
1035: foreach my $role (@{$$roleinfo{$poster}}) {
1.143 raeburn 1036: if ($role =~ /^cc:/) {
1037: my $cc_regexp = $roleregexp.':[^:]*:'.$statusregexp;
1038: if ($role =~ /$cc_regexp/) {
1039: $$shown{$idx} = 1;
1.144 raeburn 1040: last;
1.143 raeburn 1041: }
1042: } elsif ($role =~ /^$rolematch$/) {
1.116 raeburn 1043: $$shown{$idx} = 1;
1044: last;
1045: }
1046: }
1047: }
1.143 raeburn 1048: } else {
1049: $$shown{$idx} = 1;
1.116 raeburn 1050: }
1051: }
1052: unless ($$notshown{$idx} == 1) {
1053: if ($prevread > 0 && $prevread <= $posttime) {
1054: $$newitem{$idx} = 1;
1055: $$discussionitems[$idx] .= '
1056: <p><table border="0" width="100%">
1057: <tr><td align="left"><font color="#FF0000"><b>NEW</b></font></td>';
1058: } else {
1059: $$newitem{$idx} = 0;
1060: $$discussionitems[$idx] .= '
1061: <p><table border="0" width="100%">
1062: <tr><td align="left"> </td>';
1063: }
1064: $$discussionitems[$idx] .= '<td align ="left"> '.
1065: '<b>'.$subject.'</b> '.
1066: $sender.'</b> '.$vgrlink.' ('.
1067: &Apache::lonlocal::locallocaltime($posttime).')</td>';
1068: if ($$dischash{$toggkey}) {
1069: $$discussionitems[$idx].='<td align="right"> '.
1070: $ctlink.'</td>';
1071: }
1072: $$discussionitems[$idx].= '</tr></table><blockquote>'.
1073: $message.'</blockquote></p>';
1074: if ($contrib{$idx.':history'}) {
1075: my @postversions = ();
1076: $$discussionitems[$idx] .= &mt('This post has been edited by the author.');
1077: if ($seeid) {
1078: $$discussionitems[$idx] .= ' <a href="/adm/feedback?allversions='.$ressymb.':::'.$idx.'">'.&mt('Display all versions').'</a>';
1079: }
1080: $$discussionitems[$idx].='<br/>'.&mt('Earlier version(s) were posted on: ');
1081: if ($contrib{$idx.':history'} =~ m/:/) {
1082: @postversions = split/:/,$contrib{$idx.':history'};
1083: } else {
1084: @postversions = ("$contrib{$idx.':history'}");
1085: }
1086: for (my $i=0; $i<@postversions; $i++) {
1087: my $version = $i+1;
1088: $$discussionitems[$idx] .= '<b>'.$version.'.</b> - '.&Apache::lonlocal::locallocaltime($postversions[$i]).' ';
1089: }
1090: }
1091: }
1092: }
1093: }
1094: }
1095: }
1096: }
1097: }
1098:
1.143 raeburn 1099: sub filter_regexp {
1100: my ($rolefilter,$sectionpick,$statusfilter) = @_;
1101: my ($roleregexp,$secregexp,$statusregexp);
1102: my $skiptest = 1;
1103: if (@{$rolefilter} > 0) {
1104: my @okrolefilter = ();
1105: foreach (@{$rolefilter}) {
1106: unless ($_ eq '') {
1107: push @okrolefilter, $_;
1108: }
1109: }
1110: if (@okrolefilter > 0) {
1111: if (grep/^all$/,@okrolefilter) {
1112: $roleregexp='[^:]+';
1113: } else {
1114: if (@okrolefilter == 1) {
1115: $roleregexp=$okrolefilter[0];
1116: } else {
1117: $roleregexp='('.join('|',@okrolefilter).')';
1118: }
1119: $skiptest = 0;
1120: }
1121: }
1122: }
1123: if (@{$sectionpick} > 0) {
1124: my @oksectionpick = ();
1125: foreach (@{$sectionpick}) {
1126: unless ($_ eq '') {
1127: push @oksectionpick, $_;
1128: }
1129: }
1130: if ((@oksectionpick > 0) && (!grep/^all$/,@oksectionpick)) {
1131: if (@oksectionpick == 1) {
1132: $secregexp = $oksectionpick[0];
1133: } else {
1134: $secregexp .= '('.join('|',@oksectionpick).')';
1135: }
1136: $skiptest = 0;
1137: } else {
1138: $secregexp .= '[^:]*';
1139: }
1140: }
1141: if (defined($statusfilter) && $statusfilter ne '') {
1142: if ($statusfilter eq 'all') {
1143: $statusregexp = '[^:]+';
1144: } else {
1145: $statusregexp = $statusfilter;
1146: $skiptest = 0;
1147: }
1148: }
1149: return ($skiptest,$roleregexp,$secregexp,$statusregexp);
1150: }
1151:
1152:
1.116 raeburn 1153: sub get_post_contents {
1154: my ($contrib,$idx,$seeid,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$numver) = @_;
1155: my $discussion = '';
1156: my $start=$numver;
1157: my $end=$numver + 1;
1158: %{$$imsfiles{$idx}}=();
1159: if ($type eq 'allversions') {
1160: unless($seeid) {
1161: $discussion=&mt('You do not have privileges to view all versions of posts.').&mt('Please select a different role');
1162: return $discussion;
1163: }
1164: }
1.126 albertel 1165: # $$screenname=&Apache::loncommon::screenname(
1166: # $$contrib{$idx.':sendername'},
1167: # $$contrib{$idx.':senderdomain'});
1168: # $$plainname=&Apache::loncommon::nickname(
1169: # $$contrib{$idx.':sendername'},
1170: # $$contrib{$idx.':senderdomain'});
1171: ($$screenname,$$plainname)=($$contrib{$idx.':screenname'},
1172: $$contrib{$idx.':plainname'});
1.116 raeburn 1173: my $sender=&Apache::loncommon::aboutmewrapper(
1174: $$plainname,
1175: $$contrib{$idx.':sendername'},
1176: $$contrib{$idx.':senderdomain'}).' ('.
1177: $$contrib{$idx.':sendername'}.' at '.
1178: $$contrib{$idx.':senderdomain'}.')';
1179: my $attachmenturls = $$contrib{$idx.':attachmenturl'};
1180: my @postversions = ();
1181: if ($type eq 'allversions' || $type eq 'export') {
1182: $start = 0;
1183: if ($$contrib{$idx.':history'}) {
1184: if ($$contrib{$idx.':history'} =~ m/:/) {
1185: @postversions = split/:/,$$contrib{$idx.':history'};
1186: } else {
1187: @postversions = ("$$contrib{$idx.':history'}");
1188: }
1189: }
1190: &get_post_versions($messages,$$contrib{$idx.':message'},1);
1191: &get_post_versions($subjects,$$contrib{$idx.':subject'},1);
1192: push @postversions,$$contrib{$idx.':timestamp'};
1193: $end = @postversions;
1194: } else {
1195: &get_post_versions($messages,$$contrib{$idx.':message'},1,$numver);
1196: &get_post_versions($subjects,$$contrib{$idx.':subject'},1,$numver);
1197: }
1198:
1199: if ($$contrib{$idx.':anonymous'}) {
1200: $sender.=' ['.&mt('anonymous').'] '.$$screenname;
1201: }
1202: if ($type eq 'allversions') {
1203: $discussion=('<b>'.$sender.'</b><br /><ul>');
1204: }
1205: for (my $i=$start; $i<$end; $i++) {
1206: my ($timesent,$attachmsg);
1207: my %currattach = ();
1208: $timesent = &Apache::lonlocal::locallocaltime($postversions[$i]);
1.165 albertel 1209: &newline_to_br(\$messages->{$i});
1.116 raeburn 1210: $$messages{$i}=&Apache::lontexconvert::msgtexconverted($$messages{$i});
1211: $$subjects{$i}=~s/\n/\<br \/\>/g;
1212: $$subjects{$i}=&Apache::lontexconvert::msgtexconverted($$subjects{$i});
1213: if ($attachmenturls) {
1214: &extract_attachments($attachmenturls,$idx,$i,\$attachmsg,$allattachments,\%currattach);
1215: }
1216: if ($type eq 'export') {
1217: $$imsfiles{$idx}{$i} = '';
1218: if ($attachmsg) {
1219: $$attachtxt{$i} = '<br />Attachments:<br />';
1220: foreach (sort keys %currattach) {
1221: if ($$allattachments{$_}{'filename'} =~ m-^/uploaded/([^/]+/[^/]+)(/feedback)?(/?\d*)/([^/]+)$-) {
1222: my $fname = $1.$3.'/'.$4;
1223: $$imsfiles{$idx}{$i} .= '<file href="'.$fname.'">'."\n";
1224: $$attachtxt{$i}.= '<a href="'.$fname.'">'.$4.'</a><br />';
1225: }
1226: }
1227: }
1228: } else {
1229: if ($attachmsg) {
1230: $$attachtxt{$i} = '<br />Attachments:'.$attachmsg.'<br />';
1231: } else {
1232: $$attachtxt{$i} = '';
1233: }
1234: }
1235: if ($type eq 'allversions') {
1236: $discussion.= <<"END";
1237: <li><b>$$subjects{$i}</b>, $timesent<br />
1238: $$messages{$i}<br />
1239: $$attachtxt{$i}</li>
1240: END
1241: }
1242: }
1243: if ($type eq 'allversions') {
1244: $discussion.=('</ul></body></html>');
1245: return $discussion;
1246: } else {
1247: return;
1248: }
1249: }
1250:
1251: sub replicate_attachments {
1252: my ($attachrefs,$tempexport) = @_;
1253: my $response;
1254: foreach my $id (keys %{$attachrefs}) {
1255: if ($$attachrefs{$id}{'filename'} =~ m-^/uploaded/([^/]+)/([^/]+)(/feedback)?(/?\d*)/([^/]+)$-) {
1256: my $path = $tempexport;
1257: my $tail = $1.'/'.$2.$4;
1258: my @extras = split/\//,$tail;
1259: my $destination = $tempexport.'/'.$1.'/'.$2.$4.'/'.$5;
1260: if (!-e $destination) {
1261: my $i= 0;
1262: while ($i<@extras) {
1263: $path .= '/'.$extras[$i];
1264: if (!-e $path) {
1265: mkdir($path,0700);
1266: }
1267: $i ++;
1268: }
1269: my ($content,$rtncode);
1270: my $uploadreply = &Apache::lonnet::getuploaded('GET',$$attachrefs{$id}{'filename'},$1,$2,$content,$rtncode);
1271: if ($uploadreply eq 'ok') {
1.125 raeburn 1272: my $attachcopy;
1273: if ($attachcopy = Apache::File->new('>'.$destination)) {
1274: print $attachcopy $content;
1275: close($attachcopy);
1276: } else {
1277: $response .= 'Error copying file attachment - '.$5.' to IMS package: '.$!.'<br />'."\n";
1278: }
1.116 raeburn 1279: } else {
1.125 raeburn 1280: &Apache::lonnet::logthis("Replication of attachment failed when building IMS export of discussion posts - domain: $1, course: $2, file: $$attachrefs{$id}{'filename'} -error: $rtncode");
1281: $response .= 'Error copying file attachment - '.$5.' to IMS package: '.$rtncode.'<br />'."\n";
1.116 raeburn 1282: }
1283: }
1284: }
1285: }
1.125 raeburn 1286: return $response;
1.116 raeburn 1287: }
1288:
1.6 albertel 1289: sub mail_screen {
1290: my ($r,$feedurl,$options) = @_;
1.157 albertel 1291: if (exists($env{'form.origpage'})) {
1.108 raeburn 1292: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss']);
1293: }
1.45 www 1294: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
1.102 raeburn 1295: '','onLoad="window.focus();setposttype();"');
1.51 albertel 1296: my $title=&Apache::lonnet::gettitle($feedurl);
1297: if (!$title) { $title = $feedurl; }
1.69 www 1298: my $quote='';
1.78 raeburn 1299: my $subject = '';
1.108 raeburn 1300: my $comment = '';
1.80 raeburn 1301: my $prevtag = '';
1.102 raeburn 1302: my $parentmsg = '';
1.108 raeburn 1303: my ($symb,$idx,$attachmenturls);
1304: my $numoldver = 0;
1305: my $attachmsg = '';
1306: my $newattachmsg = '';
1307: my @currnewattach = ();
1308: my @currdelold = ();
1309: my @keepold = ();
1.113 raeburn 1310: my %attachments = ();
1.108 raeburn 1311: my %currattach = ();
1312: my $attachnum = 0;
1313: my $anonchk = (<<END);
1314: function anonchk() {
1315: if (document.mailform.anondiscuss.checked == true) {
1316: document.attachment.anondiscuss.value = '1'
1317: }
1318: if (document.mailform.discuss.checked == true) {
1319: document.attachment.discuss.value = '1'
1320: }
1321: return
1322: }
1323: END
1324: my $anonscript;
1.157 albertel 1325: if (exists($env{'form.origpage'})) {
1.108 raeburn 1326: $anonscript = (<<END);
1.102 raeburn 1327: function setposttype() {
1.157 albertel 1328: var anondisc = $env{'form.anondiscuss'};
1329: var disc = $env{'form.discuss'};
1.108 raeburn 1330: if (anondisc == 1) {
1331: document.mailform.anondiscuss.checked = true
1332: }
1333: if (disc == 1) {
1334: document.mailform.discuss.checked = true
1335: }
1.102 raeburn 1336: return
1337: }
1338: END
1.108 raeburn 1339: } else {
1340: $anonscript = (<<END);
1341: function setposttype() {
1342: return
1343: }
1344: END
1345: }
1.157 albertel 1346: if (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
1347: if ($env{'form.replydisc'}) {
1348: ($symb,$idx)=split(/\:\:\:/,$env{'form.replydisc'});
1.102 raeburn 1349: } else {
1.157 albertel 1350: ($symb,$idx)=split(/\:\:\:/,$env{'form.editdisc'});
1.102 raeburn 1351: }
1.157 albertel 1352: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
1353: $env{'course.'.$env{'request.course.id'}.'.domain'},
1354: $env{'course.'.$env{'request.course.id'}.'.num'});
1.80 raeburn 1355: unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
1.112 raeburn 1356: if ($contrib{$idx.':history'}) {
1357: if ($contrib{$idx.':history'} =~ /:/) {
1358: my @oldversions = split/:/,$contrib{$idx.':history'};
1359: $numoldver = @oldversions;
1360: } else {
1361: $numoldver = 1;
1362: }
1363: }
1.157 albertel 1364: if ($env{'form.replydisc'}) {
1.102 raeburn 1365: if ($contrib{$idx.':history'}) {
1366: if ($contrib{$idx.':history'} =~ /:/) {
1367: my @oldversions = split/:/,$contrib{$idx.':history'};
1368: $numoldver = @oldversions;
1369: } else {
1370: $numoldver = 1;
1371: }
1372: }
1.108 raeburn 1373: my $message;
1374: if ($idx > 0) {
1.116 raeburn 1375: my %msgversions = ();
1376: &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
1377: $message = $msgversions{$numoldver};
1.108 raeburn 1378: }
1.165 albertel 1379: &newline_to_br(\$message);
1.108 raeburn 1380: $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
1.102 raeburn 1381: if ($idx > 0) {
1.116 raeburn 1382: my %subversions = ();
1383: &get_post_versions(\%subversions,$contrib{$idx.':subject'},1,$numoldver);
1384: $subject = 'Re: '.$subversions{$numoldver};
1.102 raeburn 1385: }
1.108 raeburn 1386: $subject = &HTML::Entities::encode($subject,'<>&"');
1.102 raeburn 1387: } else {
1.108 raeburn 1388: $attachmenturls = $contrib{$idx.':attachmenturl'};
1.116 raeburn 1389: if ($idx > 0) {
1390: my %msgversions = ();
1391: &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
1392: $comment = $msgversions{$numoldver};
1393: my %subversions = ();
1394: &get_post_versions(\%subversions,$contrib{$idx.':subject'},0,$numoldver);
1395: $subject = $subversions{$numoldver};
1.102 raeburn 1396: }
1397: if (defined($contrib{$idx.':replyto'})) {
1398: $parentmsg = $contrib{$idx.':replyto'};
1399: }
1.157 albertel 1400: unless (exists($env{'form.origpage'})) {
1.108 raeburn 1401: my $anonflag = 0;
1402: if ($contrib{$idx.':anonymous'}) {
1403: $anonflag = 1;
1404: }
1405: $anonscript = (<<END);
1.102 raeburn 1406: function setposttype () {
1407: var currtype = $anonflag
1408: if (currtype == 1) {
1409: document.mailform.elements.discuss.checked = false
1410: document.mailform.elements.anondiscuss.checked = true
1411: }
1412: if (currtype == 0) {
1413: document.mailform.elements.anondiscuss.checked = false
1414: document.mailform.elements.discuss.checked = true
1415: }
1416: return
1417: }
1418: END
1.108 raeburn 1419: }
1.79 raeburn 1420: }
1.69 www 1421: }
1.157 albertel 1422: if ($env{'form.previous'}) {
1423: $prevtag = '<input type="hidden" name="previous" value="'.$env{'form.previous'}.'" />';
1.80 raeburn 1424: }
1.69 www 1425: }
1.108 raeburn 1426:
1.157 albertel 1427: if ($env{'form.origpage'}) {
1428: $subject = &Apache::lonnet::unescape($env{'form.subject'});
1429: $comment = &Apache::lonnet::unescape($env{'form.comment'});
1.108 raeburn 1430: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
1431: }
1.85 www 1432: my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
1.86 www 1433: my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
1.74 www 1434: my $send=&mt('Send');
1.152 albertel 1435: my $html=&Apache::lonxml::xmlbegin();
1.102 raeburn 1436: $r->print(<<END);
1.152 albertel 1437: $html
1.1 www 1438: <head>
1439: <title>The LearningOnline Network with CAPA</title>
1.7 albertel 1440: <meta http-equiv="pragma" content="no-cache"></meta>
1.85 www 1441: $htmlheader
1.63 albertel 1442: <script type="text/javascript">
1443: //<!--
1.5 www 1444: function gosubmit() {
1445: var rec=0;
1.12 albertel 1446: if (typeof(document.mailform.elements.author)!="undefined") {
1.5 www 1447: if (document.mailform.elements.author.checked) {
1448: rec=1;
1449: }
1450: }
1.12 albertel 1451: if (typeof(document.mailform.elements.question)!="undefined") {
1.5 www 1452: if (document.mailform.elements.question.checked) {
1453: rec=1;
1454: }
1455: }
1.12 albertel 1456: if (typeof(document.mailform.elements.course)!="undefined") {
1.5 www 1457: if (document.mailform.elements.course.checked) {
1458: rec=1;
1459: }
1460: }
1.12 albertel 1461: if (typeof(document.mailform.elements.policy)!="undefined") {
1.5 www 1462: if (document.mailform.elements.policy.checked) {
1463: rec=1;
1464: }
1465: }
1.12 albertel 1466: if (typeof(document.mailform.elements.discuss)!="undefined") {
1.10 www 1467: if (document.mailform.elements.discuss.checked) {
1468: rec=1;
1469: }
1470: }
1.14 www 1471: if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
1472: if (document.mailform.elements.anondiscuss.checked) {
1473: rec=1;
1474: }
1475: }
1.5 www 1476:
1477: if (rec) {
1.118 albertel 1478: if (typeof(document.mailform.onsubmit)=='function') {
1.105 www 1479: document.mailform.onsubmit();
1480: }
1.5 www 1481: document.mailform.submit();
1482: } else {
1483: alert('Please check a feedback type.');
1484: }
1485: }
1.108 raeburn 1486: $anonchk
1.102 raeburn 1487: $anonscript
1.63 albertel 1488: //-->
1.5 www 1489: </script>
1.1 www 1490: </head>
1.29 www 1491: $bodytag
1.51 albertel 1492: <h2><tt>$title</tt></h2>
1.43 www 1493: <form action="/adm/feedback" method="post" name="mailform"
1494: enctype="multipart/form-data">
1.80 raeburn 1495: $prevtag
1.63 albertel 1496: <input type="hidden" name="postdata" value="$feedurl" />
1.102 raeburn 1497: END
1.157 albertel 1498: if ($env{'form.replydisc'}) {
1.102 raeburn 1499: $r->print(<<END);
1.157 albertel 1500: <input type="hidden" name="replydisc" value="$env{'form.replydisc'}" />
1.102 raeburn 1501: END
1.157 albertel 1502: } elsif ($env{'form.editdisc'}) {
1.102 raeburn 1503: $r->print(<<END);
1.157 albertel 1504: <input type="hidden" name="editdisc" value ="$env{'form.editdisc'}" />
1.102 raeburn 1505: <input type="hidden" name="parentmsg" value ="$parentmsg" />
1506: END
1507: }
1.108 raeburn 1508: $r->print(<<END);
1.5 www 1509: Please check at least one of the following feedback types:
1.63 albertel 1510: $options<hr />
1.69 www 1511: $quote
1.63 albertel 1512: <p>My question/comment/feedback:</p>
1513: <p>
1.47 bowersj2 1514: $latexHelp
1.78 raeburn 1515: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
1516: <p>
1.108 raeburn 1517: <textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">$comment
1.63 albertel 1518: </textarea></p>
1519: <p>
1.108 raeburn 1520: END
1.157 albertel 1521: if ( ($env{'form.editdisc'}) || ($env{'form.replydisc'}) ) {
1522: if ($env{'form.origpage'}) {
1.108 raeburn 1523: foreach (@currnewattach) {
1524: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
1525: }
1526: foreach (@currdelold) {
1527: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
1528: }
1529: }
1.157 albertel 1530: if ($env{'form.editdisc'}) {
1.108 raeburn 1531: if ($attachmenturls) {
1.113 raeburn 1532: &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\%attachments,\%currattach,\@currdelold);
1.108 raeburn 1533: $attachnum = scalar(keys %currattach);
1534: foreach (keys %currattach) {
1535: $r->print('<input type="hidden" name="keepold" value="'.$_.'" />'."\n");
1536: }
1537: }
1538: }
1539: } else {
1540: $r->print(<<END);
1.42 www 1541: Attachment (128 KB max size): <input type="file" name="attachment" />
1542: </p>
1.108 raeburn 1543: END
1544: }
1545: $r->print(<<END);
1.42 www 1546: <p>
1547: <input type="hidden" name="sendit" value="1" />
1.74 www 1548: <input type="button" value="$send" onClick='gosubmit();' />
1.42 www 1549: </p>
1.2 www 1550: </form>
1.108 raeburn 1551: END
1.157 albertel 1552: if ($env{'form.editdisc'} || $env{'form.replydisc'}) {
1.108 raeburn 1553: my $now = time;
1554: my $ressymb = $symb;
1555: my $postidx = '';
1.157 albertel 1556: if ($env{'form.editdisc'}) {
1.108 raeburn 1557: $postidx = $idx;
1558: }
1559: if (@currnewattach > 0) {
1560: $attachnum += @currnewattach;
1561: }
1562: $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver));
1563: if ($attachnum > 0) {
1564: if (@currnewattach > 0) {
1565: $newattachmsg .= '<b>New attachments</b><br />';
1566: if (@currnewattach > 1) {
1567: $newattachmsg .= '<ol>';
1568: foreach my $item (@currnewattach) {
1569: $item =~ m#.*/([^/]+)$#;
1570: $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
1571: }
1572: $newattachmsg .= '</ol>'."\n";
1573: } else {
1574: $currnewattach[0] =~ m#.*/([^/]+)$#;
1575: $newattachmsg .= '<a href="'.$currnewattach[0].'">'.$1.'</a><br />'."\n";
1576: }
1577: }
1578: if ($attachmsg) {
1579: $r->print("<b>Retained attachments</b>:$attachmsg<br />\n");
1580: }
1581: if ($newattachmsg) {
1582: $r->print("$newattachmsg<br />");
1583: }
1584: }
1585: }
1586: $r->print(&generate_preview_button().
1587: &Apache::lonhtmlcommon::htmlareaselectactive('comment').
1588: '</body></html>');
1.6 albertel 1589: }
1590:
1.97 raeburn 1591: sub print_display_options {
1.111 raeburn 1592: my ($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl) = @_;
1.135 albertel 1593: &Apache::loncommon::content_type($r,'text/html');
1594: $r->send_http_header;
1.98 raeburn 1595:
1.97 raeburn 1596: my $function = &Apache::loncommon::get_users_function();
1597: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1.157 albertel 1598: $env{'user.domain'});
1.97 raeburn 1599: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1600: '','');
1601:
1602: my %lt = &Apache::lonlocal::texthash(
1603: 'dido' => 'Discussion display options',
1604: 'pref' => 'Display Preference',
1605: 'curr' => 'Current setting ',
1606: 'actn' => 'Action',
1607: 'deff' => 'Default for all discussions',
1608: 'prca' => 'Preferences can be set for this discussion that determine ....',
1609: 'whpo' => 'Which posts are displayed when you display this bulletin board or resource, and',
1.111 raeburn 1610: 'unwh' => 'Under what circumstances posts are identified as "NEW", and',
1611: 'wipa' => 'Whether individual posts can be marked as read/unread',
1.97 raeburn 1612: 'allposts' => 'All posts',
1613: 'unread' => 'New posts only',
1.111 raeburn 1614: 'unmark' => 'Posts not marked read',
1.97 raeburn 1615: 'ondisp' => 'Once displayed',
1.111 raeburn 1616: 'onmark' => 'Once marked not NEW ',
1617: 'toggon' => 'Shown',
1618: 'toggoff' => 'Not shown',
1.97 raeburn 1619: 'disa' => 'Posts displayed?',
1.111 raeburn 1620: 'npmr' => 'New posts cease to be identified as "NEW"?',
1621: 'dotm' => 'Option to mark each post as read/unread?',
1.97 raeburn 1622: 'chgt' => 'Change to ',
1623: 'mkdf' => 'Set to ',
1.111 raeburn 1624: 'yhni' => 'You have not indicated that you wish to change any of the discussion settings',
1.97 raeburn 1625: 'ywbr' => 'You will be returned to the previous page if you click OK.'
1626: );
1627:
1.111 raeburn 1628: my $dispchangeA = $lt{'unread'};
1629: my $dispchangeB = $lt{'unmark'};
1.97 raeburn 1630: my $markchange = $lt{'ondisp'};
1.111 raeburn 1631: my $toggchange = $lt{'toggon'};
1.97 raeburn 1632: my $currdisp = $lt{'allposts'};
1633: my $currmark = $lt{'onmark'};
1634: my $discdisp = 'allposts';
1635: my $discmark = 'onmark';
1.111 raeburn 1636: my $currtogg = $lt{'toggoff'};
1637: my $disctogg = 'toggoff';
1.97 raeburn 1638:
1.111 raeburn 1639: if ($dispchgA eq 'allposts') {
1640: $dispchangeA = $lt{'allposts'};
1.97 raeburn 1641: $currdisp = $lt{'unread'};
1642: $discdisp = 'unread';
1643: }
1.111 raeburn 1644:
1.97 raeburn 1645: if ($markchg eq 'markonread') {
1646: $markchange = $lt{'onmark'};
1647: $currmark = $lt{'ondisp'};
1648: $discmark = 'ondisp';
1649: }
1.111 raeburn 1650:
1651: if ($dispchgB eq 'onlyunread') {
1652: $dispchangeB = $lt{'unread'};
1653: $currdisp = $lt{'unmark'};
1654: $discdisp = 'unmark';
1655: }
1656: if ($toggchg eq 'toggoff') {
1657: $toggchange = $lt{'toggoff'};
1658: $currtogg = $lt{'toggon'};
1659: $disctogg = 'toggon';
1660: }
1.152 albertel 1661: my $html=&Apache::lonxml::xmlbegin();
1.97 raeburn 1662: $r->print(<<END);
1.152 albertel 1663: $html
1.97 raeburn 1664: <head>
1665: <title>$lt{'dido'}</title>
1666: <meta http-equiv="pragma" content="no-cache" />
1667: <script>
1.111 raeburn 1668: function discdispChk(caller) {
1669: var disctogg = '$toggchg'
1670: if (caller == 0) {
1671: if (document.modifydisp.discdisp[0].checked == true) {
1672: if (document.modifydisp.discdisp[1].checked == true) {
1673: document.modifydisp.discdisp[1].checked = false
1674: }
1675: }
1676: }
1677: if (caller == 1) {
1678: if (document.modifydisp.discdisp[1].checked == true) {
1679: if (document.modifydisp.discdisp[0].checked == true) {
1680: document.modifydisp.discdisp[0].checked = false
1681: }
1682: if (disctogg == 'toggon') {
1683: document.modifydisp.disctogg.checked = true
1684: }
1685: if (disctogg == 'toggoff') {
1686: document.modifydisp.disctogg.checked = false
1687: }
1688: }
1689: }
1690: if (caller == 2) {
1691: var dispchgB = '$dispchgB'
1692: if (disctogg == 'toggoff') {
1693: if (document.modifydisp.disctogg.checked == true) {
1694: if (dispchgB == 'onlyunmark') {
1695: document.modifydisp.discdisp[1].checked = false
1696: }
1697: }
1698: }
1699: }
1700: }
1701:
1.97 raeburn 1702: function setDisp() {
1703: var prev = "$previous"
1704: var chktotal = 0
1.111 raeburn 1705: if (document.modifydisp.discdisp[0].checked == true) {
1706: document.modifydisp.$dispchgA.value = "$symb"
1707: chktotal ++
1708: }
1709: if (document.modifydisp.discdisp[1].checked == true) {
1710: document.modifydisp.$dispchgB.value = "$symb"
1.97 raeburn 1711: chktotal ++
1712: }
1713: if (document.modifydisp.discmark.checked == true) {
1714: document.modifydisp.$markchg.value = "$symb"
1715: chktotal ++
1716: }
1.111 raeburn 1717: if (document.modifydisp.disctogg.checked == true) {
1718: document.modifydisp.$toggchg.value = "$symb"
1719: chktotal ++
1720: }
1.97 raeburn 1721: if (chktotal > 0) {
1722: document.modifydisp.submit()
1723: } else {
1724: if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}")) {
1725: if (prev > 0) {
1726: location.href = "$feedurl?previous=$previous"
1727: } else {
1728: location.href = "$feedurl"
1729: }
1730: }
1731: }
1732: }
1733: </script>
1734: </head>
1735: $bodytag
1736: <form name="modifydisp" method="post" action="/adm/feedback">
1.111 raeburn 1737: $lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li><li>$lt{'wipa'}</li></ol>
1.97 raeburn 1738: <br />
1739: <table border="0" cellpadding="0" cellspacing="0">
1740: <tr>
1741: <td width="100%" bgcolor="#000000">
1742: <table width="100%" border="0" cellpadding="1" cellspacing="0">
1743: <tr>
1744: <td width="100%" bgcolor="#000000">
1745: <table border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
1746: <tr bgcolor="$tabcolor">
1747: <td><b>$lt{'pref'}</b></td>
1748: <td><b>$lt{'curr'}</b></td>
1749: <td><b>$lt{'actn'}?</b></td>
1750: </tr>
1751: <tr bgcolor="#dddddd">
1752: <td>$lt{'disa'}</td>
1753: <td>$lt{$discdisp}</td>
1.151 albertel 1754: <td><label><input type="checkbox" name="discdisp" onClick="discdispChk('0')" /> $lt{'chgt'} "$dispchangeA"</label>
1.111 raeburn 1755: <br />
1.151 albertel 1756: <label><input type="checkbox" name="discdisp" onClick="discdispChk('1')" /> $lt{'chgt'} "$dispchangeB"</label>
1.111 raeburn 1757: </td>
1.97 raeburn 1758: </tr><tr bgcolor="#eeeeee">
1759: <td>$lt{'npmr'}</td>
1760: <td>$lt{$discmark}</td>
1.151 albertel 1761: <td><label><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</label></td>
1.111 raeburn 1762: </tr><tr bgcolor="#dddddd">
1763: <td>$lt{'dotm'}</td>
1764: <td>$lt{$disctogg}</td>
1.151 albertel 1765: <td><label><input type="checkbox" name="disctogg" onClick="discdispChk('2')" />$lt{'chgt'} "$toggchange"</label></td>
1.97 raeburn 1766: </tr>
1767: </table>
1768: </td>
1769: </tr>
1770: </table>
1771: </td>
1772: </tr>
1773: </table>
1774: <br />
1775: <br />
1.137 albertel 1776: <input type="hidden" name="symb" value="$symb" />
1.97 raeburn 1777: <input type="hidden" name="previous" value="$previous" />
1.111 raeburn 1778: <input type="hidden" name="$dispchgA" value=""/>
1779: <input type="hidden" name="$dispchgB" value=""/>
1.97 raeburn 1780: <input type="hidden" name="$markchg" value=""/>
1.111 raeburn 1781: <input type="hidden" name="$toggchg" value="" />
1.97 raeburn 1782: <input type="button" name="sub" value="Store Changes" onClick="javascript:setDisp()" />
1783: <br />
1784: <br />
1785: </form>
1786: </body>
1787: </html>
1788: END
1789: return;
1790: }
1791:
1.100 raeburn 1792: sub print_sortfilter_options {
1793: my ($r,$symb,$previous,$feedurl) = @_;
1.133 albertel 1794:
1.135 albertel 1795: &Apache::loncommon::content_type($r,'text/html');
1796: $r->send_http_header;
1797:
1.139 albertel 1798: &Apache::lonenc::check_encrypt(\$symb);
1.100 raeburn 1799: my @sections = ();
1800: my $section_sel = '';
1801: my $numsections = 0;
1802: my $numvisible = 5;
1803: my %sectioncount = ();
1.144 raeburn 1804:
1.157 albertel 1805: $numsections = &Apache::loncommon::get_sections($env{'course.'.$env{'request.course.id'}.'.domain'},$env{'course.'.$env{'request.course.id'}.'.num'},\%sectioncount);
1.144 raeburn 1806:
1.157 albertel 1807: if ($env{'request.course.sec'} !~ /^\s*$/) { #Restrict section choice to current section
1808: @sections = ('all',$env{'request.course.sec'});
1.144 raeburn 1809: $numvisible = 2;
1.100 raeburn 1810: } else {
1811: @sections = sort {$a cmp $b} keys(%sectioncount);
1812: unshift(@sections,'all'); # Put 'all' at the front of the list
1813: if ($numsections < 4) {
1814: $numvisible = $numsections + 1;
1815: }
1816: }
1817: foreach (@sections) {
1818: $section_sel .= " <option value=\"$_\" />$_\n";
1819: }
1820:
1821: my $function = &Apache::loncommon::get_users_function();
1822: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1.157 albertel 1823: $env{'user.domain'});
1.100 raeburn 1824: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1825: '','');
1826: my %lt = &Apache::lonlocal::texthash(
1827: 'diso' => 'Discussion sorting and filtering options',
1828: 'diop' => 'Display Options',
1829: 'curr' => 'Current setting ',
1830: 'actn' => 'Action',
1.143 raeburn 1831: 'prca' => 'Set options that control the sort order of posts, and/or which posts are displayed.',
1.100 raeburn 1832: 'soor' => 'Sort order',
1.143 raeburn 1833: 'spur' => 'Specific user roles',
1834: 'sprs' => 'Specific role status',
1.100 raeburn 1835: 'spse' => 'Specific sections',
1836: 'psub' => 'Pick specific users (by name)',
1.101 raeburn 1837: 'shal' => 'Show a list of current posters'
1.100 raeburn 1838: );
1.143 raeburn 1839:
1840: my %sort_types = ();
1841: my %role_types = ();
1842: my %status_types = ();
1843: &sort_filter_names(\%sort_types,\%role_types,\%status_types);
1.152 albertel 1844: my $html=&Apache::lonxml::xmlbegin();
1.100 raeburn 1845: $r->print(<<END);
1.152 albertel 1846: $html
1.100 raeburn 1847: <head>
1848: <title>$lt{'diso'}</title>
1849: <meta http-equiv="pragma" content="no-cache" />
1.144 raeburn 1850: <script type="text/javascript">
1851: function verifyFilter() {
1852: var rolenum = 0
1853: for (var i=0; i<document.modifyshown.rolefilter.length; i++) {
1854: if (document.modifyshown.rolefilter.options[i].selected == true) {
1855: rolenum ++
1856: }
1857: }
1858: if (rolenum == 0) {
1859: document.modifyshown.rolefilter.options[0].selected = true
1860: }
1861:
1862: var secnum = 0
1863: for (var i=0; i<document.modifyshown.sectionpick.length; i++) {
1864: if (document.modifyshown.sectionpick.options[i].selected == true) {
1865: secnum ++
1866: }
1867: }
1868: if (secnum == 0) {
1869: document.modifyshown.sectionpick.options[0].selected = true
1870: }
1871: document.modifyshown.submit();
1872: }
1873: </script>
1.100 raeburn 1874: </head>
1875: $bodytag
1876: <form name="modifyshown" method="post" action="/adm/feedback">
1877: <b>$lt{'diso'}</b><br/> $lt{'prca'}
1878: <br /><br />
1879: <table border="0">
1880: <tr>
1881: <td><b>$lt{'soor'}</b></td>
1882: <td> </td>
1.143 raeburn 1883: <td><b>$lt{'sprs'}</b></td>
1.100 raeburn 1884: <td> </td>
1.143 raeburn 1885: <td><b>$lt{'spur'}</b></td>
1.100 raeburn 1886: <td> </td>
1887: <td><b>$lt{'spse'}</b></td>
1888: <td> </td>
1889: <td><b>$lt{'psub'}</b></td>
1890: </tr>
1891: <tr>
1.143 raeburn 1892: <td align="center">
1.100 raeburn 1893: <select name="sortposts">
1.144 raeburn 1894: <option value="ascdate" selected="selected" />$sort_types{'ascdate'}
1.143 raeburn 1895: <option value="descdate" />$sort_types{'descdate'}
1896: <option value="thread" />$sort_types{'thread'}
1897: <option value="subject" />$sort_types{'subject'}
1898: <option value="username" />$sort_types{'username'}
1899: <option value="lastfirst" />$sort_types{'lastfirst'}
1.100 raeburn 1900: </select>
1901: </td>
1902: <td> </td>
1.143 raeburn 1903: <td align="center">
1904: <select name="statusfilter">
1.144 raeburn 1905: <option value="all" selected="selected" />$status_types{'all'}
1.143 raeburn 1906: <option value="Active" />$status_types{'Active'}
1907: <option value="Expired" />$status_types{'Expired'}
1.100 raeburn 1908: </select>
1909: </td>
1910: <td> </td>
1.143 raeburn 1911: <td align="center">
1912: <select name="rolefilter" multiple="true" size="5">
1913: <option value="all" />$role_types{'all'}
1914: <option value="st" />$role_types{'st'}
1915: <option value="cc" />$role_types{'cc'}
1916: <option value="in" />$role_types{'in'}
1917: <option value="ta" />$role_types{'ta'}
1918: <option value="ep" />$role_types{'ep'}
1919: <option value="ad" />$role_types{'ad'}
1920: <option value="cr" />$role_types{'cr'}
1.100 raeburn 1921: </select>
1922: </td>
1923: <td> </td>
1.143 raeburn 1924: <td align="center">
1.100 raeburn 1925: <select name="sectionpick" multiple="true" size="$numvisible">
1926: $section_sel
1927: </select>
1928: </td>
1929: <td> </td>
1.151 albertel 1930: <td><label><input type="checkbox" name="posterlist" value="$symb" />$lt{'shal'}</label></td>
1.100 raeburn 1931: </tr>
1932: </table>
1933: <br />
1934: <br />
1935: <input type="hidden" name="previous" value="$previous" />
1936: <input type="hidden" name="applysort" value="$symb" />
1.144 raeburn 1937: <input type="button" name="sub" value="Store Changes" onClick="verifyFilter()" />
1.100 raeburn 1938: <br />
1939: <br />
1940: </form>
1941: </body>
1942: </html>
1943: END
1944: }
1945:
1.101 raeburn 1946: sub print_showposters {
1947: my ($r,$symb,$previous,$feedurl,$sortposts) = @_;
1.133 albertel 1948:
1.154 albertel 1949: &Apache::loncommon::content_type($r,'text/html');
1950: $r->send_http_header;
1951:
1.139 albertel 1952: &Apache::lonenc::check_encrypt(\$symb);
1.157 albertel 1953: my $crs='/'.$env{'request.course.id'};
1954: if ($env{'request.course.sec'}) {
1955: $crs.='_'.$env{'request.course.sec'};
1.102 raeburn 1956: }
1.101 raeburn 1957: $crs=~s/\_/\//g;
1958: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.157 albertel 1959: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
1960: $env{'course.'.$env{'request.course.id'}.'.domain'},
1961: $env{'course.'.$env{'request.course.id'}.'.num'});
1.101 raeburn 1962: my %namesort = ();
1963: my %postcounts = ();
1964: my %lt=&Apache::lonlocal::texthash(
1965: 'diso' => 'Discussion filtering options',
1966: );
1967: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1968: '','');
1969: if ($contrib{'version'}) {
1970: for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
1971: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
1972: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
1973: unless ((($hidden) && (!$seeid)) || ($deleted)) {
1974: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
1975: my %names = &Apache::lonnet::get('environment',['firstname','lastname'],$contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
1976: my $lastname = $names{'lastname'};
1977: my $firstname = $names{'firstname'};
1978: if ($lastname eq '') {
1979: $lastname = '_';
1980: }
1981: if ($firstname eq '') {
1982: $firstname = '_';
1983: }
1984: unless (defined($namesort{$lastname})) {
1985: %{$namesort{$lastname}} = ();
1986: }
1987: my $poster = $contrib{$idx.':sendername'}.':'.$contrib{$idx.':senderdomain'};
1988: $postcounts{$poster} ++;
1989: if (defined($namesort{$lastname}{$firstname})) {
1990: if (!grep/^$poster$/,@{$namesort{$lastname}{$firstname}}) {
1991: push @{$namesort{$lastname}{$firstname}}, $poster;
1992: }
1993: } else {
1994: @{$namesort{$lastname}{$firstname}} = ("$poster");
1995: }
1996: }
1997: }
1998: }
1999: }
1.152 albertel 2000: my $html=&Apache::lonxml::xmlbegin();
1.101 raeburn 2001: $r->print(<<END);
1.152 albertel 2002: $html
1.101 raeburn 2003: <head>
2004: <title>$lt{'diso'}</title>
2005: <meta http-equiv="pragma" content="no-cache" />
2006: </head>
2007: $bodytag
2008: <form name="pickpostersform" method="post">
2009: <table border="0">
2010: <tr>
2011: <td bgcolor="#777777">
2012: <table border="0" cellpadding="3">
2013: <tr bgcolor="#e6ffff">
2014: <td><b>No.</b></td>
2015: <td><b>Select</b></td>
2016: <td><b>Fullname</b><font color="#999999">(Username/domain)</font></td>
2017: <td><b>Posts</td>
2018: </tr>
2019: END
2020: my $count = 0;
2021: foreach my $last (sort keys %namesort) {
2022: foreach my $first (sort keys %{$namesort{$last}}) {
2023: foreach (sort @{$namesort{$last}{$first}}) {
2024: my ($uname,$udom) = split/:/,$_;
2025: if (!$uname || !$udom) {
2026: next;
2027: } else {
2028: $count ++;
1.151 albertel 2029: $r->print('<tr bgcolor="#ffffe6"><td align="right">'.$count.'</td><td align="center"><label><input name="stuinfo" type="checkbox" value="'.$_.'" /></td><td>'.$last.', '.$first.' ('.$uname.','.$udom.')</label></td><td>'.$postcounts{$_}.'</td></tr>');
1.101 raeburn 2030: }
2031: }
2032: }
2033: }
2034: $r->print(<<END);
2035: </table>
2036: </td>
2037: </tr>
2038: </table>
2039: <br />
2040: <input type="hidden" name="sortposts" value="$sortposts" />
2041: <input type="hidden" name="userpick" value="$symb" />
2042: <input type="button" name="store" value="Display posts" onClick="javascript:document.pickpostersform.submit()" />
2043: </form>
2044: </body>
2045: </html>
2046: END
2047: }
2048:
1.112 raeburn 2049: sub get_post_versions {
1.116 raeburn 2050: my ($versions,$incoming,$htmldecode,$numver) = @_;
2051: if ($incoming =~ /^<version num="0">/) {
2052: my $p = HTML::LCParser->new(\$incoming);
2053: my $done = 0;
2054: while ( (my $token = $p->get_tag("version")) && (!$done)) {
2055: my $num = $token->[1]{num};
2056: my $text = $p->get_text("/version");
2057: if (defined($numver)) {
2058: if ($num == $numver) {
2059: if ($htmldecode) {
2060: $text = &HTML::Entities::decode($text);
2061: }
2062: $$versions{$numver}=$text;
2063: $done = 1;
2064: }
2065: } else {
2066: if ($htmldecode) {
2067: $text = &HTML::Entities::decode($text);
2068: }
2069: $$versions{$num}=$text;
1.112 raeburn 2070: }
1.116 raeburn 2071: }
2072: } else {
2073: if (!defined($numver)) {
2074: $numver = 0;
2075: }
2076: if ($htmldecode) {
2077: $$versions{$numver} = $incoming;
1.112 raeburn 2078: } else {
1.116 raeburn 2079: $$versions{$numver} = &HTML::Entities::encode($incoming,'<>&"');
1.112 raeburn 2080: }
2081: }
2082: return;
2083: }
2084:
1.113 raeburn 2085: sub get_post_attachments {
2086: my ($attachments,$attachmenturls) = @_;
2087: my $num;
1.116 raeburn 2088: if ($attachmenturls =~ m/^<attachment id="0">/) {
2089: my $p = HTML::LCParser->new(\$attachmenturls);
2090: while (my $token = $p->get_tag("attachment","filename","post")) {
2091: if ($token->[0] eq "attachment") {
2092: $num = $token->[1]{id};
2093: %{$$attachments{$num}} =();
2094: } elsif ($token->[0] eq "filename") {
2095: $$attachments{$num}{'filename'} = $p->get_text("/filename");
2096: } elsif ($token->[0] eq "post") {
2097: my $id = $token->[1]{id};
2098: $$attachments{$num}{$id} = $p->get_text("/post");
2099: }
1.113 raeburn 2100: }
1.116 raeburn 2101: } else {
2102: %{$$attachments{'0'}} = ();
2103: $$attachments{'0'}{'filename'} = $attachmenturls;
2104: $$attachments{'0'}{'0'} = 'n';
1.113 raeburn 2105: }
1.116 raeburn 2106:
1.113 raeburn 2107: return;
2108: }
2109:
1.150 albertel 2110: sub fail_redirect {
1.6 albertel 2111: my ($r,$feedurl) = @_;
1.70 www 2112: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.150 albertel 2113: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.152 albertel 2114: my $html=&Apache::lonxml::xmlbegin();
1.6 albertel 2115: $r->print (<<ENDFAILREDIR);
1.152 albertel 2116: $html
2117: <head>
2118: <title>Feedback not sent</title>
1.63 albertel 2119: <meta http-equiv="pragma" content="no-cache" />
2120: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.5 www 2121: </head>
2122: <body bgcolor="#FFFFFF">
1.150 albertel 2123: <img align="right" src="$logo" />
1.8 www 2124: <b>Sorry, no recipients ...</b>
1.121 albertel 2125: <br /><a href="$feedurl">Continue</a>
1.5 www 2126: </body>
2127: </html>
2128: ENDFAILREDIR
2129: }
1.4 www 2130:
1.6 albertel 2131: sub redirect_back {
1.143 raeburn 2132: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$numpicks) = @_;
1.100 raeburn 2133: my $sorttag = '';
1.101 raeburn 2134: my $roletag = '';
2135: my $statustag = '';
2136: my $sectag = '';
2137: my $userpicktag = '';
2138: my $qrystr = '';
1.80 raeburn 2139: my $prevtag = '';
1.133 albertel 2140:
1.135 albertel 2141: &Apache::loncommon::content_type($r,'text/html');
2142: $r->send_http_header;
2143:
1.133 albertel 2144: &dewrapper(\$feedurl);
1.70 www 2145: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.80 raeburn 2146: if ($previous > 0) {
2147: $qrystr = 'previous='.$previous;
2148: if ($feedurl =~ /\?register=1/) {
2149: $feedurl .= '&'.$qrystr;
2150: } else {
2151: $feedurl .= '?'.$qrystr;
2152: }
2153: $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
2154: }
1.100 raeburn 2155: if (defined($sort)) {
2156: my $sortqry = 'sortposts='.$sort;
2157: if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) {
2158: $feedurl .= '&'.$sortqry;
2159: } else {
2160: $feedurl .= '?'.$sortqry;
2161: }
2162: $sorttag = '<input type="hidden" name="sortposts" value="'.$sort.'" />';
1.143 raeburn 2163: if (defined($numpicks)) {
1.101 raeburn 2164: my $userpickqry = 'totposters='.$numpicks;
2165: $feedurl .= '&'.$userpickqry;
2166: $userpicktag = '<input type="hidden" name="totposters" value="'.$numpicks.'" />';
2167: } else {
1.143 raeburn 2168: if (ref($sectionpick) eq 'ARRAY') {
2169: $feedurl .= '§ionpick=';
2170: $sectag .= '<input type="hidden" name="sectionpick" value="';
2171: foreach (@{$sectionpick}) {
2172: $feedurl .= $_.',';
2173: $sectag .= $_.',';
2174: }
2175: $feedurl =~ s/,$//;
2176: $sectag =~ s/,$//;
2177: $sectag .= '" />';
2178: } else {
2179: $feedurl .= '§ionpick='.$sectionpick;
2180: $sectag = '<input type="hidden" name="sectionpick" value="'.$sectionpick.'" />';
2181: }
2182: if (ref($rolefilter) eq 'ARRAY') {
2183: $feedurl .= '&rolefilter=';
2184: $roletag .= '<input type="hidden" name="rolefilter" value="';
2185: foreach (@{$rolefilter}) {
2186: $feedurl .= $_.',';
2187: $roletag .= $_.',';
2188: }
2189: $feedurl =~ s/,$//;
2190: $roletag =~ s/,$//;
2191: $roletag .= '" />';
2192: } else {
2193: $feedurl .= '&rolefilter='.$rolefilter;
2194: $roletag = '<input type="hidden" name="rolefilter" value="'.$rolefilter.'" />';
2195: }
1.101 raeburn 2196: $feedurl .= '&statusfilter='.$statusfilter;
2197: $statustag ='<input type="hidden" name="statusfilter" value="'.$statusfilter.'" />';
2198: }
1.100 raeburn 2199: }
1.129 albertel 2200: $feedurl=&Apache::lonenc::check_encrypt($feedurl);
1.150 albertel 2201: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.152 albertel 2202: my $html=&Apache::lonxml::xmlbegin();
1.6 albertel 2203: $r->print (<<ENDREDIR);
1.152 albertel 2204: $html
1.3 www 2205: <head>
2206: <title>Feedback sent</title>
1.63 albertel 2207: <meta http-equiv="pragma" content="no-cache" />
1.80 raeburn 2208: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.2 www 2209: </head>
1.49 www 2210: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1.150 albertel 2211: <img align="right" src="$logo" />
1.5 www 2212: $typestyle
1.32 albertel 2213: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1.63 albertel 2214: <font color="red">$status</font>
1.49 www 2215: <form name="reldt" action="$feedurl" target="loncapaclient">
1.80 raeburn 2216: $prevtag
1.100 raeburn 2217: $sorttag
1.101 raeburn 2218: $statustag
2219: $roletag
2220: $sectag
2221: $userpicktag
1.49 www 2222: </form>
1.121 albertel 2223: <br /><a href="$feedurl">Continue</a>
1.2 www 2224: </body>
2225: </html>
2226: ENDREDIR
2227: }
1.6 albertel 2228:
2229: sub no_redirect_back {
2230: my ($r,$feedurl) = @_;
1.107 www 2231: my $nofeed=&mt('Sorry, no feedback possible on this resource ...');
1.120 albertel 2232: my $continue=&mt('Continue');
1.152 albertel 2233: my $html=&Apache::lonxml::xmlbegin();
1.6 albertel 2234: $r->print (<<ENDNOREDIR);
1.152 albertel 2235: $html
2236: <head>
2237: <title>Feedback not sent</title>
1.63 albertel 2238: <meta http-equiv="pragma" content="no-cache" />
1.7 albertel 2239: ENDNOREDIR
2240:
1.8 www 2241: if ($feedurl!~/^\/adm\/feedback/) {
1.129 albertel 2242: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.
2243: &Apache::lonenc::check_encrypt($feedurl).'">');
1.7 albertel 2244: }
1.129 albertel 2245: $feedurl=&Apache::lonenc::check_encrypt($feedurl);
1.150 albertel 2246: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.8 www 2247: $r->print (<<ENDNOREDIRTWO);
1.2 www 2248: </head>
1.49 www 2249: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
1.150 albertel 2250: <img align="right" src="$logo" />
1.107 www 2251: <b>$nofeed</b>
1.121 albertel 2252: <br /><a href="$feedurl">$continue</a>
1.2 www 2253: </body>
2254: </html>
1.8 www 2255: ENDNOREDIRTWO
1.2 www 2256: }
1.6 albertel 2257:
2258: sub screen_header {
1.141 raeburn 2259: my ($feedurl,$symb) = @_;
1.65 www 2260: my $msgoptions='';
2261: my $discussoptions='';
1.157 albertel 2262: unless (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
1.167 www 2263: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) {
1.65 www 2264: $msgoptions=
1.151 albertel 2265: '<p><label><input type="checkbox" name="author" /> '.
2266: &mt('Feedback to resource author').'</label></p>';
1.65 www 2267: }
2268: if (&feedback_available(1)) {
2269: $msgoptions.=
1.151 albertel 2270: '<p><label><input type="checkbox" name="question" /> '.
2271: &mt('Question about resource content').'</label></p>';
1.65 www 2272: }
2273: if (&feedback_available(0,1)) {
2274: $msgoptions.=
1.151 albertel 2275: '<p><label><input type="checkbox" name="course" /> '.
2276: &mt('Question/Comment/Feedback about course content').
2277: '</label></p>';
1.65 www 2278: }
2279: if (&feedback_available(0,0,1)) {
2280: $msgoptions.=
1.151 albertel 2281: '<p><label><input type="checkbox" name="policy" /> '.
2282: &mt('Question/Comment/Feedback about course policy').
2283: '</label></p>';
1.65 www 2284: }
2285: }
1.157 albertel 2286: if ($env{'request.course.id'}) {
1.141 raeburn 2287: if (&discussion_open(undef,$symb) &&
1.90 albertel 2288: &Apache::lonnet::allowed('pch',
1.157 albertel 2289: $env{'request.course.id'}.
2290: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
1.151 albertel 2291: $discussoptions='<label><input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
1.157 albertel 2292: ($env{'form.replydisc'}?' checked="1"':'').' /> '.
1.65 www 2293: &mt('Contribution to course discussion of resource');
1.151 albertel 2294: $discussoptions.='</label><br /><label><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
1.65 www 2295: &mt('Anonymous contribution to course discussion of resource').
1.151 albertel 2296: ' <i>('.&mt('name only visible to course faculty').')</i></label>';
1.141 raeburn 2297: }
1.65 www 2298: }
1.149 albertel 2299: if ($msgoptions) { $msgoptions='<h2><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/feedback.gif').'" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
1.65 www 2300: if ($discussoptions) {
1.149 albertel 2301: $discussoptions='<h2><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/chat.gif').'" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
1.65 www 2302: return $msgoptions.$discussoptions;
1.6 albertel 2303: }
2304:
2305: sub resource_output {
2306: my ($feedurl) = @_;
1.46 albertel 2307: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
1.6 albertel 2308: $usersaw=~s/\<body[^\>]*\>//gi;
2309: $usersaw=~s/\<\/body\>//gi;
2310: $usersaw=~s/\<html\>//gi;
2311: $usersaw=~s/\<\/html\>//gi;
2312: $usersaw=~s/\<head\>//gi;
2313: $usersaw=~s/\<\/head\>//gi;
2314: $usersaw=~s/action\s*\=/would_be_action\=/gi;
2315: return $usersaw;
2316: }
2317:
2318: sub clear_out_html {
1.39 www 2319: my ($message,$override)=@_;
1.88 www 2320: unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
1.107 www 2321: # Always allow the <m>-tag
2322: my %html=(M=>1);
2323: # Check if more is allowed
1.157 albertel 2324: my $cid=$env{'request.course.id'};
2325: if (($env{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
1.39 www 2326: ($override)) {
1.37 albertel 2327: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
1.88 www 2328: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
2329: # <SUP>
1.107 www 2330: %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
2331: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
1.155 albertel 2332: M=>1, ALGEBRA=>1, SUB=>1, SUP=>1, SPAN=>1,
1.107 www 2333: H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
2334: }
2335: # Do the substitution of everything that is not explicitly allowed
2336: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
1.48 albertel 2337: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
1.107 www 2338: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
1.48 albertel 2339: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
1.6 albertel 2340: return $message;
2341: }
2342:
2343: sub assemble_email {
1.40 albertel 2344: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1.6 albertel 2345: my $email=<<"ENDEMAIL";
2346: $message
2347: ENDEMAIL
2348: my $citations=<<"ENDCITE";
2349: <h2>Previous attempts of student (if applicable)</h2>
2350: $prevattempts
1.63 albertel 2351: <br /><hr />
1.6 albertel 2352: <h2>Original screen output (if applicable)</h2>
2353: $usersaw
1.40 albertel 2354: <h2>Correct Answer(s) (if applicable)</h2>
2355: $useranswer
1.6 albertel 2356: ENDCITE
2357: return ($email,$citations);
2358: }
2359:
1.35 www 2360: sub secapply {
2361: my $rec=shift;
1.36 www 2362: my $defaultflag=shift;
2363: $rec=~s/\s+//g;
2364: $rec=~s/\@/\:/g;
2365: my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
2366: if ($sections) {
2367: foreach (split(/\;/,$sections)) {
1.157 albertel 2368: if (($_ eq $env{'request.course.sec'}) ||
1.36 www 2369: ($defaultflag && ($_ eq '*'))) {
2370: return $adr;
2371: }
2372: }
2373: } else {
2374: return $rec;
2375: }
2376: return '';
1.35 www 2377: }
2378:
1.163 albertel 2379: =pod
2380:
2381: =over 4
2382:
2383: =item *
2384:
2385: decide_receiver($feedurl,$author,$question,$course,$policy,$defaultflag);
2386:
2387: Arguments
2388: $feedurl - /res/ url of resource (only need if $author is true)
2389: $author,$question,$course,$policy - all true/false parameters
2390: if true will attempt to find the addresses of user that should receive
2391: this type of feedback (author - feedback to author of resource $feedurl,
2392: $question 'Resource Content Questions', $course 'Course Content Question',
2393: $policy 'Course Policy')
2394: (Additionally it also checks $env for whether the corresponding form.<name>
2395: element exists, for ease of use in a html response context)
2396:
2397: $defaultflag - (internal should be left blank) if true gather addresses
2398: that aren't for a section even if I have a section
2399: (used for reccursion internally, first we look for
2400: addresses for our specific section then we recurse
2401: and look for non section addresses)
2402:
2403: Returns
2404: $typestyle - string of html text, describing what addresses were found
2405: %to - a hash, which keys are addresses of users to send messages to
2406: the keys will look like name:domain
2407:
2408: =cut
2409:
1.6 albertel 2410: sub decide_receiver {
1.36 www 2411: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1.6 albertel 2412: my $typestyle='';
2413: my %to=();
1.157 albertel 2414: if ($env{'form.author'}||$author) {
1.163 albertel 2415: $typestyle.='Submitting as Author Feedback<br />';
1.6 albertel 2416: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
2417: $to{$2.':'.$1}=1;
2418: }
1.157 albertel 2419: if ($env{'form.question'}||$question) {
1.163 albertel 2420: $typestyle.='Submitting as Question<br />';
1.24 harris41 2421: foreach (split(/\,/,
1.157 albertel 2422: $env{'course.'.$env{'request.course.id'}.'.question.email'})
1.24 harris41 2423: ) {
1.36 www 2424: my $rec=&secapply($_,$defaultflag);
2425: if ($rec) { $to{$rec}=1; }
1.24 harris41 2426: }
1.6 albertel 2427: }
1.157 albertel 2428: if ($env{'form.course'}||$course) {
1.63 albertel 2429: $typestyle.='Submitting as Comment<br />';
1.24 harris41 2430: foreach (split(/\,/,
1.157 albertel 2431: $env{'course.'.$env{'request.course.id'}.'.comment.email'})
1.24 harris41 2432: ) {
1.36 www 2433: my $rec=&secapply($_,$defaultflag);
2434: if ($rec) { $to{$rec}=1; }
1.24 harris41 2435: }
1.6 albertel 2436: }
1.157 albertel 2437: if ($env{'form.policy'}||$policy) {
1.63 albertel 2438: $typestyle.='Submitting as Policy Feedback<br />';
1.24 harris41 2439: foreach (split(/\,/,
1.157 albertel 2440: $env{'course.'.$env{'request.course.id'}.'.policy.email'})
1.24 harris41 2441: ) {
1.36 www 2442: my $rec=&secapply($_,$defaultflag);
2443: if ($rec) { $to{$rec}=1; }
1.24 harris41 2444: }
1.6 albertel 2445: }
1.36 www 2446: if ((scalar(%to) eq '0') && (!$defaultflag)) {
2447: ($typestyle,%to)=
2448: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
2449: }
1.6 albertel 2450: return ($typestyle,%to);
1.36 www 2451: }
2452:
2453: sub feedback_available {
2454: my ($question,$course,$policy)=@_;
2455: my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
2456: return scalar(%to);
1.6 albertel 2457: }
2458:
2459: sub send_msg {
1.43 www 2460: my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1.6 albertel 2461: my $status='';
2462: my $sendsomething=0;
1.24 harris41 2463: foreach (keys %to) {
1.6 albertel 2464: if ($_) {
1.22 www 2465: my $declutter=&Apache::lonnet::declutter($feedurl);
1.8 www 2466: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.43 www 2467: 'Feedback ['.$declutter.']',$email,$citations,$feedurl,
2468: $attachmenturl)=~/ok/) {
1.63 albertel 2469: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1.6 albertel 2470: } else {
2471: $sendsomething++;
2472: }
2473: }
1.24 harris41 2474: }
1.18 www 2475:
2476: my %record=&Apache::lonnet::restore('_feedback');
2477: my ($temp)=keys %record;
2478: unless ($temp=~/^error\:/) {
2479: my %newrecord=();
2480: $newrecord{'resource'}=$feedurl;
2481: $newrecord{'subnumber'}=$record{'subnumber'}+1;
2482: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1.63 albertel 2483: $status.='<br />'.&mt('Not registered').'<br />';
1.18 www 2484: }
2485: }
2486:
1.6 albertel 2487: return ($status,$sendsomething);
2488: }
2489:
1.13 www 2490: sub adddiscuss {
1.78 raeburn 2491: my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1.13 www 2492: my $status='';
1.122 raeburn 2493: my $realsymb;
2494: if ($symb=~/^bulletin___/) {
2495: my $filename=(&Apache::lonnet::decode_symb($symb))[2];
2496: $filename=~s|^adm/wrapper/||;
2497: $realsymb=&Apache::lonnet::symbread($filename);
2498: }
2499: if (&discussion_open(undef,$realsymb) &&
1.157 albertel 2500: &Apache::lonnet::allowed('pch',$env{'request.course.id'}.
2501: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
1.20 www 2502:
1.13 www 2503: my %contrib=('message' => $email,
1.157 albertel 2504: 'sendername' => $env{'user.name'},
2505: 'senderdomain' => $env{'user.domain'},
2506: 'screenname' => $env{'environment.screenname'},
2507: 'plainname' => $env{'environment.firstname'}.' '.
2508: $env{'environment.middlename'}.' '.
2509: $env{'environment.lastname'}.' '.
2510: $env{'enrironment.generation'},
1.78 raeburn 2511: 'attachmenturl'=> $attachmenturl,
2512: 'subject' => $subject);
1.157 albertel 2513: if ($env{'form.replydisc'}) {
2514: $contrib{'replyto'}=(split(/\:\:\:/,$env{'form.replydisc'}))[1];
1.65 www 2515: }
1.14 www 2516: if ($anon) {
2517: $contrib{'anonymous'}='true';
2518: }
1.13 www 2519: if (($symb) && ($email)) {
1.157 albertel 2520: if ($env{'form.editdisc'}) {
1.102 raeburn 2521: my %newcontrib = ();
2522: $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
2523: $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
2524: $contrib{'timestamp'} = time;
2525: $contrib{'history'} = '';
2526: my $numoldver = 0;
1.157 albertel 2527: my ($oldsymb,$oldidx)=split(/\:\:\:/,$env{'form.editdisc'});
1.132 albertel 2528: &Apache::lonenc::check_decrypt(\$oldsymb);
1.110 raeburn 2529: $oldsymb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.102 raeburn 2530: # get timestamp for last post and history
1.157 albertel 2531: my %oldcontrib=&Apache::lonnet::restore($oldsymb,$env{'request.course.id'},
2532: $env{'course.'.$env{'request.course.id'}.'.domain'},
2533: $env{'course.'.$env{'request.course.id'}.'.num'});
1.102 raeburn 2534: if (defined($oldcontrib{$oldidx.':replyto'})) {
2535: $contrib{'replyto'} = $oldcontrib{$oldidx.':replyto'};
2536: }
2537: if (defined($oldcontrib{$oldidx.':history'})) {
2538: if ($oldcontrib{$oldidx.':history'} =~ /:/) {
2539: my @oldversions = split/:/,$oldcontrib{$oldidx.':history'};
2540: $numoldver = @oldversions;
2541: } else {
2542: $numoldver = 1;
2543: }
2544: $contrib{'history'} = $oldcontrib{$oldidx.':history'}.':';
2545: }
1.108 raeburn 2546: my $numnewver = $numoldver + 1;
1.102 raeburn 2547: if (defined($oldcontrib{$oldidx.':subject'})) {
1.112 raeburn 2548: if ($oldcontrib{$oldidx.':subject'} =~ /^<version num="0">/) {
2549: $contrib{'subject'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
2550: $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.$contrib{'subject'};
1.108 raeburn 2551: } else {
1.112 raeburn 2552: $contrib{'subject'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':subject'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
1.108 raeburn 2553: }
1.102 raeburn 2554: }
2555: if (defined($oldcontrib{$oldidx.':message'})) {
1.112 raeburn 2556: if ($oldcontrib{$oldidx.':message'} =~ /^<version num="0">/) {
2557: $contrib{'message'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
2558: $contrib{'message'} = $oldcontrib{$oldidx.':message'}.$contrib{'message'};
1.108 raeburn 2559: } else {
1.112 raeburn 2560: $contrib{'message'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':message'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
1.108 raeburn 2561: }
1.102 raeburn 2562: }
2563: $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
2564: foreach (keys %contrib) {
2565: my $key = $oldidx.':'.&Apache::lonnet::escape($oldsymb).':'.$_;
2566: $newcontrib{$key} = $contrib{$_};
2567: }
1.157 albertel 2568: my $put_reply = &Apache::lonnet::putstore($env{'request.course.id'},
1.102 raeburn 2569: \%newcontrib,
1.157 albertel 2570: $env{'course.'.$env{'request.course.id'}.'.domain'},
2571: $env{'course.'.$env{'request.course.id'}.'.num'});
1.102 raeburn 2572: $status='Editing class discussion'.($anon?' (anonymous)':'');
2573: } else {
2574: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1.157 albertel 2575: &Apache::lonnet::store(\%contrib,$symb,$env{'request.course.id'},
2576: $env{'course.'.$env{'request.course.id'}.'.domain'},
2577: $env{'course.'.$env{'request.course.id'}.'.num'});
1.102 raeburn 2578: }
1.21 www 2579: my %storenewentry=($symb => time);
1.63 albertel 2580: $status.='<br />'.&mt('Updating discussion time').': '.
1.21 www 2581: &Apache::lonnet::put('discussiontimes',\%storenewentry,
1.157 albertel 2582: $env{'course.'.$env{'request.course.id'}.'.domain'},
2583: $env{'course.'.$env{'request.course.id'}.'.num'});
1.13 www 2584: }
1.17 www 2585: my %record=&Apache::lonnet::restore('_discussion');
2586: my ($temp)=keys %record;
2587: unless ($temp=~/^error\:/) {
2588: my %newrecord=();
2589: $newrecord{'resource'}=$symb;
2590: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.63 albertel 2591: $status.='<br />'.&mt('Registering').': '.
1.21 www 2592: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20 www 2593: }
2594: } else {
2595: $status.='Failed.';
1.17 www 2596: }
1.63 albertel 2597: return $status.'<br />';
1.13 www 2598: }
2599:
1.33 www 2600: # ----------------------------------------------------------- Preview function
2601:
2602: sub show_preview {
2603: my $r=shift;
1.135 albertel 2604: &Apache::loncommon::content_type($r,'text/html');
2605: $r->send_http_header;
1.157 albertel 2606: my $message=&clear_out_html($env{'form.comment'});
1.165 albertel 2607: &newline_to_br(\$message);
1.106 www 2608: $message=&Apache::lonspeller::markeduptext($message);
1.33 www 2609: $message=&Apache::lontexconvert::msgtexconverted($message);
1.157 albertel 2610: my $subject=&clear_out_html($env{'form.subject'});
1.78 raeburn 2611: $subject=~s/\n/\<br \/\>/g;
2612: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.153 albertel 2613: my $html=&Apache::lonxml::xmlbegin();
2614: $r->print($html.'<head>'.
2615: '</head><body><table border="2"><tr><td>'.
2616: '<b>Subject:</b> '.$subject.'<br /><br />'.
2617: $message.'</td></tr></table></body></html>');
1.33 www 2618: }
2619:
1.165 albertel 2620:
2621: sub newline_to_br {
2622: my ($message)=@_;
2623: my $newmessage;
2624: my $parser=HTML::LCParser->new($message);
2625: while (my $token=$parser->get_token()) {
2626: if ($token->[0] eq 'T') {
2627: my $text=$token->[1];
2628: $text=~s/\n/\<br \/\>/g;
2629: $newmessage.=$text;
2630: } elsif ($token->[0] eq 'D' || $token->[0] eq 'C') {
2631: $newmessage.=$token->[1];
2632: } elsif ($token->[0] eq 'PI' || $token->[0] eq 'E') {
2633: $newmessage.=$token->[2];
2634: } elsif ($token->[0] eq 'S') {
2635: $newmessage.=$token->[4];
2636: }
2637:
2638: }
2639: $$message=$newmessage;
2640: }
2641:
1.33 www 2642: sub generate_preview_button {
1.107 www 2643: my $pre=&mt("Show Preview and Check Spelling");
1.33 www 2644: return(<<ENDPREVIEW);
2645: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.78 raeburn 2646: <input type="hidden" name="subject">
1.33 www 2647: <input type="hidden" name="comment" />
1.65 www 2648: <input type="button" value="$pre"
1.119 albertel 2649: onClick="if (typeof(document.mailform.onsubmit)=='function') {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 2650: </form>
2651: ENDPREVIEW
2652: }
1.71 www 2653:
1.108 raeburn 2654: sub modify_attachments {
2655: my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls)=@_;
1.157 albertel 2656: my $orig_subject = &Apache::lonnet::unescape($env{'form.subject'});
1.124 raeburn 2657: my $subject=&clear_out_html($orig_subject);
1.108 raeburn 2658: $subject=~s/\n/\<br \/\>/g;
2659: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.157 albertel 2660: my $timestamp=$env{'form.timestamp'};
2661: my $numoldver=$env{'form.numoldver'};
1.108 raeburn 2662: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Attachments',
2663: '','');
2664: my $msg = '';
1.113 raeburn 2665: my %attachments = ();
1.108 raeburn 2666: my %currattach = ();
2667: if ($idx) {
1.113 raeburn 2668: &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\%attachments,\%currattach,$currdelold);
1.108 raeburn 2669: }
1.139 albertel 2670: &Apache::lonenc::check_encrypt(\$symb);
1.152 albertel 2671: my $html=&Apache::lonxml::xmlbegin();
1.108 raeburn 2672: $r->print(<<END);
1.152 albertel 2673: $html
1.108 raeburn 2674: <head>
2675: <title>Managing Attachments</title>
2676: <script>
2677: function setAction () {
2678: document.modattachments.action = document.modattachments.origpage.value;
2679: document.modattachments.submit();
2680: }
2681: </script>
2682: </head>
2683: $bodytag
2684: <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
2685: <table border="2">
2686: <tr>
2687: <td>
1.124 raeburn 2688: <b>Subject:</b> $subject</b><br /><br />
1.108 raeburn 2689: END
2690: if ($idx) {
2691: if ($attachmenturls) {
2692: my @currold = keys %currattach;
2693: if (@currold > 0) {
2694: $r->print("The following attachments were part of the most recent saved version of this posting.<br />Check the checkboxes for any you wish to remove<br />\n");
1.113 raeburn 2695: foreach my $id (@currold) {
2696: my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'});
2697: $attachurl =~ m#/([^/]+)$#;
1.151 albertel 2698: $r->print('<label><input type="checkbox" name="deloldattach" value="'.$id.'" /> '.$1.'</label><br />'."\n");
1.108 raeburn 2699: }
2700: $r->print("<br />");
2701: }
2702: }
2703: }
2704: if (@{$currnewattach} > 0) {
2705: $r->print("The following attachments have been uploaded for inclusion with this posting.<br />Check the checkboxes for any you wish to remove<br />\n");
2706: foreach (@{$currnewattach}) {
2707: $_ =~ m#/([^/]+)$#;
1.151 albertel 2708: $r->print('<label><input type="checkbox" name="delnewattach" value="'.$_.'" /> '.$1.'</label><br />'."\n");
1.108 raeburn 2709: }
2710: $r->print("<br />");
2711: }
2712: $r->print(<<END);
2713: Add a new attachment to this post. <input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onClick="this.form.submit()" />
2714: </td>
2715: </tr>
2716: </table>
1.157 albertel 2717: <input type="hidden" name="subject" value="$env{'form.subject'}" />
2718: <input type="hidden" name="comment" value="$env{'form.comment'}" />
2719: <input type="hidden" name="timestamp" value="$env{'form.timestamp'}" />
2720: <input type="hidden" name="idx" value="$env{'form.idx'}" />
2721: <input type="hidden" name="numoldver" value="$env{'form.numoldver'}" />
2722: <input type="hidden" name="origpage" value="$env{'form.origpage'}" />
2723: <input type="hidden" name="anondiscuss" value="$env{'form.anondiscuss'}" />
2724: <input type="hidden" name="discuss" value="$env{'form.discuss'}" />
1.108 raeburn 2725: END
2726: foreach (@{$currnewattach}) {
2727: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
2728: }
2729: foreach (@{$currdelold}) {
2730: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
2731: }
2732: $r->print(<<END);
2733: <input type="button" name="rtntoedit" value="Store Changes" onClick="setAction()"/>
2734: </form>
2735: </body>
2736: </html>
2737: END
2738: return;
2739: }
2740:
2741: sub process_attachments {
2742: my ($currnewattach,$currdelold,$keepold) = @_;
1.158 albertel 2743:
2744: @{$currnewattach}=
2745: &Apache::loncommon::get_env_multiple('form.currnewattach');
2746: @{$currdelold}=
2747: &Apache::loncommon::get_env_multiple('form.deloldattach');
1.157 albertel 2748: if (exists($env{'form.delnewattach'})) {
1.158 albertel 2749: my @currdelnew =
2750: &Apache::loncommon::get_env_multiple('form.delnewattach');
1.108 raeburn 2751: my @currnew = ();
2752: foreach my $newone (@{$currnewattach}) {
2753: my $delflag = 0;
2754: foreach (@currdelnew) {
2755: if ($newone eq $_) {
2756: $delflag = 1;
2757: last;
2758: }
2759: }
2760: unless ($delflag) {
2761: push @currnew, $newone;
2762: }
2763: }
2764: @{$currnewattach} = @currnew;
2765: }
1.158 albertel 2766: @{$keepold} = &Apache::loncommon::get_env_multiple('form.keepold');
1.108 raeburn 2767: }
2768:
2769: sub generate_attachments_button {
2770: my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,$numoldver,$mode) = @_;
2771: my $origpage = $ENV{'REQUEST_URI'};
2772: my $att=$attachnum.' '.&mt("attachments");
2773: my $response = (<<END);
2774: <form name="attachment" action="/adm/feedback?attach=$ressymb" method="post">
2775: Click to add/remove attachments: <input type="button" value="$att"
1.124 raeburn 2776: onClick="if (typeof(document.mailform.onsubmit)=='function') {document.mailform.onsubmit();};this.form.comment.value=escape(document.mailform.comment.value);this.form.subject.value=escape(document.mailform.subject.value);
1.108 raeburn 2777: END
2778: unless ($mode eq 'board') {
2779: $response .= 'javascript:anonchk();';
2780: }
2781: $response .= (<<ENDATTACH);
2782: this.form.submit();" />
2783: <input type="hidden" name="origpage" value="$origpage" />
2784: <input type="hidden" name="idx" value="$idx" />
2785: <input type="hidden" name="timestamp" value="$now" />
2786: <input type="hidden" name="subject" />
2787: <input type="hidden" name="comment" />
1.164 albertel 2788: <input type="hidden" name="anondiscuss" value = "0" />
2789: <input type="hidden" name="discuss" value = "0" />
1.108 raeburn 2790: <input type="hidden" name="numoldver" value="$numoldver" />
2791: ENDATTACH
2792: if (defined($deloldattach)) {
2793: if (@{$deloldattach} > 0) {
2794: foreach (@{$deloldattach}) {
2795: $response .= '<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n";
2796: }
2797: }
2798: }
2799: if (defined($currnewattach)) {
2800: if (@{$currnewattach} > 0) {
2801: foreach (@{$currnewattach}) {
2802: $response .= '<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
2803: }
2804: }
2805: }
2806: $response .= '</form>';
2807: return $response;
2808: }
2809:
2810: sub extract_attachments {
2811: my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;
1.116 raeburn 2812: %{$attachments}=();
2813: &get_post_attachments($attachments,$attachmenturls);
2814: foreach my $id (sort keys %{$attachments}) {
2815: if (exists($$attachments{$id}{$numoldver})) {
2816: if (defined($currdelold)) {
2817: if (@{$currdelold} > 0) {
2818: unless (grep/^$id$/,@{$currdelold}) {
2819: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2820: }
1.113 raeburn 2821: } else {
2822: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2823: }
1.116 raeburn 2824: } else {
2825: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2826: }
2827: }
1.116 raeburn 2828: }
2829: my @attached = (sort { $a <=> $b } keys %{$currattach});
2830: if (@attached == 1) {
2831: my $id = $attached[0];
2832: my $attachurl;
2833: if ($attachmenturls =~ m/^<attachment id="0">/) {
2834: $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
2835: } else {
2836: $attachurl = $$attachments{$id}{'filename'};
2837: }
2838: $attachurl=~m|/([^/]+)$|;
2839: $$message.='<br /><a href="'.$attachurl.'"><tt>'.
2840: $1.'</tt></a><br />';
2841: &Apache::lonnet::allowuploaded('/adm/feedback',
2842: $attachurl);
2843: } elsif (@attached > 1) {
2844: $$message.='<ol>';
2845: foreach (@attached) {
2846: my $id = $_;
1.113 raeburn 2847: my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
1.116 raeburn 2848: my ($fname)
2849: =($attachurl=~m|/([^/]+)$|);
2850: $$message .= '<li><a href="'.$attachurl.
2851: '"><tt>'.
2852: $fname.'</tt></a></li>';
1.108 raeburn 2853: &Apache::lonnet::allowuploaded('/adm/feedback',
1.116 raeburn 2854: $attachurl);
1.108 raeburn 2855: }
1.116 raeburn 2856: $$message .= '</ol>';
1.108 raeburn 2857: }
2858: }
2859:
2860: sub construct_attachmenturl {
2861: my ($currnewattach,$keepold,$symb,$idx)=@_;
2862: my $oldattachmenturl;
2863: my $newattachmenturl;
1.113 raeburn 2864: my $startnum = 0;
1.108 raeburn 2865: my $currver = 0;
1.157 albertel 2866: if (($env{'form.editdisc'}) && ($idx)) {
2867: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
2868: $env{'course.'.$env{'request.course.id'}.'.domain'},
2869: $env{'course.'.$env{'request.course.id'}.'.num'});
1.108 raeburn 2870: $oldattachmenturl = $contrib{$idx.':attachmenturl'};
2871: if ($contrib{$idx.':history'}) {
2872: if ($contrib{$idx.':history'} =~ /:/) {
2873: my @oldversions = split/:/,$contrib{$idx.':history'};
2874: $currver = 1 + scalar(@oldversions);
2875: } else {
2876: $currver = 2;
2877: }
2878: } else {
2879: $currver = 1;
2880: }
2881: if ($oldattachmenturl) {
1.113 raeburn 2882: if ($oldattachmenturl =~ m/^<attachment id="0">/) {
2883: my %attachments = ();
2884: my $prevver = $currver-1;
2885: &get_post_attachments(\%attachments,$oldattachmenturl);
1.116 raeburn 2886: my $numattach = scalar(keys %attachments);
1.113 raeburn 2887: $startnum += $numattach;
2888: foreach my $num (sort {$a <=> $b} keys %attachments) {
2889: $newattachmenturl .= '<attachment id="'.$num.'"><filename>'.$attachments{$num}{'filename'}.'</filename>';
1.116 raeburn 2890: foreach $_ (sort {$a <=> $b} keys %{$attachments{$num}}) {
2891: unless ($_ eq 'filename') {
2892: $newattachmenturl .= '<post id="'.$_.'">'.$attachments{$num}{$_}.'</post>';
2893: }
1.113 raeburn 2894: }
2895: if (grep/^$num$/,@{$keepold}) {
2896: $newattachmenturl .= '<post id="'.$currver.'">'.$attachments{$num}{$prevver}.'</post>';
1.108 raeburn 2897: }
1.113 raeburn 2898: $newattachmenturl .= '</attachment>';
1.108 raeburn 2899: }
2900: } else {
1.116 raeburn 2901: $newattachmenturl = '<attachment id="0"><filename>'.&HTML::Entities::encode($oldattachmenturl).'</filename><post id="0">n</post>';
1.108 raeburn 2902: unless (grep/^0$/,@{$keepold}) {
1.113 raeburn 2903: $newattachmenturl .= '<post id="1">n</post>';
1.108 raeburn 2904: }
1.113 raeburn 2905: $newattachmenturl .= '</attachment>';
1.108 raeburn 2906: $startnum ++;
2907: }
2908: }
2909: }
2910: for (my $i=0; $i<@{$currnewattach}; $i++) {
2911: my $attachnum = $startnum + $i;
1.113 raeburn 2912: $newattachmenturl .= '<attachment id="'.$attachnum.'"><filename>'.&HTML::Entities::encode($$currnewattach[$i]).'</filename><post id="'.$currver.'">n</post></attachment>';
1.108 raeburn 2913: }
2914: return $newattachmenturl;
2915: }
1.128 raeburn 2916:
2917: sub has_discussion {
2918: my $resourcesref = shift;
2919: my $navmap = Apache::lonnavmaps::navmap->new();
2920: my @allres=$navmap->retrieveResources();
2921: foreach my $resource (@allres) {
2922: if ($resource->hasDiscussion()) {
1.162 albertel 2923: my $ressymb = $resource->wrap_symb();
1.128 raeburn 2924: push @{$resourcesref}, $ressymb;
2925: }
2926: }
2927: return;
1.143 raeburn 2928: }
2929:
2930: sub sort_filter_names {
2931: my ($sort_types,$role_types,$status_types) = @_;
2932: %{$sort_types} = (
2933: ascdate => 'Date order - oldest first',
2934: descdate => 'Date order - newest first',
2935: thread => 'Threaded',
2936: subject => 'By subject',
2937: username => 'By domain and username',
2938: lastfirst => 'By last name, first name'
2939: );
2940: %{$role_types} = (
2941: all => 'All roles',
2942: st => 'Students',
2943: cc => 'Course Coordinators',
2944: in => 'Instructors',
2945: ta => 'TAs',
2946: ep => 'Exam proctors',
2947: ad => 'Administrators',
2948: cr => 'Custom roles'
2949: );
2950: %{$status_types} = (
2951: all => 'Roles of any status',
2952: Active => 'Only active roles',
2953: Expired => 'Only inactive roles'
2954: );
2955: }
1.108 raeburn 2956:
1.6 albertel 2957: sub handler {
2958: my $r = shift;
1.8 www 2959: if ($r->header_only) {
1.71 www 2960: &Apache::loncommon::content_type($r,'text/html');
1.8 www 2961: $r->send_http_header;
2962: return OK;
2963: }
1.15 www 2964:
2965: # --------------------------- Get query string for limited number of parameters
2966:
1.97 raeburn 2967: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.137 albertel 2968: ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export']);
1.143 raeburn 2969:
1.157 albertel 2970: if ($env{'form.discsymb'}) {
2971: my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.discsymb'});
1.111 raeburn 2972: my $readkey = $symb.'_read';
2973: my $chgcount = 0;
1.157 albertel 2974: my %readinghash = &Apache::lonnet::get('nohist_'.$env{'request.course.id'}.'_discuss',[$readkey],$env{'user.domain'},$env{'user.name'});
2975: foreach my $key (keys %env) {
1.111 raeburn 2976: if ($key =~ m/^form\.postunread_(\d+)/) {
2977: if ($readinghash{$readkey} =~ /\.$1\./) {
2978: $readinghash{$readkey} =~ s/\.$1\.//;
2979: $chgcount ++;
2980: }
2981: } elsif ($key =~ m/^form\.postread_(\d+)/) {
2982: unless ($readinghash{$readkey} =~ /\.$1\./) {
2983: $readinghash{$readkey} .= '.'.$1.'.';
2984: $chgcount ++;
2985: }
2986: }
2987: }
2988: if ($chgcount > 0) {
1.157 albertel 2989: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
2990: \%readinghash,$env{'user.domain'},$env{'user.name'});
1.111 raeburn 2991: }
1.133 albertel 2992: &redirect_back($r,$feedurl,&mt('Marked postings read/unread').'<br />',
1.157 albertel 2993: '0','0','',$env{'form.previous'},'','','',);
1.111 raeburn 2994: return OK;
2995: }
1.157 albertel 2996: if ($env{'form.allversions'}) {
1.109 raeburn 2997: &Apache::loncommon::content_type($r,'text/html');
2998: $r->send_http_header;
1.152 albertel 2999: my $html=&Apache::lonxml::xmlbegin();
1.133 albertel 3000: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Versions');
1.143 raeburn 3001: $r->print(<<END);
1.152 albertel 3002: $html
1.109 raeburn 3003: <head>
3004: <title>Post Versions</title>
3005: <meta http-equiv="pragma" content="no-cache" />
3006: </head>
3007: $bodytag
3008: END
1.157 albertel 3009: my $crs='/'.$env{'request.course.id'};
3010: if ($env{'request.course.sec'}) {
3011: $crs.='_'.$env{'request.course.sec'};
1.109 raeburn 3012: }
1.133 albertel 3013: $crs=~s|_|/|g;
1.109 raeburn 3014: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.157 albertel 3015: my ($symb,$idx)=split(/\:\:\:/,$env{'form.allversions'});
1.133 albertel 3016: ($symb)=&get_feedurl_and_clean_symb($symb);
1.109 raeburn 3017: if ($idx > 0) {
1.116 raeburn 3018: my %messages = ();
3019: my %subjects = ();
3020: my %attachmsgs = ();
3021: my %allattachments = ();
3022: my %imsfiles = ();
3023: my ($screenname,$plainname);
1.157 albertel 3024: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
3025: $env{'course.'.$env{'request.course.id'}.'.domain'},
3026: $env{'course.'.$env{'request.course.id'}.'.num'});
1.133 albertel 3027: $r->print(&get_post_contents(\%contrib,$idx,$seeid,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname));
1.109 raeburn 3028: }
3029: return OK;
3030: }
1.157 albertel 3031: if ($env{'form.posterlist'}) {
3032: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.applysort'});
3033: &print_showposters($r,$symb,$env{'form.previous'},$feedurl,
3034: $env{'form.sortposts'});
1.101 raeburn 3035: return OK;
3036: }
1.157 albertel 3037: if ($env{'form.userpick'}) {
1.133 albertel 3038: my @posters = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.157 albertel 3039: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.userpick'});
1.101 raeburn 3040: my $numpicks = @posters;
1.133 albertel 3041: my %discinfo;
3042: $discinfo{$symb.'_userpick'} = join('&',@posters);
1.157 albertel 3043: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
3044: \%discinfo,$env{'user.domain'},$env{'user.name'});
1.133 albertel 3045: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0',
1.157 albertel 3046: '',$env{'form.previous'},$env{'form.sortposts'},'','','',
1.133 albertel 3047: $numpicks);
1.101 raeburn 3048: return OK;
3049: }
1.157 albertel 3050: if ($env{'form.applysort'}) {
3051: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.applysort'});
1.133 albertel 3052: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0',
1.157 albertel 3053: '',$env{'form.previous'},$env{'form.sortposts'},
3054: $env{'form.rolefilter'},$env{'form.statusfilter'},
3055: $env{'form.sectionpick'});
1.100 raeburn 3056: return OK;
1.157 albertel 3057: } elsif ($env{'form.cmd'} eq 'sortfilter') {
3058: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
3059: &print_sortfilter_options($r,$symb,$env{'form.previous'},$feedurl);
1.100 raeburn 3060: return OK;
1.157 albertel 3061: } elsif ($env{'form.navtime'}) {
1.99 raeburn 3062: my %discinfo = ();
3063: my @resources = ();
1.157 albertel 3064: if (defined($env{'form.navmaps'})) {
3065: if ($env{'form.navmaps'} =~ /:/) {
3066: @resources = split/:/,$env{'form.navmaps'};
1.128 raeburn 3067: } else {
1.157 albertel 3068: @resources = ("$env{'form.navmaps'}");
1.128 raeburn 3069: }
1.99 raeburn 3070: } else {
1.128 raeburn 3071: &has_discussion(\@resources);
1.99 raeburn 3072: }
3073: my $numitems = @resources;
3074: my $feedurl = '/adm/navmaps';
1.157 albertel 3075: if ($env{'form.navurl'}) { $feedurl .= '?'.$env{'form.navurl'}; }
1.99 raeburn 3076: my %lt = &Apache::lonlocal::texthash(
3077: 'mnpa' => 'Marked "New" posts as read in a total of',
1.128 raeburn 3078: 'robb' => 'resources/bulletin boards.',
3079: 'twnp' => 'There are currently no resources or bulletin boards with unread discussion postings.'
1.99 raeburn 3080: );
3081: foreach (@resources) {
3082: my $ressymb=$_;
1.132 albertel 3083: &Apache::lonenc::check_decrypt(\$ressymb);
1.99 raeburn 3084: my $lastkey = $ressymb.'_lastread';
1.157 albertel 3085: $discinfo{$lastkey} = $env{'form.navtime'};
1.99 raeburn 3086: }
1.128 raeburn 3087: my $textline = "<b>$lt{'mnpa'} $numitems $lt{'robb'}</b>";
3088: if ($numitems > 0) {
1.157 albertel 3089: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
3090: \%discinfo,$env{'user.domain'},$env{'user.name'});
1.128 raeburn 3091: } else {
3092: $textline = "<b>$lt{'twnp'}</b>";
3093: }
1.99 raeburn 3094: &Apache::loncommon::content_type($r,'text/html');
3095: $r->send_http_header;
1.150 albertel 3096: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.152 albertel 3097: my $html=&Apache::lonxml::xmlbegin();
1.99 raeburn 3098: $r->print (<<ENDREDIR);
1.152 albertel 3099: $html
1.99 raeburn 3100: <head>
3101: <title>New posts marked as read</title>
3102: <meta http-equiv="pragma" content="no-cache" />
3103: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
3104: </head>
3105: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1.150 albertel 3106: <img align="right" src="$logo" />
1.128 raeburn 3107: $textline
1.99 raeburn 3108: <form name="reldt" action="$feedurl" target="loncapaclient">
3109: </form>
1.121 albertel 3110: <br /><a href="$feedurl">Continue</a>
1.99 raeburn 3111: </body>
3112: </html>
3113: ENDREDIR
3114: return OK;
1.157 albertel 3115: } elsif ($env{'form.modifydisp'}) {
3116: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.modifydisp'});
1.133 albertel 3117: my ($dispchgA,$dispchgB,$markchg,$toggchg) =
1.157 albertel 3118: split(/_/,$env{'form.changes'});
3119: &print_display_options($r,$symb,$env{'form.previous'},$dispchgA,
1.133 albertel 3120: $dispchgB,$markchg,$toggchg,$feedurl);
1.97 raeburn 3121: return OK;
1.157 albertel 3122: } elsif ($env{'form.markondisp'} || $env{'form.markonread'} ||
3123: $env{'form.allposts'} || $env{'form.onlyunread'} ||
3124: $env{'form.onlyunmark'} || $env{'form.toggoff'} ||
3125: $env{'form.toggon'} || $env{'form.markread'}) {
3126: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
1.137 albertel 3127: my %discinfo;
1.133 albertel 3128: # ------------------------ Modify setting for read/unread toggle for each post
1.157 albertel 3129: if ($env{'form.toggoff'}) { $discinfo{$symb.'_readtoggle'}=0; }
3130: if ($env{'form.toggon'}) { $discinfo{$symb.'_readtoggle'}=1; }
1.133 albertel 3131: # --------- Modify setting for identification of 'NEW' posts in this discussion
1.157 albertel 3132: if ($env{'form.markondisp'}) {
1.137 albertel 3133: $discinfo{$symb.'_lastread'} = time;
3134: $discinfo{$symb.'_markondisp'} = 1;
3135: }
1.157 albertel 3136: if ($env{'form.markonread'}) {
3137: if ( $env{'form.previous'} > 0 ) {
3138: $discinfo{$symb.'_lastread'} = $env{'form.previous'};
1.137 albertel 3139: }
3140: $discinfo{$symb.'_markondisp'} = 0;
1.84 raeburn 3141: }
1.133 albertel 3142: # --------------------------------- Modify display setting for this discussion
1.157 albertel 3143: if ($env{'form.allposts'}) {
1.137 albertel 3144: $discinfo{$symb.'_showonlyunread'} = 0;
3145: $discinfo{$symb.'_showonlyunmark'} = 0;
1.84 raeburn 3146: }
1.157 albertel 3147: if ($env{'form.onlyunread'}) { $discinfo{$symb.'_showonlyunread'} = 1; }
3148: if ($env{'form.onlyunmark'}) { $discinfo{$symb.'_showonlyunmark'} = 1; }
1.137 albertel 3149: # ----------------------------------------------------- Mark new posts not NEW
1.157 albertel 3150: if ($env{'form.markread'}) { $discinfo{$symb.'_lastread'} = time; }
3151: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
3152: \%discinfo,$env{'user.domain'},$env{'user.name'});
3153: my $previous=$env{'form.previous'};
3154: if ($env{'form.markondisp'}) { $previous=undef; }
1.133 albertel 3155: &redirect_back($r,$feedurl,&mt('Changed display status').'<br />',
3156: '0','0','',$previous);
1.84 raeburn 3157: return OK;
1.157 albertel 3158: } elsif (($env{'form.hide'}) || ($env{'form.unhide'})) {
1.15 www 3159: # ----------------------------------------------------------------- Hide/unhide
1.157 albertel 3160: my $entry=$env{'form.hide'}?$env{'form.hide'}:$env{'form.unhide'};
1.133 albertel 3161: my ($symb,$idx)=split(/\:\:\:/,$entry);
3162: ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
1.15 www 3163:
1.157 albertel 3164: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
3165: $env{'course.'.$env{'request.course.id'}.'.domain'},
3166: $env{'course.'.$env{'request.course.id'}.'.num'});
1.15 www 3167:
1.133 albertel 3168: my $currenthidden=$contrib{'hidden'};
3169: my $currentstudenthidden=$contrib{'studenthidden'};
1.15 www 3170:
1.157 albertel 3171: my $crs='/'.$env{'request.course.id'};
3172: if ($env{'request.course.sec'}) {
3173: $crs.='_'.$env{'request.course.sec'};
1.133 albertel 3174: }
3175: $crs=~s/\_/\//g;
3176: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.102 raeburn 3177:
1.157 albertel 3178: if ($env{'form.hide'}) {
1.133 albertel 3179: $currenthidden.='.'.$idx.'.';
3180: unless ($seeid) {
3181: $currentstudenthidden.='.'.$idx.'.';
3182: }
3183: } else {
3184: $currenthidden=~s/\.$idx\.//g;
3185: }
3186: my %newhash=('hidden' => $currenthidden);
1.157 albertel 3187: if ( ($env{'form.hide'}) && (!$seeid) ) {
1.133 albertel 3188: $newhash{'studenthidden'} = $currentstudenthidden;
3189: }
1.38 www 3190:
1.157 albertel 3191: &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
3192: $env{'course.'.$env{'request.course.id'}.'.domain'},
3193: $env{'course.'.$env{'request.course.id'}.'.num'});
1.38 www 3194:
1.133 albertel 3195: &redirect_back($r,$feedurl,&mt('Changed discussion status').'<br />',
1.157 albertel 3196: '0','0','',$env{'form.previous'});
1.135 albertel 3197: return OK;
1.157 albertel 3198: } elsif ($env{'form.cmd'}=~/^(threadedoff|threadedon)$/) {
3199: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
3200: if ($env{'form.cmd'} eq 'threadedon') {
1.69 www 3201: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
3202: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
3203: } else {
3204: &Apache::lonnet::del('environment',['threadeddiscussion']);
3205: &Apache::lonnet::delenv('environment\.threadeddiscussion');
1.72 albertel 3206: }
1.133 albertel 3207: &redirect_back($r,$feedurl,&mt('Changed discussion view mode').'<br />',
1.157 albertel 3208: '0','0','',$env{'form.previous'});
1.135 albertel 3209: return OK;
1.157 albertel 3210: } elsif ($env{'form.deldisc'}) {
1.38 www 3211: # --------------------------------------------------------------- Hide for good
1.157 albertel 3212: my ($symb,$idx)=split(/\:\:\:/,$env{'form.deldisc'});
1.133 albertel 3213: ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
1.157 albertel 3214: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
3215: $env{'course.'.$env{'request.course.id'}.'.domain'},
3216: $env{'course.'.$env{'request.course.id'}.'.num'});
1.135 albertel 3217: my %newhash=('deleted' => $contrib{'deleted'}.".$idx.");
1.157 albertel 3218: &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
3219: $env{'course.'.$env{'request.course.id'}.'.domain'},
3220: $env{'course.'.$env{'request.course.id'}.'.num'});
1.135 albertel 3221: &redirect_back($r,$feedurl,&mt('Changed discussion status').'<br />',
1.157 albertel 3222: '0','0','',$env{'form.previous'});
1.135 albertel 3223: return OK;
1.157 albertel 3224: } elsif ($env{'form.preview'}) {
1.33 www 3225: # -------------------------------------------------------- User wants a preview
3226: &show_preview($r);
1.135 albertel 3227: return OK;
1.157 albertel 3228: } elsif ($env{'form.attach'}) {
1.108 raeburn 3229: # -------------------------------------------------------- Work on attachments
3230: &Apache::loncommon::content_type($r,'text/html');
3231: $r->send_http_header;
3232: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','anondiscuss','discuss']);
1.133 albertel 3233: my (@currnewattach,@currdelold,@keepold);
1.108 raeburn 3234: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
1.157 albertel 3235: if (exists($env{'form.addnewattach.filename'})) {
3236: unless (length($env{'form.addnewattach'})>131072) {
3237: my $subdir = 'feedback/'.$env{'form.timestamp'};
1.108 raeburn 3238: my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);
1.139 albertel 3239: push @currnewattach, $newattachment;
1.108 raeburn 3240: }
3241: }
1.133 albertel 3242: my $attachmenturls;
1.157 albertel 3243: my ($symb) = &get_feedurl_and_clean_symb($env{'form.attach'});
3244: my $idx = $env{'form.idx'};
1.108 raeburn 3245: if ($idx) {
1.157 albertel 3246: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
3247: $env{'course.'.$env{'request.course.id'}.'.domain'},
3248: $env{'course.'.$env{'request.course.id'}.'.num'});
1.108 raeburn 3249: $attachmenturls = $contrib{$idx.':attachmenturl'};
3250: }
1.133 albertel 3251: &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,
3252: $attachmenturls);
1.135 albertel 3253: return OK;
1.157 albertel 3254: } elsif ($env{'form.export'}) {
1.116 raeburn 3255: &Apache::loncommon::content_type($r,'text/html');
3256: $r->send_http_header;
1.157 albertel 3257: my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.export'});
1.133 albertel 3258: my $mode='board';
1.116 raeburn 3259: my $status='OPEN';
1.157 albertel 3260: my $previous=$env{'form.previous'};
1.168 albertel 3261: if ($feedurl =~ /\.(problem|exam|quiz|assess|survey|form|library|task)$/) {
1.116 raeburn 3262: $mode='problem';
3263: $status=$Apache::inputtags::status[-1];
3264: }
3265: my $discussion = &list_discussion($mode,$status,$symb);
3266: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion');
3267: $r->print($bodytag.$discussion);
3268: return OK;
1.15 www 3269: } else {
3270: # ------------------------------------------------------------- Normal feedback
1.157 albertel 3271: my $feedurl=$env{'form.postdata'};
1.133 albertel 3272: $feedurl=~s/^http\:\/\///;
3273: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
3274: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
3275: $feedurl=~s/\?.+$//;
1.8 www 3276:
1.133 albertel 3277: my $symb;
1.157 albertel 3278: if ($env{'form.replydisc'}) {
3279: $symb=(split(/\:\:\:/,$env{'form.replydisc'}))[0];
1.133 albertel 3280: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3281: $feedurl=&Apache::lonnet::clutter($url);
1.157 albertel 3282: } elsif ($env{'form.editdisc'}) {
3283: $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
1.52 www 3284: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1.133 albertel 3285: $feedurl=&Apache::lonnet::clutter($url);
1.157 albertel 3286: } elsif ($env{'form.origpage'}) {
1.133 albertel 3287: $symb="";
3288: } else {
3289: $symb=&Apache::lonnet::symbread($feedurl);
3290: }
3291: unless ($symb) {
1.157 albertel 3292: $symb=$env{'form.symb'};
1.133 albertel 3293: if ($symb) {
3294: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3295: $feedurl=&Apache::lonnet::clutter($url);
3296: }
3297: }
3298: &Apache::lonenc::check_decrypt(\$symb);
3299: my $goahead=1;
1.168 albertel 3300: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
1.133 albertel 3301: unless ($symb) { $goahead=0; }
3302: }
3303: # backward compatibility (bulletin boards used to be 'wrapped')
1.159 raeburn 3304: &dewrapper(\$feedurl);
1.133 albertel 3305: if (!$goahead) {
3306: # Ambiguous Problem Resource
3307: $r->internal_redirect('/adm/ambiguous');
3308: return OK;
1.31 www 3309: }
1.8 www 3310: # Go ahead with feedback, no ambiguous reference
1.133 albertel 3311: unless (
3312: (
3313: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
3314: )
3315: ||
1.157 albertel 3316: ($env{'request.course.id'} && ($feedurl!~m:^/adm:))
1.133 albertel 3317: ||
1.157 albertel 3318: ($env{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.133 albertel 3319: ) {
1.135 albertel 3320: &Apache::loncommon::content_type($r,'text/html');
3321: $r->send_http_header;
1.133 albertel 3322: # Unable to give feedback
3323: &no_redirect_back($r,$feedurl);
3324: }
1.6 albertel 3325: # --------------------------------------------------- Print login screen header
1.157 albertel 3326: unless ($env{'form.sendit'}) {
1.135 albertel 3327: &Apache::loncommon::content_type($r,'text/html');
3328: $r->send_http_header;
1.141 raeburn 3329: my $options=&screen_header($feedurl,$symb);
1.133 albertel 3330: if ($options) {
3331: &mail_screen($r,$feedurl,$options);
3332: } else {
3333: &fail_redirect($r,$feedurl);
3334: }
3335: return OK;
1.6 albertel 3336: }
3337:
3338: # Get previous user input
1.9 albertel 3339: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.157 albertel 3340: $symb,$env{'user.name'},$env{'user.domain'},
3341: $env{'request.course.id'});
1.6 albertel 3342:
3343: # Get output from resource
3344: my $usersaw=&resource_output($feedurl);
3345:
1.50 albertel 3346: # Get resource answer (need to allow student to view grades for this to work)
3347: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1.40 albertel 3348: my $useranswer=&Apache::loncommon::get_student_answers(
1.157 albertel 3349: $symb,$env{'user.name'},$env{'user.domain'},
3350: $env{'request.course.id'});
1.50 albertel 3351: &Apache::lonnet::delenv('allowed.vgr');
1.42 www 3352: # Get attachments, if any, and not too large
3353: my $attachmenturl='';
1.157 albertel 3354: if (($env{'form.origpage'}) || ($env{'form.editdisc'}) ||
3355: ($env{'form.replydisc'})) {
1.133 albertel 3356: my ($symb,$idx);
1.157 albertel 3357: if ($env{'form.replydisc'}) {
3358: ($symb,$idx)=split(/\:\:\:/,$env{'form.replydisc'});
3359: } elsif ($env{'form.editdisc'}) {
3360: ($symb,$idx)=split(/\:\:\:/,$env{'form.editdisc'});
3361: } elsif ($env{'form.origpage'}) {
3362: $symb = $env{'form.symb'};
1.133 albertel 3363: }
1.132 albertel 3364: &Apache::lonenc::check_decrypt(\$symb);
1.133 albertel 3365: my @currnewattach = ();
3366: my @deloldattach = ();
3367: my @keepold = ();
3368: &process_attachments(\@currnewattach,\@deloldattach,\@keepold);
3369: $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
3370: $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);
1.157 albertel 3371: } elsif ($env{'form.attachment.filename'}) {
3372: unless (length($env{'form.attachment'})>131072) {
1.82 albertel 3373: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1.42 www 3374: }
3375: }
1.6 albertel 3376: # Filter HTML out of message (could be nasty)
1.157 albertel 3377: my $message=&clear_out_html($env{'form.comment'});
1.6 albertel 3378:
3379: # Assemble email
1.8 www 3380: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.133 albertel 3381: $usersaw,$useranswer);
1.40 albertel 3382:
1.6 albertel 3383: # Who gets this?
3384: my ($typestyle,%to) = &decide_receiver($feedurl);
3385:
3386: # Actually send mail
1.43 www 3387: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
1.133 albertel 3388: $attachmenturl,%to);
1.13 www 3389:
3390: # Discussion? Store that.
3391:
1.32 albertel 3392: my $numpost=0;
1.157 albertel 3393: if ($env{'form.discuss'} || $env{'form.anondiscuss'}) {
3394: my $subject = &clear_out_html($env{'form.subject'});
3395: my $anonmode=(defined($env{'form.anondiscuss'}));
1.133 albertel 3396: $typestyle.=&adddiscuss($symb,$message,$anonmode,$attachmenturl,
3397: $subject);
1.32 albertel 3398: $numpost++;
1.14 www 3399: }
1.133 albertel 3400:
1.6 albertel 3401: # Receipt screen and redirect back to where came from
1.157 albertel 3402: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$env{'form.previous'});
1.133 albertel 3403: }
3404: return OK;
3405: }
1.6 albertel 3406:
1.133 albertel 3407: sub wrap_symb {
3408: my ($ressymb)=@_;
3409: if ($ressymb =~ /bulletin___\d+___/) {
3410: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
3411: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
3412: }
1.6 albertel 3413: }
1.133 albertel 3414: return $ressymb;
3415: }
3416: sub dewrapper {
3417: my ($feedurl)=@_;
3418: if ($$feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
3419: $$feedurl=~s|^/adm/wrapper||;
3420: }
3421: }
3422:
3423: sub get_feedurl {
3424: my ($symb)=@_;
3425: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3426: my $feedurl = &Apache::lonnet::clutter($url);
3427: &dewrapper(\$feedurl);
3428: return $feedurl;
1.15 www 3429: }
1.1 www 3430:
1.133 albertel 3431: sub get_feedurl_and_clean_symb {
3432: my ($symb)=@_;
3433: &Apache::lonenc::check_decrypt(\$symb);
3434: # backward compatibility (bulletin boards used to be 'wrapped')
3435: unless ($symb =~ m|bulletin___\d+___adm/wrapper|) {
3436: $symb=~s|(bulletin___\d+___)|$1adm/wrapper|;
3437: }
3438: my $feedurl = &get_feedurl($symb);
3439: return ($symb,$feedurl);
3440: }
1.1 www 3441: 1;
3442: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>