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