Annotation of loncom/interface/lonfeedback.pm, revision 1.91

1.1       www         1: # The LearningOnline Network
                      2: # Feedback
                      3: #
1.91    ! matthew     4: # $Id: lonfeedback.pm,v 1.90 2004/06/03 20:28:22 albertel 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 ()
                     38: use Apache::lonhtmlcommon();
1.54      www        39: 
1.90      albertel   40: sub discussion_closed {
                     41:     my ($status)=@_;
1.77      www        42:     if (!($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER'
                     43: 	  || $status eq 'OPEN')) {
1.90      albertel   44: 	return '1';
1.75      albertel   45:     }
1.89      albertel   46:     my $close=&Apache::lonnet::EXT('resource.0.discussend');
                     47:     if (defined($close) && $close ne '' && $close < time) {
1.90      albertel   48: 	return '1'
1.89      albertel   49:     }
1.90      albertel   50:     return 0;
                     51: }
1.84      raeburn    52: 
1.90      albertel   53: sub list_discussion {
                     54:     my ($mode,$status,$symb)=@_;
                     55: 
                     56:     if (&discussion_closed($status)) {
                     57: 	return '';
                     58:     }
1.84      raeburn    59:     my @bgcols = ("#cccccc","#eeeeee");
1.57      www        60:     my $discussiononly=0;
                     61:     if ($mode eq 'board') { $discussiononly=1; }
1.55      www        62:     unless ($ENV{'request.course.id'}) { return ''; }
                     63:     my $crs='/'.$ENV{'request.course.id'};
                     64:     if ($ENV{'request.course.sec'}) {
                     65: 	$crs.='_'.$ENV{'request.course.sec'};
                     66:     }                 
                     67:     $crs=~s/\_/\//g;
1.54      www        68:     unless ($symb) {
                     69: 	$symb=&Apache::lonnet::symbread();
                     70:     }
                     71:     unless ($symb) { return ''; }
1.78      raeburn    72: 
1.80      raeburn    73: # backward compatibility (bulletin boards used to be 'wrapped')
                     74:     my $ressymb=$symb;
                     75:     if ($mode eq 'board') {
                     76:         unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                     77:             $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
                     78:         }
                     79:     }
                     80: 
                     81: # Get discussion display settings for this discussion
                     82:     my $lastkey = $ressymb.'_lastread';
                     83:     my $showkey = $ressymb.'_showonlyunread';
                     84:     my $visitkey = $ressymb.'_visit';
1.84      raeburn    85:     my $ondispkey = $ressymb.'_markondisp';
                     86:     my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$visitkey,$ondispkey],$ENV{'user.domain'},$ENV{'user.name'});
                     87:     my %discinfo = ();
1.80      raeburn    88:     my $showonlyunread = 0;
1.84      raeburn    89:     my $markondisp = 0;
1.79      raeburn    90:     my $prevread = 0;
1.81      raeburn    91:     my $previous = 0;
1.80      raeburn    92:     my $visit = 0;
                     93:     my $newpostsflag = 0;
                     94: 
1.81      raeburn    95: # Retain identification of "NEW" posts identified in last display, if continuing 'previous' browsing of posts.
                     96:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous']);
                     97:     $previous = $ENV{'form.previous'};
1.80      raeburn    98:     if ($previous > 0) {
                     99:         $prevread = $previous;
                    100:     } elsif (defined($dischash{$lastkey})) {
1.84      raeburn   101:         unless ($dischash{$lastkey} eq '') {
                    102:             $prevread = $dischash{$lastkey};
                    103:         }
1.80      raeburn   104:     }
1.79      raeburn   105: 
1.84      raeburn   106: # Get discussion display default settings for user
                    107:     my %userenv = &Apache::lonnet::get('environment',['discdisplay','discmarkread'],$ENV{'user.domain'},$ENV{'user.name'});
1.83      raeburn   108:     my $discdisplay=$userenv{'discdisplay'};
                    109:     if ($discdisplay eq 'unread') {
                    110:         $showonlyunread = 1;
                    111:     }
1.84      raeburn   112:     my $discmarkread=$userenv{'discmarkread'};
                    113:     if ($discmarkread eq 'ondisp') {
                    114:         $markondisp = 1;
                    115:     }
                    116: 
                    117: # Override user's default if user specified display setting for this discussion
                    118:     if (defined($dischash{$ondispkey})) {
                    119:         $markondisp = $dischash{$ondispkey};
                    120:     }
                    121:     if ($markondisp) {
                    122:         $discinfo{$lastkey} = time;
                    123:     }
1.83      raeburn   124: 
1.80      raeburn   125:     if (defined($dischash{$showkey})) {
                    126:         $showonlyunread = $dischash{$showkey};
                    127:     }
                    128: 
                    129:     if (defined($dischash{$visitkey})) {
                    130:         $visit = $dischash{$visitkey};
1.78      raeburn   131:     }
1.80      raeburn   132:     $visit ++;
1.78      raeburn   133: 
1.54      www       134:     my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.77      www       135:     my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
                    136: 	&& ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/));
1.68      www       137:     my @discussionitems=();
1.73      albertel  138:     my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
1.54      www       139: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    140: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.67      www       141:     my $visible=0;
1.68      www       142:     my @depth=();
                    143:     my @original=();
                    144:     my @index=();
                    145:     my @replies=();
                    146:     my %alldiscussion=();
1.80      raeburn   147:     my %notshown = ();
1.84      raeburn   148:     my %newitem = ();
1.68      www       149:     my $maxdepth=0;
                    150: 
1.69      www       151:     my $target='';
                    152:     unless ($ENV{'browser.interface'} eq 'textual' ||
                    153: 	    $ENV{'environment.remote'} eq 'off' ) {
                    154: 	$target='target="LONcom"';
                    155:     }
1.79      raeburn   156:     
                    157:     my $now = time;
1.80      raeburn   158:     $discinfo{$visitkey} = $visit;
                    159: 
                    160:     &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.79      raeburn   161: 
1.54      www       162:     if ($contrib{'version'}) {
1.84      raeburn   163:         my $oldest = $contrib{'1:timestamp'};
                    164:         if ($prevread eq '0') {
                    165:             $prevread = $oldest-1;
                    166:         }
1.64      www       167: 	for (my $id=1;$id<=$contrib{'version'};$id++) {
                    168: 	    my $idx=$id;
1.80      raeburn   169:             my $posttime = $contrib{$idx.':timestamp'};
1.84      raeburn   170:             if ($prevread <= $posttime) {
1.80      raeburn   171:                 $newpostsflag = 1;
                    172:             }
1.54      www       173: 	    my $hidden=($contrib{'hidden'}=~/\.$idx\./);
                    174: 	    my $deleted=($contrib{'deleted'}=~/\.$idx\./);
1.68      www       175: 	    my $origindex='0.';
1.69      www       176: 	    if (($contrib{$idx.':replyto'}) && ($ENV{'environment.threadeddiscussion'})) {
1.68      www       177: # this is a follow-up message
                    178: 		$original[$idx]=$original[$contrib{$idx.':replyto'}];
                    179: 		$depth[$idx]=$depth[$contrib{$idx.':replyto'}]+1;
                    180: 		$origindex=$index[$contrib{$idx.':replyto'}];
                    181: 		if ($depth[$idx]>$maxdepth) { $maxdepth=$depth[$idx]; }
                    182: 	    } else {
                    183: # this is an original message
                    184: 		$original[$idx]=0;
                    185: 		$depth[$idx]=0;
                    186: 	    }
                    187: 	    if ($replies[$depth[$idx]]) {
                    188: 		$replies[$depth[$idx]]++;
                    189: 	    } else {
                    190: 		$replies[$depth[$idx]]=1;
                    191: 	    }
1.54      www       192: 	    unless ((($hidden) && (!$seeid)) || ($deleted)) {
1.67      www       193: 		$visible++;
1.54      www       194: 		my $message=$contrib{$idx.':message'};
                    195: 		$message=~s/\n/\<br \/\>/g;
                    196: 		$message=&Apache::lontexconvert::msgtexconverted($message);
1.78      raeburn   197:                 my $subject=$contrib{$idx.':subject'};
                    198:                 if (defined($subject)) {
                    199:                     $subject=~s/\n/\<br \/\>/g;
                    200:                     $subject=&Apache::lontexconvert::msgtexconverted($subject);
                    201:                 }
1.54      www       202: 		if ($contrib{$idx.':attachmenturl'}) {
1.82      albertel  203: 		    my ($fname)
                    204:                         =($contrib{$idx.':attachmenturl'}=~m|/([^/]+)$|);
                    205: 		    &Apache::lonnet::allowuploaded('/adm/feedback',
                    206: 					   $contrib{$idx.':attachmenturl'});
                    207: 		    $message.='<p>'.&mt('Attachment').
                    208: 			': <a href="'.$contrib{$idx.':attachmenturl'}.'"><tt>'.
                    209: 			$fname.'</tt></a></p>';
1.54      www       210: 		}
                    211: 		if ($message) {
                    212: 		    if ($hidden) {
                    213: 			$message='<font color="#888888">'.$message.'</font>';
                    214: 		    }
                    215: 		    my $screenname=&Apache::loncommon::screenname(
                    216: 					    $contrib{$idx.':sendername'},
                    217: 					    $contrib{$idx.':senderdomain'});
                    218: 		    my $plainname=&Apache::loncommon::nickname(
                    219: 					    $contrib{$idx.':sendername'},
                    220: 					    $contrib{$idx.':senderdomain'});
                    221: 		    
1.62      www       222: 		    my $sender=&mt('Anonymous');
1.54      www       223: 		    if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
                    224: 			$sender=&Apache::loncommon::aboutmewrapper(
                    225: 					 $plainname,
                    226: 					 $contrib{$idx.':sendername'},
                    227: 					 $contrib{$idx.':senderdomain'}).' ('.
                    228: 					 $contrib{$idx.':sendername'}.' at '.
                    229: 					 $contrib{$idx.':senderdomain'}.')';
                    230: 			if ($contrib{$idx.':anonymous'}) {
1.62      www       231: 			    $sender.=' ['.&mt('anonymous').'] '.
1.54      www       232: 				$screenname;
                    233: 			}
                    234: 			if ($seeid) {
                    235: 			    if ($hidden) {
                    236: 				$sender.=' <a href="/adm/feedback?unhide='.
1.80      raeburn   237: 				    $ressymb.':::'.$idx;
                    238:                                 if ($newpostsflag) {
                    239:                                     $sender .= '&previous='.$prevread;
                    240:                                 }
                    241:                                 $sender .= '">'.&mt('Make Visible').'</a>';
1.54      www       242: 			    } else {
                    243: 				$sender.=' <a href="/adm/feedback?hide='.
1.80      raeburn   244: 				    $ressymb.':::'.$idx;
                    245:                                 if ($newpostsflag) {
                    246:                                     $sender .= '&previous='.$prevread;
                    247:                                 }
                    248:                                 $sender .= '">'.&mt('Hide').'</a>';
1.54      www       249: 			    }                     
                    250: 			    $sender.=' <a href="/adm/feedback?deldisc='.
1.80      raeburn   251: 				$ressymb.':::'.$idx;
                    252:                                 if ($newpostsflag) {
                    253:                                     $sender .= '&previous='.$prevread;
                    254:                                 }
                    255:                                 $sender .= '">'.&mt('Delete').'</a>';
1.64      www       256: 			}
1.54      www       257: 		    } else {
                    258: 			if ($screenname) {
                    259: 			    $sender='<i>'.$screenname.'</i>';
                    260: 			}
1.77      www       261: 		    }
1.91    ! matthew   262: 		    if (!&discussion_closed($status) &&
1.90      albertel  263: 			&Apache::lonnet::allowed('pch',
1.77      www       264: 						 $ENV{'request.course.id'}.
                    265: 						 ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
                    266: 			$sender.=' <a href="/adm/feedback?replydisc='.
1.80      raeburn   267: 			    $ressymb.':::'.$idx;
                    268:                         if ($newpostsflag) {
                    269:                             $sender .= '&previous='.$prevread;
                    270:                         }
                    271:                         $sender .= '" '.$target.'>'.&mt('Reply').'</a>';
1.54      www       272: 		    }
                    273: 		    my $vgrlink;
                    274: 		    if ($viewgrades) {
                    275: 			$vgrlink=&Apache::loncommon::submlink('Submissions',
                    276:             $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb);
                    277: 		    }
1.68      www       278: #figure out at what position this needs to print
                    279: 		    my $thisindex=$idx;
1.69      www       280: 		    if ($ENV{'environment.threadeddiscussion'}) {
1.68      www       281: 			$thisindex=$origindex.substr('00'.$replies[$depth[$idx]],-2,2);	
                    282: 		    }
                    283: 		    $alldiscussion{$thisindex}=$idx;
                    284: 		    $index[$idx]=$thisindex;
1.79      raeburn   285:                     my $spansize = 2;
1.80      raeburn   286:                     if ($showonlyunread && $prevread > $posttime) {
                    287:                         $notshown{$idx} = 1;
1.78      raeburn   288:                     } else {
1.80      raeburn   289:                         if ($prevread > 0 && $prevread <= $posttime) {
1.84      raeburn   290:                             $newitem{$idx} = 1;
                    291:                             $discussionitems[$idx] .= '
                    292:                              <p><table border="0" width="100%">
                    293:                               <tr><td align="left"><font color="#FF0000"><b>NEW</b></font></td>';
                    294:                         } else {
                    295:                             $newitem{$idx} = 0;
                    296:                             $discussionitems[$idx] .= '
                    297:                              <p><table border="0" width="100%">
                    298:                               <tr><td align="left">&nbsp;</td>';
1.80      raeburn   299:                         }
                    300:                         $discussionitems[$idx] .= '<td align ="left">&nbsp;&nbsp;'.
                    301:                             '<b>'.$subject.'</b>&nbsp;&nbsp;'.
                    302:                             $sender.'</b> '.$vgrlink.' ('.
                    303:                             localtime($posttime).')</td></tr>'.
                    304:                             '</table><blockquote>'.$message.'</blockquote></p>';
1.78      raeburn   305:                     }
                    306:                 }
                    307:             }
1.54      www       308: 	}
1.64      www       309:     }
1.80      raeburn   310: 
1.67      www       311:     my $discussion='';
1.84      raeburn   312: 
                    313:     my $function = &Apache::loncommon::get_users_function();
                    314:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
                    315:                                                     $ENV{'user.domain'});
                    316:     my %lt = &Apache::lonlocal::texthash(
                    317:         'cuse' => 'Current settings for this discussion',
                    318:         'allposts' => 'All posts',
                    319:         'unread' => 'New posts only',
                    320:         'ondisp' => 'Once displayed',
                    321:         'onmark' => 'Once marked read',
                    322:         'disa' => 'Posts to be displayed',
                    323:         'npce' => 'Posts cease to be marked "NEW"',
                    324:         'chgt' => 'Change to ',
                    325:     );
                    326: 
                    327:     my $currdisp = $lt{'allposts'};
                    328:     my $currmark = $lt{'onmark'};
                    329:     my $dispchange = $lt{'unread'};
                    330:     my $markchange = $lt{'ondisp'};
                    331:     my $displink = '/adm/feedback?onlyunread='.$ressymb;
                    332:     my $marklink = '/adm/feedback?markondisp='.$ressymb;
                    333: 
                    334:     if ($markondisp) {
                    335:         $currmark = $lt{'ondisp'};
                    336:         $markchange = $lt{'onmark'};
                    337:         $marklink = '/adm/feedback?markonread='.$ressymb;
                    338:         if ($newpostsflag) {
                    339:             $marklink .= '&previous='.$prevread;
                    340:         }
                    341:     }
                    342: 
                    343:     if ($showonlyunread) {
                    344:         $currdisp = $lt{'unread'};
                    345:         $dispchange = $lt{'allposts'};
                    346:         $displink = '/adm/feedback?allposts='.$ressymb;
                    347:     }
                    348: 
                    349:     if ($newpostsflag) {
                    350:         $displink .= '&previous='.$prevread;
                    351:     }
                    352: 
1.67      www       353:     if ($visible) {
1.80      raeburn   354: # Print the discusssion
1.67      www       355: 	$discussion.='<table bgcolor="#AAAAAA" cellpadding="2" cellspacing="2" border="0">';
1.84      raeburn   356: 	my $colspan=$maxdepth+1;
                    357:         $discussion .= '<tr bgcolor="#FFFFFF"><td colspan="'.$colspan.'" valign="top">'.
                    358:         '<table border="0" bgcolor="#FFFFFF" width="100%" cellspacing="2" cellpadding="2">'.
                    359:         '<tr><td align="left"><b>'.$lt{'cuse'}.'</b></td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td align="right"><b>'.$lt{'chgt'}.'</b></td></tr>'.
                    360:         '<tr><td>'.$lt{'disa'}.':&nbsp;<i>'.$currdisp.'</i></td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td align="right"><a href="'.$displink.'">'.$dispchange.'</a></td></tr>'.
                    361:         '<tr><td>'.$lt{'npce'}.':&nbsp;<i>'.$currmark.'</i></td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td align="right"><a href="'.$marklink.'">'.$markchange.'</a></td></tr>'.
                    362:         '</table></td></tr>'.
                    363:         '<tr><td bgcolor="#DDDDBB" colspan="'.$colspan.'">'.
                    364:         '<table border="0" width="100%" bgcolor="#DDDDBB"><tr>';
                    365:         if ($visible>2) {
                    366: 	    $discussion.='<td align="left">'.
                    367:             '<a href="/adm/feedback?threadedon='.$ressymb;
                    368:             if ($newpostsflag) {
                    369:                 $discussion .= '&previous='.$prevread;
                    370:             }
                    371:             $discussion .='">'.&mt('Threaded View').'</a>&nbsp;&nbsp;'.
                    372:             '<a href="/adm/feedback?threadedoff='.$ressymb;
                    373:             if ($newpostsflag) {
                    374:                 $discussion .= '&previous='.$prevread;
                    375:             }
                    376:             $discussion .='">'.&mt('Chronological View').'</a>&nbsp;&nbsp;</td>';
                    377: 	} 
                    378:         if ($newpostsflag) {
                    379:             if (!$markondisp) {
                    380:                 $discussion .='<td align="right"><a href="/adm/feedback?markread='.$ressymb.'">'.&mt('Mark new posts as read').'</a>&nbsp;&nbsp;';
1.78      raeburn   381:             } else {
1.84      raeburn   382:                 $discussion .= '<td>&nbsp;</td>';
1.78      raeburn   383:             }
1.84      raeburn   384:         } else {
                    385:             $discussion .= '<td>&nbsp;</td>';
                    386:         }
                    387:         $discussion .= '</tr></table></td></tr>';
                    388: 
1.80      raeburn   389:         my $numhidden = keys %notshown;
                    390:         if ($numhidden > 0) {
                    391:             my $colspan = $maxdepth+1;
                    392:             $discussion.="\n".'<tr><td bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
                    393:                          '<a href="/adm/feedback?allposts='.$ressymb;
                    394:             if ($newpostsflag) {
                    395:                 $discussion .= '&previous='.$prevread;
                    396:             }
                    397:             $discussion .= '">'.&mt('Show all posts').'</a> '.&mt('to display').' '.
                    398:                          $numhidden.' '.&mt('previously viewed posts').
                    399:                          '<br/></td></tr>';
                    400:         }
1.68      www       401: 	foreach (sort { $a <=> $b } keys %alldiscussion) {
1.80      raeburn   402:             unless ($notshown{$alldiscussion{$_}} eq '1') {
                    403: 	        $discussion.="\n<tr>";
                    404: 	        my $thisdepth=$depth[$alldiscussion{$_}];
                    405: 	        for (1..$thisdepth) {
                    406: 		    $discussion.='<td>&nbsp;&nbsp;&nbsp;</td>';
                    407: 	        }
                    408: 	        my $colspan=$maxdepth-$thisdepth+1;
1.84      raeburn   409:                 $discussion.='<td  bgcolor="'.$bgcols[$newitem{$alldiscussion{$_}}].'" colspan="'.$colspan.'">'.
1.80      raeburn   410:                              $discussionitems[$alldiscussion{$_}].
                    411: 	                     '</td></tr>';
1.69      www       412: 	    }
1.80      raeburn   413:         }
                    414:         $discussion.='</table><br /><br />';
1.54      www       415:     }
                    416:     if ($discussiononly) {
                    417: 	$discussion.=(<<ENDDISCUSS);
                    418: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">
                    419: <input type="submit" name="discuss" value="Post Discussion" />
                    420: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
1.73      albertel  421: <input type="hidden" name="symb" value="$ressymb" />
1.54      www       422: <input type="hidden" name="sendit" value="true" />
                    423: <br />
                    424: <font size="1">Note: in anonymous discussion, your name is visible only to
                    425: course faculty</font><br />
1.78      raeburn   426: <b>Title:</b>&nbsp;<input type="text" name="subject" value="" size="30" /><br /><br />
1.88      www       427: <textarea name="comment" cols="60" rows="12" wrap="hard"></textarea>
1.54      www       428: <p>
                    429: Attachment (128 KB max size): <input type="file" name="attachment" />
                    430: </p>
                    431: </form>
                    432: ENDDISCUSS
                    433:       $discussion.=&generate_preview_button();
1.74      www       434:     } else {
1.90      albertel  435: 	if (!&discussion_closed($status) &&
                    436: 	    &Apache::lonnet::allowed('pch',
1.74      www       437: 				   $ENV{'request.course.id'}.
                    438: 	($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
                    439: 			    $discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
                    440: 				$symb.':::" '.$target.'>'.
                    441: 				'<img src="/adm/lonMisc/chat.gif" border="0" />'.
                    442: 				&mt('Post Discussion').'</a></td></tr></table>';
                    443: 			}
                    444:     }
1.54      www       445:    return $discussion;
                    446: }
1.1       www       447: 
1.6       albertel  448: sub mail_screen {
                    449:   my ($r,$feedurl,$options) = @_;
1.45      www       450:   my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
                    451:                                           '','onLoad="window.focus();"');
1.51      albertel  452:   my $title=&Apache::lonnet::gettitle($feedurl);
                    453:   if (!$title) { $title = $feedurl; }
1.69      www       454:   my $quote='';
1.78      raeburn   455:   my $subject = '';
1.80      raeburn   456:   my $prevtag = '';
1.69      www       457:   if ($ENV{'form.replydisc'}) {
                    458:       my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
                    459:       my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                    460: 					   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    461: 					   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.80      raeburn   462:       unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
1.69      www       463: 	  my $message=$contrib{$idx.':message'};
                    464: 	  $message=~s/\n/\<br \/\>/g;
                    465: 	  $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
1.79      raeburn   466:           if ($idx > 0) {
                    467:               $subject = 'Re: '.$contrib{$idx.':subject'};
                    468:           }
1.69      www       469:       }
1.80      raeburn   470:       if ($ENV{'form.previous'}) {
                    471:           $prevtag = '<input type="hidden" name="previous" value="'.$ENV{'form.previous'}.'" />';
                    472:       }
1.69      www       473:   }
1.85      www       474:   my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
1.86      www       475:   my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
1.74      www       476:   my $send=&mt('Send');
1.6       albertel  477:   $r->print(<<ENDDOCUMENT);
1.1       www       478: <html>
                    479: <head>
                    480: <title>The LearningOnline Network with CAPA</title>
1.7       albertel  481: <meta http-equiv="pragma" content="no-cache"></meta>
1.85      www       482: $htmlheader
1.63      albertel  483: <script type="text/javascript">
                    484: //<!--
1.5       www       485:     function gosubmit() {
                    486:         var rec=0;
1.12      albertel  487:         if (typeof(document.mailform.elements.author)!="undefined") {
1.5       www       488:           if (document.mailform.elements.author.checked) {
                    489:              rec=1;
                    490:           } 
                    491:         }
1.12      albertel  492:         if (typeof(document.mailform.elements.question)!="undefined") {
1.5       www       493:           if (document.mailform.elements.question.checked) {
                    494:              rec=1;
                    495:           } 
                    496:         }
1.12      albertel  497:         if (typeof(document.mailform.elements.course)!="undefined") {
1.5       www       498:           if (document.mailform.elements.course.checked) {
                    499:              rec=1;
                    500:           } 
                    501:         }
1.12      albertel  502:         if (typeof(document.mailform.elements.policy)!="undefined") {
1.5       www       503:           if (document.mailform.elements.policy.checked) {
                    504:              rec=1;
                    505:           } 
                    506:         }
1.12      albertel  507:         if (typeof(document.mailform.elements.discuss)!="undefined") {
1.10      www       508:           if (document.mailform.elements.discuss.checked) {
                    509:              rec=1;
                    510:           } 
                    511:         }
1.14      www       512:         if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
                    513:           if (document.mailform.elements.anondiscuss.checked) {
                    514:              rec=1;
                    515:           } 
                    516:         }
1.5       www       517: 
                    518:         if (rec) {
1.86      www       519: 	    document.mailform.onsubmit();
1.5       www       520: 	    document.mailform.submit();
                    521:         } else {
                    522:             alert('Please check a feedback type.');
                    523: 	}
                    524:     }
1.63      albertel  525: //-->
1.5       www       526: </script>
1.1       www       527: </head>
1.29      www       528: $bodytag
1.51      albertel  529: <h2><tt>$title</tt></h2>
1.43      www       530: <form action="/adm/feedback" method="post" name="mailform"
                    531: enctype="multipart/form-data">
1.80      raeburn   532: $prevtag
1.63      albertel  533: <input type="hidden" name="postdata" value="$feedurl" />
1.68      www       534: <input type="hidden" name="replydisc" value="$ENV{'form.replydisc'}" />
1.5       www       535: Please check at least one of the following feedback types:
1.63      albertel  536: $options<hr />
1.69      www       537: $quote
1.63      albertel  538: <p>My question/comment/feedback:</p>
                    539: <p>
1.47      bowersj2  540: $latexHelp
1.78      raeburn   541: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
                    542: <p>
1.63      albertel  543: <textarea name="comment" cols="60" rows="10" wrap="hard">
                    544: </textarea></p>
                    545: <p>
1.42      www       546: Attachment (128 KB max size): <input type="file" name="attachment" />
                    547: </p>
                    548: <p>
                    549: <input type="hidden" name="sendit" value="1" />
1.74      www       550: <input type="button" value="$send" onClick='gosubmit();' />
1.42      www       551: </p>
1.2       www       552: </form>
1.1       www       553: ENDDOCUMENT
1.85      www       554: $r->print(&generate_preview_button().
                    555: &Apache::lonhtmlcommon::htmlareaactive().
                    556: '</body></html>');
1.6       albertel  557: }
                    558: 
                    559: sub fail_redirect {
                    560:   my ($r,$feedurl) = @_;
1.70      www       561:   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.6       albertel  562:   $r->print (<<ENDFAILREDIR);
1.72      albertel  563: <html>
1.5       www       564: <head><title>Feedback not sent</title>
1.63      albertel  565: <meta http-equiv="pragma" content="no-cache" />
                    566: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.5       www       567: </head>
                    568: <body bgcolor="#FFFFFF">
1.63      albertel  569: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.8       www       570: <b>Sorry, no recipients  ...</b>
1.5       www       571: </body>
                    572: </html>
                    573: ENDFAILREDIR
                    574: }
1.4       www       575: 
1.6       albertel  576: sub redirect_back {
1.80      raeburn   577:   my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous) = @_;
                    578:   my $prevtag = '';
                    579:   my $qrystr = '';
1.70      www       580:   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.80      raeburn   581:   if ($previous > 0) {
                    582:       $qrystr = 'previous='.$previous;
                    583:       if ($feedurl =~ /\?register=1/) {
                    584:           $feedurl .= '&'.$qrystr;
                    585:       } else {
                    586:           $feedurl .= '?'.$qrystr;
                    587:       }
                    588:       $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
                    589:   }
1.6       albertel  590:   $r->print (<<ENDREDIR);
1.72      albertel  591: <html>
1.3       www       592: <head>
                    593: <title>Feedback sent</title>
1.63      albertel  594: <meta http-equiv="pragma" content="no-cache" />
1.80      raeburn   595: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.2       www       596: </head>
1.49      www       597: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1.63      albertel  598: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.5       www       599: $typestyle
1.32      albertel  600: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1.63      albertel  601: <font color="red">$status</font>
1.49      www       602: <form name="reldt" action="$feedurl" target="loncapaclient">
1.80      raeburn   603: $prevtag
1.49      www       604: </form>
1.2       www       605: </body>
                    606: </html>
                    607: ENDREDIR
                    608: }
1.6       albertel  609: 
                    610: sub no_redirect_back {
                    611:   my ($r,$feedurl) = @_;
                    612:   $r->print (<<ENDNOREDIR);
1.72      albertel  613: <html>
1.2       www       614: <head><title>Feedback not sent</title>
1.63      albertel  615: <meta http-equiv="pragma" content="no-cache" />
1.7       albertel  616: ENDNOREDIR
                    617: 
1.8       www       618:   if ($feedurl!~/^\/adm\/feedback/) { 
1.7       albertel  619:     $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
                    620:   }
                    621:   
1.8       www       622:   $r->print (<<ENDNOREDIRTWO);
1.2       www       623: </head>
1.49      www       624: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
1.63      albertel  625: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.8       www       626: <b>Sorry, no feedback possible on this resource  ...</b>
1.2       www       627: </body>
                    628: </html>
1.8       www       629: ENDNOREDIRTWO
1.2       www       630: }
1.6       albertel  631: 
                    632: sub screen_header {
1.65      www       633:     my ($feedurl) = @_;
                    634:     my $msgoptions='';
                    635:     my $discussoptions='';
                    636:     unless ($ENV{'form.replydisc'}) {
                    637: 	if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
                    638: 	    $msgoptions= 
                    639: 		'<p><input type="checkbox" name="author" /> '.
                    640: 		&mt('Feedback to resource author').'</p>';
                    641: 	}
                    642: 	if (&feedback_available(1)) {
                    643: 	    $msgoptions.=
                    644: 		'<br /><input type="checkbox" name="question" /> '.
                    645: 		&mt('Question about resource content');
                    646: 	}
                    647: 	if (&feedback_available(0,1)) {
                    648: 	    $msgoptions.=
                    649: 		'<br /><input type="checkbox" name="course" /> '.
                    650: 		&mt('Question/Comment/Feedback about course content');
                    651: 	}
                    652: 	if (&feedback_available(0,0,1)) {
                    653: 	    $msgoptions.=
                    654: 		'<br /><input type="checkbox" name="policy" /> '.
                    655: 		&mt('Question/Comment/Feedback about course policy');
                    656: 	}
                    657:     }
                    658:     if ($ENV{'request.course.id'}) {
1.90      albertel  659: 	if (not &discussion_closed() &&
                    660: 	    &Apache::lonnet::allowed('pch',
1.65      www       661: 				     $ENV{'request.course.id'}.
                    662: 				     ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.74      www       663: 	    $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
                    664: 		($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
1.65      www       665: 		&mt('Contribution to course discussion of resource');
                    666: 	    $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
                    667: 		&mt('Anonymous contribution to course discussion of resource').
                    668: 		' <i>('.&mt('name only visible to course faculty').')</i>';
1.20      www       669:       }
1.65      www       670:     }
1.74      www       671:     if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
1.65      www       672:     if ($discussoptions) { 
1.74      www       673: 	$discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
1.65      www       674:     return $msgoptions.$discussoptions;
1.6       albertel  675: }
                    676: 
                    677: sub resource_output {
                    678:   my ($feedurl) = @_;
1.46      albertel  679:   my $usersaw=&Apache::lonnet::ssi_body($feedurl);
1.6       albertel  680:   $usersaw=~s/\<body[^\>]*\>//gi;
                    681:   $usersaw=~s/\<\/body\>//gi;
                    682:   $usersaw=~s/\<html\>//gi;
                    683:   $usersaw=~s/\<\/html\>//gi;
                    684:   $usersaw=~s/\<head\>//gi;
                    685:   $usersaw=~s/\<\/head\>//gi;
                    686:   $usersaw=~s/action\s*\=/would_be_action\=/gi;
                    687:   return $usersaw;
                    688: }
                    689: 
                    690: sub clear_out_html {
1.39      www       691:   my ($message,$override)=@_;
1.88      www       692:   unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
1.37      albertel  693:   my $cid=$ENV{'request.course.id'};
1.39      www       694:   if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
                    695:       ($override)) {
1.37      albertel  696:       # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG> 
1.88      www       697:       # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
                    698:       # <SUP>
1.37      albertel  699:       my %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
1.61      www       700: 		BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
1.88      www       701:                 M=>1, SUB=>1, SUP=>1, SPAN=>1, 
                    702: 		H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
1.37      albertel  703: 
                    704:       $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
1.48      albertel  705: 	  {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\&lt;$1"}/ge;
1.37      albertel  706:       $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
1.48      albertel  707: 	  {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\&gt;"}/ge;
1.37      albertel  708:   } else {
                    709:       $message=~s/\</\&lt\;/g;
                    710:       $message=~s/\>/\&gt\;/g;
                    711:   }
1.6       albertel  712:   return $message;
                    713: }
                    714: 
                    715: sub assemble_email {
1.40      albertel  716:   my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1.6       albertel  717:   my $email=<<"ENDEMAIL";
                    718: Refers to <a href="$feedurl">$feedurl</a>
                    719: 
                    720: $message
                    721: ENDEMAIL
                    722:     my $citations=<<"ENDCITE";
                    723: <h2>Previous attempts of student (if applicable)</h2>
                    724: $prevattempts
1.63      albertel  725: <br /><hr />
1.6       albertel  726: <h2>Original screen output (if applicable)</h2>
                    727: $usersaw
1.40      albertel  728: <h2>Correct Answer(s) (if applicable)</h2>
                    729: $useranswer
1.6       albertel  730: ENDCITE
                    731:   return ($email,$citations);
                    732: }
                    733: 
1.35      www       734: sub secapply {
                    735:     my $rec=shift;
1.36      www       736:     my $defaultflag=shift;
                    737:     $rec=~s/\s+//g;
                    738:     $rec=~s/\@/\:/g;
                    739:     my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
                    740:     if ($sections) {
                    741: 	foreach (split(/\;/,$sections)) {
                    742:             if (($_ eq $ENV{'request.course.sec'}) ||
                    743:                 ($defaultflag && ($_ eq '*'))) {
                    744:                 return $adr; 
                    745:             }
                    746:         }
                    747:     } else {
                    748:        return $rec;
                    749:     }
                    750:     return '';
1.35      www       751: }
                    752: 
1.6       albertel  753: sub decide_receiver {
1.36      www       754:   my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1.6       albertel  755:   my $typestyle='';
                    756:   my %to=();
1.36      www       757:   if ($ENV{'form.author'}||$author) {
1.8       www       758:     $typestyle.='Submitting as Author Feedback<br>';
1.6       albertel  759:     $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
                    760:     $to{$2.':'.$1}=1;
                    761:   }
1.36      www       762:   if ($ENV{'form.question'}||$question) {
1.8       www       763:     $typestyle.='Submitting as Question<br>';
1.24      harris41  764:     foreach (split(/\,/,
                    765: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
                    766: 	     ) {
1.36      www       767: 	my $rec=&secapply($_,$defaultflag);
                    768:         if ($rec) { $to{$rec}=1; }
1.24      harris41  769:     } 
1.6       albertel  770:   }
1.36      www       771:   if ($ENV{'form.course'}||$course) {
1.63      albertel  772:     $typestyle.='Submitting as Comment<br />';
1.24      harris41  773:     foreach (split(/\,/,
                    774: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
                    775: 	     ) {
1.36      www       776: 	my $rec=&secapply($_,$defaultflag);
                    777:         if ($rec) { $to{$rec}=1; }
1.24      harris41  778:     } 
1.6       albertel  779:   }
1.36      www       780:   if ($ENV{'form.policy'}||$policy) {
1.63      albertel  781:     $typestyle.='Submitting as Policy Feedback<br />';
1.24      harris41  782:     foreach (split(/\,/,
                    783: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
                    784: 	     ) {
1.36      www       785: 	my $rec=&secapply($_,$defaultflag);
                    786:         if ($rec) { $to{$rec}=1; }
1.24      harris41  787:     } 
1.6       albertel  788:   }
1.36      www       789:   if ((scalar(%to) eq '0') && (!$defaultflag)) {
                    790:      ($typestyle,%to)=
                    791: 	 &decide_receiver($feedurl,$author,$question,$course,$policy,1);
                    792:   }
1.6       albertel  793:   return ($typestyle,%to);
1.36      www       794: }
                    795: 
                    796: sub feedback_available {
                    797:     my ($question,$course,$policy)=@_;
                    798:     my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
                    799:     return scalar(%to);
1.6       albertel  800: }
                    801: 
                    802: sub send_msg {
1.43      www       803:   my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1.6       albertel  804:   my $status='';
                    805:   my $sendsomething=0;
1.24      harris41  806:   foreach (keys %to) {
1.6       albertel  807:     if ($_) {
1.22      www       808:       my $declutter=&Apache::lonnet::declutter($feedurl);
1.8       www       809:       unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.43      www       810:                'Feedback ['.$declutter.']',$email,$citations,$feedurl,
                    811:                 $attachmenturl)=~/ok/) {
1.63      albertel  812: 	$status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1.6       albertel  813:       } else {
                    814: 	$sendsomething++;
                    815:       }
                    816:     }
1.24      harris41  817:   }
1.18      www       818: 
                    819:     my %record=&Apache::lonnet::restore('_feedback');
                    820:     my ($temp)=keys %record;
                    821:     unless ($temp=~/^error\:/) {
                    822:        my %newrecord=();
                    823:        $newrecord{'resource'}=$feedurl;
                    824:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
                    825:        unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1.63      albertel  826: 	   $status.='<br />'.&mt('Not registered').'<br />';
1.18      www       827:        }
                    828:     }
                    829:        
1.6       albertel  830:   return ($status,$sendsomething);
                    831: }
                    832: 
1.13      www       833: sub adddiscuss {
1.78      raeburn   834:     my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1.13      www       835:     my $status='';
1.90      albertel  836:     if (not &discussion_closed() &&
                    837: 	&Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
1.23      www       838:         ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.20      www       839: 
1.13      www       840:     my %contrib=('message'      => $email,
                    841:                  'sendername'   => $ENV{'user.name'},
1.26      www       842:                  'senderdomain' => $ENV{'user.domain'},
                    843:                  'screenname'   => $ENV{'environment.screenname'},
                    844:                  'plainname'    => $ENV{'environment.firstname'}.' '.
                    845: 		                   $ENV{'environment.middlename'}.' '.
                    846:                                    $ENV{'environment.lastname'}.' '.
1.42      www       847:                                    $ENV{'enrironment.generation'},
1.78      raeburn   848:                  'attachmenturl'=> $attachmenturl,
                    849:                  'subject'      => $subject);
1.65      www       850:     if ($ENV{'form.replydisc'}) {
1.66      www       851: 	$contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
1.65      www       852:     }
1.14      www       853:     if ($anon) {
                    854: 	$contrib{'anonymous'}='true';
                    855:     }
1.13      www       856:     if (($symb) && ($email)) {
1.14      www       857:        $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1.13      www       858:         &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
                    859:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17      www       860: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.21      www       861:         my %storenewentry=($symb => time);
1.63      albertel  862:         $status.='<br />'.&mt('Updating discussion time').': '.
1.21      www       863:         &Apache::lonnet::put('discussiontimes',\%storenewentry,
                    864:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    865: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.13      www       866:     }
1.17      www       867:     my %record=&Apache::lonnet::restore('_discussion');
                    868:     my ($temp)=keys %record;
                    869:     unless ($temp=~/^error\:/) {
                    870:        my %newrecord=();
                    871:        $newrecord{'resource'}=$symb;
                    872:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.63      albertel  873:        $status.='<br />'.&mt('Registering').': '.
1.21      www       874:                &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20      www       875:     }
                    876:     } else {
                    877: 	$status.='Failed.';
1.17      www       878:     }
1.63      albertel  879:     return $status.'<br />';   
1.13      www       880: }
                    881: 
1.33      www       882: # ----------------------------------------------------------- Preview function
                    883: 
                    884: sub show_preview {
                    885:     my $r=shift;
                    886:     my $message=&clear_out_html($ENV{'form.comment'});
                    887:     $message=~s/\n/\<br \/\>/g;
                    888:     $message=&Apache::lontexconvert::msgtexconverted($message);
1.78      raeburn   889:     my $subject=&clear_out_html($ENV{'form.subject'});
                    890:     $subject=~s/\n/\<br \/\>/g;
                    891:     $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.33      www       892:     $r->print('<table border="2"><tr><td>'.
1.78      raeburn   893:        '<b>Subject:</b> '.$subject.'<br /><br />'.
1.33      www       894:        $message.'</td></tr></table>');
                    895: }
                    896: 
                    897: sub generate_preview_button {
1.65      www       898:     my $pre=&mt("Show Preview");
1.33      www       899:     return(<<ENDPREVIEW);
                    900: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.78      raeburn   901: <input type="hidden" name="subject">
1.33      www       902: <input type="hidden" name="comment" />
1.65      www       903: <input type="button" value="$pre"
1.87      www       904: onClick="document.mailform.onsubmit();this.form.comment.value=document.mailform.comment.value;this.form.subject.value=document.mailform.subject.value;this.form.submit();" />
1.33      www       905: </form>
                    906: ENDPREVIEW
                    907: }
1.71      www       908: 
1.6       albertel  909: sub handler {
                    910:   my $r = shift;
1.8       www       911:   if ($r->header_only) {
1.71      www       912:      &Apache::loncommon::content_type($r,'text/html');
1.8       www       913:      $r->send_http_header;
                    914:      return OK;
                    915:   }
1.15      www       916: 
                    917: # --------------------------- Get query string for limited number of parameters
                    918: 
1.27      stredwic  919:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.84      raeburn   920:          ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff','onlyunread','allposts','previous','markread','markonread','markondisp']);
                    921: 
                    922:   if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
                    923: # ---------------------- Modify setting for identification of 'NEW' posts in this discussion
1.15      www       924: 
1.84      raeburn   925:       &Apache::loncommon::content_type($r,'text/html');
                    926:       $r->send_http_header;
                    927:       my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
                    928:       my $ressymb = $symb;
                    929:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                    930:       unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                    931:           $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
                    932:       }
                    933:                                                                                           
                    934:       my %discinfo = ();
                    935:       my $lastkey = $ressymb.'_lastread';
                    936:       my $ondispkey = $ressymb.'_markondisp';
                    937:       if ($ENV{'form.markondisp'}) {
                    938:           $discinfo{$lastkey} = time;
                    939:           $discinfo{$ondispkey} = 1;
                    940:       } elsif ($ENV{'form.markonread'}) {
                    941:           if ( defined($ENV{'previous'}) ) {
                    942:               $discinfo{$lastkey} = $ENV{'previous'};
                    943:           }
                    944:           $discinfo{$ondispkey} = 0;
                    945:       }
                    946:       &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
                    947:       if ($ENV{'form.markondisp'}) {
                    948:           &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0');
                    949:       } else {
                    950:           &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$ENV{'form.previous'});
                    951:       }
                    952:       return OK;
                    953:   } elsif (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'})) {
1.80      raeburn   954: # ----------------------------------------------------------------- Modify display setting for this discussion 
1.78      raeburn   955:       &Apache::loncommon::content_type($r,'text/html');
                    956:       $r->send_http_header;
1.80      raeburn   957:       my $symb=$ENV{'form.allposts'}?$ENV{'form.allposts'}:$ENV{'form.onlyunread'};
1.84      raeburn   958:       my $ressymb = $symb;
1.78      raeburn   959:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.84      raeburn   960:       unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                    961:           $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
                    962:       }
                    963:       my %discinfo = ();
                    964:       if ($ENV{'form.allposts'}) {
                    965:           $discinfo{$ressymb.'_showonlyunread'} = 0;
                    966:       } elsif ($ENV{'form.onlyunread'}) {
                    967:           $discinfo{$ressymb.'_showonlyunread'} = 1;
                    968:       }
                    969:       &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
                    970:       &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$ENV{'form.previous'});
                    971:       return OK;
                    972:   } elsif ($ENV{'form.markread'}) {
                    973: # ----------------------------------------------------------------- Mark new posts as read
                    974:       &Apache::loncommon::content_type($r,'text/html');
                    975:       $r->send_http_header;
                    976:       my $symb=$ENV{'form.markread'};
                    977:       my $ressymb = $symb;
                    978:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                    979:       unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                    980:           $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1.78      raeburn   981:       }
1.84      raeburn   982:       my %discinfo = ();
                    983:       my $lastkey = $ressymb.'_lastread';
                    984:       $discinfo{$lastkey} = time;
                    985:       &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
                    986:       &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0');
1.78      raeburn   987:       return OK;
                    988:   } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1.15      www       989: # ----------------------------------------------------------------- Hide/unhide
1.71      www       990:     &Apache::loncommon::content_type($r,'text/html');
1.15      www       991:     $r->send_http_header;
                    992: 
                    993:     my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
                    994: 
                    995:     my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52      www       996:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.15      www       997: 
                    998:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                    999:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1000: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   1001: 
                   1002:         
                   1003:     my $currenthidden=$contrib{'hidden'};
                   1004:     
                   1005:     if ($ENV{'form.hide'}) {
                   1006: 	$currenthidden.='.'.$idx.'.';
                   1007:     } else {
                   1008:         $currenthidden=~s/\.$idx\.//g;
                   1009:     }
                   1010:     my %newhash=('hidden' => $currenthidden);
1.38      www      1011: 
                   1012:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
                   1013:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1014: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   1015: 
                   1016:     &redirect_back($r,&Apache::lonnet::clutter($url),
1.80      raeburn  1017:        &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.69      www      1018:   } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1.72      albertel 1019:       &Apache::loncommon::content_type($r,'text/html');
                   1020:       $r->send_http_header;
1.69      www      1021:       if ($ENV{'form.threadedon'}) {
                   1022: 	  &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
                   1023: 	  &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
                   1024:       } else {
                   1025:  	  &Apache::lonnet::del('environment',['threadeddiscussion']);
                   1026: 	  &Apache::lonnet::delenv('environment\.threadeddiscussion');
1.72      albertel 1027:       }
1.69      www      1028:       my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
                   1029:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                   1030:       &redirect_back($r,&Apache::lonnet::clutter($url),
1.80      raeburn  1031: 		     &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
1.38      www      1032:   } elsif ($ENV{'form.deldisc'}) {
                   1033: # --------------------------------------------------------------- Hide for good
1.71      www      1034:     &Apache::loncommon::content_type($r,'text/html');
1.38      www      1035:     $r->send_http_header;
                   1036: 
                   1037:     my $entry=$ENV{'form.deldisc'};
                   1038: 
                   1039:     my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52      www      1040:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.38      www      1041: 
                   1042:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                   1043:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1044: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   1045: 
                   1046:         
                   1047:     my $currentdeleted=$contrib{'deleted'};
                   1048:     
                   1049:     $currentdeleted.='.'.$idx.'.';
                   1050: 
                   1051:     my %newhash=('deleted' => $currentdeleted);
1.15      www      1052: 
                   1053:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
                   1054:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1055: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   1056: 
1.30      www      1057:     &redirect_back($r,&Apache::lonnet::clutter($url),
1.80      raeburn  1058:        &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.33      www      1059:   } elsif ($ENV{'form.preview'}) {
                   1060: # -------------------------------------------------------- User wants a preview
1.76      albertel 1061:       $r->content_type('text/html');
                   1062:       $r->send_http_header;
1.33      www      1063:       &show_preview($r);
1.15      www      1064:   } else {
                   1065: # ------------------------------------------------------------- Normal feedback
1.6       albertel 1066:   my $feedurl=$ENV{'form.postdata'};
                   1067:   $feedurl=~s/^http\:\/\///;
                   1068:   $feedurl=~s/^$ENV{'SERVER_NAME'}//;
                   1069:   $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.62      www      1070:   $feedurl=~s/\?.+$//;
1.8       www      1071: 
1.66      www      1072:   my $symb;
                   1073:   if ($ENV{'form.replydisc'}) {
                   1074:       $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
                   1075:       my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
                   1076:       $feedurl=&Apache::lonnet::clutter($url);
                   1077:   } else {
                   1078:       $symb=&Apache::lonnet::symbread($feedurl);
                   1079:   }
1.31      www      1080:   unless ($symb) {
                   1081:       $symb=$ENV{'form.symb'};
                   1082:       if ($symb) {
1.52      www      1083: 	  my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1.31      www      1084:           $feedurl=&Apache::lonnet::clutter($url);
                   1085:       }
                   1086:   }
1.8       www      1087:   my $goahead=1;
                   1088:   if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
                   1089:       unless ($symb) { $goahead=0; }
                   1090:   }
1.74      www      1091:   # backward compatibility (bulltin boards used to be 'wrapped')
1.73      albertel 1092:   if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
                   1093:       $feedurl=~s|^/adm/wrapper||;
                   1094:   }
1.8       www      1095:   if ($goahead) {
                   1096: # Go ahead with feedback, no ambiguous reference
1.71      www      1097:     &Apache::loncommon::content_type($r,'text/html');
1.8       www      1098:     $r->send_http_header;
1.6       albertel 1099:   
1.8       www      1100:     if (
1.7       albertel 1101:       (
                   1102:        ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
                   1103:       ) 
                   1104:       || 
                   1105:       ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1.31      www      1106:       ||
                   1107:       ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.7       albertel 1108:      ) {
1.6       albertel 1109: # --------------------------------------------------- Print login screen header
                   1110:     unless ($ENV{'form.sendit'}) {
                   1111:       my $options=&screen_header($feedurl);
                   1112:       if ($options) {
                   1113: 	&mail_screen($r,$feedurl,$options);
                   1114:       } else {
                   1115: 	&fail_redirect($r,$feedurl);
                   1116:       }
                   1117:     } else {
                   1118:       
                   1119: # Get previous user input
1.9       albertel 1120:       my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11      albertel 1121:             $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9       albertel 1122:             $ENV{'request.course.id'});
1.6       albertel 1123: 
                   1124: # Get output from resource
                   1125:       my $usersaw=&resource_output($feedurl);
                   1126: 
1.50      albertel 1127: # Get resource answer (need to allow student to view grades for this to work)
                   1128:       &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1.40      albertel 1129:       my $useranswer=&Apache::loncommon::get_student_answers(
                   1130:                        $symb,$ENV{'user.name'},$ENV{'user.domain'},
                   1131: 		       $ENV{'request.course.id'});
1.50      albertel 1132:       &Apache::lonnet::delenv('allowed.vgr');
1.42      www      1133: # Get attachments, if any, and not too large
                   1134:       my $attachmenturl='';
                   1135:       if ($ENV{'form.attachment.filename'}) {
                   1136: 	  unless (length($ENV{'form.attachment'})>131072) {
1.82      albertel 1137: 	      $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1.42      www      1138: 	  }
                   1139:       }
1.6       albertel 1140: # Filter HTML out of message (could be nasty)
1.39      www      1141:       my $message=&clear_out_html($ENV{'form.comment'});
1.6       albertel 1142: 
                   1143: # Assemble email
1.8       www      1144:       my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.40      albertel 1145:           $usersaw,$useranswer);
                   1146:  
1.6       albertel 1147: # Who gets this?
                   1148:       my ($typestyle,%to) = &decide_receiver($feedurl);
                   1149: 
                   1150: # Actually send mail
1.43      www      1151:       my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
                   1152:           $attachmenturl,%to);
1.13      www      1153: 
                   1154: # Discussion? Store that.
                   1155: 
1.32      albertel 1156:       my $numpost=0;
1.13      www      1157:       if ($ENV{'form.discuss'}) {
1.78      raeburn  1158:           my $subject = &clear_out_html($ENV{'form.subject'});
                   1159: 	  $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
1.32      albertel 1160: 	  $numpost++;
1.13      www      1161:       }
1.6       albertel 1162: 
1.14      www      1163:       if ($ENV{'form.anondiscuss'}) {
1.78      raeburn  1164:           my $subject = &clear_out_html($ENV{'form.subject'});
                   1165: 	  $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
1.32      albertel 1166: 	  $numpost++;
1.14      www      1167:       }
                   1168: 
                   1169: 
1.6       albertel 1170: # Receipt screen and redirect back to where came from
1.80      raeburn  1171:       &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1.6       albertel 1172: 
                   1173:     }
1.8       www      1174:    } else {
1.7       albertel 1175: # Unable to give feedback
1.6       albertel 1176:     &no_redirect_back($r,$feedurl);
1.8       www      1177:    }
                   1178:   } else {
                   1179: # Ambiguous Problem Resource
1.60      albertel 1180:       if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1.53      albertel 1181: 	  &Apache::lonnet::cleanenv();
1.58      albertel 1182:       }
1.53      albertel 1183:       $r->internal_redirect('/adm/ambiguous');
1.6       albertel 1184:   }
1.15      www      1185: }
1.6       albertel 1186:   return OK;
1.1       www      1187: } 
                   1188: 
                   1189: 1;
                   1190: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>