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