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

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

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