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