[system] / trunk / webwork2 / lib / WeBWorK / ContentGenerator.pm Repository:
ViewVC logotype

Diff of /trunk/webwork2/lib/WeBWorK/ContentGenerator.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1918 Revision 1984
1################################################################################ 1################################################################################
2# WeBWorK Online Homework Delivery System 2# WeBWorK Online Homework Delivery System
3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator.pm,v 1.88 2004/03/17 08:15:31 sh002i Exp $ 4# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator.pm,v 1.92 2004/04/27 02:45:14 sh002i Exp $
5# 5#
6# This program is free software; you can redistribute it and/or modify it under 6# This program is free software; you can redistribute it and/or modify it under
7# the terms of either: (a) the GNU General Public License as published by the 7# the terms of either: (a) the GNU General Public License as published by the
8# Free Software Foundation; either version 2, or (at your option) any later 8# Free Software Foundation; either version 2, or (at your option) any later
9# version, or (b) the "Artistic License" which comes with this package. 9# version, or (b) the "Artistic License" which comes with this package.
226 my ($self) = @_; 226 my ($self) = @_;
227 227
228 return $self->{r}; 228 return $self->{r};
229} 229}
230 230
231=item reply_with_file($type, $source, $name) 231=item reply_with_file($type, $source, $name, $delete_after)
232 232
233Enables file sending mode, causing go() to send the file specified by $source to 233Enables file sending mode, causing go() to send the file specified by $source to
234the client after calling pre_header_initialize(). The content type sent is 234the client after calling pre_header_initialize(). The content type sent is
235$type, and the suggested client-side file name is $name. 235$type, and the suggested client-side file name is $name. If $delete_after is
236true, $source is deleted after it is sent.
236 237
237=cut 238=cut
238 239
239sub reply_with_file { 240sub reply_with_file {
240 my ($self, $type, $source, $name) = @_; 241 my ($self, $type, $source, $name, $delete_after) = @_;
242 $delete_after ||= "";
241 243
242 $self->{reply_with_file} = { 244 $self->{reply_with_file} = {
243 type => $type, 245 type => $type,
244 source => $source, 246 source => $source,
245 name => $name, 247 name => $name,
248 delete_after => $delete_after,
246 }; 249 };
247} 250}
248 251
249=item do_reply_with_file($fileHash) 252=item do_reply_with_file($fileHash)
250 253
254 257
255sub do_reply_with_file { 258sub do_reply_with_file {
256 my ($self, $fileHash) = @_; 259 my ($self, $fileHash) = @_;
257 my $r = $self->r; 260 my $r = $self->r;
258 261
259 my $type = $self->{sendFile}->{type}; 262 my $type = $fileHash->{type};
260 my $source = $fileHash->{source}; 263 my $source = $fileHash->{source};
261 my $name = $self->{sendFile}->{name}; 264 my $name = $fileHash->{name};
265 my $delete_after = $fileHash->{delete_after};
262 266
263 # if there was a problem, we return here and let go() worry about sending the reply 267 # if there was a problem, we return here and let go() worry about sending the reply
264 return NOT_FOUND unless -e $source; 268 return NOT_FOUND unless -e $source;
265 return FORBIDDEN unless -r $source; 269 return FORBIDDEN unless -r $source;
266 270
276 # send the file 280 # send the file
277 $r->send_fd($fh); 281 $r->send_fd($fh);
278 282
279 # close the file and go home 283 # close the file and go home
280 close $fh; 284 close $fh;
285
286 if ($delete_after) {
287 unlink $source or warn "failed to unlink $source after sending: $!";
288 }
281} 289}
282 290
283=item reply_with_redirect($url) 291=item reply_with_redirect($url)
284 292
285Enables redirect mode, causing go() to redirect to the given URL after calling 293Enables redirect mode, causing go() to redirect to the given URL after calling
686 694
687=cut 695=cut
688 696
689#sub siblings { } 697#sub siblings { }
690 698
699=item timestamp()
700
701Defined in this package.
702
703Display the current time and date using default format "3:37pm on Jan 7, 2004".
704The display format can be adjusted by giving a style in the template.
705For example,
706
707 <!--#timestamp style="%m/%d/%y at %I:%M%P"-->
708
709will give standard WeBWorK time format. Wording and other formatting
710can be done in the template itself.
711=cut
712
713sub timestamp {
714 my ($self, $args) = @_;
715 my $formatstring = "%l:%M%P on %b %e, %Y";
716 $formatstring = $args->{style} if(defined($args->{style}));
717 return(Date::Format::time2str($formatstring, time()));
718}
719
691=item submiterror() 720=item submiterror()
692 721
693Defined in this package. 722Defined in this package.
694 723
695Print any error messages resulting from the last form submission. 724Print any error messages resulting from the last form submission.
1246=cut 1275=cut
1247 1276
1248sub nbsp { 1277sub nbsp {
1249 my $self = shift; 1278 my $self = shift;
1250 my $str = shift; 1279 my $str = shift;
1251 ($str =~/\S/) ? $str : '&nbsp;'; 1280 (defined $str && $str =~/\S/) ? $str : '&nbsp;';
1252} 1281}
1253 1282
1254=item errorOutput($error, $details) 1283=item errorOutput($error, $details)
1255 1284
1256=cut 1285=cut

Legend:
Removed from v.1918  
changed lines
  Added in v.1984

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9