File:  [LON-CAPA] / loncom / homework / outputtags.pm
Revision 1.33: download - view: text, annotated - select for diffs
Tue Oct 7 17:52:29 2003 UTC (20 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
Internationalization and German localization, spelling mistake.

    1: # The LearningOnline Network with CAPA 
    2: # tags that create controlled output
    3: #
    4: # $Id: outputtags.pm,v 1.33 2003/10/07 17:52:29 www Exp $
    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: 
   29: package Apache::outputtags; 
   30: 
   31: use strict;
   32: use Apache::lonnet;
   33: use POSIX qw(strftime);
   34: 
   35: BEGIN {
   36:     &Apache::lonxml::register('Apache::outputtags',('displayduedate','displaytitle','displayweight'));
   37: }
   38: 
   39: sub initialize_outputtags {
   40:     %Apache::outputtags::showonce=();
   41: }
   42: 
   43: sub start_displayduedate {
   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;
   50:     }
   51:     my $status=$Apache::inputtags::status['-1'];
   52:     &Apache::lonxml::debug("got a $status in duedatebox");
   53:     my $style = &Apache::lonxml::get_param('style',$parstack,$safeeval);
   54:     if (($status =~ /CAN.*_ANSWER/) && ($target eq 'web')) {
   55: #	my $format = &Apache::lonxml::get_param('format',$parstack,$safeeval);
   56: #	if ($format eq '') {
   57: #	    &Apache::lonxml::debug("using default format");
   58: #	    $format="%c";
   59: #	}
   60: 	my $id = $Apache::inputtags::part;
   61: 	my $date = &Apache::lonnet::EXT("resource.$id.duedate");
   62: 	&Apache::lonxml::debug("duedatebox found $date for $id");
   63: 	if (lc($style) !~ 'plain') { 
   64: 	    $result ='<table border="on"><tr><td>Due '.
   65: 		&Apache::lonnavmaps::timeToHumanString($date).
   66: 		'</td></tr></table>';
   67: 	} else {
   68: 	    $result=&mt('Due').' '.&Apache::lonnavmaps::timeToHumanString($date);
   69: 	}
   70: #        } else {
   71: #	    $result ='<table border="on"><tr><td>No due date set.</td></tr></table>';
   72: #	}
   73:     } elsif ( $target eq 'edit' ) {
   74: 	$result=&Apache::edit::tag_start($target,$token);
   75: 	$result.='</td></tr>';
   76: 	$result.=&Apache::edit::end_table();
   77:     }
   78:     return $result;
   79: }
   80: 
   81: sub end_displayduedate {
   82:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   83:     my @result;
   84:     if ($target eq 'edit') { $result[1]='no'; }
   85:     return @result;
   86: }
   87: 
   88: sub start_displaytitle {
   89:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   90:     my $result='';
   91:     if (exists($Apache::outputtags::showonce{'displayduetitle'})) {
   92: 	return '';
   93:     } else {
   94: 	$Apache::outputtags::showonce{'displayduetitle'}=1;
   95:     }
   96:     my $name=&Apache::structuretags::get_resource_name();
   97:     my $style = &Apache::lonxml::get_param('style',$parstack,$safeeval);
   98:     if ($target eq 'web') {
   99: 	$result=$name;
  100: 	if (lc($style) !~ 'plain') { $result="<h1>$name</h1>"; }
  101:     } elsif ($target eq 'edit') {
  102: 	$result=&Apache::edit::tag_start($target,$token);
  103: 	$result.='</td></tr>';
  104: 	$result.=&Apache::edit::end_table();
  105:     } elsif ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
  106: 	$name=&Apache::lonxml::latex_special_symbols($name);
  107: 	if (lc($style) !~ 'plain') { 
  108: 	    $result='\vskip 0 mm\noindent\textbf{'.$name.'}\vskip 0 mm';
  109: 	} else {
  110: 	    $result=$name;
  111: 	}
  112:     }
  113:     return $result;
  114: }
  115: 
  116: sub end_displaytitle {
  117:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  118:     my @result;
  119:     if ($target eq 'edit') { $result[1]='no'; }
  120:     return @result;
  121: }
  122: 
  123: sub multipart {
  124:     my ($uri)=@_;
  125:     if (!defined($uri)) { $uri=$ENV{'request.uri'}; }
  126:     my @parts;
  127:     my $metadata = &Apache::lonnet::metadata($uri,'packages');
  128:     foreach (split(/\,/,$metadata)) {
  129: 	if ($_ =~ /^part_(.*)$/) {
  130: 	    my $part = $1;
  131: 	    if ($part ne '0') { push(@parts,$part); }
  132: 	}
  133:     }
  134:     return @parts;
  135: }
  136: 
  137: sub start_displayweight {
  138:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  139:     my $result;
  140:     if (exists($Apache::outputtags::showonce{'displayweight'})) {
  141: 	if(grep(/^\Q$Apache::inputtags::part\E$/,
  142: 		@{$Apache::outputtags::showonce{'displayweight'}})) {
  143: 	    return '';
  144: 	}
  145:     }
  146:     push(@{$Apache::outputtags::showonce{'displayweight'}},
  147: 	 $Apache::inputtags::part);
  148:     my $status=$Apache::inputtags::status['-1'];
  149:     if ($target eq 'web' || $target eq 'tex') {
  150: 	my $id = $Apache::inputtags::part;
  151: 	if ($id ne '0') {
  152: 	    my $weight = &Apache::lonnet::EXT("resource.$id.weight");
  153: 	    if (!defined($weight) || ($weight eq '')) { $weight=1; }
  154: 	    $result.=$weight;
  155: 	} else {
  156: 	    my @parts=&multipart($ENV{'request.uri'});
  157: 	    my $weight;
  158: 	    if (@parts) {
  159: 	        foreach my $part (@parts) {
  160: 		    my $pweight=&Apache::lonnet::EXT("resource.$part.weight");
  161: 		    if (!defined($pweight) || ($pweight eq '')) { $pweight=1; }
  162: 		    $weight+=$pweight;
  163: 	        }
  164: 	    } else {
  165: 		$weight = &Apache::lonnet::EXT("resource.$id.weight");
  166:                 if (!defined($weight) || ($weight eq '')) { $weight=1; }
  167: 	    }
  168: 	    $result=$weight;
  169: 	}
  170:     } elsif ( $target eq 'edit' ) {
  171: 	$result=&Apache::edit::tag_start($target,$token);
  172: 	$result.='</td></tr>';
  173: 	$result.=&Apache::edit::end_table();
  174:     }
  175:     return $result;
  176: }
  177: 
  178: sub end_displayweight {
  179:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  180:     my @result;
  181:     if ($target eq 'edit') { $result[1]='no'; }
  182:     return @result;
  183: }
  184: 
  185: 1;
  186: __END__

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