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