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