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