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