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