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