]> git.p6c8.net - devedit.git/blob - modules/Output.pm
Removed templates/confirm_unlock.htm
[devedit.git] / modules / Output.pm
1 package Output;
2
3 #
4 # Dev-Editor - Module Output
5 #
6 # HTML generating routines
7 #
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2005-04-22
10 #
11
12 use strict;
13
14 use vars qw(@EXPORT);
15
16 use CGI qw(header
17 escape);
18
19 use Template;
20 use Tool;
21
22 ### Export ###
23
24 use base qw(Exporter);
25
26 @EXPORT = qw(error_template
27 error
28 abort);
29
30 my $tpl_error;
31
32 # error_template()
33 #
34 # Set the path to the template file used for error messages
35 # (I'm lazy...)
36 #
37 # Params: Template file
38
39 sub error_template($)
40 {
41 $tpl_error = shift;
42 }
43
44 # error()
45 #
46 # Format an error message
47 #
48 # Params: 1. Error message
49 # 2. Display a link to this path at the bottom of the page (optional)
50 # Please use the unencoded form of the string!
51 # 3. Hash reference: Template variables (optional)
52 #
53 # Return: Formatted message (Scalar Reference)
54
55 sub error($;$$)
56 {
57 my ($message,$path,$vars) = @_;
58
59 my $tpl = new Template;
60 $tpl->read_file($tpl_error);
61
62 $tpl->fillin('ERROR',$message);
63 $tpl->fillin('BACK',encode_html($path));
64 $tpl->fillin('BACK_URL',escape($path));
65 $tpl->fillin('SCRIPT',encode_html($ENV{'SCRIPT_NAME'}));
66
67 $tpl->parse_if_block('dir',defined $path);
68
69 if(ref($vars) eq 'HASH')
70 {
71 while(my ($key,$value) = each(%$vars))
72 {
73 $tpl->fillin($key,$value);
74 }
75 }
76
77 my $output = header(-type => 'text/html');
78 $output .= $tpl->get_template;
79
80 return \$output;
81 }
82
83 # abort()
84 #
85 # Print an error message and exit script
86 # ^^^^^
87 #
88 # Params: 1. Error message
89 # 2. Display a link to this path at the bottom of the page (optional)
90 # 3. Hash reference: Template variables (optional)
91
92 sub abort($;$$)
93 {
94 my $output = error(shift,shift,shift);
95 print $$output;
96 exit;
97 }
98
99 # it's true, baby ;-)
100
101 1;
102
103 #
104 ### End ###

patrick-canterino.de