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