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