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