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