Annotation of loncom/interface/lonfeedback.pm, revision 1.173
1.1 www 1: # The LearningOnline Network
2: # Feedback
3: #
1.173 ! www 4: # $Id: lonfeedback.pm,v 1.172 2005/11/09 11:41:02 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'}) {
1199: if ($$contrib{$idx.':history'} =~ m/:/) {
1200: @postversions = split/:/,$$contrib{$idx.':history'};
1201: } else {
1202: @postversions = ("$$contrib{$idx.':history'}");
1203: }
1204: }
1205: &get_post_versions($messages,$$contrib{$idx.':message'},1);
1206: &get_post_versions($subjects,$$contrib{$idx.':subject'},1);
1207: push @postversions,$$contrib{$idx.':timestamp'};
1208: $end = @postversions;
1209: } else {
1210: &get_post_versions($messages,$$contrib{$idx.':message'},1,$numver);
1211: &get_post_versions($subjects,$$contrib{$idx.':subject'},1,$numver);
1212: }
1213:
1214: if ($$contrib{$idx.':anonymous'}) {
1215: $sender.=' ['.&mt('anonymous').'] '.$$screenname;
1216: }
1217: if ($type eq 'allversions') {
1218: $discussion=('<b>'.$sender.'</b><br /><ul>');
1219: }
1220: for (my $i=$start; $i<$end; $i++) {
1221: my ($timesent,$attachmsg);
1222: my %currattach = ();
1223: $timesent = &Apache::lonlocal::locallocaltime($postversions[$i]);
1.165 albertel 1224: &newline_to_br(\$messages->{$i});
1.116 raeburn 1225: $$messages{$i}=&Apache::lontexconvert::msgtexconverted($$messages{$i});
1226: $$subjects{$i}=~s/\n/\<br \/\>/g;
1227: $$subjects{$i}=&Apache::lontexconvert::msgtexconverted($$subjects{$i});
1228: if ($attachmenturls) {
1229: &extract_attachments($attachmenturls,$idx,$i,\$attachmsg,$allattachments,\%currattach);
1230: }
1231: if ($type eq 'export') {
1232: $$imsfiles{$idx}{$i} = '';
1233: if ($attachmsg) {
1234: $$attachtxt{$i} = '<br />Attachments:<br />';
1235: foreach (sort keys %currattach) {
1236: if ($$allattachments{$_}{'filename'} =~ m-^/uploaded/([^/]+/[^/]+)(/feedback)?(/?\d*)/([^/]+)$-) {
1237: my $fname = $1.$3.'/'.$4;
1238: $$imsfiles{$idx}{$i} .= '<file href="'.$fname.'">'."\n";
1239: $$attachtxt{$i}.= '<a href="'.$fname.'">'.$4.'</a><br />';
1240: }
1241: }
1242: }
1243: } else {
1244: if ($attachmsg) {
1245: $$attachtxt{$i} = '<br />Attachments:'.$attachmsg.'<br />';
1246: } else {
1247: $$attachtxt{$i} = '';
1248: }
1249: }
1250: if ($type eq 'allversions') {
1251: $discussion.= <<"END";
1252: <li><b>$$subjects{$i}</b>, $timesent<br />
1253: $$messages{$i}<br />
1254: $$attachtxt{$i}</li>
1255: END
1256: }
1257: }
1258: if ($type eq 'allversions') {
1259: $discussion.=('</ul></body></html>');
1260: return $discussion;
1261: } else {
1262: return;
1263: }
1264: }
1265:
1266: sub replicate_attachments {
1267: my ($attachrefs,$tempexport) = @_;
1268: my $response;
1269: foreach my $id (keys %{$attachrefs}) {
1270: if ($$attachrefs{$id}{'filename'} =~ m-^/uploaded/([^/]+)/([^/]+)(/feedback)?(/?\d*)/([^/]+)$-) {
1271: my $path = $tempexport;
1272: my $tail = $1.'/'.$2.$4;
1273: my @extras = split/\//,$tail;
1274: my $destination = $tempexport.'/'.$1.'/'.$2.$4.'/'.$5;
1275: if (!-e $destination) {
1276: my $i= 0;
1277: while ($i<@extras) {
1278: $path .= '/'.$extras[$i];
1279: if (!-e $path) {
1280: mkdir($path,0700);
1281: }
1282: $i ++;
1283: }
1284: my ($content,$rtncode);
1285: my $uploadreply = &Apache::lonnet::getuploaded('GET',$$attachrefs{$id}{'filename'},$1,$2,$content,$rtncode);
1286: if ($uploadreply eq 'ok') {
1.125 raeburn 1287: my $attachcopy;
1288: if ($attachcopy = Apache::File->new('>'.$destination)) {
1289: print $attachcopy $content;
1290: close($attachcopy);
1291: } else {
1292: $response .= 'Error copying file attachment - '.$5.' to IMS package: '.$!.'<br />'."\n";
1293: }
1.116 raeburn 1294: } else {
1.125 raeburn 1295: &Apache::lonnet::logthis("Replication of attachment failed when building IMS export of discussion posts - domain: $1, course: $2, file: $$attachrefs{$id}{'filename'} -error: $rtncode");
1296: $response .= 'Error copying file attachment - '.$5.' to IMS package: '.$rtncode.'<br />'."\n";
1.116 raeburn 1297: }
1298: }
1299: }
1300: }
1.125 raeburn 1301: return $response;
1.116 raeburn 1302: }
1303:
1.6 albertel 1304: sub mail_screen {
1305: my ($r,$feedurl,$options) = @_;
1.157 albertel 1306: if (exists($env{'form.origpage'})) {
1.108 raeburn 1307: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss']);
1308: }
1.45 www 1309: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
1.102 raeburn 1310: '','onLoad="window.focus();setposttype();"');
1.51 albertel 1311: my $title=&Apache::lonnet::gettitle($feedurl);
1312: if (!$title) { $title = $feedurl; }
1.69 www 1313: my $quote='';
1.78 raeburn 1314: my $subject = '';
1.108 raeburn 1315: my $comment = '';
1.80 raeburn 1316: my $prevtag = '';
1.102 raeburn 1317: my $parentmsg = '';
1.108 raeburn 1318: my ($symb,$idx,$attachmenturls);
1319: my $numoldver = 0;
1320: my $attachmsg = '';
1321: my $newattachmsg = '';
1322: my @currnewattach = ();
1323: my @currdelold = ();
1324: my @keepold = ();
1.113 raeburn 1325: my %attachments = ();
1.108 raeburn 1326: my %currattach = ();
1327: my $attachnum = 0;
1328: my $anonchk = (<<END);
1329: function anonchk() {
1330: if (document.mailform.anondiscuss.checked == true) {
1331: document.attachment.anondiscuss.value = '1'
1332: }
1333: if (document.mailform.discuss.checked == true) {
1334: document.attachment.discuss.value = '1'
1335: }
1336: return
1337: }
1338: END
1339: my $anonscript;
1.157 albertel 1340: if (exists($env{'form.origpage'})) {
1.108 raeburn 1341: $anonscript = (<<END);
1.102 raeburn 1342: function setposttype() {
1.157 albertel 1343: var anondisc = $env{'form.anondiscuss'};
1344: var disc = $env{'form.discuss'};
1.108 raeburn 1345: if (anondisc == 1) {
1346: document.mailform.anondiscuss.checked = true
1347: }
1348: if (disc == 1) {
1349: document.mailform.discuss.checked = true
1350: }
1.102 raeburn 1351: return
1352: }
1353: END
1.108 raeburn 1354: } else {
1355: $anonscript = (<<END);
1356: function setposttype() {
1357: return
1358: }
1359: END
1360: }
1.157 albertel 1361: if (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
1362: if ($env{'form.replydisc'}) {
1363: ($symb,$idx)=split(/\:\:\:/,$env{'form.replydisc'});
1.102 raeburn 1364: } else {
1.157 albertel 1365: ($symb,$idx)=split(/\:\:\:/,$env{'form.editdisc'});
1.102 raeburn 1366: }
1.157 albertel 1367: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
1368: $env{'course.'.$env{'request.course.id'}.'.domain'},
1369: $env{'course.'.$env{'request.course.id'}.'.num'});
1.80 raeburn 1370: unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
1.112 raeburn 1371: if ($contrib{$idx.':history'}) {
1372: if ($contrib{$idx.':history'} =~ /:/) {
1373: my @oldversions = split/:/,$contrib{$idx.':history'};
1374: $numoldver = @oldversions;
1375: } else {
1376: $numoldver = 1;
1377: }
1378: }
1.157 albertel 1379: if ($env{'form.replydisc'}) {
1.102 raeburn 1380: if ($contrib{$idx.':history'}) {
1381: if ($contrib{$idx.':history'} =~ /:/) {
1382: my @oldversions = split/:/,$contrib{$idx.':history'};
1383: $numoldver = @oldversions;
1384: } else {
1385: $numoldver = 1;
1386: }
1387: }
1.108 raeburn 1388: my $message;
1389: if ($idx > 0) {
1.116 raeburn 1390: my %msgversions = ();
1391: &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
1392: $message = $msgversions{$numoldver};
1.108 raeburn 1393: }
1.165 albertel 1394: &newline_to_br(\$message);
1.108 raeburn 1395: $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
1.102 raeburn 1396: if ($idx > 0) {
1.116 raeburn 1397: my %subversions = ();
1398: &get_post_versions(\%subversions,$contrib{$idx.':subject'},1,$numoldver);
1399: $subject = 'Re: '.$subversions{$numoldver};
1.102 raeburn 1400: }
1.108 raeburn 1401: $subject = &HTML::Entities::encode($subject,'<>&"');
1.102 raeburn 1402: } else {
1.108 raeburn 1403: $attachmenturls = $contrib{$idx.':attachmenturl'};
1.116 raeburn 1404: if ($idx > 0) {
1405: my %msgversions = ();
1406: &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
1407: $comment = $msgversions{$numoldver};
1408: my %subversions = ();
1409: &get_post_versions(\%subversions,$contrib{$idx.':subject'},0,$numoldver);
1410: $subject = $subversions{$numoldver};
1.102 raeburn 1411: }
1412: if (defined($contrib{$idx.':replyto'})) {
1413: $parentmsg = $contrib{$idx.':replyto'};
1414: }
1.157 albertel 1415: unless (exists($env{'form.origpage'})) {
1.108 raeburn 1416: my $anonflag = 0;
1417: if ($contrib{$idx.':anonymous'}) {
1418: $anonflag = 1;
1419: }
1420: $anonscript = (<<END);
1.102 raeburn 1421: function setposttype () {
1422: var currtype = $anonflag
1423: if (currtype == 1) {
1424: document.mailform.elements.discuss.checked = false
1425: document.mailform.elements.anondiscuss.checked = true
1426: }
1427: if (currtype == 0) {
1428: document.mailform.elements.anondiscuss.checked = false
1429: document.mailform.elements.discuss.checked = true
1430: }
1431: return
1432: }
1433: END
1.108 raeburn 1434: }
1.79 raeburn 1435: }
1.69 www 1436: }
1.157 albertel 1437: if ($env{'form.previous'}) {
1438: $prevtag = '<input type="hidden" name="previous" value="'.$env{'form.previous'}.'" />';
1.80 raeburn 1439: }
1.69 www 1440: }
1.108 raeburn 1441:
1.157 albertel 1442: if ($env{'form.origpage'}) {
1443: $subject = &Apache::lonnet::unescape($env{'form.subject'});
1444: $comment = &Apache::lonnet::unescape($env{'form.comment'});
1.108 raeburn 1445: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
1446: }
1.85 www 1447: my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
1.86 www 1448: my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
1.74 www 1449: my $send=&mt('Send');
1.152 albertel 1450: my $html=&Apache::lonxml::xmlbegin();
1.102 raeburn 1451: $r->print(<<END);
1.152 albertel 1452: $html
1.1 www 1453: <head>
1454: <title>The LearningOnline Network with CAPA</title>
1.7 albertel 1455: <meta http-equiv="pragma" content="no-cache"></meta>
1.85 www 1456: $htmlheader
1.63 albertel 1457: <script type="text/javascript">
1458: //<!--
1.5 www 1459: function gosubmit() {
1460: var rec=0;
1.12 albertel 1461: if (typeof(document.mailform.elements.author)!="undefined") {
1.5 www 1462: if (document.mailform.elements.author.checked) {
1463: rec=1;
1464: }
1465: }
1.12 albertel 1466: if (typeof(document.mailform.elements.question)!="undefined") {
1.5 www 1467: if (document.mailform.elements.question.checked) {
1468: rec=1;
1469: }
1470: }
1.12 albertel 1471: if (typeof(document.mailform.elements.course)!="undefined") {
1.5 www 1472: if (document.mailform.elements.course.checked) {
1473: rec=1;
1474: }
1475: }
1.12 albertel 1476: if (typeof(document.mailform.elements.policy)!="undefined") {
1.5 www 1477: if (document.mailform.elements.policy.checked) {
1478: rec=1;
1479: }
1480: }
1.12 albertel 1481: if (typeof(document.mailform.elements.discuss)!="undefined") {
1.10 www 1482: if (document.mailform.elements.discuss.checked) {
1483: rec=1;
1484: }
1485: }
1.14 www 1486: if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
1487: if (document.mailform.elements.anondiscuss.checked) {
1488: rec=1;
1489: }
1490: }
1.5 www 1491:
1492: if (rec) {
1.118 albertel 1493: if (typeof(document.mailform.onsubmit)=='function') {
1.105 www 1494: document.mailform.onsubmit();
1495: }
1.5 www 1496: document.mailform.submit();
1497: } else {
1498: alert('Please check a feedback type.');
1499: }
1500: }
1.108 raeburn 1501: $anonchk
1.102 raeburn 1502: $anonscript
1.63 albertel 1503: //-->
1.5 www 1504: </script>
1.1 www 1505: </head>
1.29 www 1506: $bodytag
1.51 albertel 1507: <h2><tt>$title</tt></h2>
1.43 www 1508: <form action="/adm/feedback" method="post" name="mailform"
1509: enctype="multipart/form-data">
1.80 raeburn 1510: $prevtag
1.63 albertel 1511: <input type="hidden" name="postdata" value="$feedurl" />
1.102 raeburn 1512: END
1.157 albertel 1513: if ($env{'form.replydisc'}) {
1.102 raeburn 1514: $r->print(<<END);
1.157 albertel 1515: <input type="hidden" name="replydisc" value="$env{'form.replydisc'}" />
1.102 raeburn 1516: END
1.157 albertel 1517: } elsif ($env{'form.editdisc'}) {
1.102 raeburn 1518: $r->print(<<END);
1.157 albertel 1519: <input type="hidden" name="editdisc" value ="$env{'form.editdisc'}" />
1.102 raeburn 1520: <input type="hidden" name="parentmsg" value ="$parentmsg" />
1521: END
1522: }
1.108 raeburn 1523: $r->print(<<END);
1.5 www 1524: Please check at least one of the following feedback types:
1.63 albertel 1525: $options<hr />
1.69 www 1526: $quote
1.63 albertel 1527: <p>My question/comment/feedback:</p>
1528: <p>
1.47 bowersj2 1529: $latexHelp
1.78 raeburn 1530: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
1531: <p>
1.108 raeburn 1532: <textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">$comment
1.63 albertel 1533: </textarea></p>
1534: <p>
1.108 raeburn 1535: END
1.157 albertel 1536: if ( ($env{'form.editdisc'}) || ($env{'form.replydisc'}) ) {
1537: if ($env{'form.origpage'}) {
1.108 raeburn 1538: foreach (@currnewattach) {
1539: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
1540: }
1541: foreach (@currdelold) {
1542: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
1543: }
1544: }
1.157 albertel 1545: if ($env{'form.editdisc'}) {
1.108 raeburn 1546: if ($attachmenturls) {
1.113 raeburn 1547: &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\%attachments,\%currattach,\@currdelold);
1.108 raeburn 1548: $attachnum = scalar(keys %currattach);
1549: foreach (keys %currattach) {
1550: $r->print('<input type="hidden" name="keepold" value="'.$_.'" />'."\n");
1551: }
1552: }
1553: }
1554: } else {
1555: $r->print(<<END);
1.42 www 1556: Attachment (128 KB max size): <input type="file" name="attachment" />
1557: </p>
1.108 raeburn 1558: END
1559: }
1560: $r->print(<<END);
1.42 www 1561: <p>
1562: <input type="hidden" name="sendit" value="1" />
1.74 www 1563: <input type="button" value="$send" onClick='gosubmit();' />
1.42 www 1564: </p>
1.2 www 1565: </form>
1.108 raeburn 1566: END
1.157 albertel 1567: if ($env{'form.editdisc'} || $env{'form.replydisc'}) {
1.108 raeburn 1568: my $now = time;
1569: my $ressymb = $symb;
1570: my $postidx = '';
1.157 albertel 1571: if ($env{'form.editdisc'}) {
1.108 raeburn 1572: $postidx = $idx;
1573: }
1574: if (@currnewattach > 0) {
1575: $attachnum += @currnewattach;
1576: }
1577: $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver));
1578: if ($attachnum > 0) {
1579: if (@currnewattach > 0) {
1580: $newattachmsg .= '<b>New attachments</b><br />';
1581: if (@currnewattach > 1) {
1582: $newattachmsg .= '<ol>';
1583: foreach my $item (@currnewattach) {
1584: $item =~ m#.*/([^/]+)$#;
1585: $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
1586: }
1587: $newattachmsg .= '</ol>'."\n";
1588: } else {
1589: $currnewattach[0] =~ m#.*/([^/]+)$#;
1590: $newattachmsg .= '<a href="'.$currnewattach[0].'">'.$1.'</a><br />'."\n";
1591: }
1592: }
1593: if ($attachmsg) {
1594: $r->print("<b>Retained attachments</b>:$attachmsg<br />\n");
1595: }
1596: if ($newattachmsg) {
1597: $r->print("$newattachmsg<br />");
1598: }
1599: }
1600: }
1601: $r->print(&generate_preview_button().
1602: &Apache::lonhtmlcommon::htmlareaselectactive('comment').
1603: '</body></html>');
1.6 albertel 1604: }
1605:
1.97 raeburn 1606: sub print_display_options {
1.111 raeburn 1607: my ($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl) = @_;
1.135 albertel 1608: &Apache::loncommon::content_type($r,'text/html');
1609: $r->send_http_header;
1.98 raeburn 1610:
1.97 raeburn 1611: my $function = &Apache::loncommon::get_users_function();
1612: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1.157 albertel 1613: $env{'user.domain'});
1.97 raeburn 1614: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1615: '','');
1616:
1617: my %lt = &Apache::lonlocal::texthash(
1618: 'dido' => 'Discussion display options',
1619: 'pref' => 'Display Preference',
1620: 'curr' => 'Current setting ',
1621: 'actn' => 'Action',
1622: 'deff' => 'Default for all discussions',
1623: 'prca' => 'Preferences can be set for this discussion that determine ....',
1624: 'whpo' => 'Which posts are displayed when you display this bulletin board or resource, and',
1.111 raeburn 1625: 'unwh' => 'Under what circumstances posts are identified as "NEW", and',
1626: 'wipa' => 'Whether individual posts can be marked as read/unread',
1.97 raeburn 1627: 'allposts' => 'All posts',
1628: 'unread' => 'New posts only',
1.111 raeburn 1629: 'unmark' => 'Posts not marked read',
1.97 raeburn 1630: 'ondisp' => 'Once displayed',
1.111 raeburn 1631: 'onmark' => 'Once marked not NEW ',
1632: 'toggon' => 'Shown',
1633: 'toggoff' => 'Not shown',
1.97 raeburn 1634: 'disa' => 'Posts displayed?',
1.111 raeburn 1635: 'npmr' => 'New posts cease to be identified as "NEW"?',
1636: 'dotm' => 'Option to mark each post as read/unread?',
1.97 raeburn 1637: 'chgt' => 'Change to ',
1638: 'mkdf' => 'Set to ',
1.111 raeburn 1639: 'yhni' => 'You have not indicated that you wish to change any of the discussion settings',
1.97 raeburn 1640: 'ywbr' => 'You will be returned to the previous page if you click OK.'
1641: );
1642:
1.111 raeburn 1643: my $dispchangeA = $lt{'unread'};
1644: my $dispchangeB = $lt{'unmark'};
1.97 raeburn 1645: my $markchange = $lt{'ondisp'};
1.111 raeburn 1646: my $toggchange = $lt{'toggon'};
1.97 raeburn 1647: my $currdisp = $lt{'allposts'};
1648: my $currmark = $lt{'onmark'};
1649: my $discdisp = 'allposts';
1650: my $discmark = 'onmark';
1.111 raeburn 1651: my $currtogg = $lt{'toggoff'};
1652: my $disctogg = 'toggoff';
1.97 raeburn 1653:
1.111 raeburn 1654: if ($dispchgA eq 'allposts') {
1655: $dispchangeA = $lt{'allposts'};
1.97 raeburn 1656: $currdisp = $lt{'unread'};
1657: $discdisp = 'unread';
1658: }
1.111 raeburn 1659:
1.97 raeburn 1660: if ($markchg eq 'markonread') {
1661: $markchange = $lt{'onmark'};
1662: $currmark = $lt{'ondisp'};
1663: $discmark = 'ondisp';
1664: }
1.111 raeburn 1665:
1666: if ($dispchgB eq 'onlyunread') {
1667: $dispchangeB = $lt{'unread'};
1668: $currdisp = $lt{'unmark'};
1669: $discdisp = 'unmark';
1670: }
1671: if ($toggchg eq 'toggoff') {
1672: $toggchange = $lt{'toggoff'};
1673: $currtogg = $lt{'toggon'};
1674: $disctogg = 'toggon';
1675: }
1.152 albertel 1676: my $html=&Apache::lonxml::xmlbegin();
1.97 raeburn 1677: $r->print(<<END);
1.152 albertel 1678: $html
1.97 raeburn 1679: <head>
1680: <title>$lt{'dido'}</title>
1681: <meta http-equiv="pragma" content="no-cache" />
1682: <script>
1.111 raeburn 1683: function discdispChk(caller) {
1684: var disctogg = '$toggchg'
1685: if (caller == 0) {
1686: if (document.modifydisp.discdisp[0].checked == true) {
1687: if (document.modifydisp.discdisp[1].checked == true) {
1688: document.modifydisp.discdisp[1].checked = false
1689: }
1690: }
1691: }
1692: if (caller == 1) {
1693: if (document.modifydisp.discdisp[1].checked == true) {
1694: if (document.modifydisp.discdisp[0].checked == true) {
1695: document.modifydisp.discdisp[0].checked = false
1696: }
1697: if (disctogg == 'toggon') {
1698: document.modifydisp.disctogg.checked = true
1699: }
1700: if (disctogg == 'toggoff') {
1701: document.modifydisp.disctogg.checked = false
1702: }
1703: }
1704: }
1705: if (caller == 2) {
1706: var dispchgB = '$dispchgB'
1707: if (disctogg == 'toggoff') {
1708: if (document.modifydisp.disctogg.checked == true) {
1709: if (dispchgB == 'onlyunmark') {
1710: document.modifydisp.discdisp[1].checked = false
1711: }
1712: }
1713: }
1714: }
1715: }
1716:
1.97 raeburn 1717: function setDisp() {
1718: var prev = "$previous"
1719: var chktotal = 0
1.111 raeburn 1720: if (document.modifydisp.discdisp[0].checked == true) {
1721: document.modifydisp.$dispchgA.value = "$symb"
1722: chktotal ++
1723: }
1724: if (document.modifydisp.discdisp[1].checked == true) {
1725: document.modifydisp.$dispchgB.value = "$symb"
1.97 raeburn 1726: chktotal ++
1727: }
1728: if (document.modifydisp.discmark.checked == true) {
1729: document.modifydisp.$markchg.value = "$symb"
1730: chktotal ++
1731: }
1.111 raeburn 1732: if (document.modifydisp.disctogg.checked == true) {
1733: document.modifydisp.$toggchg.value = "$symb"
1734: chktotal ++
1735: }
1.97 raeburn 1736: if (chktotal > 0) {
1737: document.modifydisp.submit()
1738: } else {
1739: if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}")) {
1740: if (prev > 0) {
1741: location.href = "$feedurl?previous=$previous"
1742: } else {
1743: location.href = "$feedurl"
1744: }
1745: }
1746: }
1747: }
1748: </script>
1749: </head>
1750: $bodytag
1751: <form name="modifydisp" method="post" action="/adm/feedback">
1.111 raeburn 1752: $lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li><li>$lt{'wipa'}</li></ol>
1.97 raeburn 1753: <br />
1754: <table border="0" cellpadding="0" cellspacing="0">
1755: <tr>
1756: <td width="100%" bgcolor="#000000">
1757: <table width="100%" border="0" cellpadding="1" cellspacing="0">
1758: <tr>
1759: <td width="100%" bgcolor="#000000">
1760: <table border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
1761: <tr bgcolor="$tabcolor">
1762: <td><b>$lt{'pref'}</b></td>
1763: <td><b>$lt{'curr'}</b></td>
1764: <td><b>$lt{'actn'}?</b></td>
1765: </tr>
1766: <tr bgcolor="#dddddd">
1767: <td>$lt{'disa'}</td>
1768: <td>$lt{$discdisp}</td>
1.151 albertel 1769: <td><label><input type="checkbox" name="discdisp" onClick="discdispChk('0')" /> $lt{'chgt'} "$dispchangeA"</label>
1.111 raeburn 1770: <br />
1.151 albertel 1771: <label><input type="checkbox" name="discdisp" onClick="discdispChk('1')" /> $lt{'chgt'} "$dispchangeB"</label>
1.111 raeburn 1772: </td>
1.97 raeburn 1773: </tr><tr bgcolor="#eeeeee">
1774: <td>$lt{'npmr'}</td>
1775: <td>$lt{$discmark}</td>
1.151 albertel 1776: <td><label><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</label></td>
1.111 raeburn 1777: </tr><tr bgcolor="#dddddd">
1778: <td>$lt{'dotm'}</td>
1779: <td>$lt{$disctogg}</td>
1.151 albertel 1780: <td><label><input type="checkbox" name="disctogg" onClick="discdispChk('2')" />$lt{'chgt'} "$toggchange"</label></td>
1.97 raeburn 1781: </tr>
1782: </table>
1783: </td>
1784: </tr>
1785: </table>
1786: </td>
1787: </tr>
1788: </table>
1789: <br />
1790: <br />
1.137 albertel 1791: <input type="hidden" name="symb" value="$symb" />
1.97 raeburn 1792: <input type="hidden" name="previous" value="$previous" />
1.111 raeburn 1793: <input type="hidden" name="$dispchgA" value=""/>
1794: <input type="hidden" name="$dispchgB" value=""/>
1.97 raeburn 1795: <input type="hidden" name="$markchg" value=""/>
1.111 raeburn 1796: <input type="hidden" name="$toggchg" value="" />
1.97 raeburn 1797: <input type="button" name="sub" value="Store Changes" onClick="javascript:setDisp()" />
1798: <br />
1799: <br />
1800: </form>
1801: </body>
1802: </html>
1803: END
1804: return;
1805: }
1806:
1.100 raeburn 1807: sub print_sortfilter_options {
1808: my ($r,$symb,$previous,$feedurl) = @_;
1.133 albertel 1809:
1.135 albertel 1810: &Apache::loncommon::content_type($r,'text/html');
1811: $r->send_http_header;
1812:
1.139 albertel 1813: &Apache::lonenc::check_encrypt(\$symb);
1.100 raeburn 1814: my @sections = ();
1815: my $section_sel = '';
1816: my $numsections = 0;
1817: my $numvisible = 5;
1818: my %sectioncount = ();
1.144 raeburn 1819:
1.157 albertel 1820: $numsections = &Apache::loncommon::get_sections($env{'course.'.$env{'request.course.id'}.'.domain'},$env{'course.'.$env{'request.course.id'}.'.num'},\%sectioncount);
1.144 raeburn 1821:
1.157 albertel 1822: if ($env{'request.course.sec'} !~ /^\s*$/) { #Restrict section choice to current section
1823: @sections = ('all',$env{'request.course.sec'});
1.144 raeburn 1824: $numvisible = 2;
1.100 raeburn 1825: } else {
1826: @sections = sort {$a cmp $b} keys(%sectioncount);
1827: unshift(@sections,'all'); # Put 'all' at the front of the list
1828: if ($numsections < 4) {
1829: $numvisible = $numsections + 1;
1830: }
1831: }
1832: foreach (@sections) {
1833: $section_sel .= " <option value=\"$_\" />$_\n";
1834: }
1835:
1836: my $function = &Apache::loncommon::get_users_function();
1837: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
1.157 albertel 1838: $env{'user.domain'});
1.100 raeburn 1839: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1840: '','');
1841: my %lt = &Apache::lonlocal::texthash(
1842: 'diso' => 'Discussion sorting and filtering options',
1843: 'diop' => 'Display Options',
1844: 'curr' => 'Current setting ',
1845: 'actn' => 'Action',
1.143 raeburn 1846: 'prca' => 'Set options that control the sort order of posts, and/or which posts are displayed.',
1.100 raeburn 1847: 'soor' => 'Sort order',
1.143 raeburn 1848: 'spur' => 'Specific user roles',
1849: 'sprs' => 'Specific role status',
1.100 raeburn 1850: 'spse' => 'Specific sections',
1851: 'psub' => 'Pick specific users (by name)',
1.101 raeburn 1852: 'shal' => 'Show a list of current posters'
1.100 raeburn 1853: );
1.143 raeburn 1854:
1855: my %sort_types = ();
1856: my %role_types = ();
1857: my %status_types = ();
1858: &sort_filter_names(\%sort_types,\%role_types,\%status_types);
1.152 albertel 1859: my $html=&Apache::lonxml::xmlbegin();
1.100 raeburn 1860: $r->print(<<END);
1.152 albertel 1861: $html
1.100 raeburn 1862: <head>
1863: <title>$lt{'diso'}</title>
1864: <meta http-equiv="pragma" content="no-cache" />
1.144 raeburn 1865: <script type="text/javascript">
1866: function verifyFilter() {
1867: var rolenum = 0
1868: for (var i=0; i<document.modifyshown.rolefilter.length; i++) {
1869: if (document.modifyshown.rolefilter.options[i].selected == true) {
1870: rolenum ++
1871: }
1872: }
1873: if (rolenum == 0) {
1874: document.modifyshown.rolefilter.options[0].selected = true
1875: }
1876:
1877: var secnum = 0
1878: for (var i=0; i<document.modifyshown.sectionpick.length; i++) {
1879: if (document.modifyshown.sectionpick.options[i].selected == true) {
1880: secnum ++
1881: }
1882: }
1883: if (secnum == 0) {
1884: document.modifyshown.sectionpick.options[0].selected = true
1885: }
1886: document.modifyshown.submit();
1887: }
1888: </script>
1.100 raeburn 1889: </head>
1890: $bodytag
1891: <form name="modifyshown" method="post" action="/adm/feedback">
1892: <b>$lt{'diso'}</b><br/> $lt{'prca'}
1893: <br /><br />
1894: <table border="0">
1895: <tr>
1896: <td><b>$lt{'soor'}</b></td>
1897: <td> </td>
1.143 raeburn 1898: <td><b>$lt{'sprs'}</b></td>
1.100 raeburn 1899: <td> </td>
1.143 raeburn 1900: <td><b>$lt{'spur'}</b></td>
1.100 raeburn 1901: <td> </td>
1902: <td><b>$lt{'spse'}</b></td>
1903: <td> </td>
1904: <td><b>$lt{'psub'}</b></td>
1905: </tr>
1906: <tr>
1.143 raeburn 1907: <td align="center">
1.100 raeburn 1908: <select name="sortposts">
1.144 raeburn 1909: <option value="ascdate" selected="selected" />$sort_types{'ascdate'}
1.143 raeburn 1910: <option value="descdate" />$sort_types{'descdate'}
1911: <option value="thread" />$sort_types{'thread'}
1912: <option value="subject" />$sort_types{'subject'}
1913: <option value="username" />$sort_types{'username'}
1914: <option value="lastfirst" />$sort_types{'lastfirst'}
1.100 raeburn 1915: </select>
1916: </td>
1917: <td> </td>
1.143 raeburn 1918: <td align="center">
1919: <select name="statusfilter">
1.144 raeburn 1920: <option value="all" selected="selected" />$status_types{'all'}
1.143 raeburn 1921: <option value="Active" />$status_types{'Active'}
1922: <option value="Expired" />$status_types{'Expired'}
1.100 raeburn 1923: </select>
1924: </td>
1925: <td> </td>
1.143 raeburn 1926: <td align="center">
1927: <select name="rolefilter" multiple="true" size="5">
1928: <option value="all" />$role_types{'all'}
1929: <option value="st" />$role_types{'st'}
1930: <option value="cc" />$role_types{'cc'}
1931: <option value="in" />$role_types{'in'}
1932: <option value="ta" />$role_types{'ta'}
1933: <option value="ep" />$role_types{'ep'}
1934: <option value="ad" />$role_types{'ad'}
1935: <option value="cr" />$role_types{'cr'}
1.100 raeburn 1936: </select>
1937: </td>
1938: <td> </td>
1.143 raeburn 1939: <td align="center">
1.100 raeburn 1940: <select name="sectionpick" multiple="true" size="$numvisible">
1941: $section_sel
1942: </select>
1943: </td>
1944: <td> </td>
1.151 albertel 1945: <td><label><input type="checkbox" name="posterlist" value="$symb" />$lt{'shal'}</label></td>
1.100 raeburn 1946: </tr>
1947: </table>
1948: <br />
1949: <br />
1950: <input type="hidden" name="previous" value="$previous" />
1951: <input type="hidden" name="applysort" value="$symb" />
1.144 raeburn 1952: <input type="button" name="sub" value="Store Changes" onClick="verifyFilter()" />
1.100 raeburn 1953: <br />
1954: <br />
1955: </form>
1956: </body>
1957: </html>
1958: END
1959: }
1960:
1.101 raeburn 1961: sub print_showposters {
1962: my ($r,$symb,$previous,$feedurl,$sortposts) = @_;
1.133 albertel 1963:
1.154 albertel 1964: &Apache::loncommon::content_type($r,'text/html');
1965: $r->send_http_header;
1966:
1.139 albertel 1967: &Apache::lonenc::check_encrypt(\$symb);
1.157 albertel 1968: my $crs='/'.$env{'request.course.id'};
1969: if ($env{'request.course.sec'}) {
1970: $crs.='_'.$env{'request.course.sec'};
1.102 raeburn 1971: }
1.101 raeburn 1972: $crs=~s/\_/\//g;
1973: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.157 albertel 1974: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
1975: $env{'course.'.$env{'request.course.id'}.'.domain'},
1976: $env{'course.'.$env{'request.course.id'}.'.num'});
1.101 raeburn 1977: my %namesort = ();
1978: my %postcounts = ();
1979: my %lt=&Apache::lonlocal::texthash(
1980: 'diso' => 'Discussion filtering options',
1981: );
1982: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
1983: '','');
1984: if ($contrib{'version'}) {
1985: for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
1986: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
1987: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
1988: unless ((($hidden) && (!$seeid)) || ($deleted)) {
1989: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
1990: my %names = &Apache::lonnet::get('environment',['firstname','lastname'],$contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
1991: my $lastname = $names{'lastname'};
1992: my $firstname = $names{'firstname'};
1993: if ($lastname eq '') {
1994: $lastname = '_';
1995: }
1996: if ($firstname eq '') {
1997: $firstname = '_';
1998: }
1999: unless (defined($namesort{$lastname})) {
2000: %{$namesort{$lastname}} = ();
2001: }
2002: my $poster = $contrib{$idx.':sendername'}.':'.$contrib{$idx.':senderdomain'};
2003: $postcounts{$poster} ++;
2004: if (defined($namesort{$lastname}{$firstname})) {
2005: if (!grep/^$poster$/,@{$namesort{$lastname}{$firstname}}) {
2006: push @{$namesort{$lastname}{$firstname}}, $poster;
2007: }
2008: } else {
2009: @{$namesort{$lastname}{$firstname}} = ("$poster");
2010: }
2011: }
2012: }
2013: }
2014: }
1.152 albertel 2015: my $html=&Apache::lonxml::xmlbegin();
1.101 raeburn 2016: $r->print(<<END);
1.152 albertel 2017: $html
1.101 raeburn 2018: <head>
2019: <title>$lt{'diso'}</title>
2020: <meta http-equiv="pragma" content="no-cache" />
2021: </head>
2022: $bodytag
2023: <form name="pickpostersform" method="post">
2024: <table border="0">
2025: <tr>
2026: <td bgcolor="#777777">
2027: <table border="0" cellpadding="3">
2028: <tr bgcolor="#e6ffff">
2029: <td><b>No.</b></td>
2030: <td><b>Select</b></td>
2031: <td><b>Fullname</b><font color="#999999">(Username/domain)</font></td>
2032: <td><b>Posts</td>
2033: </tr>
2034: END
2035: my $count = 0;
2036: foreach my $last (sort keys %namesort) {
2037: foreach my $first (sort keys %{$namesort{$last}}) {
2038: foreach (sort @{$namesort{$last}{$first}}) {
2039: my ($uname,$udom) = split/:/,$_;
2040: if (!$uname || !$udom) {
2041: next;
2042: } else {
2043: $count ++;
1.151 albertel 2044: $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 2045: }
2046: }
2047: }
2048: }
2049: $r->print(<<END);
2050: </table>
2051: </td>
2052: </tr>
2053: </table>
2054: <br />
2055: <input type="hidden" name="sortposts" value="$sortposts" />
2056: <input type="hidden" name="userpick" value="$symb" />
2057: <input type="button" name="store" value="Display posts" onClick="javascript:document.pickpostersform.submit()" />
2058: </form>
2059: </body>
2060: </html>
2061: END
2062: }
2063:
1.112 raeburn 2064: sub get_post_versions {
1.116 raeburn 2065: my ($versions,$incoming,$htmldecode,$numver) = @_;
2066: if ($incoming =~ /^<version num="0">/) {
2067: my $p = HTML::LCParser->new(\$incoming);
2068: my $done = 0;
2069: while ( (my $token = $p->get_tag("version")) && (!$done)) {
2070: my $num = $token->[1]{num};
2071: my $text = $p->get_text("/version");
2072: if (defined($numver)) {
2073: if ($num == $numver) {
2074: if ($htmldecode) {
2075: $text = &HTML::Entities::decode($text);
2076: }
2077: $$versions{$numver}=$text;
2078: $done = 1;
2079: }
2080: } else {
2081: if ($htmldecode) {
2082: $text = &HTML::Entities::decode($text);
2083: }
2084: $$versions{$num}=$text;
1.112 raeburn 2085: }
1.116 raeburn 2086: }
2087: } else {
2088: if (!defined($numver)) {
2089: $numver = 0;
2090: }
2091: if ($htmldecode) {
2092: $$versions{$numver} = $incoming;
1.112 raeburn 2093: } else {
1.116 raeburn 2094: $$versions{$numver} = &HTML::Entities::encode($incoming,'<>&"');
1.112 raeburn 2095: }
2096: }
2097: return;
2098: }
2099:
1.113 raeburn 2100: sub get_post_attachments {
2101: my ($attachments,$attachmenturls) = @_;
2102: my $num;
1.116 raeburn 2103: if ($attachmenturls =~ m/^<attachment id="0">/) {
2104: my $p = HTML::LCParser->new(\$attachmenturls);
2105: while (my $token = $p->get_tag("attachment","filename","post")) {
2106: if ($token->[0] eq "attachment") {
2107: $num = $token->[1]{id};
2108: %{$$attachments{$num}} =();
2109: } elsif ($token->[0] eq "filename") {
2110: $$attachments{$num}{'filename'} = $p->get_text("/filename");
2111: } elsif ($token->[0] eq "post") {
2112: my $id = $token->[1]{id};
2113: $$attachments{$num}{$id} = $p->get_text("/post");
2114: }
1.113 raeburn 2115: }
1.116 raeburn 2116: } else {
2117: %{$$attachments{'0'}} = ();
2118: $$attachments{'0'}{'filename'} = $attachmenturls;
2119: $$attachments{'0'}{'0'} = 'n';
1.113 raeburn 2120: }
1.116 raeburn 2121:
1.113 raeburn 2122: return;
2123: }
2124:
1.150 albertel 2125: sub fail_redirect {
1.6 albertel 2126: my ($r,$feedurl) = @_;
1.70 www 2127: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.150 albertel 2128: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.152 albertel 2129: my $html=&Apache::lonxml::xmlbegin();
1.6 albertel 2130: $r->print (<<ENDFAILREDIR);
1.152 albertel 2131: $html
2132: <head>
2133: <title>Feedback not sent</title>
1.63 albertel 2134: <meta http-equiv="pragma" content="no-cache" />
2135: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.5 www 2136: </head>
2137: <body bgcolor="#FFFFFF">
1.150 albertel 2138: <img align="right" src="$logo" />
1.8 www 2139: <b>Sorry, no recipients ...</b>
1.121 albertel 2140: <br /><a href="$feedurl">Continue</a>
1.5 www 2141: </body>
2142: </html>
2143: ENDFAILREDIR
2144: }
1.4 www 2145:
1.6 albertel 2146: sub redirect_back {
1.143 raeburn 2147: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$numpicks) = @_;
1.100 raeburn 2148: my $sorttag = '';
1.101 raeburn 2149: my $roletag = '';
2150: my $statustag = '';
2151: my $sectag = '';
2152: my $userpicktag = '';
2153: my $qrystr = '';
1.80 raeburn 2154: my $prevtag = '';
1.133 albertel 2155:
1.135 albertel 2156: &Apache::loncommon::content_type($r,'text/html');
2157: $r->send_http_header;
2158:
1.133 albertel 2159: &dewrapper(\$feedurl);
1.70 www 2160: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.80 raeburn 2161: if ($previous > 0) {
2162: $qrystr = 'previous='.$previous;
2163: if ($feedurl =~ /\?register=1/) {
2164: $feedurl .= '&'.$qrystr;
2165: } else {
2166: $feedurl .= '?'.$qrystr;
2167: }
2168: $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
2169: }
1.100 raeburn 2170: if (defined($sort)) {
2171: my $sortqry = 'sortposts='.$sort;
2172: if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) {
2173: $feedurl .= '&'.$sortqry;
2174: } else {
2175: $feedurl .= '?'.$sortqry;
2176: }
2177: $sorttag = '<input type="hidden" name="sortposts" value="'.$sort.'" />';
1.143 raeburn 2178: if (defined($numpicks)) {
1.101 raeburn 2179: my $userpickqry = 'totposters='.$numpicks;
2180: $feedurl .= '&'.$userpickqry;
2181: $userpicktag = '<input type="hidden" name="totposters" value="'.$numpicks.'" />';
2182: } else {
1.143 raeburn 2183: if (ref($sectionpick) eq 'ARRAY') {
2184: $feedurl .= '§ionpick=';
2185: $sectag .= '<input type="hidden" name="sectionpick" value="';
2186: foreach (@{$sectionpick}) {
2187: $feedurl .= $_.',';
2188: $sectag .= $_.',';
2189: }
2190: $feedurl =~ s/,$//;
2191: $sectag =~ s/,$//;
2192: $sectag .= '" />';
2193: } else {
2194: $feedurl .= '§ionpick='.$sectionpick;
2195: $sectag = '<input type="hidden" name="sectionpick" value="'.$sectionpick.'" />';
2196: }
2197: if (ref($rolefilter) eq 'ARRAY') {
2198: $feedurl .= '&rolefilter=';
2199: $roletag .= '<input type="hidden" name="rolefilter" value="';
2200: foreach (@{$rolefilter}) {
2201: $feedurl .= $_.',';
2202: $roletag .= $_.',';
2203: }
2204: $feedurl =~ s/,$//;
2205: $roletag =~ s/,$//;
2206: $roletag .= '" />';
2207: } else {
2208: $feedurl .= '&rolefilter='.$rolefilter;
2209: $roletag = '<input type="hidden" name="rolefilter" value="'.$rolefilter.'" />';
2210: }
1.101 raeburn 2211: $feedurl .= '&statusfilter='.$statusfilter;
2212: $statustag ='<input type="hidden" name="statusfilter" value="'.$statusfilter.'" />';
2213: }
1.100 raeburn 2214: }
1.129 albertel 2215: $feedurl=&Apache::lonenc::check_encrypt($feedurl);
1.150 albertel 2216: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.152 albertel 2217: my $html=&Apache::lonxml::xmlbegin();
1.6 albertel 2218: $r->print (<<ENDREDIR);
1.152 albertel 2219: $html
1.3 www 2220: <head>
2221: <title>Feedback sent</title>
1.63 albertel 2222: <meta http-equiv="pragma" content="no-cache" />
1.80 raeburn 2223: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.2 www 2224: </head>
1.49 www 2225: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1.150 albertel 2226: <img align="right" src="$logo" />
1.5 www 2227: $typestyle
1.32 albertel 2228: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1.63 albertel 2229: <font color="red">$status</font>
1.49 www 2230: <form name="reldt" action="$feedurl" target="loncapaclient">
1.80 raeburn 2231: $prevtag
1.100 raeburn 2232: $sorttag
1.101 raeburn 2233: $statustag
2234: $roletag
2235: $sectag
2236: $userpicktag
1.49 www 2237: </form>
1.121 albertel 2238: <br /><a href="$feedurl">Continue</a>
1.2 www 2239: </body>
2240: </html>
2241: ENDREDIR
2242: }
1.6 albertel 2243:
2244: sub no_redirect_back {
2245: my ($r,$feedurl) = @_;
1.107 www 2246: my $nofeed=&mt('Sorry, no feedback possible on this resource ...');
1.120 albertel 2247: my $continue=&mt('Continue');
1.152 albertel 2248: my $html=&Apache::lonxml::xmlbegin();
1.6 albertel 2249: $r->print (<<ENDNOREDIR);
1.152 albertel 2250: $html
2251: <head>
2252: <title>Feedback not sent</title>
1.63 albertel 2253: <meta http-equiv="pragma" content="no-cache" />
1.7 albertel 2254: ENDNOREDIR
2255:
1.8 www 2256: if ($feedurl!~/^\/adm\/feedback/) {
1.129 albertel 2257: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.
2258: &Apache::lonenc::check_encrypt($feedurl).'">');
1.7 albertel 2259: }
1.129 albertel 2260: $feedurl=&Apache::lonenc::check_encrypt($feedurl);
1.150 albertel 2261: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.8 www 2262: $r->print (<<ENDNOREDIRTWO);
1.2 www 2263: </head>
1.49 www 2264: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
1.150 albertel 2265: <img align="right" src="$logo" />
1.107 www 2266: <b>$nofeed</b>
1.121 albertel 2267: <br /><a href="$feedurl">$continue</a>
1.2 www 2268: </body>
2269: </html>
1.8 www 2270: ENDNOREDIRTWO
1.2 www 2271: }
1.6 albertel 2272:
2273: sub screen_header {
1.141 raeburn 2274: my ($feedurl,$symb) = @_;
1.65 www 2275: my $msgoptions='';
2276: my $discussoptions='';
1.157 albertel 2277: unless (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
1.167 www 2278: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) {
1.65 www 2279: $msgoptions=
1.151 albertel 2280: '<p><label><input type="checkbox" name="author" /> '.
2281: &mt('Feedback to resource author').'</label></p>';
1.65 www 2282: }
2283: if (&feedback_available(1)) {
2284: $msgoptions.=
1.151 albertel 2285: '<p><label><input type="checkbox" name="question" /> '.
2286: &mt('Question about resource content').'</label></p>';
1.65 www 2287: }
2288: if (&feedback_available(0,1)) {
2289: $msgoptions.=
1.151 albertel 2290: '<p><label><input type="checkbox" name="course" /> '.
2291: &mt('Question/Comment/Feedback about course content').
2292: '</label></p>';
1.65 www 2293: }
2294: if (&feedback_available(0,0,1)) {
2295: $msgoptions.=
1.151 albertel 2296: '<p><label><input type="checkbox" name="policy" /> '.
2297: &mt('Question/Comment/Feedback about course policy').
2298: '</label></p>';
1.65 www 2299: }
2300: }
1.157 albertel 2301: if ($env{'request.course.id'}) {
1.141 raeburn 2302: if (&discussion_open(undef,$symb) &&
1.90 albertel 2303: &Apache::lonnet::allowed('pch',
1.157 albertel 2304: $env{'request.course.id'}.
2305: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
1.151 albertel 2306: $discussoptions='<label><input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
1.157 albertel 2307: ($env{'form.replydisc'}?' checked="1"':'').' /> '.
1.65 www 2308: &mt('Contribution to course discussion of resource');
1.151 albertel 2309: $discussoptions.='</label><br /><label><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
1.65 www 2310: &mt('Anonymous contribution to course discussion of resource').
1.173 ! www 2311: ' <i>('.&mt('name only visible to course faculty').')</i></label> '.
! 2312: '<a href="/adm/preferences?action=changescreenname">'.&mt('Change Screenname').'</a>';
1.141 raeburn 2313: }
1.65 www 2314: }
1.149 albertel 2315: if ($msgoptions) { $msgoptions='<h2><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/feedback.gif').'" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
1.65 www 2316: if ($discussoptions) {
1.149 albertel 2317: $discussoptions='<h2><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/chat.gif').'" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
1.65 www 2318: return $msgoptions.$discussoptions;
1.6 albertel 2319: }
2320:
2321: sub resource_output {
2322: my ($feedurl) = @_;
1.46 albertel 2323: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
1.6 albertel 2324: $usersaw=~s/\<body[^\>]*\>//gi;
2325: $usersaw=~s/\<\/body\>//gi;
2326: $usersaw=~s/\<html\>//gi;
2327: $usersaw=~s/\<\/html\>//gi;
2328: $usersaw=~s/\<head\>//gi;
2329: $usersaw=~s/\<\/head\>//gi;
2330: $usersaw=~s/action\s*\=/would_be_action\=/gi;
2331: return $usersaw;
2332: }
2333:
2334: sub clear_out_html {
1.39 www 2335: my ($message,$override)=@_;
1.88 www 2336: unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
1.107 www 2337: # Always allow the <m>-tag
2338: my %html=(M=>1);
2339: # Check if more is allowed
1.157 albertel 2340: my $cid=$env{'request.course.id'};
2341: if (($env{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
1.39 www 2342: ($override)) {
1.37 albertel 2343: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
1.88 www 2344: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
2345: # <SUP>
1.107 www 2346: %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
2347: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
1.155 albertel 2348: M=>1, ALGEBRA=>1, SUB=>1, SUP=>1, SPAN=>1,
1.107 www 2349: H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
2350: }
2351: # Do the substitution of everything that is not explicitly allowed
2352: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
1.48 albertel 2353: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
1.107 www 2354: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
1.48 albertel 2355: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
1.6 albertel 2356: return $message;
2357: }
2358:
2359: sub assemble_email {
1.40 albertel 2360: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1.6 albertel 2361: my $email=<<"ENDEMAIL";
2362: $message
2363: ENDEMAIL
2364: my $citations=<<"ENDCITE";
2365: <h2>Previous attempts of student (if applicable)</h2>
2366: $prevattempts
1.63 albertel 2367: <br /><hr />
1.6 albertel 2368: <h2>Original screen output (if applicable)</h2>
2369: $usersaw
1.40 albertel 2370: <h2>Correct Answer(s) (if applicable)</h2>
2371: $useranswer
1.6 albertel 2372: ENDCITE
2373: return ($email,$citations);
2374: }
2375:
1.35 www 2376: sub secapply {
2377: my $rec=shift;
1.36 www 2378: my $defaultflag=shift;
2379: $rec=~s/\s+//g;
2380: $rec=~s/\@/\:/g;
2381: my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
2382: if ($sections) {
2383: foreach (split(/\;/,$sections)) {
1.157 albertel 2384: if (($_ eq $env{'request.course.sec'}) ||
1.36 www 2385: ($defaultflag && ($_ eq '*'))) {
2386: return $adr;
2387: }
2388: }
2389: } else {
2390: return $rec;
2391: }
2392: return '';
1.35 www 2393: }
2394:
1.163 albertel 2395: =pod
2396:
2397: =over 4
2398:
2399: =item *
2400:
2401: decide_receiver($feedurl,$author,$question,$course,$policy,$defaultflag);
2402:
2403: Arguments
2404: $feedurl - /res/ url of resource (only need if $author is true)
2405: $author,$question,$course,$policy - all true/false parameters
2406: if true will attempt to find the addresses of user that should receive
2407: this type of feedback (author - feedback to author of resource $feedurl,
2408: $question 'Resource Content Questions', $course 'Course Content Question',
2409: $policy 'Course Policy')
2410: (Additionally it also checks $env for whether the corresponding form.<name>
2411: element exists, for ease of use in a html response context)
2412:
2413: $defaultflag - (internal should be left blank) if true gather addresses
2414: that aren't for a section even if I have a section
2415: (used for reccursion internally, first we look for
2416: addresses for our specific section then we recurse
2417: and look for non section addresses)
2418:
2419: Returns
2420: $typestyle - string of html text, describing what addresses were found
2421: %to - a hash, which keys are addresses of users to send messages to
2422: the keys will look like name:domain
2423:
2424: =cut
2425:
1.6 albertel 2426: sub decide_receiver {
1.36 www 2427: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1.6 albertel 2428: my $typestyle='';
2429: my %to=();
1.157 albertel 2430: if ($env{'form.author'}||$author) {
1.163 albertel 2431: $typestyle.='Submitting as Author Feedback<br />';
1.6 albertel 2432: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
2433: $to{$2.':'.$1}=1;
2434: }
1.157 albertel 2435: if ($env{'form.question'}||$question) {
1.163 albertel 2436: $typestyle.='Submitting as Question<br />';
1.24 harris41 2437: foreach (split(/\,/,
1.157 albertel 2438: $env{'course.'.$env{'request.course.id'}.'.question.email'})
1.24 harris41 2439: ) {
1.36 www 2440: my $rec=&secapply($_,$defaultflag);
2441: if ($rec) { $to{$rec}=1; }
1.24 harris41 2442: }
1.6 albertel 2443: }
1.157 albertel 2444: if ($env{'form.course'}||$course) {
1.63 albertel 2445: $typestyle.='Submitting as Comment<br />';
1.24 harris41 2446: foreach (split(/\,/,
1.157 albertel 2447: $env{'course.'.$env{'request.course.id'}.'.comment.email'})
1.24 harris41 2448: ) {
1.36 www 2449: my $rec=&secapply($_,$defaultflag);
2450: if ($rec) { $to{$rec}=1; }
1.24 harris41 2451: }
1.6 albertel 2452: }
1.157 albertel 2453: if ($env{'form.policy'}||$policy) {
1.63 albertel 2454: $typestyle.='Submitting as Policy Feedback<br />';
1.24 harris41 2455: foreach (split(/\,/,
1.157 albertel 2456: $env{'course.'.$env{'request.course.id'}.'.policy.email'})
1.24 harris41 2457: ) {
1.36 www 2458: my $rec=&secapply($_,$defaultflag);
2459: if ($rec) { $to{$rec}=1; }
1.24 harris41 2460: }
1.6 albertel 2461: }
1.36 www 2462: if ((scalar(%to) eq '0') && (!$defaultflag)) {
2463: ($typestyle,%to)=
2464: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
2465: }
1.6 albertel 2466: return ($typestyle,%to);
1.36 www 2467: }
2468:
2469: sub feedback_available {
2470: my ($question,$course,$policy)=@_;
2471: my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
2472: return scalar(%to);
1.6 albertel 2473: }
2474:
2475: sub send_msg {
1.43 www 2476: my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1.6 albertel 2477: my $status='';
2478: my $sendsomething=0;
1.24 harris41 2479: foreach (keys %to) {
1.6 albertel 2480: if ($_) {
1.22 www 2481: my $declutter=&Apache::lonnet::declutter($feedurl);
1.8 www 2482: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.43 www 2483: 'Feedback ['.$declutter.']',$email,$citations,$feedurl,
2484: $attachmenturl)=~/ok/) {
1.63 albertel 2485: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1.6 albertel 2486: } else {
2487: $sendsomething++;
2488: }
2489: }
1.24 harris41 2490: }
1.18 www 2491:
2492: my %record=&Apache::lonnet::restore('_feedback');
2493: my ($temp)=keys %record;
2494: unless ($temp=~/^error\:/) {
2495: my %newrecord=();
2496: $newrecord{'resource'}=$feedurl;
2497: $newrecord{'subnumber'}=$record{'subnumber'}+1;
2498: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1.63 albertel 2499: $status.='<br />'.&mt('Not registered').'<br />';
1.18 www 2500: }
2501: }
2502:
1.6 albertel 2503: return ($status,$sendsomething);
2504: }
2505:
1.13 www 2506: sub adddiscuss {
1.78 raeburn 2507: my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1.13 www 2508: my $status='';
1.122 raeburn 2509: my $realsymb;
2510: if ($symb=~/^bulletin___/) {
2511: my $filename=(&Apache::lonnet::decode_symb($symb))[2];
2512: $filename=~s|^adm/wrapper/||;
2513: $realsymb=&Apache::lonnet::symbread($filename);
2514: }
2515: if (&discussion_open(undef,$realsymb) &&
1.157 albertel 2516: &Apache::lonnet::allowed('pch',$env{'request.course.id'}.
2517: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
1.20 www 2518:
1.13 www 2519: my %contrib=('message' => $email,
1.157 albertel 2520: 'sendername' => $env{'user.name'},
2521: 'senderdomain' => $env{'user.domain'},
2522: 'screenname' => $env{'environment.screenname'},
2523: 'plainname' => $env{'environment.firstname'}.' '.
2524: $env{'environment.middlename'}.' '.
2525: $env{'environment.lastname'}.' '.
2526: $env{'enrironment.generation'},
1.78 raeburn 2527: 'attachmenturl'=> $attachmenturl,
2528: 'subject' => $subject);
1.157 albertel 2529: if ($env{'form.replydisc'}) {
2530: $contrib{'replyto'}=(split(/\:\:\:/,$env{'form.replydisc'}))[1];
1.65 www 2531: }
1.14 www 2532: if ($anon) {
2533: $contrib{'anonymous'}='true';
2534: }
1.13 www 2535: if (($symb) && ($email)) {
1.157 albertel 2536: if ($env{'form.editdisc'}) {
1.102 raeburn 2537: my %newcontrib = ();
2538: $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
2539: $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
2540: $contrib{'timestamp'} = time;
2541: $contrib{'history'} = '';
2542: my $numoldver = 0;
1.157 albertel 2543: my ($oldsymb,$oldidx)=split(/\:\:\:/,$env{'form.editdisc'});
1.132 albertel 2544: &Apache::lonenc::check_decrypt(\$oldsymb);
1.110 raeburn 2545: $oldsymb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
1.102 raeburn 2546: # get timestamp for last post and history
1.157 albertel 2547: my %oldcontrib=&Apache::lonnet::restore($oldsymb,$env{'request.course.id'},
2548: $env{'course.'.$env{'request.course.id'}.'.domain'},
2549: $env{'course.'.$env{'request.course.id'}.'.num'});
1.102 raeburn 2550: if (defined($oldcontrib{$oldidx.':replyto'})) {
2551: $contrib{'replyto'} = $oldcontrib{$oldidx.':replyto'};
2552: }
2553: if (defined($oldcontrib{$oldidx.':history'})) {
2554: if ($oldcontrib{$oldidx.':history'} =~ /:/) {
2555: my @oldversions = split/:/,$oldcontrib{$oldidx.':history'};
2556: $numoldver = @oldversions;
2557: } else {
2558: $numoldver = 1;
2559: }
2560: $contrib{'history'} = $oldcontrib{$oldidx.':history'}.':';
2561: }
1.108 raeburn 2562: my $numnewver = $numoldver + 1;
1.102 raeburn 2563: if (defined($oldcontrib{$oldidx.':subject'})) {
1.112 raeburn 2564: if ($oldcontrib{$oldidx.':subject'} =~ /^<version num="0">/) {
2565: $contrib{'subject'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
2566: $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.$contrib{'subject'};
1.108 raeburn 2567: } else {
1.112 raeburn 2568: $contrib{'subject'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':subject'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
1.108 raeburn 2569: }
1.102 raeburn 2570: }
2571: if (defined($oldcontrib{$oldidx.':message'})) {
1.112 raeburn 2572: if ($oldcontrib{$oldidx.':message'} =~ /^<version num="0">/) {
2573: $contrib{'message'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
2574: $contrib{'message'} = $oldcontrib{$oldidx.':message'}.$contrib{'message'};
1.108 raeburn 2575: } else {
1.112 raeburn 2576: $contrib{'message'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':message'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
1.108 raeburn 2577: }
1.102 raeburn 2578: }
2579: $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
2580: foreach (keys %contrib) {
2581: my $key = $oldidx.':'.&Apache::lonnet::escape($oldsymb).':'.$_;
2582: $newcontrib{$key} = $contrib{$_};
2583: }
1.157 albertel 2584: my $put_reply = &Apache::lonnet::putstore($env{'request.course.id'},
1.102 raeburn 2585: \%newcontrib,
1.157 albertel 2586: $env{'course.'.$env{'request.course.id'}.'.domain'},
2587: $env{'course.'.$env{'request.course.id'}.'.num'});
1.102 raeburn 2588: $status='Editing class discussion'.($anon?' (anonymous)':'');
2589: } else {
2590: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1.157 albertel 2591: &Apache::lonnet::store(\%contrib,$symb,$env{'request.course.id'},
2592: $env{'course.'.$env{'request.course.id'}.'.domain'},
2593: $env{'course.'.$env{'request.course.id'}.'.num'});
1.102 raeburn 2594: }
1.21 www 2595: my %storenewentry=($symb => time);
1.63 albertel 2596: $status.='<br />'.&mt('Updating discussion time').': '.
1.21 www 2597: &Apache::lonnet::put('discussiontimes',\%storenewentry,
1.157 albertel 2598: $env{'course.'.$env{'request.course.id'}.'.domain'},
2599: $env{'course.'.$env{'request.course.id'}.'.num'});
1.13 www 2600: }
1.17 www 2601: my %record=&Apache::lonnet::restore('_discussion');
2602: my ($temp)=keys %record;
2603: unless ($temp=~/^error\:/) {
2604: my %newrecord=();
2605: $newrecord{'resource'}=$symb;
2606: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.63 albertel 2607: $status.='<br />'.&mt('Registering').': '.
1.21 www 2608: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20 www 2609: }
2610: } else {
2611: $status.='Failed.';
1.17 www 2612: }
1.63 albertel 2613: return $status.'<br />';
1.13 www 2614: }
2615:
1.33 www 2616: # ----------------------------------------------------------- Preview function
2617:
2618: sub show_preview {
2619: my $r=shift;
1.135 albertel 2620: &Apache::loncommon::content_type($r,'text/html');
2621: $r->send_http_header;
1.157 albertel 2622: my $message=&clear_out_html($env{'form.comment'});
1.165 albertel 2623: &newline_to_br(\$message);
1.106 www 2624: $message=&Apache::lonspeller::markeduptext($message);
1.33 www 2625: $message=&Apache::lontexconvert::msgtexconverted($message);
1.157 albertel 2626: my $subject=&clear_out_html($env{'form.subject'});
1.78 raeburn 2627: $subject=~s/\n/\<br \/\>/g;
2628: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.153 albertel 2629: my $html=&Apache::lonxml::xmlbegin();
2630: $r->print($html.'<head>'.
2631: '</head><body><table border="2"><tr><td>'.
2632: '<b>Subject:</b> '.$subject.'<br /><br />'.
2633: $message.'</td></tr></table></body></html>');
1.33 www 2634: }
2635:
1.165 albertel 2636:
2637: sub newline_to_br {
2638: my ($message)=@_;
2639: my $newmessage;
2640: my $parser=HTML::LCParser->new($message);
2641: while (my $token=$parser->get_token()) {
2642: if ($token->[0] eq 'T') {
2643: my $text=$token->[1];
2644: $text=~s/\n/\<br \/\>/g;
2645: $newmessage.=$text;
2646: } elsif ($token->[0] eq 'D' || $token->[0] eq 'C') {
2647: $newmessage.=$token->[1];
2648: } elsif ($token->[0] eq 'PI' || $token->[0] eq 'E') {
2649: $newmessage.=$token->[2];
2650: } elsif ($token->[0] eq 'S') {
2651: $newmessage.=$token->[4];
2652: }
2653:
2654: }
2655: $$message=$newmessage;
2656: }
2657:
1.33 www 2658: sub generate_preview_button {
1.171 www 2659: my ($formname,$fieldname)=@_;
2660: unless ($formname) { $formname='mailform'; }
2661: unless ($fieldname) { $fieldname='comment'; }
1.107 www 2662: my $pre=&mt("Show Preview and Check Spelling");
1.33 www 2663: return(<<ENDPREVIEW);
2664: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.78 raeburn 2665: <input type="hidden" name="subject">
1.33 www 2666: <input type="hidden" name="comment" />
1.65 www 2667: <input type="button" value="$pre"
1.171 www 2668: 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 2669: </form>
2670: ENDPREVIEW
2671: }
1.71 www 2672:
1.108 raeburn 2673: sub modify_attachments {
2674: my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls)=@_;
1.157 albertel 2675: my $orig_subject = &Apache::lonnet::unescape($env{'form.subject'});
1.124 raeburn 2676: my $subject=&clear_out_html($orig_subject);
1.108 raeburn 2677: $subject=~s/\n/\<br \/\>/g;
2678: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.157 albertel 2679: my $timestamp=$env{'form.timestamp'};
2680: my $numoldver=$env{'form.numoldver'};
1.108 raeburn 2681: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Attachments',
2682: '','');
2683: my $msg = '';
1.113 raeburn 2684: my %attachments = ();
1.108 raeburn 2685: my %currattach = ();
2686: if ($idx) {
1.113 raeburn 2687: &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\%attachments,\%currattach,$currdelold);
1.108 raeburn 2688: }
1.139 albertel 2689: &Apache::lonenc::check_encrypt(\$symb);
1.152 albertel 2690: my $html=&Apache::lonxml::xmlbegin();
1.108 raeburn 2691: $r->print(<<END);
1.152 albertel 2692: $html
1.108 raeburn 2693: <head>
2694: <title>Managing Attachments</title>
2695: <script>
2696: function setAction () {
2697: document.modattachments.action = document.modattachments.origpage.value;
2698: document.modattachments.submit();
2699: }
2700: </script>
2701: </head>
2702: $bodytag
2703: <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
2704: <table border="2">
2705: <tr>
2706: <td>
1.124 raeburn 2707: <b>Subject:</b> $subject</b><br /><br />
1.108 raeburn 2708: END
2709: if ($idx) {
2710: if ($attachmenturls) {
2711: my @currold = keys %currattach;
2712: if (@currold > 0) {
2713: $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 2714: foreach my $id (@currold) {
2715: my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'});
2716: $attachurl =~ m#/([^/]+)$#;
1.151 albertel 2717: $r->print('<label><input type="checkbox" name="deloldattach" value="'.$id.'" /> '.$1.'</label><br />'."\n");
1.108 raeburn 2718: }
2719: $r->print("<br />");
2720: }
2721: }
2722: }
2723: if (@{$currnewattach} > 0) {
2724: $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");
2725: foreach (@{$currnewattach}) {
2726: $_ =~ m#/([^/]+)$#;
1.151 albertel 2727: $r->print('<label><input type="checkbox" name="delnewattach" value="'.$_.'" /> '.$1.'</label><br />'."\n");
1.108 raeburn 2728: }
2729: $r->print("<br />");
2730: }
2731: $r->print(<<END);
2732: Add a new attachment to this post. <input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onClick="this.form.submit()" />
2733: </td>
2734: </tr>
2735: </table>
1.157 albertel 2736: <input type="hidden" name="subject" value="$env{'form.subject'}" />
2737: <input type="hidden" name="comment" value="$env{'form.comment'}" />
2738: <input type="hidden" name="timestamp" value="$env{'form.timestamp'}" />
2739: <input type="hidden" name="idx" value="$env{'form.idx'}" />
2740: <input type="hidden" name="numoldver" value="$env{'form.numoldver'}" />
2741: <input type="hidden" name="origpage" value="$env{'form.origpage'}" />
2742: <input type="hidden" name="anondiscuss" value="$env{'form.anondiscuss'}" />
2743: <input type="hidden" name="discuss" value="$env{'form.discuss'}" />
1.108 raeburn 2744: END
2745: foreach (@{$currnewattach}) {
2746: $r->print('<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n");
2747: }
2748: foreach (@{$currdelold}) {
2749: $r->print('<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n");
2750: }
2751: $r->print(<<END);
2752: <input type="button" name="rtntoedit" value="Store Changes" onClick="setAction()"/>
2753: </form>
2754: </body>
2755: </html>
2756: END
2757: return;
2758: }
2759:
2760: sub process_attachments {
2761: my ($currnewattach,$currdelold,$keepold) = @_;
1.158 albertel 2762:
2763: @{$currnewattach}=
2764: &Apache::loncommon::get_env_multiple('form.currnewattach');
2765: @{$currdelold}=
2766: &Apache::loncommon::get_env_multiple('form.deloldattach');
1.157 albertel 2767: if (exists($env{'form.delnewattach'})) {
1.158 albertel 2768: my @currdelnew =
2769: &Apache::loncommon::get_env_multiple('form.delnewattach');
1.108 raeburn 2770: my @currnew = ();
2771: foreach my $newone (@{$currnewattach}) {
2772: my $delflag = 0;
2773: foreach (@currdelnew) {
2774: if ($newone eq $_) {
2775: $delflag = 1;
2776: last;
2777: }
2778: }
2779: unless ($delflag) {
2780: push @currnew, $newone;
2781: }
2782: }
2783: @{$currnewattach} = @currnew;
2784: }
1.158 albertel 2785: @{$keepold} = &Apache::loncommon::get_env_multiple('form.keepold');
1.108 raeburn 2786: }
2787:
2788: sub generate_attachments_button {
2789: my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,$numoldver,$mode) = @_;
2790: my $origpage = $ENV{'REQUEST_URI'};
2791: my $att=$attachnum.' '.&mt("attachments");
2792: my $response = (<<END);
2793: <form name="attachment" action="/adm/feedback?attach=$ressymb" method="post">
2794: Click to add/remove attachments: <input type="button" value="$att"
1.124 raeburn 2795: 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 2796: END
2797: unless ($mode eq 'board') {
2798: $response .= 'javascript:anonchk();';
2799: }
2800: $response .= (<<ENDATTACH);
2801: this.form.submit();" />
2802: <input type="hidden" name="origpage" value="$origpage" />
2803: <input type="hidden" name="idx" value="$idx" />
2804: <input type="hidden" name="timestamp" value="$now" />
2805: <input type="hidden" name="subject" />
2806: <input type="hidden" name="comment" />
1.164 albertel 2807: <input type="hidden" name="anondiscuss" value = "0" />
2808: <input type="hidden" name="discuss" value = "0" />
1.108 raeburn 2809: <input type="hidden" name="numoldver" value="$numoldver" />
2810: ENDATTACH
2811: if (defined($deloldattach)) {
2812: if (@{$deloldattach} > 0) {
2813: foreach (@{$deloldattach}) {
2814: $response .= '<input type="hidden" name="deloldattach" value="'.$_.'" />'."\n";
2815: }
2816: }
2817: }
2818: if (defined($currnewattach)) {
2819: if (@{$currnewattach} > 0) {
2820: foreach (@{$currnewattach}) {
2821: $response .= '<input type="hidden" name="currnewattach" value="'.$_.'" />'."\n";
2822: }
2823: }
2824: }
2825: $response .= '</form>';
2826: return $response;
2827: }
2828:
2829: sub extract_attachments {
2830: my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;
1.116 raeburn 2831: %{$attachments}=();
2832: &get_post_attachments($attachments,$attachmenturls);
2833: foreach my $id (sort keys %{$attachments}) {
2834: if (exists($$attachments{$id}{$numoldver})) {
2835: if (defined($currdelold)) {
2836: if (@{$currdelold} > 0) {
2837: unless (grep/^$id$/,@{$currdelold}) {
2838: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2839: }
1.113 raeburn 2840: } else {
2841: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2842: }
1.116 raeburn 2843: } else {
2844: $$currattach{$id} = $$attachments{$id}{$numoldver};
1.108 raeburn 2845: }
2846: }
1.116 raeburn 2847: }
2848: my @attached = (sort { $a <=> $b } keys %{$currattach});
2849: if (@attached == 1) {
2850: my $id = $attached[0];
2851: my $attachurl;
2852: if ($attachmenturls =~ m/^<attachment id="0">/) {
2853: $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
2854: } else {
2855: $attachurl = $$attachments{$id}{'filename'};
2856: }
2857: $attachurl=~m|/([^/]+)$|;
2858: $$message.='<br /><a href="'.$attachurl.'"><tt>'.
2859: $1.'</tt></a><br />';
2860: &Apache::lonnet::allowuploaded('/adm/feedback',
2861: $attachurl);
2862: } elsif (@attached > 1) {
2863: $$message.='<ol>';
2864: foreach (@attached) {
2865: my $id = $_;
1.113 raeburn 2866: my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
1.116 raeburn 2867: my ($fname)
2868: =($attachurl=~m|/([^/]+)$|);
2869: $$message .= '<li><a href="'.$attachurl.
2870: '"><tt>'.
2871: $fname.'</tt></a></li>';
1.108 raeburn 2872: &Apache::lonnet::allowuploaded('/adm/feedback',
1.116 raeburn 2873: $attachurl);
1.108 raeburn 2874: }
1.116 raeburn 2875: $$message .= '</ol>';
1.108 raeburn 2876: }
2877: }
2878:
2879: sub construct_attachmenturl {
2880: my ($currnewattach,$keepold,$symb,$idx)=@_;
2881: my $oldattachmenturl;
2882: my $newattachmenturl;
1.113 raeburn 2883: my $startnum = 0;
1.108 raeburn 2884: my $currver = 0;
1.157 albertel 2885: if (($env{'form.editdisc'}) && ($idx)) {
2886: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
2887: $env{'course.'.$env{'request.course.id'}.'.domain'},
2888: $env{'course.'.$env{'request.course.id'}.'.num'});
1.108 raeburn 2889: $oldattachmenturl = $contrib{$idx.':attachmenturl'};
2890: if ($contrib{$idx.':history'}) {
2891: if ($contrib{$idx.':history'} =~ /:/) {
2892: my @oldversions = split/:/,$contrib{$idx.':history'};
2893: $currver = 1 + scalar(@oldversions);
2894: } else {
2895: $currver = 2;
2896: }
2897: } else {
2898: $currver = 1;
2899: }
2900: if ($oldattachmenturl) {
1.113 raeburn 2901: if ($oldattachmenturl =~ m/^<attachment id="0">/) {
2902: my %attachments = ();
2903: my $prevver = $currver-1;
2904: &get_post_attachments(\%attachments,$oldattachmenturl);
1.116 raeburn 2905: my $numattach = scalar(keys %attachments);
1.113 raeburn 2906: $startnum += $numattach;
2907: foreach my $num (sort {$a <=> $b} keys %attachments) {
2908: $newattachmenturl .= '<attachment id="'.$num.'"><filename>'.$attachments{$num}{'filename'}.'</filename>';
1.116 raeburn 2909: foreach $_ (sort {$a <=> $b} keys %{$attachments{$num}}) {
2910: unless ($_ eq 'filename') {
2911: $newattachmenturl .= '<post id="'.$_.'">'.$attachments{$num}{$_}.'</post>';
2912: }
1.113 raeburn 2913: }
2914: if (grep/^$num$/,@{$keepold}) {
2915: $newattachmenturl .= '<post id="'.$currver.'">'.$attachments{$num}{$prevver}.'</post>';
1.108 raeburn 2916: }
1.113 raeburn 2917: $newattachmenturl .= '</attachment>';
1.108 raeburn 2918: }
2919: } else {
1.116 raeburn 2920: $newattachmenturl = '<attachment id="0"><filename>'.&HTML::Entities::encode($oldattachmenturl).'</filename><post id="0">n</post>';
1.108 raeburn 2921: unless (grep/^0$/,@{$keepold}) {
1.113 raeburn 2922: $newattachmenturl .= '<post id="1">n</post>';
1.108 raeburn 2923: }
1.113 raeburn 2924: $newattachmenturl .= '</attachment>';
1.108 raeburn 2925: $startnum ++;
2926: }
2927: }
2928: }
2929: for (my $i=0; $i<@{$currnewattach}; $i++) {
2930: my $attachnum = $startnum + $i;
1.113 raeburn 2931: $newattachmenturl .= '<attachment id="'.$attachnum.'"><filename>'.&HTML::Entities::encode($$currnewattach[$i]).'</filename><post id="'.$currver.'">n</post></attachment>';
1.108 raeburn 2932: }
2933: return $newattachmenturl;
2934: }
1.128 raeburn 2935:
2936: sub has_discussion {
2937: my $resourcesref = shift;
2938: my $navmap = Apache::lonnavmaps::navmap->new();
2939: my @allres=$navmap->retrieveResources();
2940: foreach my $resource (@allres) {
2941: if ($resource->hasDiscussion()) {
1.162 albertel 2942: my $ressymb = $resource->wrap_symb();
1.128 raeburn 2943: push @{$resourcesref}, $ressymb;
2944: }
2945: }
2946: return;
1.143 raeburn 2947: }
2948:
2949: sub sort_filter_names {
2950: my ($sort_types,$role_types,$status_types) = @_;
2951: %{$sort_types} = (
2952: ascdate => 'Date order - oldest first',
2953: descdate => 'Date order - newest first',
2954: thread => 'Threaded',
2955: subject => 'By subject',
2956: username => 'By domain and username',
2957: lastfirst => 'By last name, first name'
2958: );
2959: %{$role_types} = (
2960: all => 'All roles',
2961: st => 'Students',
2962: cc => 'Course Coordinators',
2963: in => 'Instructors',
2964: ta => 'TAs',
2965: ep => 'Exam proctors',
2966: ad => 'Administrators',
2967: cr => 'Custom roles'
2968: );
2969: %{$status_types} = (
2970: all => 'Roles of any status',
2971: Active => 'Only active roles',
2972: Expired => 'Only inactive roles'
2973: );
2974: }
1.108 raeburn 2975:
1.6 albertel 2976: sub handler {
2977: my $r = shift;
1.8 www 2978: if ($r->header_only) {
1.71 www 2979: &Apache::loncommon::content_type($r,'text/html');
1.8 www 2980: $r->send_http_header;
2981: return OK;
2982: }
1.15 www 2983:
2984: # --------------------------- Get query string for limited number of parameters
2985:
1.97 raeburn 2986: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.137 albertel 2987: ['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 2988:
1.157 albertel 2989: if ($env{'form.discsymb'}) {
2990: my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.discsymb'});
1.111 raeburn 2991: my $readkey = $symb.'_read';
2992: my $chgcount = 0;
1.157 albertel 2993: my %readinghash = &Apache::lonnet::get('nohist_'.$env{'request.course.id'}.'_discuss',[$readkey],$env{'user.domain'},$env{'user.name'});
2994: foreach my $key (keys %env) {
1.111 raeburn 2995: if ($key =~ m/^form\.postunread_(\d+)/) {
2996: if ($readinghash{$readkey} =~ /\.$1\./) {
2997: $readinghash{$readkey} =~ s/\.$1\.//;
2998: $chgcount ++;
2999: }
3000: } elsif ($key =~ m/^form\.postread_(\d+)/) {
3001: unless ($readinghash{$readkey} =~ /\.$1\./) {
3002: $readinghash{$readkey} .= '.'.$1.'.';
3003: $chgcount ++;
3004: }
3005: }
3006: }
3007: if ($chgcount > 0) {
1.157 albertel 3008: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
3009: \%readinghash,$env{'user.domain'},$env{'user.name'});
1.111 raeburn 3010: }
1.133 albertel 3011: &redirect_back($r,$feedurl,&mt('Marked postings read/unread').'<br />',
1.157 albertel 3012: '0','0','',$env{'form.previous'},'','','',);
1.111 raeburn 3013: return OK;
3014: }
1.157 albertel 3015: if ($env{'form.allversions'}) {
1.109 raeburn 3016: &Apache::loncommon::content_type($r,'text/html');
3017: $r->send_http_header;
1.152 albertel 3018: my $html=&Apache::lonxml::xmlbegin();
1.133 albertel 3019: my $bodytag=&Apache::loncommon::bodytag('Discussion Post Versions');
1.143 raeburn 3020: $r->print(<<END);
1.152 albertel 3021: $html
1.109 raeburn 3022: <head>
3023: <title>Post Versions</title>
3024: <meta http-equiv="pragma" content="no-cache" />
3025: </head>
3026: $bodytag
3027: END
1.157 albertel 3028: my $crs='/'.$env{'request.course.id'};
3029: if ($env{'request.course.sec'}) {
3030: $crs.='_'.$env{'request.course.sec'};
1.109 raeburn 3031: }
1.133 albertel 3032: $crs=~s|_|/|g;
1.109 raeburn 3033: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.157 albertel 3034: my ($symb,$idx)=split(/\:\:\:/,$env{'form.allversions'});
1.133 albertel 3035: ($symb)=&get_feedurl_and_clean_symb($symb);
1.109 raeburn 3036: if ($idx > 0) {
1.116 raeburn 3037: my %messages = ();
3038: my %subjects = ();
3039: my %attachmsgs = ();
3040: my %allattachments = ();
3041: my %imsfiles = ();
3042: my ($screenname,$plainname);
1.157 albertel 3043: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
3044: $env{'course.'.$env{'request.course.id'}.'.domain'},
3045: $env{'course.'.$env{'request.course.id'}.'.num'});
1.133 albertel 3046: $r->print(&get_post_contents(\%contrib,$idx,$seeid,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname));
1.109 raeburn 3047: }
3048: return OK;
3049: }
1.157 albertel 3050: if ($env{'form.posterlist'}) {
3051: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.applysort'});
3052: &print_showposters($r,$symb,$env{'form.previous'},$feedurl,
3053: $env{'form.sortposts'});
1.101 raeburn 3054: return OK;
3055: }
1.157 albertel 3056: if ($env{'form.userpick'}) {
1.133 albertel 3057: my @posters = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.157 albertel 3058: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.userpick'});
1.101 raeburn 3059: my $numpicks = @posters;
1.133 albertel 3060: my %discinfo;
3061: $discinfo{$symb.'_userpick'} = join('&',@posters);
1.157 albertel 3062: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
3063: \%discinfo,$env{'user.domain'},$env{'user.name'});
1.133 albertel 3064: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0',
1.157 albertel 3065: '',$env{'form.previous'},$env{'form.sortposts'},'','','',
1.133 albertel 3066: $numpicks);
1.101 raeburn 3067: return OK;
3068: }
1.157 albertel 3069: if ($env{'form.applysort'}) {
3070: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.applysort'});
1.133 albertel 3071: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0',
1.157 albertel 3072: '',$env{'form.previous'},$env{'form.sortposts'},
3073: $env{'form.rolefilter'},$env{'form.statusfilter'},
3074: $env{'form.sectionpick'});
1.100 raeburn 3075: return OK;
1.157 albertel 3076: } elsif ($env{'form.cmd'} eq 'sortfilter') {
3077: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
3078: &print_sortfilter_options($r,$symb,$env{'form.previous'},$feedurl);
1.100 raeburn 3079: return OK;
1.157 albertel 3080: } elsif ($env{'form.navtime'}) {
1.99 raeburn 3081: my %discinfo = ();
3082: my @resources = ();
1.157 albertel 3083: if (defined($env{'form.navmaps'})) {
3084: if ($env{'form.navmaps'} =~ /:/) {
3085: @resources = split/:/,$env{'form.navmaps'};
1.128 raeburn 3086: } else {
1.157 albertel 3087: @resources = ("$env{'form.navmaps'}");
1.128 raeburn 3088: }
1.99 raeburn 3089: } else {
1.128 raeburn 3090: &has_discussion(\@resources);
1.99 raeburn 3091: }
3092: my $numitems = @resources;
3093: my $feedurl = '/adm/navmaps';
1.157 albertel 3094: if ($env{'form.navurl'}) { $feedurl .= '?'.$env{'form.navurl'}; }
1.99 raeburn 3095: my %lt = &Apache::lonlocal::texthash(
3096: 'mnpa' => 'Marked "New" posts as read in a total of',
1.128 raeburn 3097: 'robb' => 'resources/bulletin boards.',
3098: 'twnp' => 'There are currently no resources or bulletin boards with unread discussion postings.'
1.99 raeburn 3099: );
3100: foreach (@resources) {
3101: my $ressymb=$_;
1.132 albertel 3102: &Apache::lonenc::check_decrypt(\$ressymb);
1.99 raeburn 3103: my $lastkey = $ressymb.'_lastread';
1.157 albertel 3104: $discinfo{$lastkey} = $env{'form.navtime'};
1.99 raeburn 3105: }
1.128 raeburn 3106: my $textline = "<b>$lt{'mnpa'} $numitems $lt{'robb'}</b>";
3107: if ($numitems > 0) {
1.157 albertel 3108: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
3109: \%discinfo,$env{'user.domain'},$env{'user.name'});
1.128 raeburn 3110: } else {
3111: $textline = "<b>$lt{'twnp'}</b>";
3112: }
1.99 raeburn 3113: &Apache::loncommon::content_type($r,'text/html');
3114: $r->send_http_header;
1.150 albertel 3115: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
1.152 albertel 3116: my $html=&Apache::lonxml::xmlbegin();
1.99 raeburn 3117: $r->print (<<ENDREDIR);
1.152 albertel 3118: $html
1.99 raeburn 3119: <head>
3120: <title>New posts marked as read</title>
3121: <meta http-equiv="pragma" content="no-cache" />
3122: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
3123: </head>
3124: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1.150 albertel 3125: <img align="right" src="$logo" />
1.128 raeburn 3126: $textline
1.99 raeburn 3127: <form name="reldt" action="$feedurl" target="loncapaclient">
3128: </form>
1.121 albertel 3129: <br /><a href="$feedurl">Continue</a>
1.99 raeburn 3130: </body>
3131: </html>
3132: ENDREDIR
3133: return OK;
1.157 albertel 3134: } elsif ($env{'form.modifydisp'}) {
3135: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.modifydisp'});
1.133 albertel 3136: my ($dispchgA,$dispchgB,$markchg,$toggchg) =
1.157 albertel 3137: split(/_/,$env{'form.changes'});
3138: &print_display_options($r,$symb,$env{'form.previous'},$dispchgA,
1.133 albertel 3139: $dispchgB,$markchg,$toggchg,$feedurl);
1.97 raeburn 3140: return OK;
1.157 albertel 3141: } elsif ($env{'form.markondisp'} || $env{'form.markonread'} ||
3142: $env{'form.allposts'} || $env{'form.onlyunread'} ||
3143: $env{'form.onlyunmark'} || $env{'form.toggoff'} ||
3144: $env{'form.toggon'} || $env{'form.markread'}) {
3145: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
1.137 albertel 3146: my %discinfo;
1.133 albertel 3147: # ------------------------ Modify setting for read/unread toggle for each post
1.157 albertel 3148: if ($env{'form.toggoff'}) { $discinfo{$symb.'_readtoggle'}=0; }
3149: if ($env{'form.toggon'}) { $discinfo{$symb.'_readtoggle'}=1; }
1.133 albertel 3150: # --------- Modify setting for identification of 'NEW' posts in this discussion
1.157 albertel 3151: if ($env{'form.markondisp'}) {
1.137 albertel 3152: $discinfo{$symb.'_lastread'} = time;
3153: $discinfo{$symb.'_markondisp'} = 1;
3154: }
1.157 albertel 3155: if ($env{'form.markonread'}) {
3156: if ( $env{'form.previous'} > 0 ) {
3157: $discinfo{$symb.'_lastread'} = $env{'form.previous'};
1.137 albertel 3158: }
3159: $discinfo{$symb.'_markondisp'} = 0;
1.84 raeburn 3160: }
1.133 albertel 3161: # --------------------------------- Modify display setting for this discussion
1.157 albertel 3162: if ($env{'form.allposts'}) {
1.137 albertel 3163: $discinfo{$symb.'_showonlyunread'} = 0;
3164: $discinfo{$symb.'_showonlyunmark'} = 0;
1.84 raeburn 3165: }
1.157 albertel 3166: if ($env{'form.onlyunread'}) { $discinfo{$symb.'_showonlyunread'} = 1; }
3167: if ($env{'form.onlyunmark'}) { $discinfo{$symb.'_showonlyunmark'} = 1; }
1.137 albertel 3168: # ----------------------------------------------------- Mark new posts not NEW
1.157 albertel 3169: if ($env{'form.markread'}) { $discinfo{$symb.'_lastread'} = time; }
3170: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
3171: \%discinfo,$env{'user.domain'},$env{'user.name'});
3172: my $previous=$env{'form.previous'};
3173: if ($env{'form.markondisp'}) { $previous=undef; }
1.133 albertel 3174: &redirect_back($r,$feedurl,&mt('Changed display status').'<br />',
3175: '0','0','',$previous);
1.84 raeburn 3176: return OK;
1.157 albertel 3177: } elsif (($env{'form.hide'}) || ($env{'form.unhide'})) {
1.15 www 3178: # ----------------------------------------------------------------- Hide/unhide
1.157 albertel 3179: my $entry=$env{'form.hide'}?$env{'form.hide'}:$env{'form.unhide'};
1.133 albertel 3180: my ($symb,$idx)=split(/\:\:\:/,$entry);
3181: ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
1.15 www 3182:
1.157 albertel 3183: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
3184: $env{'course.'.$env{'request.course.id'}.'.domain'},
3185: $env{'course.'.$env{'request.course.id'}.'.num'});
1.15 www 3186:
1.133 albertel 3187: my $currenthidden=$contrib{'hidden'};
3188: my $currentstudenthidden=$contrib{'studenthidden'};
1.15 www 3189:
1.157 albertel 3190: my $crs='/'.$env{'request.course.id'};
3191: if ($env{'request.course.sec'}) {
3192: $crs.='_'.$env{'request.course.sec'};
1.133 albertel 3193: }
3194: $crs=~s/\_/\//g;
3195: my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.102 raeburn 3196:
1.157 albertel 3197: if ($env{'form.hide'}) {
1.133 albertel 3198: $currenthidden.='.'.$idx.'.';
3199: unless ($seeid) {
3200: $currentstudenthidden.='.'.$idx.'.';
3201: }
3202: } else {
3203: $currenthidden=~s/\.$idx\.//g;
3204: }
3205: my %newhash=('hidden' => $currenthidden);
1.157 albertel 3206: if ( ($env{'form.hide'}) && (!$seeid) ) {
1.133 albertel 3207: $newhash{'studenthidden'} = $currentstudenthidden;
3208: }
1.38 www 3209:
1.157 albertel 3210: &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
3211: $env{'course.'.$env{'request.course.id'}.'.domain'},
3212: $env{'course.'.$env{'request.course.id'}.'.num'});
1.38 www 3213:
1.133 albertel 3214: &redirect_back($r,$feedurl,&mt('Changed discussion status').'<br />',
1.157 albertel 3215: '0','0','',$env{'form.previous'});
1.135 albertel 3216: return OK;
1.157 albertel 3217: } elsif ($env{'form.cmd'}=~/^(threadedoff|threadedon)$/) {
3218: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
3219: if ($env{'form.cmd'} eq 'threadedon') {
1.69 www 3220: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
3221: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
3222: } else {
3223: &Apache::lonnet::del('environment',['threadeddiscussion']);
3224: &Apache::lonnet::delenv('environment\.threadeddiscussion');
1.72 albertel 3225: }
1.133 albertel 3226: &redirect_back($r,$feedurl,&mt('Changed discussion view mode').'<br />',
1.157 albertel 3227: '0','0','',$env{'form.previous'});
1.135 albertel 3228: return OK;
1.157 albertel 3229: } elsif ($env{'form.deldisc'}) {
1.38 www 3230: # --------------------------------------------------------------- Hide for good
1.157 albertel 3231: my ($symb,$idx)=split(/\:\:\:/,$env{'form.deldisc'});
1.133 albertel 3232: ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
1.157 albertel 3233: my %contrib=&Apache::lonnet::restore($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: my %newhash=('deleted' => $contrib{'deleted'}.".$idx.");
1.157 albertel 3237: &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
3238: $env{'course.'.$env{'request.course.id'}.'.domain'},
3239: $env{'course.'.$env{'request.course.id'}.'.num'});
1.135 albertel 3240: &redirect_back($r,$feedurl,&mt('Changed discussion status').'<br />',
1.157 albertel 3241: '0','0','',$env{'form.previous'});
1.135 albertel 3242: return OK;
1.157 albertel 3243: } elsif ($env{'form.preview'}) {
1.33 www 3244: # -------------------------------------------------------- User wants a preview
3245: &show_preview($r);
1.135 albertel 3246: return OK;
1.157 albertel 3247: } elsif ($env{'form.attach'}) {
1.108 raeburn 3248: # -------------------------------------------------------- Work on attachments
3249: &Apache::loncommon::content_type($r,'text/html');
3250: $r->send_http_header;
3251: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','anondiscuss','discuss']);
1.133 albertel 3252: my (@currnewattach,@currdelold,@keepold);
1.108 raeburn 3253: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
1.157 albertel 3254: if (exists($env{'form.addnewattach.filename'})) {
3255: unless (length($env{'form.addnewattach'})>131072) {
3256: my $subdir = 'feedback/'.$env{'form.timestamp'};
1.108 raeburn 3257: my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);
1.139 albertel 3258: push @currnewattach, $newattachment;
1.108 raeburn 3259: }
3260: }
1.133 albertel 3261: my $attachmenturls;
1.157 albertel 3262: my ($symb) = &get_feedurl_and_clean_symb($env{'form.attach'});
3263: my $idx = $env{'form.idx'};
1.108 raeburn 3264: if ($idx) {
1.157 albertel 3265: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
3266: $env{'course.'.$env{'request.course.id'}.'.domain'},
3267: $env{'course.'.$env{'request.course.id'}.'.num'});
1.108 raeburn 3268: $attachmenturls = $contrib{$idx.':attachmenturl'};
3269: }
1.133 albertel 3270: &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,
3271: $attachmenturls);
1.135 albertel 3272: return OK;
1.157 albertel 3273: } elsif ($env{'form.export'}) {
1.116 raeburn 3274: &Apache::loncommon::content_type($r,'text/html');
3275: $r->send_http_header;
1.157 albertel 3276: my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.export'});
1.133 albertel 3277: my $mode='board';
1.116 raeburn 3278: my $status='OPEN';
1.157 albertel 3279: my $previous=$env{'form.previous'};
1.168 albertel 3280: if ($feedurl =~ /\.(problem|exam|quiz|assess|survey|form|library|task)$/) {
1.116 raeburn 3281: $mode='problem';
3282: $status=$Apache::inputtags::status[-1];
3283: }
3284: my $discussion = &list_discussion($mode,$status,$symb);
3285: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion');
3286: $r->print($bodytag.$discussion);
3287: return OK;
1.15 www 3288: } else {
3289: # ------------------------------------------------------------- Normal feedback
1.157 albertel 3290: my $feedurl=$env{'form.postdata'};
1.133 albertel 3291: $feedurl=~s/^http\:\/\///;
3292: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
3293: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
3294: $feedurl=~s/\?.+$//;
1.8 www 3295:
1.133 albertel 3296: my $symb;
1.157 albertel 3297: if ($env{'form.replydisc'}) {
3298: $symb=(split(/\:\:\:/,$env{'form.replydisc'}))[0];
1.133 albertel 3299: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3300: $feedurl=&Apache::lonnet::clutter($url);
1.157 albertel 3301: } elsif ($env{'form.editdisc'}) {
3302: $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
1.52 www 3303: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1.133 albertel 3304: $feedurl=&Apache::lonnet::clutter($url);
1.157 albertel 3305: } elsif ($env{'form.origpage'}) {
1.133 albertel 3306: $symb="";
3307: } else {
3308: $symb=&Apache::lonnet::symbread($feedurl);
3309: }
3310: unless ($symb) {
1.157 albertel 3311: $symb=$env{'form.symb'};
1.133 albertel 3312: if ($symb) {
3313: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3314: $feedurl=&Apache::lonnet::clutter($url);
3315: }
3316: }
3317: &Apache::lonenc::check_decrypt(\$symb);
3318: my $goahead=1;
1.168 albertel 3319: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
1.133 albertel 3320: unless ($symb) { $goahead=0; }
3321: }
3322: # backward compatibility (bulletin boards used to be 'wrapped')
1.159 raeburn 3323: &dewrapper(\$feedurl);
1.133 albertel 3324: if (!$goahead) {
3325: # Ambiguous Problem Resource
3326: $r->internal_redirect('/adm/ambiguous');
3327: return OK;
1.31 www 3328: }
1.8 www 3329: # Go ahead with feedback, no ambiguous reference
1.133 albertel 3330: unless (
3331: (
3332: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
3333: )
3334: ||
1.157 albertel 3335: ($env{'request.course.id'} && ($feedurl!~m:^/adm:))
1.133 albertel 3336: ||
1.157 albertel 3337: ($env{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.133 albertel 3338: ) {
1.135 albertel 3339: &Apache::loncommon::content_type($r,'text/html');
3340: $r->send_http_header;
1.133 albertel 3341: # Unable to give feedback
3342: &no_redirect_back($r,$feedurl);
3343: }
1.6 albertel 3344: # --------------------------------------------------- Print login screen header
1.157 albertel 3345: unless ($env{'form.sendit'}) {
1.135 albertel 3346: &Apache::loncommon::content_type($r,'text/html');
3347: $r->send_http_header;
1.141 raeburn 3348: my $options=&screen_header($feedurl,$symb);
1.133 albertel 3349: if ($options) {
3350: &mail_screen($r,$feedurl,$options);
3351: } else {
3352: &fail_redirect($r,$feedurl);
3353: }
3354: return OK;
1.6 albertel 3355: }
3356:
3357: # Get previous user input
1.9 albertel 3358: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.157 albertel 3359: $symb,$env{'user.name'},$env{'user.domain'},
3360: $env{'request.course.id'});
1.6 albertel 3361:
3362: # Get output from resource
3363: my $usersaw=&resource_output($feedurl);
3364:
1.50 albertel 3365: # Get resource answer (need to allow student to view grades for this to work)
3366: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1.40 albertel 3367: my $useranswer=&Apache::loncommon::get_student_answers(
1.157 albertel 3368: $symb,$env{'user.name'},$env{'user.domain'},
3369: $env{'request.course.id'});
1.50 albertel 3370: &Apache::lonnet::delenv('allowed.vgr');
1.42 www 3371: # Get attachments, if any, and not too large
3372: my $attachmenturl='';
1.157 albertel 3373: if (($env{'form.origpage'}) || ($env{'form.editdisc'}) ||
3374: ($env{'form.replydisc'})) {
1.133 albertel 3375: my ($symb,$idx);
1.157 albertel 3376: if ($env{'form.replydisc'}) {
3377: ($symb,$idx)=split(/\:\:\:/,$env{'form.replydisc'});
3378: } elsif ($env{'form.editdisc'}) {
3379: ($symb,$idx)=split(/\:\:\:/,$env{'form.editdisc'});
3380: } elsif ($env{'form.origpage'}) {
3381: $symb = $env{'form.symb'};
1.133 albertel 3382: }
1.132 albertel 3383: &Apache::lonenc::check_decrypt(\$symb);
1.133 albertel 3384: my @currnewattach = ();
3385: my @deloldattach = ();
3386: my @keepold = ();
3387: &process_attachments(\@currnewattach,\@deloldattach,\@keepold);
3388: $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
3389: $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);
1.157 albertel 3390: } elsif ($env{'form.attachment.filename'}) {
3391: unless (length($env{'form.attachment'})>131072) {
1.82 albertel 3392: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1.42 www 3393: }
3394: }
1.6 albertel 3395: # Filter HTML out of message (could be nasty)
1.157 albertel 3396: my $message=&clear_out_html($env{'form.comment'});
1.6 albertel 3397:
3398: # Assemble email
1.8 www 3399: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.133 albertel 3400: $usersaw,$useranswer);
1.40 albertel 3401:
1.6 albertel 3402: # Who gets this?
3403: my ($typestyle,%to) = &decide_receiver($feedurl);
3404:
3405: # Actually send mail
1.43 www 3406: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
1.133 albertel 3407: $attachmenturl,%to);
1.13 www 3408:
3409: # Discussion? Store that.
3410:
1.32 albertel 3411: my $numpost=0;
1.157 albertel 3412: if ($env{'form.discuss'} || $env{'form.anondiscuss'}) {
3413: my $subject = &clear_out_html($env{'form.subject'});
3414: my $anonmode=(defined($env{'form.anondiscuss'}));
1.133 albertel 3415: $typestyle.=&adddiscuss($symb,$message,$anonmode,$attachmenturl,
3416: $subject);
1.32 albertel 3417: $numpost++;
1.14 www 3418: }
1.133 albertel 3419:
1.6 albertel 3420: # Receipt screen and redirect back to where came from
1.157 albertel 3421: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$env{'form.previous'});
1.133 albertel 3422: }
3423: return OK;
3424: }
1.6 albertel 3425:
1.133 albertel 3426: sub wrap_symb {
3427: my ($ressymb)=@_;
3428: if ($ressymb =~ /bulletin___\d+___/) {
3429: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
3430: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
3431: }
1.6 albertel 3432: }
1.133 albertel 3433: return $ressymb;
3434: }
3435: sub dewrapper {
3436: my ($feedurl)=@_;
3437: if ($$feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
3438: $$feedurl=~s|^/adm/wrapper||;
3439: }
3440: }
3441:
3442: sub get_feedurl {
3443: my ($symb)=@_;
3444: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
3445: my $feedurl = &Apache::lonnet::clutter($url);
3446: &dewrapper(\$feedurl);
3447: return $feedurl;
1.15 www 3448: }
1.1 www 3449:
1.133 albertel 3450: sub get_feedurl_and_clean_symb {
3451: my ($symb)=@_;
3452: &Apache::lonenc::check_decrypt(\$symb);
3453: # backward compatibility (bulletin boards used to be 'wrapped')
3454: unless ($symb =~ m|bulletin___\d+___adm/wrapper|) {
3455: $symb=~s|(bulletin___\d+___)|$1adm/wrapper|;
3456: }
3457: my $feedurl = &get_feedurl($symb);
3458: return ($symb,$feedurl);
3459: }
1.1 www 3460: 1;
3461: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>