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

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

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