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