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