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