Annotation of loncom/homework/outputtags.pm, revision 1.34
1.13 albertel 1: # The LearningOnline Network with CAPA
2: # tags that create controlled output
3: #
1.34 ! albertel 4: # $Id: outputtags.pm,v 1.33 2003/10/07 17:52:29 www 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");
1.32 albertel 53: my $style = &Apache::lonxml::get_param('style',$parstack,$safeeval);
1.20 albertel 54: if (($status =~ /CAN.*_ANSWER/) && ($target eq 'web')) {
1.21 albertel 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: # }
1.20 albertel 60: my $id = $Apache::inputtags::part;
61: my $date = &Apache::lonnet::EXT("resource.$id.duedate");
62: &Apache::lonxml::debug("duedatebox found $date for $id");
1.32 albertel 63: if (lc($style) !~ 'plain') {
64: $result ='<table border="on"><tr><td>Due '.
65: &Apache::lonnavmaps::timeToHumanString($date).
1.21 albertel 66: '</td></tr></table>';
1.32 albertel 67: } else {
1.33 www 68: $result=&mt('Due').' '.&Apache::lonnavmaps::timeToHumanString($date);
1.32 albertel 69: }
1.21 albertel 70: # } else {
71: # $result ='<table border="on"><tr><td>No due date set.</td></tr></table>';
72: # }
1.20 albertel 73: } elsif ( $target eq 'edit' ) {
74: $result=&Apache::edit::tag_start($target,$token);
75: $result.='</td></tr>';
76: $result.=&Apache::edit::end_table();
1.5 www 77: }
1.20 albertel 78: return $result;
1.1 albertel 79: }
80:
1.2 albertel 81: sub end_displayduedate {
1.20 albertel 82: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
83: my @result;
84: if ($target eq 'edit') { $result[1]='no'; }
85: return @result;
1.2 albertel 86: }
87:
88: sub start_displaytitle {
1.20 albertel 89: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
90: my $result='';
1.21 albertel 91: if (exists($Apache::outputtags::showonce{'displayduetitle'})) {
1.20 albertel 92: return '';
93: } else {
1.21 albertel 94: $Apache::outputtags::showonce{'displayduetitle'}=1;
1.20 albertel 95: }
1.31 albertel 96: my $name=&Apache::structuretags::get_resource_name();
1.32 albertel 97: my $style = &Apache::lonxml::get_param('style',$parstack,$safeeval);
1.20 albertel 98: if ($target eq 'web') {
1.32 albertel 99: $result=$name;
100: if (lc($style) !~ 'plain') { $result="<h1>$name</h1>"; }
1.20 albertel 101: } elsif ($target eq 'edit') {
102: $result=&Apache::edit::tag_start($target,$token);
103: $result.='</td></tr>';
104: $result.=&Apache::edit::end_table();
1.25 sakharuk 105: } elsif ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
1.31 albertel 106: $name=&Apache::lonxml::latex_special_symbols($name);
1.32 albertel 107: if (lc($style) !~ 'plain') {
108: $result='\vskip 0 mm\noindent\textbf{'.$name.'}\vskip 0 mm';
109: } else {
110: $result=$name;
111: }
1.20 albertel 112: }
113: return $result;
1.2 albertel 114: }
115:
116: sub end_displaytitle {
1.22 albertel 117: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
118: my @result;
119: if ($target eq 'edit') { $result[1]='no'; }
120: return @result;
121: }
122:
1.29 albertel 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:
1.22 albertel 137: sub start_displayweight {
138: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
139: my $result;
140: if (exists($Apache::outputtags::showonce{'displayweight'})) {
1.26 albertel 141: if(grep(/^\Q$Apache::inputtags::part\E$/,
142: @{$Apache::outputtags::showonce{'displayweight'}})) {
143: return '';
144: }
1.22 albertel 145: }
1.26 albertel 146: push(@{$Apache::outputtags::showonce{'displayweight'}},
147: $Apache::inputtags::part);
1.24 albertel 148: if ($target eq 'web' || $target eq 'tex') {
1.22 albertel 149: my $id = $Apache::inputtags::part;
1.27 albertel 150: if ($id ne '0') {
151: my $weight = &Apache::lonnet::EXT("resource.$id.weight");
152: if (!defined($weight) || ($weight eq '')) { $weight=1; }
153: $result.=$weight;
154: } else {
1.29 albertel 155: my @parts=&multipart($ENV{'request.uri'});
1.27 albertel 156: my $weight;
1.30 albertel 157: if (@parts) {
158: foreach my $part (@parts) {
159: my $pweight=&Apache::lonnet::EXT("resource.$part.weight");
160: if (!defined($pweight) || ($pweight eq '')) { $pweight=1; }
161: $weight+=$pweight;
162: }
163: } else {
164: $weight = &Apache::lonnet::EXT("resource.$id.weight");
165: if (!defined($weight) || ($weight eq '')) { $weight=1; }
1.27 albertel 166: }
167: $result=$weight;
168: }
1.22 albertel 169: } elsif ( $target eq 'edit' ) {
170: $result=&Apache::edit::tag_start($target,$token);
171: $result.='</td></tr>';
172: $result.=&Apache::edit::end_table();
173: }
174: return $result;
175: }
176:
177: sub end_displayweight {
1.20 albertel 178: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
179: my @result;
180: if ($target eq 'edit') { $result[1]='no'; }
181: return @result;
1.1 albertel 182: }
183:
184: 1;
185: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>