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