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

1.13      albertel    1: # The LearningOnline Network with CAPA 
                      2: # tags that create controlled output
                      3: #
1.27    ! albertel    4: # $Id: outputtags.pm,v 1.26 2003/05/02 18:56:29 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.22      albertel   36:     &Apache::lonxml::register('Apache::outputtags',('displayduedate','displaytitle','displayweight'));
1.20      albertel   37: }
                     38: 
                     39: sub initialize_outputtags {
                     40:     %Apache::outputtags::showonce=();
1.1       albertel   41: }
                     42: 
1.2       albertel   43: sub start_displayduedate {
1.20      albertel   44:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                     45:     my $result;
                     46:     if (exists($Apache::outputtags::showonce{'displayduedate'})) {
                     47: 	return '';
                     48:     } else {
                     49: 	$Apache::outputtags::showonce{'displayduedate'}=1;
1.10      albertel   50:     }
1.20      albertel   51:     my $status=$Apache::inputtags::status['-1'];
                     52:     &Apache::lonxml::debug("got a $status in duedatebox");
                     53:     if (($status =~ /CAN.*_ANSWER/) && ($target eq 'web')) {
1.21      albertel   54: #	my $format = &Apache::lonxml::get_param('format',$parstack,$safeeval);
                     55: #	if ($format eq '') {
                     56: #	    &Apache::lonxml::debug("using default format");
                     57: #	    $format="%c";
                     58: #	}
1.20      albertel   59: 	my $id = $Apache::inputtags::part;
                     60: 	my $date = &Apache::lonnet::EXT("resource.$id.duedate");
                     61: 	&Apache::lonxml::debug("duedatebox found $date for $id");
1.21      albertel   62: 	$result ='<table border="on"><tr><td>Due '.
                     63: 	    &Apache::lonnavmaps::timeToHumanString($date).
                     64: 		'</td></tr></table>';
                     65: #        } else {
                     66: #	    $result ='<table border="on"><tr><td>No due date set.</td></tr></table>';
                     67: #	}
1.20      albertel   68:     } elsif ( $target eq 'edit' ) {
                     69: 	$result=&Apache::edit::tag_start($target,$token);
                     70: 	$result.='</td></tr>';
                     71: 	$result.=&Apache::edit::end_table();
1.5       www        72:     }
1.20      albertel   73:     return $result;
1.1       albertel   74: }
                     75: 
1.2       albertel   76: sub end_displayduedate {
1.20      albertel   77:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                     78:     my @result;
                     79:     if ($target eq 'edit') { $result[1]='no'; }
                     80:     return @result;
1.2       albertel   81: }
                     82: 
                     83: sub start_displaytitle {
1.20      albertel   84:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                     85:     my $result='';
1.21      albertel   86:     if (exists($Apache::outputtags::showonce{'displayduetitle'})) {
1.20      albertel   87: 	return '';
                     88:     } else {
1.21      albertel   89: 	$Apache::outputtags::showonce{'displayduetitle'}=1;
1.20      albertel   90:     }
                     91:     if ($target eq 'web') {
                     92: 	$result="<h1>$Apache::lonhomework::name</h1>";
                     93:     } elsif ($target eq 'edit') {
                     94: 	$result=&Apache::edit::tag_start($target,$token);
                     95: 	$result.='</td></tr>';
                     96: 	$result.=&Apache::edit::end_table();
1.25      sakharuk   97:     } elsif ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
1.20      albertel   98: 	$Apache::lonhomework::name=~s/%/\%/g;
                     99: 	$Apache::lonhomework::name=~s/&/\&/g;
                    100: 	$result='\vskip 0 mm\noindent\textbf{'.$Apache::lonhomework::name.'}\vskip 0 mm';
                    101:     }
                    102:     return $result;
1.2       albertel  103: }
                    104: 
                    105: sub end_displaytitle {
1.22      albertel  106:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    107:     my @result;
                    108:     if ($target eq 'edit') { $result[1]='no'; }
                    109:     return @result;
                    110: }
                    111: 
                    112: sub start_displayweight {
                    113:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    114:     my $result;
                    115:     if (exists($Apache::outputtags::showonce{'displayweight'})) {
1.26      albertel  116: 	if(grep(/^\Q$Apache::inputtags::part\E$/,
                    117: 		@{$Apache::outputtags::showonce{'displayweight'}})) {
                    118: 	    return '';
                    119: 	}
1.22      albertel  120:     }
1.26      albertel  121:     push(@{$Apache::outputtags::showonce{'displayweight'}},
                    122: 	 $Apache::inputtags::part);
1.22      albertel  123:     my $status=$Apache::inputtags::status['-1'];
1.24      albertel  124:     if ($target eq 'web' || $target eq 'tex') {
1.22      albertel  125: 	my $id = $Apache::inputtags::part;
1.27    ! albertel  126: 	if ($id ne '0') {
        !           127: 	    my $weight = &Apache::lonnet::EXT("resource.$id.weight");
        !           128: 	    if (!defined($weight) || ($weight eq '')) { $weight=1; }
        !           129: 	    $result.=$weight;
        !           130: 	} else {
        !           131: 	    my $metadata = &Apache::lonnet::metadata($ENV{'request.uri'},
        !           132: 						     'packages');
        !           133: 	    &Apache::lonxml::debug("metadata for $ENV{'request.uri'} is $metadata");
        !           134: 	    my $weight;
        !           135: 	    foreach (split(/\,/,$metadata)) {
        !           136: 		if ($_ =~ /^part_(.*)$/) {
        !           137: 		    my $part = $1;
        !           138: 		    my $pweight=&Apache::lonnet::EXT("resource.$part.weight");
        !           139: 		    if (!defined($pweight) || ($pweight eq '')) { $pweight=1; }
        !           140: 		    $weight+=$pweight;
        !           141: 		}
        !           142: 	    }
        !           143: 	    $result=$weight;
        !           144: 	}
1.22      albertel  145:     } elsif ( $target eq 'edit' ) {
                    146: 	$result=&Apache::edit::tag_start($target,$token);
                    147: 	$result.='</td></tr>';
                    148: 	$result.=&Apache::edit::end_table();
                    149:     }
                    150:     return $result;
                    151: }
                    152: 
                    153: sub end_displayweight {
1.20      albertel  154:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    155:     my @result;
                    156:     if ($target eq 'edit') { $result[1]='no'; }
                    157:     return @result;
1.1       albertel  158: }
                    159: 
                    160: 1;
                    161: __END__

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