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