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