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

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

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