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