Annotation of loncom/homework/outputtags.pm, revision 1.39

1.13      albertel    1: # The LearningOnline Network with CAPA 
                      2: # tags that create controlled output
                      3: #
1.39    ! foxr        4: # $Id: outputtags.pm,v 1.38 2005/04/07 06:56:22 albertel Exp $
1.13      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: #
                     28: 
1.1       albertel   29: package Apache::outputtags; 
                     30: 
                     31: use strict;
                     32: use Apache::lonnet;
                     33: use POSIX qw(strftime);
                     34: 
1.15      harris41   35: BEGIN {
1.35      albertel   36:     &Apache::lonxml::register('Apache::outputtags',('displayduedate','displaytitle','displayweight','displaystudentphoto'));
1.20      albertel   37: }
                     38: 
                     39: sub initialize_outputtags {
                     40:     %Apache::outputtags::showonce=();
1.1       albertel   41: }
                     42: 
1.39    ! foxr       43: 
1.2       albertel   44: sub start_displayduedate {
1.20      albertel   45:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                     46:     my $result;
1.39    ! foxr       47: 
        !            48:     # Different parts can have different due dates... so we keep a list
        !            49:     # of the parts for which we've displayed the duedate:
        !            50: 
1.20      albertel   51:     if (exists($Apache::outputtags::showonce{'displayduedate'})) {
1.39    ! foxr       52: 	if (grep(/^\Q$Apache::inputtags::part\E$/,
        !            53: 		 @{$Apache::outputtags::showonce{'displayduedate'}})) {
        !            54: 	    return '';
        !            55: 	}
1.10      albertel   56:     }
1.39    ! foxr       57:     push (@{$Apache::outputtags::showonce{'displayduedate'}},
        !            58: 	  $Apache::inputtags::part);
        !            59: 
1.20      albertel   60:     my $status=$Apache::inputtags::status['-1'];
                     61:     &Apache::lonxml::debug("got a $status in duedatebox");
1.32      albertel   62:     my $style = &Apache::lonxml::get_param('style',$parstack,$safeeval);
1.20      albertel   63:     if (($status =~ /CAN.*_ANSWER/) && ($target eq 'web')) {
                     64: 	my $id = $Apache::inputtags::part;
                     65: 	my $date = &Apache::lonnet::EXT("resource.$id.duedate");
                     66: 	&Apache::lonxml::debug("duedatebox found $date for $id");
1.39    ! foxr       67: 
        !            68: 	# Only show the due date if the current date is 
        !            69: 	# different from due date of the previous part.  I think
        !            70: 	# this is probably the best way to avoid due date clutter.
        !            71: 
        !            72:        	my $showduedate = 1;
        !            73: 	my $part_count  = scalar(@{$Apache::outputtags::showonce{'displayduedate'}});
        !            74: 	if ($part_count > 1) {
        !            75: 	    my $prev_part_id = $Apache::outputtags::showonce{'displayduedate'}->[$part_count-2];
        !            76: 	    my $prev_due_date = &Apache::lonnet::EXT("resource.$prev_part_id.duedate");
        !            77: 	    if ($prev_due_date == $date) {
        !            78: 		$showduedate = 0;
        !            79: 	    }
        !            80: 	}
        !            81: 
        !            82: 	if ($showduedate) {
        !            83: 	    if (lc($style) !~ 'plain') { 
        !            84: 		$result ='<table border="on"><tr><td>Due '.
        !            85: 		    &Apache::lonnavmaps::timeToHumanString($date).
        !            86: 		    '</td></tr></table>';
        !            87: 	    } else {
        !            88: 		$result=&mt('Due').' '.&Apache::lonnavmaps::timeToHumanString($date);
        !            89: 	    }
1.32      albertel   90: 	}
1.20      albertel   91:     } elsif ( $target eq 'edit' ) {
                     92: 	$result=&Apache::edit::tag_start($target,$token);
                     93: 	$result.='</td></tr>';
                     94: 	$result.=&Apache::edit::end_table();
1.5       www        95:     }
1.20      albertel   96:     return $result;
1.1       albertel   97: }
                     98: 
1.2       albertel   99: sub end_displayduedate {
1.20      albertel  100:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    101:     my @result;
                    102:     if ($target eq 'edit') { $result[1]='no'; }
                    103:     return @result;
1.2       albertel  104: }
                    105: 
                    106: sub start_displaytitle {
1.20      albertel  107:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    108:     my $result='';
1.21      albertel  109:     if (exists($Apache::outputtags::showonce{'displayduetitle'})) {
1.20      albertel  110: 	return '';
                    111:     } else {
1.21      albertel  112: 	$Apache::outputtags::showonce{'displayduetitle'}=1;
1.20      albertel  113:     }
1.31      albertel  114:     my $name=&Apache::structuretags::get_resource_name();
1.32      albertel  115:     my $style = &Apache::lonxml::get_param('style',$parstack,$safeeval);
1.20      albertel  116:     if ($target eq 'web') {
1.32      albertel  117: 	$result=$name;
                    118: 	if (lc($style) !~ 'plain') { $result="<h1>$name</h1>"; }
1.20      albertel  119:     } elsif ($target eq 'edit') {
                    120: 	$result=&Apache::edit::tag_start($target,$token);
                    121: 	$result.='</td></tr>';
                    122: 	$result.=&Apache::edit::end_table();
1.25      sakharuk  123:     } elsif ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
1.31      albertel  124: 	$name=&Apache::lonxml::latex_special_symbols($name);
1.32      albertel  125: 	if (lc($style) !~ 'plain') { 
                    126: 	    $result='\vskip 0 mm\noindent\textbf{'.$name.'}\vskip 0 mm';
                    127: 	} else {
                    128: 	    $result=$name;
                    129: 	}
1.20      albertel  130:     }
                    131:     return $result;
1.2       albertel  132: }
                    133: 
                    134: sub end_displaytitle {
1.22      albertel  135:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    136:     my @result;
                    137:     if ($target eq 'edit') { $result[1]='no'; }
                    138:     return @result;
                    139: }
                    140: 
1.29      albertel  141: sub multipart {
                    142:     my ($uri)=@_;
1.38      albertel  143:     if (!defined($uri)) { $uri=$env{'request.uri'}; }
1.29      albertel  144:     my @parts;
                    145:     my $metadata = &Apache::lonnet::metadata($uri,'packages');
                    146:     foreach (split(/\,/,$metadata)) {
                    147: 	if ($_ =~ /^part_(.*)$/) {
                    148: 	    my $part = $1;
                    149: 	    if ($part ne '0') { push(@parts,$part); }
                    150: 	}
                    151:     }
                    152:     return @parts;
                    153: }
                    154: 
1.22      albertel  155: sub start_displayweight {
                    156:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    157:     my $result;
                    158:     if (exists($Apache::outputtags::showonce{'displayweight'})) {
1.26      albertel  159: 	if(grep(/^\Q$Apache::inputtags::part\E$/,
                    160: 		@{$Apache::outputtags::showonce{'displayweight'}})) {
                    161: 	    return '';
                    162: 	}
1.22      albertel  163:     }
1.26      albertel  164:     push(@{$Apache::outputtags::showonce{'displayweight'}},
                    165: 	 $Apache::inputtags::part);
1.24      albertel  166:     if ($target eq 'web' || $target eq 'tex') {
1.22      albertel  167: 	my $id = $Apache::inputtags::part;
1.27      albertel  168: 	if ($id ne '0') {
                    169: 	    my $weight = &Apache::lonnet::EXT("resource.$id.weight");
                    170: 	    if (!defined($weight) || ($weight eq '')) { $weight=1; }
                    171: 	    $result.=$weight;
                    172: 	} else {
1.38      albertel  173: 	    my @parts=&multipart($env{'request.uri'});
1.27      albertel  174: 	    my $weight;
1.30      albertel  175: 	    if (@parts) {
                    176: 	        foreach my $part (@parts) {
                    177: 		    my $pweight=&Apache::lonnet::EXT("resource.$part.weight");
                    178: 		    if (!defined($pweight) || ($pweight eq '')) { $pweight=1; }
                    179: 		    $weight+=$pweight;
                    180: 	        }
                    181: 	    } else {
                    182: 		$weight = &Apache::lonnet::EXT("resource.$id.weight");
                    183:                 if (!defined($weight) || ($weight eq '')) { $weight=1; }
1.27      albertel  184: 	    }
                    185: 	    $result=$weight;
                    186: 	}
1.22      albertel  187:     } elsif ( $target eq 'edit' ) {
                    188: 	$result=&Apache::edit::tag_start($target,$token);
                    189: 	$result.='</td></tr>';
                    190: 	$result.=&Apache::edit::end_table();
                    191:     }
                    192:     return $result;
                    193: }
                    194: 
                    195: sub end_displayweight {
1.20      albertel  196:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    197:     my @result;
                    198:     if ($target eq 'edit') { $result[1]='no'; }
                    199:     return @result;
1.1       albertel  200: }
                    201: 
1.35      albertel  202: sub start_displaystudentphoto {
                    203:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    204:     my $result;
                    205:     my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();
1.38      albertel  206:     if ($target eq 'web' && $user eq $env{'user.name'}) {
1.37      albertel  207: 	my $url=&Apache::lonnet::studentphoto($domain,$user,"gif");
1.35      albertel  208: 	my $args;
                    209: 	my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
                    210: 	if ($width) { $args.=" width=\"$width\" "; }
                    211: 	my $height=&Apache::lonxml::get_param('heigth',$parstack,$safeeval);
                    212: 	if ($height) { $args.=" height=\"$height\" "; }
1.36      albertel  213: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval);
                    214: 	if ($align) { $args.=" align=\"$align\" "; }
1.37      albertel  215: 	$result.=" <img $args src=\"$url\" alt=\"$user\@$domain\" />";
1.35      albertel  216:     }
1.38      albertel  217:     if ($target eq 'tex' && $env{'request.role'} =~ /^cc/) {
1.37      albertel  218: 	my $url=&Apache::lonnet::studentphoto($domain,$user,"eps");
1.35      albertel  219: 	my $ua=new LWP::UserAgent;
1.37      albertel  220: 	my $request=new HTTP::Request('GET',$url);
1.35      albertel  221: 	my $response=$ua->request($request);
                    222: 	if ($response->is_success) {
                    223: 	    my $file=$user."_".$domain."_studentphoto.eps";
                    224: 	    open(FILE,">".$Apache::lonnet::perlvar{'lonPrtDir'}."/$file");
                    225: 	    print FILE $response->content;
                    226: 	    close(FILE);
                    227: 	    my $width_param=&Apache::londefdef::image_size($Apache::lonnet::perlvar{'lonPrtDir'}."/$file",'0.3',$parstack,$safeeval);
                    228: 	    $result.=' \graphicspath{{'.$Apache::lonnet::perlvar{'lonPrtDir'}.
                    229: 		'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
1.36      albertel  230: 	} else {
                    231: 	    $result="$user\@$domain";
1.35      albertel  232: 	}
                    233:     }
                    234:     return $result;
                    235: }
                    236: 
                    237: sub end_displaystudentphoto {
                    238:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    239:     my @result;
                    240:     if ($target eq 'edit') { $result[1]='no'; }
                    241:     return @result;
                    242: }
                    243: 
1.1       albertel  244: 1;
                    245: __END__

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