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

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

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