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

1.1       www         1: # The LearningOnline Network
                      2: # Feedback
                      3: #
1.92    ! albertel    4: # $Id: lonfeedback.pm,v 1.91 2004/06/04 18:58:32 matthew 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: 	&Apache::lonnet::logthis(" no open due to status $status");
        !            46: 	return 0;
1.75      albertel   47:     }
1.89      albertel   48:     my $close=&Apache::lonnet::EXT('resource.0.discussend');
                     49:     if (defined($close) && $close ne '' && $close < time) {
1.92    ! albertel   50: 	&Apache::lonnet::logthis(" no open due to time ");
        !            51: 	return 0;
1.89      albertel   52:     }
1.92    ! albertel   53:     &Apache::lonnet::logthis(" open ");
        !            54:     return 1;
        !            55: }
        !            56: 
        !            57: sub discussion_visible {
        !            58:     my ($status)=@_;
        !            59:     if (not &discussion_open($status)) {
        !            60: 	my $hidden=&Apache::lonnet::EXT('resource.0.discusshide');
        !            61: 	if (lc($hidden) eq 'yes' or $hidden eq '' or !defined($hidden))  {
        !            62: 	    &Apache::lonnet::logthis(" hidden ");
        !            63: 	    return 0;
        !            64: 	}
        !            65:     }
        !            66:     &Apache::lonnet::logthis(" visible ");
        !            67:     return 1;
1.90      albertel   68: }
1.84      raeburn    69: 
1.90      albertel   70: sub list_discussion {
                     71:     my ($mode,$status,$symb)=@_;
                     72: 
1.92    ! albertel   73:     if (not &discussion_visible($status)) { return ''; }
1.84      raeburn    74:     my @bgcols = ("#cccccc","#eeeeee");
1.57      www        75:     my $discussiononly=0;
                     76:     if ($mode eq 'board') { $discussiononly=1; }
1.55      www        77:     unless ($ENV{'request.course.id'}) { return ''; }
                     78:     my $crs='/'.$ENV{'request.course.id'};
                     79:     if ($ENV{'request.course.sec'}) {
                     80: 	$crs.='_'.$ENV{'request.course.sec'};
                     81:     }                 
                     82:     $crs=~s/\_/\//g;
1.54      www        83:     unless ($symb) {
                     84: 	$symb=&Apache::lonnet::symbread();
                     85:     }
                     86:     unless ($symb) { return ''; }
1.78      raeburn    87: 
1.80      raeburn    88: # backward compatibility (bulletin boards used to be 'wrapped')
                     89:     my $ressymb=$symb;
                     90:     if ($mode eq 'board') {
                     91:         unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
                     92:             $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
                     93:         }
                     94:     }
                     95: 
                     96: # Get discussion display settings for this discussion
                     97:     my $lastkey = $ressymb.'_lastread';
                     98:     my $showkey = $ressymb.'_showonlyunread';
                     99:     my $visitkey = $ressymb.'_visit';
1.84      raeburn   100:     my $ondispkey = $ressymb.'_markondisp';
                    101:     my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$visitkey,$ondispkey],$ENV{'user.domain'},$ENV{'user.name'});
                    102:     my %discinfo = ();
1.80      raeburn   103:     my $showonlyunread = 0;
1.84      raeburn   104:     my $markondisp = 0;
1.79      raeburn   105:     my $prevread = 0;
1.81      raeburn   106:     my $previous = 0;
1.80      raeburn   107:     my $visit = 0;
                    108:     my $newpostsflag = 0;
                    109: 
1.81      raeburn   110: # Retain identification of "NEW" posts identified in last display, if continuing 'previous' browsing of posts.
                    111:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous']);
                    112:     $previous = $ENV{'form.previous'};
1.80      raeburn   113:     if ($previous > 0) {
                    114:         $prevread = $previous;
                    115:     } elsif (defined($dischash{$lastkey})) {
1.84      raeburn   116:         unless ($dischash{$lastkey} eq '') {
                    117:             $prevread = $dischash{$lastkey};
                    118:         }
1.80      raeburn   119:     }
1.79      raeburn   120: 
1.84      raeburn   121: # Get discussion display default settings for user
                    122:     my %userenv = &Apache::lonnet::get('environment',['discdisplay','discmarkread'],$ENV{'user.domain'},$ENV{'user.name'});
1.83      raeburn   123:     my $discdisplay=$userenv{'discdisplay'};
                    124:     if ($discdisplay eq 'unread') {
                    125:         $showonlyunread = 1;
                    126:     }
1.84      raeburn   127:     my $discmarkread=$userenv{'discmarkread'};
                    128:     if ($discmarkread eq 'ondisp') {
                    129:         $markondisp = 1;
                    130:     }
                    131: 
                    132: # Override user's default if user specified display setting for this discussion
                    133:     if (defined($dischash{$ondispkey})) {
                    134:         $markondisp = $dischash{$ondispkey};
                    135:     }
                    136:     if ($markondisp) {
                    137:         $discinfo{$lastkey} = time;
                    138:     }
1.83      raeburn   139: 
1.80      raeburn   140:     if (defined($dischash{$showkey})) {
                    141:         $showonlyunread = $dischash{$showkey};
                    142:     }
                    143: 
                    144:     if (defined($dischash{$visitkey})) {
                    145:         $visit = $dischash{$visitkey};
1.78      raeburn   146:     }
1.80      raeburn   147:     $visit ++;
1.78      raeburn   148: 
1.54      www       149:     my $seeid=&Apache::lonnet::allowed('rin',$crs);
1.77      www       150:     my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
                    151: 	&& ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/));
1.68      www       152:     my @discussionitems=();
1.73      albertel  153:     my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
1.54      www       154: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    155: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.67      www       156:     my $visible=0;
1.68      www       157:     my @depth=();
                    158:     my @original=();
                    159:     my @index=();
                    160:     my @replies=();
                    161:     my %alldiscussion=();
1.80      raeburn   162:     my %notshown = ();
1.84      raeburn   163:     my %newitem = ();
1.68      www       164:     my $maxdepth=0;
                    165: 
1.69      www       166:     my $target='';
                    167:     unless ($ENV{'browser.interface'} eq 'textual' ||
                    168: 	    $ENV{'environment.remote'} eq 'off' ) {
                    169: 	$target='target="LONcom"';
                    170:     }
1.79      raeburn   171:     
                    172:     my $now = time;
1.80      raeburn   173:     $discinfo{$visitkey} = $visit;
                    174: 
                    175:     &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.79      raeburn   176: 
1.54      www       177:     if ($contrib{'version'}) {
1.84      raeburn   178:         my $oldest = $contrib{'1:timestamp'};
                    179:         if ($prevread eq '0') {
                    180:             $prevread = $oldest-1;
                    181:         }
1.64      www       182: 	for (my $id=1;$id<=$contrib{'version'};$id++) {
                    183: 	    my $idx=$id;
1.80      raeburn   184:             my $posttime = $contrib{$idx.':timestamp'};
1.84      raeburn   185:             if ($prevread <= $posttime) {
1.80      raeburn   186:                 $newpostsflag = 1;
                    187:             }
1.54      www       188: 	    my $hidden=($contrib{'hidden'}=~/\.$idx\./);
                    189: 	    my $deleted=($contrib{'deleted'}=~/\.$idx\./);
1.68      www       190: 	    my $origindex='0.';
1.69      www       191: 	    if (($contrib{$idx.':replyto'}) && ($ENV{'environment.threadeddiscussion'})) {
1.68      www       192: # this is a follow-up message
                    193: 		$original[$idx]=$original[$contrib{$idx.':replyto'}];
                    194: 		$depth[$idx]=$depth[$contrib{$idx.':replyto'}]+1;
                    195: 		$origindex=$index[$contrib{$idx.':replyto'}];
                    196: 		if ($depth[$idx]>$maxdepth) { $maxdepth=$depth[$idx]; }
                    197: 	    } else {
                    198: # this is an original message
                    199: 		$original[$idx]=0;
                    200: 		$depth[$idx]=0;
                    201: 	    }
                    202: 	    if ($replies[$depth[$idx]]) {
                    203: 		$replies[$depth[$idx]]++;
                    204: 	    } else {
                    205: 		$replies[$depth[$idx]]=1;
                    206: 	    }
1.54      www       207: 	    unless ((($hidden) && (!$seeid)) || ($deleted)) {
1.67      www       208: 		$visible++;
1.54      www       209: 		my $message=$contrib{$idx.':message'};
                    210: 		$message=~s/\n/\<br \/\>/g;
                    211: 		$message=&Apache::lontexconvert::msgtexconverted($message);
1.78      raeburn   212:                 my $subject=$contrib{$idx.':subject'};
                    213:                 if (defined($subject)) {
                    214:                     $subject=~s/\n/\<br \/\>/g;
                    215:                     $subject=&Apache::lontexconvert::msgtexconverted($subject);
                    216:                 }
1.54      www       217: 		if ($contrib{$idx.':attachmenturl'}) {
1.82      albertel  218: 		    my ($fname)
                    219:                         =($contrib{$idx.':attachmenturl'}=~m|/([^/]+)$|);
                    220: 		    &Apache::lonnet::allowuploaded('/adm/feedback',
                    221: 					   $contrib{$idx.':attachmenturl'});
                    222: 		    $message.='<p>'.&mt('Attachment').
                    223: 			': <a href="'.$contrib{$idx.':attachmenturl'}.'"><tt>'.
                    224: 			$fname.'</tt></a></p>';
1.54      www       225: 		}
                    226: 		if ($message) {
                    227: 		    if ($hidden) {
                    228: 			$message='<font color="#888888">'.$message.'</font>';
                    229: 		    }
                    230: 		    my $screenname=&Apache::loncommon::screenname(
                    231: 					    $contrib{$idx.':sendername'},
                    232: 					    $contrib{$idx.':senderdomain'});
                    233: 		    my $plainname=&Apache::loncommon::nickname(
                    234: 					    $contrib{$idx.':sendername'},
                    235: 					    $contrib{$idx.':senderdomain'});
                    236: 		    
1.62      www       237: 		    my $sender=&mt('Anonymous');
1.54      www       238: 		    if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
                    239: 			$sender=&Apache::loncommon::aboutmewrapper(
                    240: 					 $plainname,
                    241: 					 $contrib{$idx.':sendername'},
                    242: 					 $contrib{$idx.':senderdomain'}).' ('.
                    243: 					 $contrib{$idx.':sendername'}.' at '.
                    244: 					 $contrib{$idx.':senderdomain'}.')';
                    245: 			if ($contrib{$idx.':anonymous'}) {
1.62      www       246: 			    $sender.=' ['.&mt('anonymous').'] '.
1.54      www       247: 				$screenname;
                    248: 			}
                    249: 			if ($seeid) {
                    250: 			    if ($hidden) {
                    251: 				$sender.=' <a href="/adm/feedback?unhide='.
1.80      raeburn   252: 				    $ressymb.':::'.$idx;
                    253:                                 if ($newpostsflag) {
                    254:                                     $sender .= '&previous='.$prevread;
                    255:                                 }
                    256:                                 $sender .= '">'.&mt('Make Visible').'</a>';
1.54      www       257: 			    } else {
                    258: 				$sender.=' <a href="/adm/feedback?hide='.
1.80      raeburn   259: 				    $ressymb.':::'.$idx;
                    260:                                 if ($newpostsflag) {
                    261:                                     $sender .= '&previous='.$prevread;
                    262:                                 }
                    263:                                 $sender .= '">'.&mt('Hide').'</a>';
1.54      www       264: 			    }                     
                    265: 			    $sender.=' <a href="/adm/feedback?deldisc='.
1.80      raeburn   266: 				$ressymb.':::'.$idx;
                    267:                                 if ($newpostsflag) {
                    268:                                     $sender .= '&previous='.$prevread;
                    269:                                 }
                    270:                                 $sender .= '">'.&mt('Delete').'</a>';
1.64      www       271: 			}
1.54      www       272: 		    } else {
                    273: 			if ($screenname) {
                    274: 			    $sender='<i>'.$screenname.'</i>';
                    275: 			}
1.77      www       276: 		    }
1.92    ! albertel  277: 		    if (&discussion_open($status) &&
1.90      albertel  278: 			&Apache::lonnet::allowed('pch',
1.77      www       279: 						 $ENV{'request.course.id'}.
                    280: 						 ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
                    281: 			$sender.=' <a href="/adm/feedback?replydisc='.
1.80      raeburn   282: 			    $ressymb.':::'.$idx;
                    283:                         if ($newpostsflag) {
                    284:                             $sender .= '&previous='.$prevread;
                    285:                         }
                    286:                         $sender .= '" '.$target.'>'.&mt('Reply').'</a>';
1.54      www       287: 		    }
                    288: 		    my $vgrlink;
                    289: 		    if ($viewgrades) {
                    290: 			$vgrlink=&Apache::loncommon::submlink('Submissions',
                    291:             $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb);
                    292: 		    }
1.68      www       293: #figure out at what position this needs to print
                    294: 		    my $thisindex=$idx;
1.69      www       295: 		    if ($ENV{'environment.threadeddiscussion'}) {
1.68      www       296: 			$thisindex=$origindex.substr('00'.$replies[$depth[$idx]],-2,2);	
                    297: 		    }
                    298: 		    $alldiscussion{$thisindex}=$idx;
                    299: 		    $index[$idx]=$thisindex;
1.79      raeburn   300:                     my $spansize = 2;
1.80      raeburn   301:                     if ($showonlyunread && $prevread > $posttime) {
                    302:                         $notshown{$idx} = 1;
1.78      raeburn   303:                     } else {
1.80      raeburn   304:                         if ($prevread > 0 && $prevread <= $posttime) {
1.84      raeburn   305:                             $newitem{$idx} = 1;
                    306:                             $discussionitems[$idx] .= '
                    307:                              <p><table border="0" width="100%">
                    308:                               <tr><td align="left"><font color="#FF0000"><b>NEW</b></font></td>';
                    309:                         } else {
                    310:                             $newitem{$idx} = 0;
                    311:                             $discussionitems[$idx] .= '
                    312:                              <p><table border="0" width="100%">
                    313:                               <tr><td align="left">&nbsp;</td>';
1.80      raeburn   314:                         }
                    315:                         $discussionitems[$idx] .= '<td align ="left">&nbsp;&nbsp;'.
                    316:                             '<b>'.$subject.'</b>&nbsp;&nbsp;'.
                    317:                             $sender.'</b> '.$vgrlink.' ('.
                    318:                             localtime($posttime).')</td></tr>'.
                    319:                             '</table><blockquote>'.$message.'</blockquote></p>';
1.78      raeburn   320:                     }
                    321:                 }
                    322:             }
1.54      www       323: 	}
1.64      www       324:     }
1.80      raeburn   325: 
1.67      www       326:     my $discussion='';
1.84      raeburn   327: 
                    328:     my $function = &Apache::loncommon::get_users_function();
                    329:     my $color = &Apache::loncommon::designparm($function.'.tabbg',
                    330:                                                     $ENV{'user.domain'});
                    331:     my %lt = &Apache::lonlocal::texthash(
                    332:         'cuse' => 'Current settings for this discussion',
                    333:         'allposts' => 'All posts',
                    334:         'unread' => 'New posts only',
                    335:         'ondisp' => 'Once displayed',
                    336:         'onmark' => 'Once marked read',
                    337:         'disa' => 'Posts to be displayed',
                    338:         'npce' => 'Posts cease to be marked "NEW"',
                    339:         'chgt' => 'Change to ',
                    340:     );
                    341: 
                    342:     my $currdisp = $lt{'allposts'};
                    343:     my $currmark = $lt{'onmark'};
                    344:     my $dispchange = $lt{'unread'};
                    345:     my $markchange = $lt{'ondisp'};
                    346:     my $displink = '/adm/feedback?onlyunread='.$ressymb;
                    347:     my $marklink = '/adm/feedback?markondisp='.$ressymb;
                    348: 
                    349:     if ($markondisp) {
                    350:         $currmark = $lt{'ondisp'};
                    351:         $markchange = $lt{'onmark'};
                    352:         $marklink = '/adm/feedback?markonread='.$ressymb;
                    353:         if ($newpostsflag) {
                    354:             $marklink .= '&previous='.$prevread;
                    355:         }
                    356:     }
                    357: 
                    358:     if ($showonlyunread) {
                    359:         $currdisp = $lt{'unread'};
                    360:         $dispchange = $lt{'allposts'};
                    361:         $displink = '/adm/feedback?allposts='.$ressymb;
                    362:     }
                    363: 
                    364:     if ($newpostsflag) {
                    365:         $displink .= '&previous='.$prevread;
                    366:     }
                    367: 
1.67      www       368:     if ($visible) {
1.80      raeburn   369: # Print the discusssion
1.67      www       370: 	$discussion.='<table bgcolor="#AAAAAA" cellpadding="2" cellspacing="2" border="0">';
1.84      raeburn   371: 	my $colspan=$maxdepth+1;
                    372:         $discussion .= '<tr bgcolor="#FFFFFF"><td colspan="'.$colspan.'" valign="top">'.
                    373:         '<table border="0" bgcolor="#FFFFFF" width="100%" cellspacing="2" cellpadding="2">'.
                    374:         '<tr><td align="left"><b>'.$lt{'cuse'}.'</b></td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td align="right"><b>'.$lt{'chgt'}.'</b></td></tr>'.
                    375:         '<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>'.
                    376:         '<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>'.
                    377:         '</table></td></tr>'.
                    378:         '<tr><td bgcolor="#DDDDBB" colspan="'.$colspan.'">'.
                    379:         '<table border="0" width="100%" bgcolor="#DDDDBB"><tr>';
                    380:         if ($visible>2) {
                    381: 	    $discussion.='<td align="left">'.
                    382:             '<a href="/adm/feedback?threadedon='.$ressymb;
                    383:             if ($newpostsflag) {
                    384:                 $discussion .= '&previous='.$prevread;
                    385:             }
                    386:             $discussion .='">'.&mt('Threaded View').'</a>&nbsp;&nbsp;'.
                    387:             '<a href="/adm/feedback?threadedoff='.$ressymb;
                    388:             if ($newpostsflag) {
                    389:                 $discussion .= '&previous='.$prevread;
                    390:             }
                    391:             $discussion .='">'.&mt('Chronological View').'</a>&nbsp;&nbsp;</td>';
                    392: 	} 
                    393:         if ($newpostsflag) {
                    394:             if (!$markondisp) {
                    395:                 $discussion .='<td align="right"><a href="/adm/feedback?markread='.$ressymb.'">'.&mt('Mark new posts as read').'</a>&nbsp;&nbsp;';
1.78      raeburn   396:             } else {
1.84      raeburn   397:                 $discussion .= '<td>&nbsp;</td>';
1.78      raeburn   398:             }
1.84      raeburn   399:         } else {
                    400:             $discussion .= '<td>&nbsp;</td>';
                    401:         }
                    402:         $discussion .= '</tr></table></td></tr>';
                    403: 
1.80      raeburn   404:         my $numhidden = keys %notshown;
                    405:         if ($numhidden > 0) {
                    406:             my $colspan = $maxdepth+1;
                    407:             $discussion.="\n".'<tr><td bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
                    408:                          '<a href="/adm/feedback?allposts='.$ressymb;
                    409:             if ($newpostsflag) {
                    410:                 $discussion .= '&previous='.$prevread;
                    411:             }
                    412:             $discussion .= '">'.&mt('Show all posts').'</a> '.&mt('to display').' '.
                    413:                          $numhidden.' '.&mt('previously viewed posts').
                    414:                          '<br/></td></tr>';
                    415:         }
1.68      www       416: 	foreach (sort { $a <=> $b } keys %alldiscussion) {
1.80      raeburn   417:             unless ($notshown{$alldiscussion{$_}} eq '1') {
                    418: 	        $discussion.="\n<tr>";
                    419: 	        my $thisdepth=$depth[$alldiscussion{$_}];
                    420: 	        for (1..$thisdepth) {
                    421: 		    $discussion.='<td>&nbsp;&nbsp;&nbsp;</td>';
                    422: 	        }
                    423: 	        my $colspan=$maxdepth-$thisdepth+1;
1.84      raeburn   424:                 $discussion.='<td  bgcolor="'.$bgcols[$newitem{$alldiscussion{$_}}].'" colspan="'.$colspan.'">'.
1.80      raeburn   425:                              $discussionitems[$alldiscussion{$_}].
                    426: 	                     '</td></tr>';
1.69      www       427: 	    }
1.80      raeburn   428:         }
                    429:         $discussion.='</table><br /><br />';
1.54      www       430:     }
                    431:     if ($discussiononly) {
                    432: 	$discussion.=(<<ENDDISCUSS);
                    433: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">
                    434: <input type="submit" name="discuss" value="Post Discussion" />
                    435: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
1.73      albertel  436: <input type="hidden" name="symb" value="$ressymb" />
1.54      www       437: <input type="hidden" name="sendit" value="true" />
                    438: <br />
                    439: <font size="1">Note: in anonymous discussion, your name is visible only to
                    440: course faculty</font><br />
1.78      raeburn   441: <b>Title:</b>&nbsp;<input type="text" name="subject" value="" size="30" /><br /><br />
1.88      www       442: <textarea name="comment" cols="60" rows="12" wrap="hard"></textarea>
1.54      www       443: <p>
                    444: Attachment (128 KB max size): <input type="file" name="attachment" />
                    445: </p>
                    446: </form>
                    447: ENDDISCUSS
                    448:       $discussion.=&generate_preview_button();
1.74      www       449:     } else {
1.92    ! albertel  450: 	if (&discussion_open($status) &&
1.90      albertel  451: 	    &Apache::lonnet::allowed('pch',
1.74      www       452: 				   $ENV{'request.course.id'}.
                    453: 	($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
                    454: 			    $discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
                    455: 				$symb.':::" '.$target.'>'.
                    456: 				'<img src="/adm/lonMisc/chat.gif" border="0" />'.
                    457: 				&mt('Post Discussion').'</a></td></tr></table>';
                    458: 			}
                    459:     }
1.54      www       460:    return $discussion;
                    461: }
1.1       www       462: 
1.6       albertel  463: sub mail_screen {
                    464:   my ($r,$feedurl,$options) = @_;
1.45      www       465:   my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
                    466:                                           '','onLoad="window.focus();"');
1.51      albertel  467:   my $title=&Apache::lonnet::gettitle($feedurl);
                    468:   if (!$title) { $title = $feedurl; }
1.69      www       469:   my $quote='';
1.78      raeburn   470:   my $subject = '';
1.80      raeburn   471:   my $prevtag = '';
1.69      www       472:   if ($ENV{'form.replydisc'}) {
                    473:       my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
                    474:       my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                    475: 					   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    476: 					   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.80      raeburn   477:       unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
1.69      www       478: 	  my $message=$contrib{$idx.':message'};
                    479: 	  $message=~s/\n/\<br \/\>/g;
                    480: 	  $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
1.79      raeburn   481:           if ($idx > 0) {
                    482:               $subject = 'Re: '.$contrib{$idx.':subject'};
                    483:           }
1.69      www       484:       }
1.80      raeburn   485:       if ($ENV{'form.previous'}) {
                    486:           $prevtag = '<input type="hidden" name="previous" value="'.$ENV{'form.previous'}.'" />';
                    487:       }
1.69      www       488:   }
1.85      www       489:   my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
1.86      www       490:   my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
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.86      www       534: 	    document.mailform.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.63      albertel  558: <textarea name="comment" cols="60" rows="10" wrap="hard">
                    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().
                    570: &Apache::lonhtmlcommon::htmlareaactive().
                    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>