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