#
# HTML generating routines
#
-# Author: Patrick Canterino <patshaping@gmx.net>
-# Last modified: 09-22-2003
+# Author: Patrick Canterino <patrick@patshaping.de>
+# Last modified: 2005-05-11
+#
+# Copyright (C) 1999-2000 Roland Bluethgen, Frank Schoenmann
+# Copyright (C) 2003-2009 Patrick Canterino
+# All Rights Reserved.
+#
+# This file can be distributed and/or modified under the terms of
+# of the Artistic License 1.0 (see also the LICENSE file found at
+# the top level of the Dev-Editor distribution).
#
use strict;
use vars qw(@EXPORT);
-use CGI qw(header);
-use HTML::Entities;
+use CGI qw(header
+ escape);
+
+use Template;
use Tool;
### Export ###
use base qw(Exporter);
-@EXPORT = qw(htmlhead
- htmlfoot
+@EXPORT = qw(error_template
error
- abort
- error_in_use
- equal_url
- dir_link);
-
-# 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 .= <<END;
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
-"http://www.w3.org/TR/html4/loose.dtd">
-
-<html>
-<head>
-<title>$title</title>
-<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
-</head>
-<body bgcolor="#FFFFFF">
+ abort);
-<h1>$title</h1>
+my $tpl_error;
-END
-
- return $html;
-}
-
-# htmlfoot()
+# error_template()
#
-# Generate the foot of a HTML document
+# Set the path to the template file used for error messages
+# (I'm lazy...)
#
-# Params: -nothing-
-#
-# Return: Foot for the HTML document
+# Params: Template file
-sub htmlfoot
+sub error_template($)
{
- return "\n</body>\n</html>";
+ $tpl_error = shift;
}
# error()
#
# Format an error message
#
-# Params: Error message
+# Params: 1. Error message
+# 2. Display a link to this path at the bottom of the page (optional)
+# Please use the unencoded form of the string!
+# 3. Hash reference: Template variables (optional)
#
# Return: Formatted message (Scalar Reference)
-sub error($)
+sub error($;$$)
{
- my $message = shift;
+ my ($message,$path,$vars) = @_;
- my $output = htmlhead("Error");
- $output .= "<p>$message</p>";
- $output .= htmlfoot;
+ my $tpl = new Template;
+ $tpl->read_file($tpl_error);
- return \$output;
-}
+ $tpl->fillin('ERROR',$message);
+ $tpl->fillin('BACK',encode_html($path));
+ $tpl->fillin('BACK_URL',escape($path));
+ $tpl->fillin('SCRIPT',encode_html($ENV{'SCRIPT_NAME'}));
-# abort()
-#
-# Print and error message and exit script
-#
-# Params: Error message
+ $tpl->parse_if_block('dir',defined $path);
-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
-#
-# Return: Formatted message (Scalar Reference)
+ if(ref($vars) eq 'HASH')
+ {
+ while(my ($key,$value) = each(%$vars))
+ {
+ $tpl->fillin($key,$value);
+ }
+ }
-sub error_in_use($)
-{
- my $file = encode_entities(shift);
- my $dir = upper_path($file);
-
- my $message = htmlhead("File in use");
- $message .= "<p>The file '$file' is currently editet by someone else.</p>\n\n";
- $message .= "<a href=\"$ENV{'SCRIPT_NAME'}?command=show&file=$dir\"><p>Back to $dir</a></p>";
- $message .= htmlfoot;
-
- return \$message;
-}
+ my $output = header(-type => 'text/html');
+ $output .= $tpl->get_template;
-# equal_url()
-#
-# Create an "equals"-link and print it out
-#
-# Params: 1. HTTP root
-# 2. Relative path
-#
-# Return: Formatted link (String)
-
-sub equal_url($$)
-{
- my ($root,$path) = @_;
- my $url;
-
- $root =~ s!/$!!;
- $path =~ s!^/!!;
- $url = $root."/".$path;
- $url = encode_entities($url);
-
- return "<p>(equals <a href=\"$url\" target=\"_blank\">$url</a>)</p>\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 "<p><a href=\"$ENV{'SCRIPT_NAME'}?command=show&file=$dir\">Back to $dir</a></p>\n\n";
+ my $output = error(shift,shift,shift);
+ print $$output;
+ exit;
}
# it's true, baby ;-)