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

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

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