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

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

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