X-Git-Url: https://git.p6c8.net/devedit.git/blobdiff_plain/3e6b9e338fe5ea06b487202fe54217f2082cd13d..aa2bc2bfca200e713a3a831192c992d78d782c47:/modules/Output.pm?ds=sidebyside
diff --git a/modules/Output.pm b/modules/Output.pm
index e8d4bad..7248922 100644
--- a/modules/Output.pm
+++ b/modules/Output.pm
@@ -5,8 +5,8 @@ package Output;
#
# HTML generating routines
#
-# Author: Patrick Canterino
-# Last modified: 09-22-2003
+# Author: Patrick Canterino
+# Last modified: 2005-01-06
#
use strict;
@@ -15,155 +15,81 @@ use vars qw(@EXPORT);
use CGI qw(header);
use HTML::Entities;
-use Tool;
+use Template;
### Export ###
use base qw(Exporter);
-@EXPORT = qw(htmlhead
- htmlfoot
+@EXPORT = qw(error_template
error
- abort
- error_in_use
- equal_url
- dir_link);
+ abort);
-# htmlhead()
-#
-# Generate the head of a HTML document
-#
-# Params: Title and heading
-#
-# Return: Head for the HTML document
-
-sub htmlhead($)
-{
- my $title = shift;
-
- my $html = header(-type => "text/html");
-
- $html .= <
-
-
-
-$title
-
-
-
-
-$title
-
-END
-
- return $html;
-}
+my $tpl_error;
-# htmlfoot()
-#
-# Generate the foot of a HTML document
+# error_template()
#
-# Params: -nothing-
+# Set the path to the template file used for error messages
+# (I'm lazy...)
#
-# Return: Foot for the HTML document
+# Params: Template file
-sub htmlfoot
+sub error_template($)
{
- return "\n\n";
+ $tpl_error = shift;
}
# error()
#
# Format an error message
#
-# Params: Error message
-#
-# Return: Formatted message (Scalar Reference)
-
-sub error($)
-{
- my $message = shift;
-
- my $output = htmlhead("Error");
- $output .= "$message
";
- $output .= htmlfoot;
-
- return \$output;
-}
-
-# abort()
-#
-# Print and error message and exit script
-#
-# Params: Error message
-
-sub abort($)
-{
- my $output = error(shift);
- print $$output;
- exit;
-}
-
-# error_in_use()
-#
-# Create a message, that a file is currently in use
-#
-# Params: File, which is in use
+# Params: 1. Error message
+# 2. Display a link to this path at the bottom of the page (optional)
+# 3. Hash reference: Template variables (optional)
#
# Return: Formatted message (Scalar Reference)
-sub error_in_use($)
+sub error($;$$)
{
- my $file = encode_entities(shift);
- my $dir = upper_path($file);
+ my ($message,$path,$vars) = @_;
- my $message = htmlhead("File in use");
- $message .= "The file '$file' is currently editet by someone else.
\n\n";
- $message .= "Back to $dir
";
- $message .= htmlfoot;
+ my $tpl = new Template;
+ $tpl->read_file($tpl_error);
- return \$message;
-}
+ $tpl->fillin('ERROR',$message);
+ $tpl->fillin('BACK',$path);
+ $tpl->fillin('SCRIPT',encode_entities($ENV{'SCRIPT_NAME'}));
-# equal_url()
-#
-# Create an "equals"-link and print it out
-#
-# Params: 1. HTTP root
-# 2. Relative path
-#
-# Return: Formatted link (String)
+ $tpl->parse_if_block('dir',defined $path);
-sub equal_url($$)
-{
- my ($root,$path) = @_;
- my $url;
+ if(ref($vars) eq 'HASH')
+ {
+ while(my ($key,$value) = each(%$vars))
+ {
+ $tpl->fillin($key,$value);
+ }
+ }
- $root =~ s!/$!!;
- $path =~ s!^/!!;
- $url = $root."/".$path;
- $url = encode_entities($url);
+ my $output = header(-type => 'text/html');
+ $output .= $tpl->get_template;
- return "(equals $url)
\n\n";
+ return \$output;
}
-# dir_link()
-#
-# Create the link to the directory of a file and
-# print it out
+# abort()
#
-# Params: File
+# Print an error message and exit script
+# ^^^^^
#
-# Return: Formatted link (String)
+# Params: 1. Error message
+# 2. Display a link to this path at the bottom of the page (optional)
+# 3. Hash reference: Template variables (optional)
-sub dir_link($)
+sub abort($;$$)
{
- my $dir = upper_path(shift);
- $dir = encode_entities($dir);
-
- return "Back to $dir
\n\n";
+ my $output = error(shift,shift,shift);
+ print $$output;
+ exit;
}
# it's true, baby ;-)