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

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

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