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