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