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