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