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

1.1       www         1: # The LearningOnline Network
                      2: # Feedback
                      3: #
1.86    ! www         4: # $Id: lonfeedback.pm,v 1.85 2004/06/01 21:40:57 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.63      albertel  415: <textarea name="comment" cols="60" rows="10" 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.37      albertel  678:   my $cid=$ENV{'request.course.id'};
1.39      www       679:   if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
                    680:       ($override)) {
1.37      albertel  681:       # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG> 
                    682:       # <BLOCKQUOTE> <DIV .*> <DIV> <IMG>
                    683:       my %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
1.61      www       684: 		BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
                    685:                 M=>1);
1.37      albertel  686: 
                    687:       $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
1.48      albertel  688: 	  {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\&lt;$1"}/ge;
1.37      albertel  689:       $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
1.48      albertel  690: 	  {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\&gt;"}/ge;
1.37      albertel  691:   } else {
                    692:       $message=~s/\</\&lt\;/g;
                    693:       $message=~s/\>/\&gt\;/g;
                    694:   }
1.6       albertel  695:   return $message;
                    696: }
                    697: 
                    698: sub assemble_email {
1.40      albertel  699:   my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1.6       albertel  700:   my $email=<<"ENDEMAIL";
                    701: Refers to <a href="$feedurl">$feedurl</a>
                    702: 
                    703: $message
                    704: ENDEMAIL
                    705:     my $citations=<<"ENDCITE";
                    706: <h2>Previous attempts of student (if applicable)</h2>
                    707: $prevattempts
1.63      albertel  708: <br /><hr />
1.6       albertel  709: <h2>Original screen output (if applicable)</h2>
                    710: $usersaw
1.40      albertel  711: <h2>Correct Answer(s) (if applicable)</h2>
                    712: $useranswer
1.6       albertel  713: ENDCITE
                    714:   return ($email,$citations);
                    715: }
                    716: 
1.35      www       717: sub secapply {
                    718:     my $rec=shift;
1.36      www       719:     my $defaultflag=shift;
                    720:     $rec=~s/\s+//g;
                    721:     $rec=~s/\@/\:/g;
                    722:     my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
                    723:     if ($sections) {
                    724: 	foreach (split(/\;/,$sections)) {
                    725:             if (($_ eq $ENV{'request.course.sec'}) ||
                    726:                 ($defaultflag && ($_ eq '*'))) {
                    727:                 return $adr; 
                    728:             }
                    729:         }
                    730:     } else {
                    731:        return $rec;
                    732:     }
                    733:     return '';
1.35      www       734: }
                    735: 
1.6       albertel  736: sub decide_receiver {
1.36      www       737:   my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1.6       albertel  738:   my $typestyle='';
                    739:   my %to=();
1.36      www       740:   if ($ENV{'form.author'}||$author) {
1.8       www       741:     $typestyle.='Submitting as Author Feedback<br>';
1.6       albertel  742:     $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
                    743:     $to{$2.':'.$1}=1;
                    744:   }
1.36      www       745:   if ($ENV{'form.question'}||$question) {
1.8       www       746:     $typestyle.='Submitting as Question<br>';
1.24      harris41  747:     foreach (split(/\,/,
                    748: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
                    749: 	     ) {
1.36      www       750: 	my $rec=&secapply($_,$defaultflag);
                    751:         if ($rec) { $to{$rec}=1; }
1.24      harris41  752:     } 
1.6       albertel  753:   }
1.36      www       754:   if ($ENV{'form.course'}||$course) {
1.63      albertel  755:     $typestyle.='Submitting as Comment<br />';
1.24      harris41  756:     foreach (split(/\,/,
                    757: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
                    758: 	     ) {
1.36      www       759: 	my $rec=&secapply($_,$defaultflag);
                    760:         if ($rec) { $to{$rec}=1; }
1.24      harris41  761:     } 
1.6       albertel  762:   }
1.36      www       763:   if ($ENV{'form.policy'}||$policy) {
1.63      albertel  764:     $typestyle.='Submitting as Policy Feedback<br />';
1.24      harris41  765:     foreach (split(/\,/,
                    766: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
                    767: 	     ) {
1.36      www       768: 	my $rec=&secapply($_,$defaultflag);
                    769:         if ($rec) { $to{$rec}=1; }
1.24      harris41  770:     } 
1.6       albertel  771:   }
1.36      www       772:   if ((scalar(%to) eq '0') && (!$defaultflag)) {
                    773:      ($typestyle,%to)=
                    774: 	 &decide_receiver($feedurl,$author,$question,$course,$policy,1);
                    775:   }
1.6       albertel  776:   return ($typestyle,%to);
1.36      www       777: }
                    778: 
                    779: sub feedback_available {
                    780:     my ($question,$course,$policy)=@_;
                    781:     my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
                    782:     return scalar(%to);
1.6       albertel  783: }
                    784: 
                    785: sub send_msg {
1.43      www       786:   my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1.6       albertel  787:   my $status='';
                    788:   my $sendsomething=0;
1.24      harris41  789:   foreach (keys %to) {
1.6       albertel  790:     if ($_) {
1.22      www       791:       my $declutter=&Apache::lonnet::declutter($feedurl);
1.8       www       792:       unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.43      www       793:                'Feedback ['.$declutter.']',$email,$citations,$feedurl,
                    794:                 $attachmenturl)=~/ok/) {
1.63      albertel  795: 	$status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1.6       albertel  796:       } else {
                    797: 	$sendsomething++;
                    798:       }
                    799:     }
1.24      harris41  800:   }
1.18      www       801: 
                    802:     my %record=&Apache::lonnet::restore('_feedback');
                    803:     my ($temp)=keys %record;
                    804:     unless ($temp=~/^error\:/) {
                    805:        my %newrecord=();
                    806:        $newrecord{'resource'}=$feedurl;
                    807:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
                    808:        unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1.63      albertel  809: 	   $status.='<br />'.&mt('Not registered').'<br />';
1.18      www       810:        }
                    811:     }
                    812:        
1.6       albertel  813:   return ($status,$sendsomething);
                    814: }
                    815: 
1.13      www       816: sub adddiscuss {
1.78      raeburn   817:     my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1.13      www       818:     my $status='';
1.23      www       819:     if (&Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
                    820:         ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.20      www       821: 
1.13      www       822:     my %contrib=('message'      => $email,
                    823:                  'sendername'   => $ENV{'user.name'},
1.26      www       824:                  'senderdomain' => $ENV{'user.domain'},
                    825:                  'screenname'   => $ENV{'environment.screenname'},
                    826:                  'plainname'    => $ENV{'environment.firstname'}.' '.
                    827: 		                   $ENV{'environment.middlename'}.' '.
                    828:                                    $ENV{'environment.lastname'}.' '.
1.42      www       829:                                    $ENV{'enrironment.generation'},
1.78      raeburn   830:                  'attachmenturl'=> $attachmenturl,
                    831:                  'subject'      => $subject);
1.65      www       832:     if ($ENV{'form.replydisc'}) {
1.66      www       833: 	$contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
1.65      www       834:     }
1.14      www       835:     if ($anon) {
                    836: 	$contrib{'anonymous'}='true';
                    837:     }
1.13      www       838:     if (($symb) && ($email)) {
1.14      www       839:        $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1.13      www       840:         &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
                    841:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17      www       842: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.21      www       843:         my %storenewentry=($symb => time);
1.63      albertel  844:         $status.='<br />'.&mt('Updating discussion time').': '.
1.21      www       845:         &Apache::lonnet::put('discussiontimes',\%storenewentry,
                    846:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    847: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.13      www       848:     }
1.17      www       849:     my %record=&Apache::lonnet::restore('_discussion');
                    850:     my ($temp)=keys %record;
                    851:     unless ($temp=~/^error\:/) {
                    852:        my %newrecord=();
                    853:        $newrecord{'resource'}=$symb;
                    854:        $newrecord{'subnumber'}=$record{'subnumber'}+1;
1.63      albertel  855:        $status.='<br />'.&mt('Registering').': '.
1.21      www       856:                &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20      www       857:     }
                    858:     } else {
                    859: 	$status.='Failed.';
1.17      www       860:     }
1.63      albertel  861:     return $status.'<br />';   
1.13      www       862: }
                    863: 
1.33      www       864: # ----------------------------------------------------------- Preview function
                    865: 
                    866: sub show_preview {
                    867:     my $r=shift;
                    868:     my $message=&clear_out_html($ENV{'form.comment'});
                    869:     $message=~s/\n/\<br \/\>/g;
                    870:     $message=&Apache::lontexconvert::msgtexconverted($message);
1.78      raeburn   871:     my $subject=&clear_out_html($ENV{'form.subject'});
                    872:     $subject=~s/\n/\<br \/\>/g;
                    873:     $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.33      www       874:     $r->print('<table border="2"><tr><td>'.
1.78      raeburn   875:        '<b>Subject:</b> '.$subject.'<br /><br />'.
1.33      www       876:        $message.'</td></tr></table>');
                    877: }
                    878: 
                    879: sub generate_preview_button {
1.65      www       880:     my $pre=&mt("Show Preview");
1.33      www       881:     return(<<ENDPREVIEW);
                    882: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.78      raeburn   883: <input type="hidden" name="subject">
1.33      www       884: <input type="hidden" name="comment" />
1.65      www       885: <input type="button" value="$pre"
1.78      raeburn   886: onClick="this.form.comment.value=document.mailform.comment.value;this.form.subject.value=document.mailform.subject.value;this.form.submit();" />
1.33      www       887: </form>
                    888: ENDPREVIEW
                    889: }
1.71      www       890: 
1.6       albertel  891: sub handler {
                    892:   my $r = shift;
1.8       www       893:   if ($r->header_only) {
1.71      www       894:      &Apache::loncommon::content_type($r,'text/html');
1.8       www       895:      $r->send_http_header;
                    896:      return OK;
                    897:   }
1.15      www       898: 
                    899: # --------------------------- Get query string for limited number of parameters
                    900: 
1.27      stredwic  901:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.84      raeburn   902:          ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff','onlyunread','allposts','previous','markread','markonread','markondisp']);
                    903: 
                    904:   if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
                    905: # ---------------------- Modify setting for identification of 'NEW' posts in this discussion
1.15      www       906: 
1.84      raeburn   907:       &Apache::loncommon::content_type($r,'text/html');
                    908:       $r->send_http_header;
                    909:       my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
                    910:       my $ressymb = $symb;
                    911:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                    912:       unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                    913:           $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
                    914:       }
                    915:                                                                                           
                    916:       my %discinfo = ();
                    917:       my $lastkey = $ressymb.'_lastread';
                    918:       my $ondispkey = $ressymb.'_markondisp';
                    919:       if ($ENV{'form.markondisp'}) {
                    920:           $discinfo{$lastkey} = time;
                    921:           $discinfo{$ondispkey} = 1;
                    922:       } elsif ($ENV{'form.markonread'}) {
                    923:           if ( defined($ENV{'previous'}) ) {
                    924:               $discinfo{$lastkey} = $ENV{'previous'};
                    925:           }
                    926:           $discinfo{$ondispkey} = 0;
                    927:       }
                    928:       &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
                    929:       if ($ENV{'form.markondisp'}) {
                    930:           &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0');
                    931:       } else {
                    932:           &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$ENV{'form.previous'});
                    933:       }
                    934:       return OK;
                    935:   } elsif (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'})) {
1.80      raeburn   936: # ----------------------------------------------------------------- Modify display setting for this discussion 
1.78      raeburn   937:       &Apache::loncommon::content_type($r,'text/html');
                    938:       $r->send_http_header;
1.80      raeburn   939:       my $symb=$ENV{'form.allposts'}?$ENV{'form.allposts'}:$ENV{'form.onlyunread'};
1.84      raeburn   940:       my $ressymb = $symb;
1.78      raeburn   941:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.84      raeburn   942:       unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                    943:           $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
                    944:       }
                    945:       my %discinfo = ();
                    946:       if ($ENV{'form.allposts'}) {
                    947:           $discinfo{$ressymb.'_showonlyunread'} = 0;
                    948:       } elsif ($ENV{'form.onlyunread'}) {
                    949:           $discinfo{$ressymb.'_showonlyunread'} = 1;
                    950:       }
                    951:       &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
                    952:       &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$ENV{'form.previous'});
                    953:       return OK;
                    954:   } elsif ($ENV{'form.markread'}) {
                    955: # ----------------------------------------------------------------- Mark new posts as read
                    956:       &Apache::loncommon::content_type($r,'text/html');
                    957:       $r->send_http_header;
                    958:       my $symb=$ENV{'form.markread'};
                    959:       my $ressymb = $symb;
                    960:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                    961:       unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                    962:           $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1.78      raeburn   963:       }
1.84      raeburn   964:       my %discinfo = ();
                    965:       my $lastkey = $ressymb.'_lastread';
                    966:       $discinfo{$lastkey} = time;
                    967:       &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
                    968:       &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0');
1.78      raeburn   969:       return OK;
                    970:   } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1.15      www       971: # ----------------------------------------------------------------- Hide/unhide
1.71      www       972:     &Apache::loncommon::content_type($r,'text/html');
1.15      www       973:     $r->send_http_header;
                    974: 
                    975:     my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
                    976: 
                    977:     my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52      www       978:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.15      www       979: 
                    980:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                    981:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    982: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    983: 
                    984:         
                    985:     my $currenthidden=$contrib{'hidden'};
                    986:     
                    987:     if ($ENV{'form.hide'}) {
                    988: 	$currenthidden.='.'.$idx.'.';
                    989:     } else {
                    990:         $currenthidden=~s/\.$idx\.//g;
                    991:     }
                    992:     my %newhash=('hidden' => $currenthidden);
1.38      www       993: 
                    994:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
                    995:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    996: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    997: 
                    998:     &redirect_back($r,&Apache::lonnet::clutter($url),
1.80      raeburn   999:        &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.69      www      1000:   } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1.72      albertel 1001:       &Apache::loncommon::content_type($r,'text/html');
                   1002:       $r->send_http_header;
1.69      www      1003:       if ($ENV{'form.threadedon'}) {
                   1004: 	  &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
                   1005: 	  &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
                   1006:       } else {
                   1007:  	  &Apache::lonnet::del('environment',['threadeddiscussion']);
                   1008: 	  &Apache::lonnet::delenv('environment\.threadeddiscussion');
1.72      albertel 1009:       }
1.69      www      1010:       my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
                   1011:       my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                   1012:       &redirect_back($r,&Apache::lonnet::clutter($url),
1.80      raeburn  1013: 		     &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
1.38      www      1014:   } elsif ($ENV{'form.deldisc'}) {
                   1015: # --------------------------------------------------------------- Hide for good
1.71      www      1016:     &Apache::loncommon::content_type($r,'text/html');
1.38      www      1017:     $r->send_http_header;
                   1018: 
                   1019:     my $entry=$ENV{'form.deldisc'};
                   1020: 
                   1021:     my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52      www      1022:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.38      www      1023: 
                   1024:     my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                   1025:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1026: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   1027: 
                   1028:         
                   1029:     my $currentdeleted=$contrib{'deleted'};
                   1030:     
                   1031:     $currentdeleted.='.'.$idx.'.';
                   1032: 
                   1033:     my %newhash=('deleted' => $currentdeleted);
1.15      www      1034: 
                   1035:     &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
                   1036:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1037: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   1038: 
1.30      www      1039:     &redirect_back($r,&Apache::lonnet::clutter($url),
1.80      raeburn  1040:        &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.33      www      1041:   } elsif ($ENV{'form.preview'}) {
                   1042: # -------------------------------------------------------- User wants a preview
1.76      albertel 1043:       $r->content_type('text/html');
                   1044:       $r->send_http_header;
1.33      www      1045:       &show_preview($r);
1.15      www      1046:   } else {
                   1047: # ------------------------------------------------------------- Normal feedback
1.6       albertel 1048:   my $feedurl=$ENV{'form.postdata'};
                   1049:   $feedurl=~s/^http\:\/\///;
                   1050:   $feedurl=~s/^$ENV{'SERVER_NAME'}//;
                   1051:   $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.62      www      1052:   $feedurl=~s/\?.+$//;
1.8       www      1053: 
1.66      www      1054:   my $symb;
                   1055:   if ($ENV{'form.replydisc'}) {
                   1056:       $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
                   1057:       my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
                   1058:       $feedurl=&Apache::lonnet::clutter($url);
                   1059:   } else {
                   1060:       $symb=&Apache::lonnet::symbread($feedurl);
                   1061:   }
1.31      www      1062:   unless ($symb) {
                   1063:       $symb=$ENV{'form.symb'};
                   1064:       if ($symb) {
1.52      www      1065: 	  my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1.31      www      1066:           $feedurl=&Apache::lonnet::clutter($url);
                   1067:       }
                   1068:   }
1.8       www      1069:   my $goahead=1;
                   1070:   if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
                   1071:       unless ($symb) { $goahead=0; }
                   1072:   }
1.74      www      1073:   # backward compatibility (bulltin boards used to be 'wrapped')
1.73      albertel 1074:   if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
                   1075:       $feedurl=~s|^/adm/wrapper||;
                   1076:   }
1.8       www      1077:   if ($goahead) {
                   1078: # Go ahead with feedback, no ambiguous reference
1.71      www      1079:     &Apache::loncommon::content_type($r,'text/html');
1.8       www      1080:     $r->send_http_header;
1.6       albertel 1081:   
1.8       www      1082:     if (
1.7       albertel 1083:       (
                   1084:        ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
                   1085:       ) 
                   1086:       || 
                   1087:       ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1.31      www      1088:       ||
                   1089:       ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.7       albertel 1090:      ) {
1.6       albertel 1091: # --------------------------------------------------- Print login screen header
                   1092:     unless ($ENV{'form.sendit'}) {
                   1093:       my $options=&screen_header($feedurl);
                   1094:       if ($options) {
                   1095: 	&mail_screen($r,$feedurl,$options);
                   1096:       } else {
                   1097: 	&fail_redirect($r,$feedurl);
                   1098:       }
                   1099:     } else {
                   1100:       
                   1101: # Get previous user input
1.9       albertel 1102:       my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11      albertel 1103:             $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9       albertel 1104:             $ENV{'request.course.id'});
1.6       albertel 1105: 
                   1106: # Get output from resource
                   1107:       my $usersaw=&resource_output($feedurl);
                   1108: 
1.50      albertel 1109: # Get resource answer (need to allow student to view grades for this to work)
                   1110:       &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1.40      albertel 1111:       my $useranswer=&Apache::loncommon::get_student_answers(
                   1112:                        $symb,$ENV{'user.name'},$ENV{'user.domain'},
                   1113: 		       $ENV{'request.course.id'});
1.50      albertel 1114:       &Apache::lonnet::delenv('allowed.vgr');
1.42      www      1115: # Get attachments, if any, and not too large
                   1116:       my $attachmenturl='';
                   1117:       if ($ENV{'form.attachment.filename'}) {
                   1118: 	  unless (length($ENV{'form.attachment'})>131072) {
1.82      albertel 1119: 	      $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1.42      www      1120: 	  }
                   1121:       }
1.6       albertel 1122: # Filter HTML out of message (could be nasty)
1.39      www      1123:       my $message=&clear_out_html($ENV{'form.comment'});
1.6       albertel 1124: 
                   1125: # Assemble email
1.8       www      1126:       my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.40      albertel 1127:           $usersaw,$useranswer);
                   1128:  
1.6       albertel 1129: # Who gets this?
                   1130:       my ($typestyle,%to) = &decide_receiver($feedurl);
                   1131: 
                   1132: # Actually send mail
1.43      www      1133:       my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
                   1134:           $attachmenturl,%to);
1.13      www      1135: 
                   1136: # Discussion? Store that.
                   1137: 
1.32      albertel 1138:       my $numpost=0;
1.13      www      1139:       if ($ENV{'form.discuss'}) {
1.78      raeburn  1140:           my $subject = &clear_out_html($ENV{'form.subject'});
                   1141: 	  $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
1.32      albertel 1142: 	  $numpost++;
1.13      www      1143:       }
1.6       albertel 1144: 
1.14      www      1145:       if ($ENV{'form.anondiscuss'}) {
1.78      raeburn  1146:           my $subject = &clear_out_html($ENV{'form.subject'});
                   1147: 	  $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
1.32      albertel 1148: 	  $numpost++;
1.14      www      1149:       }
                   1150: 
                   1151: 
1.6       albertel 1152: # Receipt screen and redirect back to where came from
1.80      raeburn  1153:       &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1.6       albertel 1154: 
                   1155:     }
1.8       www      1156:    } else {
1.7       albertel 1157: # Unable to give feedback
1.6       albertel 1158:     &no_redirect_back($r,$feedurl);
1.8       www      1159:    }
                   1160:   } else {
                   1161: # Ambiguous Problem Resource
1.60      albertel 1162:       if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1.53      albertel 1163: 	  &Apache::lonnet::cleanenv();
1.58      albertel 1164:       }
1.53      albertel 1165:       $r->internal_redirect('/adm/ambiguous');
1.6       albertel 1166:   }
1.15      www      1167: }
1.6       albertel 1168:   return OK;
1.1       www      1169: } 
                   1170: 
                   1171: 1;
                   1172: __END__

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