From fae62c16cf66ea474ae619b0abf1b5e4af048978 Mon Sep 17 00:00:00 2001 From: kirinji Date: Sun, 5 Aug 2007 02:11:21 +0000 Subject: [PATCH] Some additional changes that were missed. --- cgi-files/Modules/Database/MySQL.pm | 2517 +++++++++++++++++++ cgi-files/Modules/Database/SQLite.pm | 2788 ++++++++++++++++++++++ cgi-files/Modules/Presentation/HTML4S.pm | 2005 ++++++++++++++++ cgi-files/lang/en-GB.xml | 527 ++++ cgi-files/lang/en-uk.xml | 10 - 5 files changed, 7837 insertions(+), 10 deletions(-) create mode 100644 cgi-files/Modules/Database/MySQL.pm create mode 100644 cgi-files/Modules/Database/SQLite.pm create mode 100644 cgi-files/Modules/Presentation/HTML4S.pm create mode 100644 cgi-files/lang/en-GB.xml delete mode 100644 cgi-files/lang/en-uk.xml diff --git a/cgi-files/Modules/Database/MySQL.pm b/cgi-files/Modules/Database/MySQL.pm new file mode 100644 index 0000000..d04430f --- /dev/null +++ b/cgi-files/Modules/Database/MySQL.pm @@ -0,0 +1,2517 @@ +################################################################################# +# Kiriwrite Database Module - MySQL 5.x Database Module (MySQL5.pm) # +# Database module for mainipulating data in a MySQL 5.x database. # +# # +# Copyright (C) 2007 Steve Brokenshire # +# # +# This module is licensed under the same license as Kiriwrite which is the GPL. # +# # +# This program is free software; you can redistribute it and/or modify it under # +# the terms of the GNU General Public License as published by the Free # +# Software Foundation; as version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.# +# # +# You should have received a copy of the GNU General Public License along with # +# this program; if not, write to the Free Software Foundation, Inc., 51 # +# Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # +################################################################################# + +# Define the package (perl module) name. + +package Kiriwrite::Database::MySQL; + +# Enable strict and use warnings. + +use strict; +use warnings; +use Encode; + +# Load the following Perl modules. + +use DBI; + +# Set the following values. + +our $VERSION = "0.1.0"; +my ($options, %options); +my $database_handle; +my $string_handle; +my $error; +my $errorext; +my $database_filename; +my $second_database_filename; + +################################################################################# +# Generic Subroutines. # +################################################################################# + +sub new{ +################################################################################# +# new: Create an instance of Kiriwrite::Database::MySQL # +# # +# Usage: # +# # +# $dbmodule = Kiriwrite::Database::SQLite->new(); # +################################################################################# + + # Get the perl module name. + + my $class = shift; + my $self = {}; + + return bless($self, $class); + +} + +sub loadsettings{ +################################################################################# +# loadsettings: Loads settings into the SQLite database module # +# # +# Usage: # +# # +# $dbmodule->loadsettings(Directory, options); # +# # +# options Specifies the following options (in any order). # +# # +# Directory Specifies the directory to use for getting databases. # +# DateTime Specifies the date and time format to use. # +# Server Specifies the server to use. # +# Database Specifies the database to use. # +# Username Specifies the username to use. # +# Password Specifies the password to use. # +# Port Specifies the server port to use. # +# Protocol Specifies the protocol to use. # +# TablePrefix Specifies the table prefix to use. # +################################################################################# + + # Get the data passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + # Add the directory setting to the list of options (as it's the only + # one needed for this database module). + + %options = ( + "Directory" => $passedoptions->{"Directory"}, + "DateTime" => $passedoptions->{"DateTime"}, + "Server" => $passedoptions->{"Server"}, + "Database" => $passedoptions->{"Database"}, + "Username" => $passedoptions->{"Username"}, + "Password" => $passedoptions->{"Password"}, + "Port" => $passedoptions->{"Port"}, + "Protocol" => $passedoptions->{"Protocol"}, + "TablePrefix" => $passedoptions->{"TablePrefix"} + ); + +} + +sub convert{ +################################################################################# +# convert: Converts data into SQL formatted data. # +# # +# Usage: # +# # +# $dbmodule->convert(data); # +# # +# data Specifies the data to convert. # +################################################################################# + + # Get the data passed to the subroutine. + + my $class = shift; + my $data = shift; + + if (!$data){ + $data = ""; + } + + $data =~ s/'/''/g; + $data =~ s/\b//g; + + return $data; + +} + +sub dateconvert{ +################################################################################# +# dateconvert: Converts a SQL date into a proper date. # +# # +# Usage: # +# # +# $dbmodule->dateconvert(date); # +# # +# date Specifies the date to convert. # +################################################################################# + + # Get the date passed to the subroutine. + + my $class = shift; + my $data = shift; + + # Convert the date given into the proper date. + + # Create the following varialbes to be used later. + + my $date; + my $time; + my $day; + my $day_full; + my $month; + my $month_check; + my $month_full; + my $year; + my $year_short; + my $hour; + my $hour_full; + my $minute; + my $minute_full; + my $second; + my $second_full; + my $seek = 0; + my $timelength; + my $datelength; + my $daylength; + my $secondlength; + my $startchar = 0; + my $char; + my $length; + my $count = 0; + + # Split the date and time. + + $length = length($data); + + if ($length > 0){ + + do { + + # Get the character and check if it is a space. + + $char = substr($data, $seek, 1); + + if ($char eq ' '){ + + # The character is a space, so get the date and time. + + $date = substr($data, 0, $seek); + $timelength = $length - $seek - 1; + $time = substr($data, $seek + 1, $timelength); + + } + + $seek++; + + } until ($seek eq $length); + + # Get the year, month and date. + + $length = length($date); + $seek = 0; + + do { + + # Get the character and check if it is a dash. + + $char = substr($date, $seek, 1); + + if ($char eq '-'){ + + # The character is a dash, so get the year, month or day. + + $datelength = $seek - $startchar; + + if ($count eq 0){ + + # Get the year from the date. + + $year = substr($date, 0, $datelength) + 1900; + $startchar = $seek; + $count = 1; + + # Get the last two characters to get the short year + # version. + + $year_short = substr($year, 2, 2); + + } elsif ($count eq 1){ + + # Get the month and day from the date. + + $month = substr($date, $startchar + 1, $datelength - 1) + 1; + + # Check if the month is less then 10, if it is + # add a zero to the value. + + if ($month < 10){ + + $month_full = '0' . $month; + + } else { + + $month_full = $month; + + } + + $startchar = $seek; + $count = 2; + + $daylength = $length - $seek + 1; + $day = substr($date, $startchar + 1, $daylength); + + $day =~ s/^0//; + + # Check if the day is less than 10, if it is + # add a zero to the value. + + if ($day < 10){ + + $day_full = '0' . $day; + + } else { + + $day_full = $day; + + } + + } + + } + + $seek++; + + } until ($seek eq $length); + + # Get the length of the time value and reset certain + # values to 0. + + $length = length($time); + $seek = 0; + $count = 0; + $startchar = 0; + + do { + + # Get the character and check if it is a colon. + + $char = substr($time, $seek, 1); + + if ($char eq ':'){ + + # The character is a colon, so get the hour, minute and day. + + $timelength = $seek - $startchar; + + if ($count eq 0){ + + # Get the hour from the time. + + $hour = substr($time, 0, $timelength); + $hour =~ s/^0//; + $count = 1; + $startchar = $seek; + + # If the hour is less than ten then add a + # zero. + + if ($hour < 10){ + + $hour_full = '0' . $hour; + + } else { + + $hour_full = $hour; + + } + + } elsif ($count eq 1){ + + # Get the minute and second from the time. + + $minute = substr($time, $startchar + 1, $timelength - 1); + $minute =~ s/^0//; + $count = 2; + + # If the minute is less than ten then add a + # zero. + + if ($minute < 10){ + + $minute_full = '0' . $minute; + + } else { + + $minute_full = $minute; + + } + + $startchar = $seek; + + $secondlength = $length - $seek + 1; + $second = substr($time, $startchar + 1, $secondlength); + $second =~ s/^0//; + + # If the second is less than ten then add a + # zero. + + if ($second < 10){ + + $second_full = '0' . $second; + + } else { + + $second_full = $second; + + } + + } + + } + + $seek++; + + } until ($seek eq $length); + + # Get the setting for displaying the date and time. + + $data = $options{"DateTime"}; + + # Process the setting for displaying the date and time + # using regular expressions + + $data =~ s/DD/$day_full/g; + $data =~ s/D/$day/g; + $data =~ s/MM/$month_full/g; + $data =~ s/M/$month/g; + $data =~ s/YY/$year/g; + $data =~ s/Y/$year_short/g; + + $data =~ s/hh/$hour_full/g; + $data =~ s/h/$hour/g; + $data =~ s/mm/$minute_full/g; + $data =~ s/m/$minute/g; + $data =~ s/ss/$second_full/g; + $data =~ s/s/$second/g; + + } + + return $data; + +} + +sub geterror{ +################################################################################# +# geterror: Gets the error message (or extended error message). # +# # +# Usage: # +# # +# $dbmodule->geterror(extended); # +# # +# Extended Specifies if the extended error should be retrieved. # +################################################################################# + + # Get the data passed to the subroutine. + + my $class = shift; + my $extended = shift; + + if (!$extended){ + $extended = 0; + } + + if (!$errorext){ + $errorext = ""; + } + + if (!$error){ + $error = ""; + } + + # Check to see if extended information should be returned. + + if ($extended eq 1){ + + # Extended information should be returned. + + return $errorext; + + } else { + + # Basic information should be returned. + + return $error; + + } + +} + +sub dbpermissions{ +################################################################################# +# dbpermissions: Check if the permissions for the database are valid. # +# # +# Usage: # +# # +# $database->dbpermissions(dbname, read, write); # +# # +# dbname Specifies the database name to check. # +# read Check to see if the database can be read. # +# write Check to see if the database can be written. # +################################################################################# + + # This subroutine is not needed for this database module. + + return 0; + +} + +sub dbexists{ +################################################################################# +# dbexists: Check if the database exists. # +# # +# Usage: # +# # +# $dbmodule->dbexists(dbname); # +# # +# dbname Specifies the database name to check. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the value that was passed to the subroutine. + + my $class = shift; + my ($filename) = @_; + + my @table_data; + my $table_exists = 0; + + # Check if the table exists. + + $string_handle = $database_handle->prepare('SHOW TABLES LIKE \'' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($filename) . '_database_info\'') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@table_data = $string_handle->fetchrow_array()){ + + $table_exists = 1; + + } + + # Check if the table really does exist. + + if ($table_exists eq 1){ + + # The table exists so return a value of 0. + + return 0; + + } else { + + # The table does not exist so return a value of 1. + + return 1; + + } + +} + + +################################################################################# +# General subroutines. # +################################################################################# + +sub connect{ +################################################################################# +# connect: Connect to the server. # +# # +# Usage: # +# # +# $dbmodule->connect(); # +################################################################################# + + $error = ""; + $errorext = ""; + + # Connect to the server. + + $database_handle = DBI->connect("DBI:mysql:database=" . $options{"Database"} . ";host=" . $options{"Server"} . ";protocol=" . $options{"Protocol"} . "port=" . $options{"Port"}, $options{"Username"}, $options{"Password"}, { "mysql_enable_utf8" => 1 }) or ( $error = "DatabaseConnectionError", $errorext = DBI->errstr, return ); + $database_handle->do('SET CHARACTER SET utf8'); + $database_handle->do('SET NAMES utf8'); + +} + +sub disconnect{ +################################################################################# +# connect: Disconnect from the server. # +# # +# Usage: # +# # +# $dbmodule->disconnect(); # +################################################################################# + + # Disconnect from the server. + + if ($string_handle){ + + $string_handle->finish(); + + } + + if ($database_handle){ + + $database_handle->disconnect(); + + } + +} + +################################################################################# +# Database Subroutines. # +################################################################################# + +sub getdblist{ +################################################################################# +# getdblist: Gets the list of available databases. # +# # +# Usage: # +# # +# $dbmodule->getdblist(); # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the list of databases. + + $string_handle = $database_handle->prepare("SHOW TABLES") or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + my @final_table_list; + my @database_table_list; + my @table_name; + my $table; + + while (@table_name = $string_handle->fetchrow_array()){ + + push(@database_table_list, decode_utf8($table_name[0])); + + } + + my $table_prefix = $options{"TablePrefix"}; + + # Find all the database information tables with the correct table prefix. + + @database_table_list = grep /^$table_prefix/ , @database_table_list; + @database_table_list = grep /m*database_info$/ , @database_table_list; + + foreach $table (@database_table_list){ + + # Process each table name removing the table prefix name and + # the _database_info part. + + $table =~ s/^$table_prefix(_)//g; + $table =~ s/_database_info$//g; + + push (@final_table_list, $table); + + } + + # Return the final list of databases. + + return @final_table_list; + +} + +sub getseconddatabaseinfo{ +################################################################################# +# getseconddatabaseinfo: Get information about the database that pages will be # +# moved or copied to. # +# # +# Usage: # +# # +# $dbmodule->getseconddatabaseinfo(); # +################################################################################# + + + # Get the database information. + + my $class = shift; + my ($databaseinfo, %databaseinfo); + my ($sqldata, @sqldata); + + $error = ""; + $errorext = ""; + + $string_handle = $database_handle->prepare('SELECT name, description, notes, categories, kiriwrite_version_major, kiriwrite_version_minor, kiriwrite_version_revision FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($second_database_filename) . '_database_info LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + @sqldata = $string_handle->fetchrow_array(); + + # Process the database information into a hash. + + %databaseinfo = ( + "DatabaseName" => decode_utf8($sqldata[0]), + "Description" => decode_utf8($sqldata[1]), + "Notes" => decode_utf8($sqldata[2]), + "Categories" => decode_utf8($sqldata[3]), + "Major" => decode_utf8($sqldata[4]), + "Minor" => decode_utf8($sqldata[5]), + "Revision" => decode_utf8($sqldata[6]) + ); + + $string_handle->finish(); + + return %databaseinfo; + +} + +sub selectdb{ +################################################################################# +# selectdb: Selects the Kiriwrite database. # +# # +# Usage: # +# # +# $dbmodule->connect(options); # +# # +# options Specifies the following options in any order. # +# # +# DatabaseName Specifies the Kiriwrite database to use. # +################################################################################# + + # Get the database name. + + $error = ""; + $errorext = ""; + + my $class = shift; + my ($passedoptions) = @_; + + my $dbname = $passedoptions->{"DatabaseName"}; + + my $database_exists = $class->dbexists($dbname); + + if ($database_exists eq 1){ + + # The database does not exist so return an error value + # saying that the database does not exist. + + $error = "DoesNotExist"; + + return; + + } + + $database_filename = $dbname; + +} + +sub selectseconddb{ +################################################################################# +# selectseconddb: Selects a second Kiriwrite database for moving and copying # +# pages to. # +# # +# Usage: # +# # +# $dbmodule->selectseconddb(options); # +# # +# options Specifies the following options in any order. # +# # +# DatabaseName Specifies the Kiriwrite database to use. # +################################################################################# + + # Get the database name. + + $error = ""; + $errorext = ""; + + my $class = shift; + my ($passedoptions) = @_; + my (%database, $database); + + my $dbname = $passedoptions->{"DatabaseName"}; + + # Check if the database exists. + + my $database_exists = $class->dbexists($dbname); + + if ($database_exists eq 1){ + + # The database does not exist so return an error value + # saying that the database does not exist. + + $error = "DoesNotExist"; + + return; + + } + + # Set the second database filename. + + $second_database_filename = $dbname; + +} + +sub getdatabaseinfo{ +################################################################################# +# getdatabaseinfo: Get information about the database. # +# # +# Usage: # +# # +# $dbmodule->getdatabaseinfo(); # +################################################################################# + + # Get the database information. + + $error = ""; + $errorext = ""; + + my $class = shift; + my ($databaseinfo, %databaseinfo); + my ($sqldata, @sqldata); + + $string_handle = $database_handle->prepare('SELECT name, description, notes, categories, kiriwrite_version_major, kiriwrite_version_minor, kiriwrite_version_revision FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_info LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + @sqldata = $string_handle->fetchrow_array(); + + # Process the database information into a hash. + + %databaseinfo = ( + + "DatabaseName" => decode_utf8($sqldata[0]), + "Description" => decode_utf8($sqldata[1]), + "Notes" => decode_utf8($sqldata[2]), + "Categories" => decode_utf8($sqldata[3]), + "Major" => decode_utf8($sqldata[4]), + "Minor" => decode_utf8($sqldata[5]), + "Revision" => decode_utf8($sqldata[6]) + ); + + $string_handle->finish(); + + return %databaseinfo; + +} + +sub adddatabase{ +################################################################################# +# adddatabase: Adds a Kiriwrite database. # +# # +# Usage: # +# # +# $dbmodule->adddatabase(options); # +# # +# options Specifies the following options in any order. # +# # +# DatabaseFilename Specifies the database file/shortname to use. # +# DatabaseName Specifies the database name to use. # +# DatabaseDescription Specifies the database description to use. # +# DatabaseNotes Specifies the database notes to use. # +# DatabaseCategories Specifies the database categories to use. # +# VersionMajor Specifies the major version. # +# VersionMinor Specifies the minor version. # +# VersionRevision Specifies the revision version. # +################################################################################# + + # Get the database that was passed to the subroutine. + + $error = ""; + $errorext = ""; + + my $class = shift; + my ($passedoptions) = @_; + + my $dbfilename = $passedoptions->{"DatabaseFilename"}; + my $dbname = $passedoptions->{"DatabaseName"}; + my $dbdescription = $passedoptions->{"DatabaseDescription"}; + my $dbnotes = $passedoptions->{"DatabaseNotes"}; + my $dbcategories = $passedoptions->{"DatabaseCategories"}; + my $dbmajorver = $passedoptions->{"VersionMajor"}; + my $dbminorver = $passedoptions->{"VersionMinor"}; + my $dbrevisionver = $passedoptions->{"VersionRevision"}; + + # Check if the database with the filename given already exists. + + my $database_exists = $class->dbexists($dbfilename); + + if ($database_exists eq 0){ + + # The database filename exists so set the error value. + + $error = "DatabaseExists"; + return; + + } + + # Create the database structure (info and page tables); + + $string_handle = $database_handle->prepare('CREATE TABLE ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($dbfilename) . '_database_info ( + name varchar(256) primary key, + description varchar(512), + notes mediumtext, + categories varchar(512), + kiriwrite_version_major int(4), + kiriwrite_version_minor int(4), + kiriwrite_version_revision int(4) + ) DEFAULT CHARSET=utf8') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + $string_handle = $database_handle->prepare('CREATE TABLE ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($dbfilename) . '_database_pages ( + filename varchar(256) primary key, + pagename varchar(512), + pagedescription varchar(512), + pagesection varchar(256), + pagetemplate varchar(64), + pagedata mediumtext, + pagesettings int(1), + lastmodified datetime + ) DEFAULT CHARSET=utf8') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Convert the values into SQL query formatted values and add an entry + # to the kiriwrite_database_info table. + + $string_handle = $database_handle->prepare('INSERT INTO ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($dbfilename) . '_database_info (name, description, notes, categories, kiriwrite_version_major, kiriwrite_version_minor, kiriwrite_version_revision) VALUES( + \'' . $class->convert($dbname) . '\', + \'' . $class->convert($dbdescription) . '\', + \'' . $class->convert($dbnotes) . '\', + \'' . $class->convert($dbcategories) . '\', + \'' . $class->convert($dbmajorver) . '\', + \'' . $class->convert($dbminorver) . '\', + \'' . $class->convert($dbrevisionver) . '\' + )') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +sub editdatabase{ +################################################################################# +# editdatabase: Edits a Kiriwrite Database. # +# # +# Usage: # +# # +# $dbmodule->editdatabase(options); # +# # +# options Specifies the following options in any order. # +# # +# NewDatabaseFilename Specifies the new database filename to use. # +# DatabaseName Specifies the new database name. # +# DatabaseDescription Specifies the new database description. # +# DatabaseNotes Specifies the new database notes. # +# DatabaseCategories Specifies the new database categories. # +################################################################################# + + $error = ""; + $errorext = ""; + + my $class = shift; + my ($passedoptions) = @_; + + my $dbnewfilename = $passedoptions->{"DatabaseNewFilename"}; + my $dbname = $passedoptions->{"DatabaseName"}; + my $dbdescription = $passedoptions->{"DatabaseDescription"}; + my $dbnotes = $passedoptions->{"DatabaseNotes"}; + my $dbcategories = $passedoptions->{"DatabaseCategories"}; + + # Check if a new database filename has been specified and if a + # new database filename has been specified then change the + # database filename. + + if ($database_filename ne $dbnewfilename){ + + # Check if a table with the filename already exists before using the + # new filename. + + my $database_newexists = $class->dbexists($dbnewfilename); + + if ($database_newexists eq 0){ + + # The database filename exists so set the error value. + + $error = "DatabaseExists"; + return; + + } + + # Rename the tables. + + $string_handle = $database_handle->prepare('RENAME TABLE ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_info TO ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($dbnewfilename) . '_database_info, ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages TO ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($dbnewfilename) . '_database_pages'); + $string_handle->execute(); + + } + + # Get the current database information. + + $string_handle = $database_handle->prepare('SELECT name FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($dbnewfilename) . '_database_info LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + my @database_oldinfo = $string_handle->fetchrow_array(); + + my $dboldname = decode_utf8($database_oldinfo[0]); + + # Update the database information. + + $string_handle = $database_handle->prepare('UPDATE ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($dbnewfilename) . '_database_info SET name = \'' . $class->convert($dbname) . '\', + description = \'' . $class->convert($dbdescription) . '\', + notes = \'' . $class->convert($dbnotes) . '\', + categories = \'' . $class->convert($dbcategories) . '\'') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +sub deletedatabase{ +################################################################################# +# deletedatabase: Deletes a Kiriwrite database. # +# # +# Usage: # +# # +# $dbmodule->deletedatabase(options); # +# # +# options Specifies the following options in any order. # +# # +# DatabaseName Specifies the Kiriwrite database to delete. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the database filename. + + my $class = shift; + my ($passedoptions) = shift; + + my $databasename = $passedoptions->{"DatabaseName"}; + + my @table_data; + my $table_exists; + + # Check if the database with the filename given already exists. + + my $database_exists = $class->dbexists($databasename); + + if ($database_exists eq 1){ + + # The database does not exist so set the error value. + + $error = "DoesNotExist"; + return; + + } + + + + # Delete the database tables. + + $string_handle = $database_handle->prepare('DROP TABLE ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($databasename) . '_database_info') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Check if the _database_pages table exists and delete it if it exists. + + $string_handle = $database_handle->prepare('SHOW TABLES LIKE \'' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($databasename) . '_database_pages\'') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@table_data = $string_handle->fetchrow_array()){ + + $table_exists = 1; + + } + + # Check if the _database_pages table really does exist. + + if ($table_exists eq 1){ + + # the _database_pages table really does exist so delete it. + + $string_handle = $database_handle->prepare('DROP TABLE ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($databasename) . '_database_pages') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + } + +} + +################################################################################# +# Template subroutines. # +################################################################################# + +sub connecttemplate{ +################################################################################# +# connecttemplate: Connect to the template database. # +# # +# Usage: # +# # +# $dbmodule->connecttemplate(missingignore); # +# # +# missingignore Ignore errror about database being missing. # +################################################################################# + + $error = ""; + $errorext = ""; + + my $class = shift; + my $ignoremissing = shift; + my $templatedb_exists = 0; + my @templatedb_check; + + # Check if the template database exists. + + $string_handle = $database_handle->prepare('SHOW TABLES LIKE \'' . $class->convert($options{"TablePrefix"}) . '_templates\'') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@templatedb_check = $string_handle->fetchrow_array()){ + + $templatedb_exists = 1; + + } + + if (!$templatedb_exists){ + + if (!$ignoremissing){ + + $error = "TemplateDatabaseDoesNotExist"; + return; + + } + + } + +} + +sub disconnecttemplate{ +################################################################################# +# disconnecttemplate: Disconnect from the template database. # +# # +# Usage: # +# # +# $dbmodule->disconnecttemplate(); # +################################################################################# + + # This subroutine is not used. + +} + +sub gettemplatelist{ +################################################################################# +# gettemplatelist: Gets the list of templates. # +# # +# Usage: # +# # +# $dbmodule->gettemplatelist(); # +################################################################################# + + my $error = ""; + my $errorext = ""; + + my $class = shift; + + $string_handle = $database_handle->prepare('SELECT filename FROM ' . $class->convert($options{"TablePrefix"}) . '_templates ORDER BY filename ASC') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + my @database_template; + my @templates_list; + my $template_filename; + + while (@database_template = $string_handle->fetchrow_array()){ + + # Get certain values from the array. + + $template_filename = decode_utf8($database_template[0]); + + # Add the template to the list of templates. + + push(@templates_list, $template_filename); + + } + + return @templates_list; + +} + +sub gettemplateinfo{ +################################################################################# +# gettemplateinfo: Get information on a template. # +# # +# Usage: # +# # +# $dbmodule->gettemplateinfo(options); # +# # +# options Specifies the following options in any order. # +# # +# TemplateFilename Specifies the template filename to use. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the data passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my %page_info; + my @template_data; + + my $template_filename; + my $template_name; + my $template_description; + my $template_datemodified; + my $template_layout; + + my $template_found = 0; + + my $filename = $passedoptions->{"TemplateFilename"}; + + $string_handle = $database_handle->prepare('SELECT filename, templatename, templatedescription, templatelayout, datemodified FROM ' . $class->convert($options{"TablePrefix"}) . '_templates WHERE filename = \'' . $class->convert($filename) . '\'') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@template_data = $string_handle->fetchrow_array()){ + + # Get certain values from the array. + + $template_filename = decode_utf8($template_data[0]); + $template_name = decode_utf8($template_data[1]); + $template_description = decode_utf8($template_data[2]); + $template_layout = decode_utf8($template_data[3]); + $template_datemodified = decode_utf8($template_data[4]); + + # Process them into the hash. + + %page_info = ( + "TemplateFilename" => $template_filename, + "TemplateName" => $template_name, + "TemplateDescription" => $template_description, + "TemplateLayout" => $template_layout, + "TemplateLastModified" => $template_datemodified + ); + + $template_found = 1; + + } + + if ($template_found eq 0){ + + # The template was not found in the template database so + # write an error value. + + $error = "TemplateDoesNotExist"; + return; + + } + + return %page_info; + +} + + +sub addtemplate{ +################################################################################# +# addtemplate: Adds a template to the template database. # +# # +# Usage: # +# # +# $dbmodule->addtemplate(); # +# # +# options Specifies the following options in any order. # +# # +# TemplateFilename Specifies the new template filename. # +# TemplateName Specifies the new template name. # +# TemplateDescription Specifies the new template description. # +# TemplateLayout Specifies the new template layout. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the data passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my @page_exists; + my @templatedb_check; + my $templatedb_exists; + my $blankfile = 0; + + my $template_filename = $passedoptions->{"TemplateFilename"}; + my $template_name = $passedoptions->{"TemplateName"}; + my $template_description = $passedoptions->{"TemplateDescription"}; + my $template_layout = $passedoptions->{"TemplateLayout"}; + + # Check if the template database exists. + + $string_handle = $database_handle->prepare('SHOW TABLES LIKE \'' . $class->convert($options{"TablePrefix"}) . '_templates\'') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@templatedb_check = $string_handle->fetchrow_array()){ + + $templatedb_exists = 1; + + } + + # Check if the template database table exists and if it doesn't + # then create the template database table. + + if (!$templatedb_exists){ + + $string_handle = $database_handle->prepare('CREATE TABLE ' . $class->convert($options{"TablePrefix"}) . '_templates ( + filename varchar(256) primary key, + templatename varchar(512), + templatedescription varchar(512), + templatelayout mediumtext, + datemodified datetime + ) DEFAULT CHARSET=utf8') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + } + + # Check if the template already exists before adding. + + if (!$templatedb_exists){ + + $string_handle = $database_handle->prepare('SELECT filename FROM ' . $class->convert($options{"TablePrefix"}) . '_templates WHERE filename = \'' . $class->convert($template_filename) . '\' LIMIT 1') or ($blankfile = 1); + + if ($blankfile eq 0){ + + $string_handle->execute(); + + while (@page_exists = $string_handle->fetchrow_array()){ + + $error = "TemplatePageExists"; + return; + + } + + } + + } + + # Get the current date. + + my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; + + my $template_date = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; + + # Check if certain values are undefined and if they + # are then set them blank. + + if (!$template_name){ + + $template_name = ""; + + } + + if (!$template_description){ + + $template_description = ""; + + } + + if (!$template_layout){ + + $template_layout = ""; + + } + + $string_handle = $database_handle->prepare('INSERT INTO ' . $class->convert($options{"TablePrefix"}) . '_templates (filename, templatename, templatedescription, templatelayout, datemodified) VALUES( + \'' . $class->convert($template_filename) . '\', + \'' . $class->convert($template_name) . '\', + \'' . $class->convert($template_description) . '\', + \'' . $class->convert($template_layout) . '\', + \'' . $class->convert($template_date) . '\' + )') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +sub deletetemplate{ +################################################################################# +# deletetemplate: Deletes a template from the template database. # +# # +# Usage: # +# # +# $dbmodule->deletetemplate(options); # +# # +# options Specifies the following options in any order. # +# # +# TemplateFilename Specifies the template filename to delete. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the data passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my @pagedata; + my $template_filename = $passedoptions->{"TemplateFilename"}; + my $template_count = 0; + + # Check if the template exists. + + $string_handle = $database_handle->prepare('SELECT filename FROM ' . $class->convert($options{"TablePrefix"}) . '_templates WHERE filename = \'' . $class->convert($template_filename) . '\' LIMIT 1') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@pagedata = $string_handle->fetchrow_array()){ + + $template_count++; + + } + + if ($template_count eq 0){ + + # No pages were returned so return an error value. + + $error = "TemplateDoesNotExist"; + return; + + } + + # Delete the template from the template database. + + $string_handle = $database_handle->prepare('DELETE FROM ' . $class->convert($options{"TablePrefix"}) . '_templates WHERE filename = \'' . $class->convert($template_filename) . '\'') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +sub edittemplate{ +################################################################################# +# editttemplate: Edits a Kiriwrite template. # +# # +# Usage: # +# # +# $dbmodule->edittemplate(options); # +# # +# options Specifies the following options in any order. # +# # +# TemplateFilename Specifies the template filename to edit. # +# NewTemplateFilename Specifies the new template filename. # +# NewTemplateName Specifies the new template name. # +# NewTemplateDescription Specifies the new template description. # +# NewTemplateLayout Specifies the new template layout. # +################################################################################# + + # Get the values passed. + + my $class = shift; + my ($passedoptions) = @_; + my $template_found = 0; + my @template_info; + + # Process the values passed. + + my $template_filename = $passedoptions->{"TemplateFilename"}; + my $new_template_filename = $passedoptions->{"NewTemplateFilename"}; + my $new_template_name = $passedoptions->{"NewTemplateName"}; + my $new_template_description = $passedoptions->{"NewTemplateDescription"}; + my $new_template_layout = $passedoptions->{"NewTemplateLayout"}; + + # Check if the template exists. + + $string_handle = $database_handle->prepare('SELECT filename FROM ' . $class->convert($options{"TablePrefix"}) . '_templates WHERE filename = \'' . $class->convert($template_filename) . '\' LIMIT 1') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@template_info = $string_handle->fetchrow_array()){ + + $template_found = 1; + + } + + # Check to see if the template was found and set an error value if + # it wasn't. + + if ($template_found eq 0){ + + $error = "TemplateDoesNotExist"; + return; + + } + + # Get the date and time. + + my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; + my $templatenewdate = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; + + # Update the template information. + + $string_handle = $database_handle->prepare('UPDATE ' . $class->convert($options{"TablePrefix"}) . '_templates SET + filename = \'' . $class->convert($new_template_filename) . '\', + templatename = \'' . $class->convert($new_template_name) . '\', + templatedescription = \'' . $class->convert($new_template_description) . '\', + templatelayout = \'' . $class->convert($new_template_layout) . '\', + datemodified = \'' . $class->convert($templatenewdate) . '\' + WHERE filename = \'' . $class->convert($template_filename) . '\' + ') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +################################################################################# +# Page subroutines. # +################################################################################# + +sub getpagelist{ +################################################################################# +# getpagelist: Gets the list of pages from the database. # +# # +# Usage: # +# # +# $dbmodule->getpagelist(); # +################################################################################# + + $error = ""; + $errorext = ""; + + my $class = shift; + + $string_handle = $database_handle->prepare('SELECT filename FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + my @database_pagefilenames; + my @database_pagefilenames_final; + + # Process the collected pages. + + while (@database_pagefilenames = $string_handle->fetchrow_array){ + + # Add each page to the list of pages in the database. + + push(@database_pagefilenames_final, decode_utf8($database_pagefilenames[0])); + + } + + return @database_pagefilenames_final; + +} + +sub getpageinfo{ +################################################################################# +# getpageinfo: Gets the page information from the filename passed. # +# # +# Usage: # +# # +# $dbmodule->getpageinfo(options); # +# # +# options Specifies the following options in any order. # +# # +# PageFilename Specifies the page filename to get the page information from. # +################################################################################# + + $error = ""; + $errorext = ""; + + my $class = shift; + my ($passedoptions) = shift; + my (%database_page, $database_page); + my ($pagefilename, $pagename, $pagedescription, $pagesection, $pagetemplate, $pagedata, $pagesettings, $pagelastmodified); + + my @data_page; + my $page_found = 0; + + # Get the page from the database. + + my $page_filename = $passedoptions->{"PageFilename"}; + + $string_handle = $database_handle->prepare('SELECT filename, pagename, pagedescription, pagesection, pagetemplate, pagedata, pagesettings, lastmodified FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Check if the page exists in the database. + + while (@data_page = $string_handle->fetchrow_array()){ + + # Get the values from the array. + + $pagefilename = decode_utf8($data_page[0]); + $pagename = decode_utf8($data_page[1]); + $pagedescription = decode_utf8($data_page[2]); + $pagesection = decode_utf8($data_page[3]); + $pagetemplate = decode_utf8($data_page[4]); + $pagedata = decode_utf8($data_page[5]); + $pagesettings = decode_utf8($data_page[6]); + $pagelastmodified = decode_utf8($data_page[7]); + + # Put the values into the page hash. + + %database_page = ( + "PageFilename" => $pagefilename, + "PageName" => $pagename, + "PageDescription" => $pagedescription, + "PageSection" => $pagesection, + "PageTemplate" => $pagetemplate, + "PageContent" => $pagedata, + "PageSettings" => $pagesettings, + "PageLastModified" => $class->dateconvert($pagelastmodified), + ); + + $page_found = 1; + + } + + # Check if the page did exist. + + if (!$page_found){ + + $error = "PageDoesNotExist"; + return; + + } + + return %database_page; + +} + + +sub addpage{ +################################################################################# +# addpage: Add a page to the selected database. # +# # +# Usage: # +# # +# $dbmodule->addpage(options); # +# # +# options Specifies the following options in any order. # +# # +# PageFilename Specifies the page filename to use. # +# PageName Specifies the page name to use. # +# PageDescription Specifies the page description to use. # +# PageSection Specifies the page section to use. # +# PageTemplate Specifies the page template to use. # +# PageContent Specifies the page content to use. # +# PageSettings Specifies the page settings to use. # +################################################################################# + + # Get the data that was passed to the subroutine. + + $error = ""; + $errorext = ""; + + my $class = shift; + my ($passedoptions) = shift; + + my @database_page; + my $page_count = 0; + + # Get the values passed to the hash. + + my $page_filename = $passedoptions->{"PageFilename"}; + my $page_name = $passedoptions->{"PageName"}; + my $page_description = $passedoptions->{"PageDescription"}; + my $page_section = $passedoptions->{"PageSection"}; + my $page_template = $passedoptions->{"PageTemplate"}; + my $page_content = $passedoptions->{"PageContent"}; + my $page_settings = $passedoptions->{"PageSettings"}; + + # Check to see if the filename given already exists + # in the page database. + + $string_handle = $database_handle->prepare('SELECT filename FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Check if a page with the filename given really does + # exist. + + while (@database_page = $string_handle->fetchrow_array()){ + + # A page does exist so increment the count to 1. + + $page_count++; + + } + + if ($page_count ne 0){ + + # The page does exist so set the error value. + + $error = "PageExists"; + return; + + } + + # Check if certain values are undefined. + + if (!$page_name){ + + $page_name = ""; + + } + + if (!$page_description){ + + $page_description = ""; + + } + + if (!$page_section){ + + $page_section = ""; + + } + + if (!$page_content){ + + $page_content = ""; + + } + + my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; + my $page_date = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; + + # Add the page to the selected database. + + $string_handle = $database_handle->prepare('INSERT INTO ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages (filename, pagename, pagedescription, pagesection, pagetemplate, pagedata, pagesettings, lastmodified) VALUES ( + \'' . $class->convert($page_filename) . '\', + \'' . $class->convert($page_name) . '\', + \'' . $class->convert($page_description) . '\', + \'' . $class->convert($page_section) . '\', + \'' . $class->convert($page_template) . '\', + \'' . $class->convert($page_content) . '\', + \'' . $class->convert($page_settings) . '\', + \'' . $class->convert($page_date) . '\' + )') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +sub deletepage{ +################################################################################# +# deletepage: Delete a page from the selected database. # +# # +# Usage: # +# # +# $dbmodule->deletepage(options) # +# # +# options Specifies the following options in any order. # +# # +# PageFilename Specifies the page filename to delete. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the data that was passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + my @page_info; + my $page_found = 0; + + # Get the page filename. + + my $page_filename = $passedoptions->{"PageFilename"}; + + # Check if the page exists before deleting it. + + $string_handle = $database_handle->prepare('SELECT filename FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@page_info = $string_handle->fetchrow_array()){ + + $page_found = 1; + + } + + # Check if the page really does exist. + + if (!$page_found){ + + $error = "PageDoesNotExist"; + return; + + } + + # Delete the page. + + $string_handle = $database_handle->prepare('DELETE FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\'') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +sub editpage{ +################################################################################# +# editpage: Edit a page from the selected database. # +# # +# Usage: # +# # +# $dbmodule->editpage(options); # +# # +# options Specifies the following options in any order. # +# # +# PageFilename Specifies the filename to edit. # +# PageNewFilename Specifies the new filename to use. # +# PageNewName Specifies the new page name to use. # +# PageNewDescription Specifies the new page description to use. # +# PageNewSection Specifies the new page section to use. # +# PageNewTemplate Specifies the new page template to use. # +# PageNewContent Specifies the new page content to use. # +# PageNewSettings Specifies the new page settings to use. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the values passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + my $page_found = 0; + my @page_info; + + # Get the data that was passed to the subroutine. + + my $page_filename = $passedoptions->{"PageFilename"}; + my $page_newfilename = $passedoptions->{"PageNewFilename"}; + my $page_newname = $passedoptions->{"PageNewName"}; + my $page_newdescription = $passedoptions->{"PageNewDescription"}; + my $page_newsection = $passedoptions->{"PageNewSection"}; + my $page_newtemplate = $passedoptions->{"PageNewTemplate"}; + my $page_newcontent = $passedoptions->{"PageNewContent"}; + my $page_newsettings = $passedoptions->{"PageNewSettings"}; + + # Check if the page with the filename given exists. + + $string_handle = $database_handle->prepare('SELECT filename FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Check if the page really does exist. + + while (@page_info = $string_handle->fetchrow_array()){ + + # The page information is found. + + $page_found = 1; + + } + + # Check if the page really does exist. + + if (!$page_found){ + + $error = "PageDoesNotExist"; + return; + + } + + # Get the current date. + + my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; + my $page_date = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; + + # Edit the selected page. + + $string_handle = $database_handle->prepare('UPDATE ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages SET filename = \'' . $class->convert($page_newfilename) . '\', pagename = \'' . $class->convert($page_newname) . '\', pagedescription = \'' . $class->convert($page_newdescription) . '\', pagesection = \'' . $class->convert($page_newsection) . '\', pagetemplate = \'' . $class->convert($page_newtemplate) . '\', pagedata = \'' . $class->convert($page_newcontent) . '\', pagedata = \'' . $class->convert($page_newcontent) . '\', pagesettings = \'' . $class->convert($page_newsettings) . '\', lastmodified = \'' . $page_date . '\' WHERE filename = \'' . $class->convert($page_filename) . '\'') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +sub movepage{ +################################################################################# +# movepage: Moves a page from the old database to the new database. # +# # +# Usage: # +# # +# $dbmodule->movepage(options); # +# # +# options Specifies the following options in any order. # +# # +# PageFilename Specifies the page with the filename to move. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the values passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my (%database_page, $database_page); + my ($pagefilename, $pagename, $pagedescription, $pagesection, $pagetemplate, $pagedata, $pagesettings, $pagelastmodified); + my @page_info; + my $page_found = 0; + + # Get the data that was passed to the subroutine. + + my $page_filename = $passedoptions->{"PageFilename"}; + + # Check if the page with the filename given exists. + + $string_handle = $database_handle->prepare('SELECT filename, pagename, pagedescription, pagesection, pagetemplate, pagedata, pagesettings, lastmodified FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "OldDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Check if the page really does exist. + + while (@page_info = $string_handle->fetchrow_array()){ + + # Get the values from the array. + + $pagefilename = decode_utf8($page_info[0]); + $pagename = decode_utf8($page_info[1]); + $pagedescription = decode_utf8($page_info[2]); + $pagesection = decode_utf8($page_info[3]); + $pagetemplate = decode_utf8($page_info[4]); + $pagedata = decode_utf8($page_info[5]); + $pagesettings = decode_utf8($page_info[6]); + $pagelastmodified = decode_utf8($page_info[7]); + + # Put the values into the page hash. + + %database_page = ( + "PageFilename" => $pagefilename, + "PageName" => $pagename, + "PageDescription" => $pagedescription, + "PageSection" => $pagesection, + "PageTemplate" => $pagetemplate, + "PageContent" => $pagedata, + "PageSettings" => $pagesettings, + "PageLastModified" => $pagelastmodified, + ); + + # The page information is found. + + $page_found = 1; + + } + + # Check if the page really does exist. + + if (!$page_found){ + + $error = "PageDoesNotExist"; + return; + + } + + # Check if the page with the filename given already exists in + # the database the page is being moved to. + + $page_found = 0; + @page_info = (); + + $string_handle = $database_handle->prepare('SELECT filename FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($second_database_filename) . '_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "NewDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@page_info = $string_handle->fetchrow_array()){ + + $page_found = 1; + + } + + # Check if the page really does exist. + + if ($page_found){ + + $error = "PageAlreadyExists"; + return; + + } + + # Add the page to the new database. + + $string_handle = $database_handle->prepare('INSERT INTO ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($second_database_filename) . '_database_pages (filename, pagename, pagedescription, pagesection, pagetemplate, pagedata, pagesettings, lastmodified) VALUES ( + \'' . $class->convert($database_page{"PageFilename"}) . '\', + \'' . $class->convert($database_page{"PageName"}) . '\', + \'' . $class->convert($database_page{"PageDescription"}) . '\', + \'' . $class->convert($database_page{"PageSection"}) . '\', + \'' . $class->convert($database_page{"PageTemplate"}) . '\', + \'' . $class->convert($database_page{"PageContent"}) . '\', + \'' . $class->convert($database_page{"PageSettings"}) . '\', + \'' . $class->convert($database_page{"PageLastModified"}) . '\' + )') or ( $error = "NewDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Delete the page from the old database. + + $string_handle = $database_handle->prepare('DELETE FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages WHERE filename = \'' . $class->convert($database_page{"PageFilename"}) . '\'') or ( $error = "OldDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +sub copypage{ +################################################################################# +# copypage: Copies a page from the old database to the new database. # +# # +# Usage: # +# # +# $dbmodule->copypage(options); # +# # +# options Specifies the following options in any order. # +# # +# PageFilename Specifies the page with the filename to copy. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the values passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my (%database_page, $database_page); + my ($pagefilename, $pagename, $pagedescription, $pagesection, $pagetemplate, $pagedata, $pagesettings, $pagelastmodified); + my @page_info; + my $page_found = 0; + + # Get the data that was passed to the subroutine. + + my $page_filename = $passedoptions->{"PageFilename"}; + + # Check if the page with the filename given exists. + + $string_handle = $database_handle->prepare('SELECT filename, pagename, pagedescription, pagesection, pagetemplate, pagedata, pagesettings, lastmodified FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "OldDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Check if the page really does exist. + + while (@page_info = $string_handle->fetchrow_array()){ + + # Get the values from the array. + + $pagefilename = decode_utf8($page_info[0]); + $pagename = decode_utf8($page_info[1]); + $pagedescription = decode_utf8($page_info[2]); + $pagesection = decode_utf8($page_info[3]); + $pagetemplate = decode_utf8($page_info[4]); + $pagedata = decode_utf8($page_info[5]); + $pagesettings = decode_utf8($page_info[6]); + $pagelastmodified = decode_utf8($page_info[7]); + + # Put the values into the page hash. + + %database_page = ( + "PageFilename" => $pagefilename, + "PageName" => $pagename, + "PageDescription" => $pagedescription, + "PageSection" => $pagesection, + "PageTemplate" => $pagetemplate, + "PageContent" => $pagedata, + "PageSettings" => $pagesettings, + "PageLastModified" => $pagelastmodified, + ); + + # The page information is found. + + $page_found = 1; + + } + + # Check if the page really does exist. + + if (!$page_found){ + + $error = "PageDoesNotExist"; + return; + + } + + # Check if the page with the filename given already exists in + # the database the page is being moved to. + + $page_found = 0; + @page_info = (); + + $string_handle = $database_handle->prepare('SELECT filename FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($second_database_filename) . '_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "NewDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@page_info = $string_handle->fetchrow_array()){ + + $page_found = 1; + + } + + # Check if the page really does exist. + + if ($page_found){ + + $error = "PageAlreadyExists"; + return; + + } + + # Add the page to the new database. + + $string_handle = $database_handle->prepare('INSERT INTO ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($second_database_filename) . '_database_pages (filename, pagename, pagedescription, pagesection, pagetemplate, pagedata, pagesettings, lastmodified) VALUES ( + \'' . $class->convert($database_page{"PageFilename"}) . '\', + \'' . $class->convert($database_page{"PageName"}) . '\', + \'' . $class->convert($database_page{"PageDescription"}) . '\', + \'' . $class->convert($database_page{"PageSection"}) . '\', + \'' . $class->convert($database_page{"PageTemplate"}) . '\', + \'' . $class->convert($database_page{"PageContent"}) . '\', + \'' . $class->convert($database_page{"PageSettings"}) . '\', + \'' . $class->convert($database_page{"PageLastModified"}) . '\' + )') or ( $error = "NewDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +################################################################################# +# Filter subroutines. # +################################################################################# + +sub connectfilter{ +################################################################################# +# connectfilter: Connect to the filter database. # +# # +# Usage: # +# # +# $dbmodule->connectfilter(missingignore); # +# # +# missingignore Ignore error about database being missing. # +################################################################################# + + $error = ""; + $errorext = ""; + + my $class = shift; + my $ignoremissing = shift; + my @filterdb_check; + my $filterdb_exists = 0; + + # Check if the template database exists. + + $string_handle = $database_handle->prepare('SHOW TABLES LIKE \'' . $class->convert($options{"TablePrefix"}) . '_filters\'') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@filterdb_check = $string_handle->fetchrow_array()){ + + $filterdb_exists = 1; + + } + + if (!$filterdb_exists){ + + if (!$ignoremissing){ + + $error = "FilterDatabaseDoesNotExist"; + return; + + } + + } + +} + +sub disconnectfilter{ +################################################################################# +# disconnectfilter: Disconnect from the filter database. # +# # +# Usage: # +# # +# $dbmodule->disconnectfilter(); # +################################################################################# + + # This subroutine is not used. + +} + +sub getfilterlist{ +################################################################################# +# getfilterlist: Gets the list of filters in the filter database. # +# # +# Usage: # +# # +# $dbmodule->getfilterlist(); # +################################################################################# + + $error = ""; + $errorext = ""; + + my $class = shift; + + my @filter_list; + my @filter_data; + + # Get the list of filters available. + + $string_handle = $database_handle->prepare('SELECT id, priority FROM ' . $class->convert($options{"TablePrefix"}) . '_filters ORDER BY priority ASC') or ( $error = "FilterDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@filter_data = $string_handle->fetchrow_array()){ + + # Add the filter to the list of available filters. + + push(@filter_list, decode_utf8($filter_data[0])); + + } + + return @filter_list; + +} + +sub getfilterinfo{ +################################################################################# +# getfilterinfo: Gets information about the filter. # +# # +# Usage: # +# # +# $dbmodule->getfilterinfo(options); # +# # +# options Specifies the following options in any order. # +# # +# FilterID Specifies the filter ID number to get information from. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the values passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my %filter_info; + my $filter_exists = 0; + my @filter_data; + + # Get the values that are in the hash. + + my $filter_id = $passedoptions->{"FilterID"}; + + $string_handle = $database_handle->prepare('SELECT id, priority, findsetting, replacesetting, notes FROM ' . $class->convert($options{"TablePrefix"}) . '_filters where id = \'' . $class->convert($filter_id) . '\'') or ( $error = "FilterDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Get the filter information. + + while (@filter_data = $string_handle->fetchrow_array()){ + + $filter_info{"FilterID"} = decode_utf8($filter_data[0]); + $filter_info{"FilterPriority"} = decode_utf8($filter_data[1]); + $filter_info{"FilterFind"} = decode_utf8($filter_data[2]); + $filter_info{"FilterReplace"} = decode_utf8($filter_data[3]); + $filter_info{"FilterNotes"} = decode_utf8($filter_data[4]); + + $filter_exists = 1; + + } + + # Check if the filter exists. + + if (!$filter_exists){ + + # The filter does not exist so return + # an error value. + + $error = "FilterDoesNotExist"; + return; + + } + + # Return the filter information. + + return %filter_info; + +} + +sub addfilter{ +################################################################################# +# addfilter: Adds a filter to the filter database. # +# # +# Usage: # +# # +# $dbmodule->addfilter(options); # +# # +# options Specifies the following options in any order. # +# # +# FindFilter Specifies the find filter to add. # +# ReplaceFilter Specifies the replace filter to add. # +# Priority Specifies the filter priority to use. # +# Notes Specifies the notes to use. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the values passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + # Define some variables for later. + + my @database_filters; + my @filterdb_check; + my @filterid_list; + my @filterid_check; + my $nofiltertable = 0; + my $filter_found = 0; + my $filter_count = 0; + my $filterdb_exists = 0; + my $filter_id; + my $new_id; + + # Get the values from the hash. + + my $filter_find = $passedoptions->{"FindFilter"}; + my $filter_replace = $passedoptions->{"ReplaceFilter"}; + my $filter_priority = $passedoptions->{"Priority"}; + my $filter_notes = $passedoptions->{"Notes"}; + + # Check if the template database exists. + + $string_handle = $database_handle->prepare('SHOW TABLES LIKE \'' . $class->convert($options{"TablePrefix"}) . '_filters\'') or ( $error = "FilterDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@filterdb_check = $string_handle->fetchrow_array()){ + + $filterdb_exists = 1; + + } + + # Check if certain values are undefined and if they + # are then set them blank. + + if (!$filter_find){ + + $filter_find = ""; + + } + + if (!$filter_replace){ + + $filter_replace = ""; + + } + + if (!$filter_priority){ + + $filter_priority = 1; + + } + + if (!$filter_notes){ + + $filter_notes = ""; + + } + + # Check if there is really no filter table. + + if (!$filterdb_exists){ + + # Create the filter database table. + + $string_handle = $database_handle->prepare('CREATE TABLE ' . $class->convert($options{"TablePrefix"}) . '_filters ( + id int(7) primary key, + priority int(5), + findsetting varchar(1024), + replacesetting varchar(1024), + notes text + ) DEFAULT CHARSET=utf8') or ( $error = "FilterDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + } + + # Find the lowest filter identification number available. + + $string_handle = $database_handle->prepare('SELECT id FROM ' . $class->convert($options{"TablePrefix"}) . '_filters ORDER BY id ASC') or ( $error = "FilterDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@database_filters = $string_handle->fetchrow_array()){ + + $filter_id = decode_utf8($database_filters[0]); + + # Add the filter identification to the list of filter IDs. + + push(@filterid_list, $filter_id); + + } + + $filter_id = ""; + + # Process each filter looking for a blank available filter. + + foreach $filter_id (@filterid_list){ + + # Check the next filter ID to see if it's blank. + + $new_id = $filter_id + 1; + + $string_handle = $database_handle->prepare('SELECT id FROM ' . $class->convert($options{"TablePrefix"}) . '_filters WHERE id = \'' . $class->convert($new_id) . '\'') or ( $error = "FilterDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Get the filter identification number. + + while (@filterid_check = $string_handle->fetchrow_array()){ + + $filter_found = 1; + + } + + # Check if a filter was found. + + if (!$filter_found){ + + # No filter was found using this ID so exit the loop. + + last; + + } + + # Increment the filter count and reset the filter found value. + + $filter_count++; + $filter_found = 0; + $new_id = 0; + + } + + # Check if there were any filters in the filters database. + + if (!$filter_count && !$new_id){ + + # There were no filters in the filters database so set + # the new filter identification value to 1. + + $new_id = 1; + + } + + # Add the filter to the filter database. + + $string_handle = $database_handle->prepare('INSERT INTO ' . $class->convert($options{"TablePrefix"}) . '_filters (id, priority, findsetting, replacesetting, notes) VALUES ( + \'' . $class->convert($new_id) . '\', + \'' . $class->convert($filter_priority) . '\', + \'' . $class->convert($filter_find) . '\', + \'' . $class->convert($filter_replace) .'\', + \'' . $class->convert($filter_notes) . '\' + )') or ( $error = "FilterDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + + +sub editfilter{ +################################################################################# +# editfilter: Edits a filter in the filter database. # +# # +# Usage: # +# # +# $dbmodule->editfilter(options); # +# # +# options Specifies the following options in any order. # +# # +# FilterID Specifies the filter to edit. # +# NewFindFilter Specifies the new find filter setting. # +# NewReplaceFilter Specifies the new replace filter setting. # +# NewFilterPriority Specifies the new filter priority setting. # +# NewFilterNotes Specifies the new notes for the filter. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the values passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my @filter_data; + my $filter_exists = 1; + my $blankfile = 0; + + # Get the values from the hash. + + my $filter_id = $passedoptions->{"FilterID"}; + my $filter_newfind = $passedoptions->{"NewFindFilter"}; + my $filter_newreplace = $passedoptions->{"NewReplaceFilter"}; + my $filter_newpriority = $passedoptions->{"NewFilterPriority"}; + my $filter_newnotes = $passedoptions->{"NewFilterNotes"}; + + # Check if the filter exists before editing it. + + $string_handle = $database_handle->prepare('SELECT id FROM ' . $class->convert($options{"TablePrefix"}) . '_filters where id = \'' . $class->convert($filter_id) . '\'') or ( $error = "FilterDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Check if the filter exists. + + while (@filter_data = $string_handle->fetchrow_array()){ + + $filter_exists = 1; + + } + + # Check if the filter really does exist. + + if (!$filter_exists){ + + # The filter does not exist so return + # an error value. + + $error = "FilterDoesNotExist"; + return; + + } + + # Edit the selected filter. + + $string_handle = $database_handle->prepare('UPDATE ' . $class->convert($options{"TablePrefix"}) . '_filters SET + findsetting = \'' . $class->convert($filter_newfind) . '\', + replacesetting = \'' . $class->convert($filter_newreplace) . '\', + priority = \'' . $class->convert($filter_newpriority) . '\', + notes = \'' . $class->convert($filter_newnotes) . '\' + WHERE id = \'' . $class->convert($filter_id) . '\'') or ( $error = "FilterDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + return; + +} + +sub deletefilter{ +################################################################################# +# deletefilter: Deletes a filter from the filter database. # +# # +# Usage: # +# # +# $dbmodule->deletefilter(options); # +# # +# options Specifies the following options in any order. # +# # +# FilterID Specifies the filter to delete from the filter database. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the values passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my $filter_exists = 0; + my @filter_data; + + # Get the values from the hash. + + my $filter_id = $passedoptions->{"FilterID"}; + + # Check if the filter exists before deleting. + + $string_handle = $database_handle->prepare('SELECT id FROM ' . $class->convert($options{"TablePrefix"}) . '_filters where id = \'' . $class->convert($filter_id) . '\'') or ( $error = "FilterDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@filter_data = $string_handle->fetchrow_array()){ + + $filter_exists = 1; + + } + + # Check to see if the filter really does exist. + + if (!$filter_exists){ + + $error = "FilterDoesNotExist"; + return; + + } + + # Delete the filter from the filter database. + + $string_handle = $database_handle->prepare('DELETE FROM ' . $class->convert($options{"TablePrefix"}) . '_filters where id = \'' . $class->convert($filter_id) . '\'') or ( $error = "FilterDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +1; \ No newline at end of file diff --git a/cgi-files/Modules/Database/SQLite.pm b/cgi-files/Modules/Database/SQLite.pm new file mode 100644 index 0000000..f179a62 --- /dev/null +++ b/cgi-files/Modules/Database/SQLite.pm @@ -0,0 +1,2788 @@ +################################################################################# +# Kiriwrite Database Module - SQLite Database Module (SQLite.pm) # +# Database module for mainipulating SQLite databases in the database directory. # +# # +# Copyright (C) 2007 Steve Brokenshire # +# # +# This module is licensed under the same license as Kiriwrite which is the GPL. # +# # +# This program is free software; you can redistribute it and/or modify it under # +# the terms of the GNU General Public License as published by the Free # +# Software Foundation; as version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.# +# # +# You should have received a copy of the GNU General Public License along with # +# this program; if not, write to the Free Software Foundation, Inc., 51 # +# Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # +################################################################################# + +# Define the package (perl module) name. + +package Kiriwrite::Database::SQLite; + +# Enable strict and use warnings. + +use strict; +use warnings; + +# Load the following Perl modules. + +use DBI; + +# Set the following values. + +our $VERSION = "0.1.0"; +my ($options, %options); +my $database_handle; +my $string_handle; +my $second_database_handle; +my $second_string_handle; +my $database_filename; +my $second_database_filename; +my $templatedb_loaded = 0; +my $templatedb_exists = 1; +my $template_string_handle; +my $template_database_handle; +my $filterdb_loaded = 0; +my $filterdb_exists = 1; +my $filterdb_string_handle; +my $filterdb_database_handle; +my $error = ""; +my $errorext = ""; + +################################################################################# +# Generic Subroutines. # +################################################################################# + +sub new{ +################################################################################# +# new: Create an instance of Kiriwrite::Database::SQLite # +# # +# Usage: # +# # +# $dbmodule = Kiriwrite::Database::SQLite->new(); # +################################################################################# + + # Get the perl module name. + + my $class = shift; + my $self = {}; + + return bless($self, $class); + +} + +sub loadsettings{ +################################################################################# +# loadsettings: Loads settings into the SQLite database module # +# # +# Usage: # +# # +# $dbmodule->loadsettings(Directory, options); # +# # +# options Specifies the following options (in any order). # +# # +# Directory Specifies the directory to use for getting databases. # +# DateTime Specifies the date and time format to use. # +# Server Specifies the server to use. # +# Database Specifies the database to use. # +# Username Specifies the username to use. # +# Password Specifies the password to use. # +# HashType Specifies the password hash type to use. # +# Port Specifies the server port to use. # +# Protocol Specifies the protocol to use. # +# TablePrefix Specifies the table prefix to use. # +################################################################################# + + # Get the data passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + # Add the directory setting to the list of options (as it's the only + # one needed for this database module). + + %options = ( + "Directory" => $passedoptions->{"Directory"}, + "DateTime" => $passedoptions->{"DateTime"}, + ); + +} + +sub convert{ +################################################################################# +# convert: Converts data into SQL formatted data. # +# # +# Usage: # +# # +# $dbmodule->convert(data); # +# # +# data Specifies the data to convert. # +################################################################################# + + # Get the data passed to the subroutine. + + my $class = shift; + my $data = shift; + + if (!$data){ + $data = ""; + } + + $data =~ s/'/''/g; + $data =~ s/\b//g; + + return $data; + +} + +sub dateconvert{ +################################################################################# +# dateconvert: Converts a SQL date into a proper date. # +# # +# Usage: # +# # +# $dbmodule->dateconvert(date); # +# # +# date Specifies the date to convert. # +################################################################################# + + # Get the date passed to the subroutine. + + my $class = shift; + my $data = shift; + + # Convert the date given into the proper date. + + # Create the following varialbes to be used later. + + my $date; + my $time; + my $day; + my $day_full; + my $month; + my $month_check; + my $month_full; + my $year; + my $year_short; + my $hour; + my $hour_full; + my $minute; + my $minute_full; + my $second; + my $second_full; + my $seek = 0; + my $timelength; + my $datelength; + my $daylength; + my $secondlength; + my $startchar = 0; + my $char; + my $length; + my $count = 0; + + # Split the date and time. + + $length = length($data); + + if ($length > 0){ + + do { + + # Get the character and check if it is a space. + + $char = substr($data, $seek, 1); + + if ($char eq ' '){ + + # The character is a space, so get the date and time. + + $date = substr($data, 0, $seek); + $timelength = $length - $seek - 1; + $time = substr($data, $seek + 1, $timelength); + + } + + $seek++; + + } until ($seek eq $length); + + # Get the year, month and date. + + $length = length($date); + $seek = 0; + + do { + + # Get the character and check if it is a dash. + + $char = substr($date, $seek, 1); + + if ($char eq '-'){ + + # The character is a dash, so get the year, month or day. + + $datelength = $seek - $startchar; + + if ($count eq 0){ + + # Get the year from the date. + + $year = substr($date, 0, $datelength) + 1900; + $startchar = $seek; + $count = 1; + + # Get the last two characters to get the short year + # version. + + $year_short = substr($year, 2, 2); + + } elsif ($count eq 1){ + + # Get the month and day from the date. + + $month = substr($date, $startchar + 1, $datelength - 1) + 1; + + # Check if the month is less then 10, if it is + # add a zero to the value. + + if ($month < 10){ + + $month_full = '0' . $month; + + } else { + + $month_full = $month; + + } + + $startchar = $seek; + $count = 2; + + $daylength = $length - $seek + 1; + $day = substr($date, $startchar + 1, $daylength); + + # Check if the day is less than 10, if it is + # add a zero to the value. + + if ($day < 10){ + + $day_full = '0' . $day; + + } else { + + $day_full = $day; + + } + + } + + } + + $seek++; + + } until ($seek eq $length); + + # Get the length of the time value and reset certain + # values to 0. + + $length = length($time); + $seek = 0; + $count = 0; + $startchar = 0; + + do { + + # Get the character and check if it is a colon. + + $char = substr($time, $seek, 1); + + if ($char eq ':'){ + + # The character is a colon, so get the hour, minute and day. + + $timelength = $seek - $startchar; + + if ($count eq 0){ + + # Get the hour from the time. + + $hour = substr($time, 0, $timelength); + $count = 1; + $startchar = $seek; + + # If the hour is less than ten then add a + # zero. + + if ($hour < 10){ + + $hour_full = '0' . $hour; + + } else { + + $hour_full = $hour; + + } + + } elsif ($count eq 1){ + + # Get the minute and second from the time. + + $minute = substr($time, $startchar + 1, $timelength - 1); + $count = 2; + + # If the minute is less than ten then add a + # zero. + + if ($minute < 10){ + + $minute_full = '0' . $minute; + + } else { + + $minute_full = $minute; + + } + + $startchar = $seek; + + $secondlength = $length - $seek + 1; + $second = substr($time, $startchar + 1, $secondlength); + + # If the second is less than ten then add a + # zero. + + if ($second < 10){ + + $second_full = '0' . $second; + + } else { + + $second_full = $second; + + } + + } + + } + + $seek++; + + } until ($seek eq $length); + + # Get the setting for displaying the date and time. + + $data = $options{"DateTime"}; + + # Process the setting for displaying the date and time + # using regular expressions + + $data =~ s/DD/$day_full/g; + $data =~ s/D/$day/g; + $data =~ s/MM/$month_full/g; + $data =~ s/M/$month/g; + $data =~ s/YY/$year/g; + $data =~ s/Y/$year_short/g; + + $data =~ s/hh/$hour_full/g; + $data =~ s/h/$hour/g; + $data =~ s/mm/$minute_full/g; + $data =~ s/m/$minute/g; + $data =~ s/ss/$second_full/g; + $data =~ s/s/$second/g; + + } + + return $data; + +} + +sub geterror{ +################################################################################# +# geterror: Gets the error message (or extended error message). # +# # +# Usage: # +# # +# $dbmodule->geterror(extended); # +# # +# Extended Specifies if the extended error should be retrieved. # +################################################################################# + + # Get the data passed to the subroutine. + + my $class = shift; + my $extended = shift; + + if (!$extended){ + $extended = 0; + } + + if (!$errorext){ + $errorext = ""; + } + + if (!$error){ + $error = ""; + } + + # Check to see if extended information should be returned. + + if ($extended eq 1){ + + # Extended information should be returned. + + return $errorext; + + } else { + + # Basic information should be returned. + + return $error; + + } + +} + +sub dbpermissions{ +################################################################################# +# dbpermissions: Check if the permissions for the database are valid. # +# # +# Usage: # +# # +# $database->dbpermissions(dbname, read, write); # +# # +# dbname Specifies the database name to check. # +# read Check to see if the database can be read. # +# write Check to see if the database can be written. # +################################################################################# + + # Get the database name, read setting and write setting. + + my ($class, $dbname, $readper, $writeper) = @_; + + # Check if the database can be read. + + if ($readper){ + + if (-r $options{"Directory"} . '/' . $dbname . ".db.sqlite"){ + + # The database can be read. + + } else { + + # The database cannot be read, so return a value + # of 1. + + return 1; + + } + + } + + # Check if the database can be written. + + if ($writeper){ + + if (-w $options{"Directory"} . '/' . $dbname . ".db.sqlite"){ + + # The database can be read. + + } else { + + # The database cannot be read, so return a value + # of 1. + + return 1; + + } + + } + + # No errors have occured while checking so return a value + # of 0. + + return 0; + +} + +sub dbexists{ +################################################################################# +# dbexists: Check if the database exists. # +# # +# Usage: # +# # +# $dbmodule->dbexists(dbname); # +# # +# dbname Specifies the database name to check. # +################################################################################# + + # Get the value that was passed to the subroutine. + + my $class = shift; + my ($filename) = @_; + + # Check if the filename exists, if it does, return a value of 1, else + # return a value of 0, meaning that the file was not found. + + if (-e $options{"Directory"} . '/' . $filename . ".db.sqlite"){ + + # Specified file does exist so return a value of 0. + + return 0; + + } else { + + # Specified file does not exist so return a value of 1. + + return 1; + + } + +} + +################################################################################# +# Database Subroutines. # +################################################################################# + +sub getdblist{ +################################################################################# +# getdblist: Gets the list of available databases. # +# # +# Usage: # +# # +# $dbmodule->getdblist(); # +################################################################################# + + # Get the list of databases. + + my @data_directory; + my @data_directory_final; + my $database; + my $database_filename_length; + my $database_filename_friendly; + + # Check if the database directory has valid permission settings. + + if (-e $options{"Directory"}){ + + # The database directory does exist. So check if + # the permission settings are valid. + + if (-r $options{"Directory"}){ + + # The permission settings for reading the directory + # are valid. + + } else { + + # The permission settings for reading the directory + # are invalid so return an error value. + + $error = "DataDirInvalidPermissions"; + return; + + } + + } else { + + # The database directory does not exist, so return an + # error value. + + $error = "DataDirMissing"; + return; + + } + + opendir(DATADIR, $options{"Directory"}); + @data_directory = grep /m*\.db.sqlite$/, readdir(DATADIR); + closedir(DATADIR); + + # Process the list of databases. + + foreach $database (@data_directory){ + + $database =~ s/.db.sqlite$//g; + $database_filename_friendly = $database; + + #$database_filename_length = length($database); + #$database_filename_friendly = substr($database, 0, $database_filename_length - 3); + push(@data_directory_final, $database_filename_friendly); + + } + + # Return the list of databases. + + return @data_directory_final; + +} + +sub getdatabaseinfo{ +################################################################################# +# getdatabaseinfo: Get information about the database. # +# # +# Usage: # +# # +# $dbmodule->getdatabaseinfo(); # +################################################################################# + + # Get the database information. + + my $class = shift; + my ($databaseinfo, %databaseinfo); + my ($sqldata, @sqldata); + + $error = ""; + $errorext = ""; + + $string_handle = $database_handle->prepare('SELECT name, description, notes, categories, kiriwrite_version_major, kiriwrite_version_minor, kiriwrite_version_revision FROM kiriwrite_database_info LIMIT 1') or ( + $error = "DatabaseError", $errorext = $database_handle->errstr, return + ); + $string_handle->execute(); + + @sqldata = $string_handle->fetchrow_array(); + + # Process the database information into a hash. + + %databaseinfo = ( + "DatabaseName" => $sqldata[0], + "Description" => $sqldata[1], + "Notes" => $sqldata[2], + "Categories" => $sqldata[3], + "Major" => $sqldata[4], + "Minor" => $sqldata[5], + "Revision" => $sqldata[6] + ); + + $string_handle->finish(); + undef $string_handle; + + return %databaseinfo; + +} + +sub getseconddatabaseinfo{ +################################################################################# +# getseconddatabaseinfo: Get information about the database that pages will be # +# moved or copied to. # +# # +# Usage: # +# # +# $dbmodule->getseconddatabaseinfo(); # +################################################################################# + + # Get the database information. + + my $class = shift; + my ($databaseinfo, %databaseinfo); + my ($sqldata, @sqldata); + + $error = ""; + $errorext = ""; + + $second_string_handle = $second_database_handle->prepare('SELECT name, description, notes, categories, kiriwrite_version_major, kiriwrite_version_minor, kiriwrite_version_revision FROM kiriwrite_database_info LIMIT 1') or ( + $error = "DatabaseError", $errorext = $second_database_handle->errstr, return + ); + $second_string_handle->execute(); + + @sqldata = $second_string_handle->fetchrow_array(); + + # Process the database information into a hash. + + %databaseinfo = ( + "DatabaseName" => $sqldata[0], + "Description" => $sqldata[1], + "Notes" => $sqldata[2], + "Categories" => $sqldata[3], + "Major" => $sqldata[4], + "Minor" => $sqldata[5], + "Revision" => $sqldata[6] + ); + + $second_string_handle->finish(); + undef $second_string_handle; + + return %databaseinfo; + +} + +sub adddatabase{ +################################################################################# +# adddatabase: Adds a Kiriwrite database. # +# # +# Usage: # +# # +# $dbmodule->adddatabase(options); # +# # +# options Specifies the following options in any order. # +# # +# DatabaseFilename Specifies the database file/shortname to use. # +# DatabaseName Specifies the database name to use. # +# DatabaseDescription Specifies the database description to use. # +# DatabaseNotes Specifies the database notes to use. # +# DatabaseCategories Specifies the database categories to use. # +# VersionMajor Specifies the major version. # +# VersionMinor Specifies the minor version. # +# VersionRevision Specifies the revision version. # +################################################################################# + + # Get the database that was passed to the subroutine. + + $error = ""; + $errorext = ""; + + my $class = shift; + my ($passedoptions) = @_; + + my $dbfilename = $passedoptions->{"DatabaseFilename"}; + my $dbname = $passedoptions->{"DatabaseName"}; + my $dbdescription = $passedoptions->{"DatabaseDescription"}; + my $dbnotes = $passedoptions->{"DatabaseNotes"}; + my $dbcategories = $passedoptions->{"DatabaseCategories"}; + my $dbmajorver = $passedoptions->{"VersionMajor"}; + my $dbminorver = $passedoptions->{"VersionMinor"}; + my $dbrevisionver = $passedoptions->{"VersionRevision"}; + + # Check if the database with the filename given already exists. + + my $database_exists = $class->dbexists($dbfilename); + + if ($database_exists eq 0){ + + # The database filename exists so set the error value. + + $error = "DatabaseExists"; + return; + + } + + # Create the database structure. + + $database_handle = DBI->connect("dbi:SQLite:dbname=" . $options{"Directory"} . '/' . $dbfilename . ".db.sqlite"); + $database_handle->{unicode} = 1; + $string_handle = $database_handle->prepare('CREATE TABLE kiriwrite_database_info( + name varchar(256) primary key, + description varchar(512), + notes text, + categories varchar(512), + kiriwrite_version_major int(4), + kiriwrite_version_minor int(4), + kiriwrite_version_revision int(4) + )') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + $string_handle = $database_handle->prepare('CREATE TABLE kiriwrite_database_pages( + filename varchar(256) primary key, + pagename varchar(512), + pagedescription varchar(512), + pagesection varchar(256), + pagetemplate varchar(64), + pagedata text, + pagesettings int(1), + lastmodified datetime + )') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Convert the values into SQL query formatted values and add an entry + # to the kiriwrite_database_info table. + + $string_handle = $database_handle->prepare('INSERT INTO kiriwrite_database_info (name, description, notes, categories, kiriwrite_version_major, kiriwrite_version_minor, kiriwrite_version_revision) VALUES( + \'' . $class->convert($dbname) . '\', + \'' . $class->convert($dbdescription) . '\', + \'' . $class->convert($dbnotes) . '\', + \'' . $class->convert($dbcategories) . '\', + \'' . $class->convert($dbmajorver) . '\', + \'' . $class->convert($dbminorver) . '\', + \'' . $class->convert($dbrevisionver) . '\' + )') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +sub editdatabase{ +################################################################################# +# editdatabase: Edits a Kiriwrite Database. # +# # +# Usage: # +# # +# $dbmodule->editdatabase(options); # +# # +# options Specifies the following options in any order. # +# # +# NewDatabaseFilename Specifies the new database filename to use. # +# DatabaseName Specifies the new database name. # +# DatabaseDescription Specifies the new database description. # +# DatabaseNotes Specifies the new database notes. # +# DatabaseCategories Specifies the new database categories. # +################################################################################# + + $error = ""; + $errorext = ""; + + my $class = shift; + my ($passedoptions) = @_; + + my $dbnewfilename = $passedoptions->{"DatabaseNewFilename"}; + my $dbname = $passedoptions->{"DatabaseName"}; + my $dbdescription = $passedoptions->{"DatabaseDescription"}; + my $dbnotes = $passedoptions->{"DatabaseNotes"}; + my $dbcategories = $passedoptions->{"DatabaseCategories"}; + + # Check if a new database filename has been specified and if a + # new database filename has been specified then change the + # database filename. + + if ($database_filename ne $dbnewfilename){ + + # A new database filename has been given so check if the output + # directory has write access. + + if (-r $options{"Directory"}){ + + # The directory is readable. + + } else { + + # The directory is not readable so set the error value. + + $error = "DataDirInvalidPermissions"; + + return; + + } + + if (-w $options{"Directory"}){ + + # The directory is writeable. + + } else { + + # The directory is not writeable so set the error value. + + $error = "DataDirInvalidPermissions"; + + return; + + } + + # Check if a database filename already exists before using the + # new filename. + + my $database_newexists = $class->dbexists($dbnewfilename); + + if ($database_newexists eq 0){ + + # The database filename exists so set the error value. + + $error = "DatabaseExists"; + return; + + } + + # Check if the database can be renamed (has write access). + + my $database_permissions = $class->dbpermissions($database_filename, 1, 1); + + if ($database_permissions eq 1){ + + # The database filename exists so set the error value. + + $error = "InvalidPermissionsSet"; + return; + + } + + # "Disconnect" from the database. + + $database_handle->disconnect(); + + # Rename the database. + + ($database_filename) = $database_filename =~ /^([a-zA-Z0-9.]+)$/; + ($dbnewfilename) = $dbnewfilename =~ /^([a-zA-Z0-9.]+)$/; + + rename($options{"Directory"} . '/' . $database_filename . '.db.sqlite', $options{"Directory"} . '/' . $dbnewfilename . '.db.sqlite'); + + # Reload the database from the new filename. + + $database_handle = DBI->connect("dbi:SQLite:dbname=" . $options{"Directory"} . '/' . $dbnewfilename . ".db.sqlite"); + $database_handle->{unicode} = 1; + $database_filename = $dbnewfilename; + + } + + # Check if the database can be altered with the new data. + + my $database_permissions = $class->dbpermissions($database_filename, 1, 1); + + if ($database_permissions eq 1){ + + # The database filename exists so set the error value. + + $error = "InvalidPermissionsSet"; + return; + + } + + # Get the current database information. + + $string_handle = $database_handle->prepare('SELECT name FROM kiriwrite_database_info LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + my @database_oldinfo = $string_handle->fetchrow_array(); + + my $dboldname = $database_oldinfo[0]; + + # Update the database information. + + $string_handle = $database_handle->prepare('UPDATE kiriwrite_database_info SET name = \'' . $class->convert($dbname) . '\', + description = \'' . $class->convert($dbdescription) . '\', + notes = \'' . $class->convert($dbnotes) . '\', + categories = \'' . $class->convert($dbcategories) . '\'') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + undef $string_handle; + return; + +} + +sub deletedatabase{ +################################################################################# +# deletedatabase: Deletes a Kiriwrite database. # +# # +# Usage: # +# # +# $dbmodule->deletedatabase(options); # +# # +# options Specifies the following options in any order. # +# # +# DatabaseName Specifies the Kiriwrite database to delete. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the database filename. + + my $class = shift; + my ($passedoptions) = shift; + + my $databasename = $passedoptions->{"DatabaseName"}; + + # Check if the database exists. + + my $database_exists = $class->dbexists($databasename); + + if ($database_exists eq 1){ + + # The database does not exist so set the error value. + + $error = "DoesNotExist"; + return; + + } + + # Check if the database permissions are valid. + + my $database_permissions = $class->dbpermissions($databasename); + + if ($database_permissions eq 1){ + + # The database permissions are invalid so set the error + # value. + + $error = "InvalidPermissionsSet"; + return; + + } + + # Delete the database. + + ($databasename) = $databasename =~ /^([a-zA-Z0-9.]+)$/; + + unlink($options{"Directory"} . '/' . $databasename . '.db.sqlite'); + +} + +sub selectdb{ +################################################################################# +# selectdb: Selects the Kiriwrite database. # +# # +# Usage: # +# # +# $dbmodule->connect(options); # +# # +# options Specifies the following options in any order. # +# # +# DatabaseName Specifies the Kiriwrite database to use. # +################################################################################# + + # Get the database name. + + $error = ""; + $errorext = ""; + + my $class = shift; + my ($passedoptions) = @_; + my (%database, $database); + + my $dbname = $passedoptions->{"DatabaseName"}; + + # Check if the database exists. + + my $database_exists = $class->dbexists($dbname); + + if ($database_exists eq 1){ + + # The database does not exist so return an error value + # saying that the database does not exist. + + $error = "DoesNotExist"; + + return; + + } + + # Check if the database has valid permissions set. + + my $database_permissions = $class->dbpermissions($dbname, 1, 0); + + if ($database_permissions eq 1){ + + # The database has invalid permissions set so return + # an error value saying that the database has invalid + # permissions set. + + $error = "InvalidPermissionsSet"; + + return; + + } + + # Connect to the database. + + $database_handle = DBI->connect("dbi:SQLite:dbname=" . $options{"Directory"} . '/' . $dbname . ".db.sqlite"); + $database_handle->{unicode} = 1; + $database_filename = $dbname; + +} + +sub selectseconddb{ +################################################################################# +# selectseconddb: Selects a second Kiriwrite database for moving and copying # +# pages to. # +# # +# Usage: # +# # +# $dbmodule->selectseconddb(options); # +# # +# options Specifies the following options in any order. # +# # +# DatabaseName Specifies the Kiriwrite database to use. # +################################################################################# + + # Get the database name. + + $error = ""; + $errorext = ""; + + my $class = shift; + my ($passedoptions) = @_; + my (%database, $database); + + my $dbname = $passedoptions->{"DatabaseName"}; + + # Check if the database exists. + + my $database_exists = $class->dbexists($dbname); + + if ($database_exists eq 1){ + + # The database does not exist so return an error value + # saying that the database does not exist. + + $error = "DoesNotExist"; + + return; + + } + + # Check if the database has valid permissions set. + + my $database_permissions = $class->dbpermissions($dbname, 1, 0); + + if ($database_permissions eq 1){ + + # The database has invalid permissions set so return + # an error value saying that the database has invalid + # permissions set. + + $error = "InvalidPermissionsSet"; + + return; + + } + + # Connect to the database. + + $second_database_handle = DBI->connect("dbi:SQLite:dbname=" . $options{"Directory"} . '/' . $dbname . ".db.sqlite"); + $second_database_handle->{unicode} = 1; + $second_database_filename = $dbname; + +} + +################################################################################# +# Page subroutines. # +################################################################################# + +sub getpagelist{ +################################################################################# +# getpagelist: Gets the list of pages from the database. # +# # +# Usage: # +# # +# $dbmodule->getpagelist(); # +################################################################################# + + $error = ""; + $errorext = ""; + + my $class = shift; + + $string_handle = $database_handle->prepare('SELECT filename FROM kiriwrite_database_pages') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + my @database_pagefilenames; + my @database_pagefilenames_final; + + # Process the collected pages. + + while (@database_pagefilenames = $string_handle->fetchrow_array){ + + # Add each page to the list of pages in the database. + + push(@database_pagefilenames_final, $database_pagefilenames[0]); + + } + + undef $string_handle; + return @database_pagefilenames_final; + +} + +sub getpageinfo{ +################################################################################# +# getpageinfo: Gets the page information from the filename passed. # +# # +# Usage: # +# # +# $dbmodule->getpageinfo(options); # +# # +# options Specifies the following options in any order. # +# # +# PageFilename Specifies the page filename to get the page information from. # +################################################################################# + + $error = ""; + $errorext = ""; + + my $class = shift; + my ($passedoptions) = shift; + my (%database_page, $database_page); + my ($pagefilename, $pagename, $pagedescription, $pagesection, $pagetemplate, $pagedata, $pagesettings, $pagelastmodified); + + my @data_page; + my $page_found = 0; + + # Get the page from the database. + + my $page_filename = $passedoptions->{"PageFilename"}; + + $string_handle = $database_handle->prepare('SELECT filename, pagename, pagedescription, pagesection, pagetemplate, pagedata, pagesettings, lastmodified FROM kiriwrite_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Check if the page exists in the database. + + while (@data_page = $string_handle->fetchrow_array()){ + + # Get the values from the array. + + $pagefilename = $data_page[0]; + $pagename = $data_page[1]; + $pagedescription = $data_page[2]; + $pagesection = $data_page[3]; + $pagetemplate = $data_page[4]; + $pagedata = $data_page[5]; + $pagesettings = $data_page[6]; + $pagelastmodified = $data_page[7]; + + # Put the values into the page hash. + + %database_page = ( + "PageFilename" => $pagefilename, + "PageName" => $pagename, + "PageDescription" => $pagedescription, + "PageSection" => $pagesection, + "PageTemplate" => $pagetemplate, + "PageContent" => $pagedata, + "PageSettings" => $pagesettings, + "PageLastModified" => $class->dateconvert($pagelastmodified), + ); + + $page_found = 1; + + } + + # Check if the page did exist. + + if (!$page_found){ + + $error = "PageDoesNotExist"; + return; + + } + + undef $string_handle; + return %database_page; + +} + +sub addpage{ +################################################################################# +# addpage: Add a page to the selected database. # +# # +# Usage: # +# # +# $dbmodule->addpage(options); # +# # +# options Specifies the following options in any order. # +# # +# PageFilename Specifies the page filename to use. # +# PageName Specifies the page name to use. # +# PageDescription Specifies the page description to use. # +# PageSection Specifies the page section to use. # +# PageTemplate Specifies the page template to use. # +# PageContent Specifies the page content to use. # +# PageSettings Specifies the page settings to use. # +################################################################################# + + # Get the data that was passed to the subroutine. + + $error = ""; + $errorext = ""; + + my $class = shift; + my ($passedoptions) = shift; + + my @database_page; + my $page_count = 0; + + # Get the values passed to the hash. + + my $page_filename = $passedoptions->{"PageFilename"}; + my $page_name = $passedoptions->{"PageName"}; + my $page_description = $passedoptions->{"PageDescription"}; + my $page_section = $passedoptions->{"PageSection"}; + my $page_template = $passedoptions->{"PageTemplate"}; + my $page_content = $passedoptions->{"PageContent"}; + my $page_settings = $passedoptions->{"PageSettings"}; + + # Check to see if the filename given already exists + # in the page database. + + $string_handle = $database_handle->prepare('SELECT filename FROM kiriwrite_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Check if a page with the filename given really does + # exist. + + while (@database_page = $string_handle->fetchrow_array()){ + + # A page does exist so increment the count to 1. + + $page_count++; + + } + + if ($page_count ne 0){ + + # The page does exist so set the error value. + + $error = "PageExists"; + return; + + } + + # Check if certain values are undefined. + + if (!$page_name){ + + $page_name = ""; + + } + + if (!$page_description){ + + $page_description = ""; + + } + + if (!$page_section){ + + $page_section = ""; + + } + + if (!$page_content){ + + $page_content = ""; + + } + + my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; + my $page_date = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; + + # Add the page to the selected database. + + $string_handle = $database_handle->prepare('INSERT INTO kiriwrite_database_pages (filename, pagename, pagedescription, pagesection, pagetemplate, pagedata, pagesettings, lastmodified) VALUES ( + \'' . $class->convert($page_filename) . '\', + \'' . $class->convert($page_name) . '\', + \'' . $class->convert($page_description) . '\', + \'' . $class->convert($page_section) . '\', + \'' . $class->convert($page_template) . '\', + \'' . $class->convert($page_content) . '\', + \'' . $class->convert($page_settings) . '\', + \'' . $class->convert($page_date) . '\' + )') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + undef $string_handle; + +} + +sub deletepage{ +################################################################################# +# deletepage: Delete a page from the selected database. # +# # +# Usage: # +# # +# $dbmodule->deletepage(options) # +# # +# options Specifies the following options in any order. # +# # +# PageFilename Specifies the page filename to delete. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the data that was passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + my @page_info; + my $page_found = 0; + + # Get the page filename. + + my $page_filename = $passedoptions->{"PageFilename"}; + + # Check if the page exists before deleting it. + + $string_handle = $database_handle->prepare('SELECT filename FROM kiriwrite_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@page_info = $string_handle->fetchrow_array()){ + + $page_found = 1; + + } + + # Check if the page really does exist. + + if (!$page_found){ + + $error = "PageDoesNotExist"; + return; + + } + + # Delete the page. + + $string_handle = $database_handle->prepare('DELETE FROM kiriwrite_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\'') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +sub editpage{ +################################################################################# +# editpage: Edit a page from the selected database. # +# # +# Usage: # +# # +# $dbmodule->editpage(options); # +# # +# options Specifies the following options in any order. # +# # +# PageFilename Specifies the filename to edit. # +# PageNewFilename Specifies the new filename to use. # +# PageNewName Specifies the new page name to use. # +# PageNewDescription Specifies the new page description to use. # +# PageNewSection Specifies the new page section to use. # +# PageNewTemplate Specifies the new page template to use. # +# PageNewContent Specifies the new page content to use. # +# PageNewSettings Specifies the new page settings to use. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the values passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + my $page_found = 0; + my @page_info; + + # Get the data that was passed to the subroutine. + + my $page_filename = $passedoptions->{"PageFilename"}; + my $page_newfilename = $passedoptions->{"PageNewFilename"}; + my $page_newname = $passedoptions->{"PageNewName"}; + my $page_newdescription = $passedoptions->{"PageNewDescription"}; + my $page_newsection = $passedoptions->{"PageNewSection"}; + my $page_newtemplate = $passedoptions->{"PageNewTemplate"}; + my $page_newcontent = $passedoptions->{"PageNewContent"}; + my $page_newsettings = $passedoptions->{"PageNewSettings"}; + + # Check if the page with the filename given exists. + + $string_handle = $database_handle->prepare('SELECT filename FROM kiriwrite_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Check if the page really does exist. + + while (@page_info = $string_handle->fetchrow_array()){ + + # The page information is found. + + $page_found = 1; + + } + + # Check if the page really does exist. + + if (!$page_found){ + + $error = "PageDoesNotExist"; + return; + + } + + # Get the current date. + + my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; + my $page_date = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; + + # Edit the selected page. + + $string_handle = $database_handle->prepare('UPDATE kiriwrite_database_pages SET filename = \'' . $class->convert($page_newfilename) . '\', pagename = \'' . $class->convert($page_newname) . '\', pagedescription = \'' . $class->convert($page_newdescription) . '\', pagesection = \'' . $class->convert($page_newsection) . '\', pagetemplate = \'' . $class->convert($page_newtemplate) . '\', pagedata = \'' . $class->convert($page_newcontent) . '\', pagedata = \'' . $class->convert($page_newcontent) . '\', pagesettings = \'' . $class->convert($page_newsettings) . '\', lastmodified = \'' . $page_date . '\' WHERE filename = \'' . $class->convert($page_filename) . '\'') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +sub movepage{ +################################################################################# +# movepage: Moves a page from the old database to the new database. # +# # +# Usage: # +# # +# $dbmodule->movepage(options); # +# # +# options Specifies the following options in any order. # +# # +# PageFilename Specifies the page with the filename to move. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the values passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my (%database_page, $database_page); + my ($pagefilename, $pagename, $pagedescription, $pagesection, $pagetemplate, $pagedata, $pagesettings, $pagelastmodified); + my @page_info; + my $page_found = 0; + + # Get the data that was passed to the subroutine. + + my $page_filename = $passedoptions->{"PageFilename"}; + + # Check if the page with the filename given exists. + + $string_handle = $database_handle->prepare('SELECT filename, pagename, pagedescription, pagesection, pagetemplate, pagedata, pagesettings, lastmodified FROM kiriwrite_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "OldDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Check if the page really does exist. + + while (@page_info = $string_handle->fetchrow_array()){ + + # Get the values from the array. + + $pagefilename = $page_info[0]; + $pagename = $page_info[1]; + $pagedescription = $page_info[2]; + $pagesection = $page_info[3]; + $pagetemplate = $page_info[4]; + $pagedata = $page_info[5]; + $pagesettings = $page_info[6]; + $pagelastmodified = $page_info[7]; + + # Put the values into the page hash. + + %database_page = ( + "PageFilename" => $pagefilename, + "PageName" => $pagename, + "PageDescription" => $pagedescription, + "PageSection" => $pagesection, + "PageTemplate" => $pagetemplate, + "PageContent" => $pagedata, + "PageSettings" => $pagesettings, + "PageLastModified" => $pagelastmodified, + ); + + # The page information is found. + + $page_found = 1; + + } + + # Check if the page really does exist. + + if (!$page_found){ + + $error = "PageDoesNotExist"; + return; + + } + + # Check if the page with the filename given already exists in + # the database the page is being moved to. + + $page_found = 0; + @page_info = (); + + $second_string_handle = $second_database_handle->prepare('SELECT filename FROM kiriwrite_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "NewDatabaseError", $errorext = $second_database_handle->errstr, return ); + $second_string_handle->execute(); + + while (@page_info = $second_string_handle->fetchrow_array()){ + + $page_found = 1; + + } + + # Check if the page really does exist. + + if ($page_found){ + + $error = "PageAlreadyExists"; + return; + + } + + # Add the page to the new database. + + $second_string_handle = $second_database_handle->prepare('INSERT INTO kiriwrite_database_pages (filename, pagename, pagedescription, pagesection, pagetemplate, pagedata, pagesettings, lastmodified) VALUES ( + \'' . $class->convert($database_page{"PageFilename"}) . '\', + \'' . $class->convert($database_page{"PageName"}) . '\', + \'' . $class->convert($database_page{"PageDescription"}) . '\', + \'' . $class->convert($database_page{"PageSection"}) . '\', + \'' . $class->convert($database_page{"PageTemplate"}) . '\', + \'' . $class->convert($database_page{"PageContent"}) . '\', + \'' . $class->convert($database_page{"PageSettings"}) . '\', + \'' . $class->convert($database_page{"PageLastModified"}) . '\' + )') or ( $error = "NewDatabaseError", $errorext = $second_database_handle->errstr, return ); + $second_string_handle->execute(); + + # Delete the page from the old database. + + $string_handle = $database_handle->prepare('DELETE FROM kiriwrite_database_pages WHERE filename = \'' . $class->convert($database_page{"PageFilename"}) . '\'') or ( $error = "OldDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + +sub copypage{ +################################################################################# +# copypage: Copies a page from the old database to the new database. # +# # +# Usage: # +# # +# $dbmodule->copypage(options); # +# # +# options Specifies the following options in any order. # +# # +# PageFilename Specifies the page with the filename to copy. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the values passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my (%database_page, $database_page); + my ($pagefilename, $pagename, $pagedescription, $pagesection, $pagetemplate, $pagedata, $pagesettings, $pagelastmodified); + my @page_info; + my $page_found = 0; + + # Get the data that was passed to the subroutine. + + my $page_filename = $passedoptions->{"PageFilename"}; + + # Check if the page with the filename given exists. + + $string_handle = $database_handle->prepare('SELECT filename, pagename, pagedescription, pagesection, pagetemplate, pagedata, pagesettings, lastmodified FROM kiriwrite_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "OldDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Check if the page really does exist. + + while (@page_info = $string_handle->fetchrow_array()){ + + # Get the values from the array. + + $pagefilename = $page_info[0]; + $pagename = $page_info[1]; + $pagedescription = $page_info[2]; + $pagesection = $page_info[3]; + $pagetemplate = $page_info[4]; + $pagedata = $page_info[5]; + $pagesettings = $page_info[6]; + $pagelastmodified = $page_info[7]; + + # Put the values into the page hash. + + %database_page = ( + "PageFilename" => $pagefilename, + "PageName" => $pagename, + "PageDescription" => $pagedescription, + "PageSection" => $pagesection, + "PageTemplate" => $pagetemplate, + "PageContent" => $pagedata, + "PageSettings" => $pagesettings, + "PageLastModified" => $pagelastmodified, + ); + + # The page information is found. + + $page_found = 1; + + } + + # Check if the page really does exist. + + if (!$page_found){ + + $error = "PageDoesNotExist"; + return; + + } + + # Check if the page with the filename given already exists in + # the database the page is being moved to. + + $page_found = 0; + @page_info = (); + + $second_string_handle = $second_database_handle->prepare('SELECT filename FROM kiriwrite_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "NewDatabaseError", $errorext = $second_database_handle->errstr, return ); + $second_string_handle->execute(); + + while (@page_info = $second_string_handle->fetchrow_array()){ + + $page_found = 1; + + } + + # Check if the page really does exist. + + if ($page_found){ + + $error = "PageAlreadyExists"; + return; + + } + + # Add the page to the new database. + + $second_string_handle = $second_database_handle->prepare('INSERT INTO kiriwrite_database_pages (filename, pagename, pagedescription, pagesection, pagetemplate, pagedata, pagesettings, lastmodified) VALUES ( + \'' . $class->convert($database_page{"PageFilename"}) . '\', + \'' . $class->convert($database_page{"PageName"}) . '\', + \'' . $class->convert($database_page{"PageDescription"}) . '\', + \'' . $class->convert($database_page{"PageSection"}) . '\', + \'' . $class->convert($database_page{"PageTemplate"}) . '\', + \'' . $class->convert($database_page{"PageContent"}) . '\', + \'' . $class->convert($database_page{"PageSettings"}) . '\', + \'' . $class->convert($database_page{"PageLastModified"}) . '\' + )') or ( $error = "NewDatabaseError", $errorext = $second_database_handle->errstr, return ); + $second_string_handle->execute(); + +} + +################################################################################# +# Filter subroutines. # +################################################################################# + +sub connectfilter{ +################################################################################# +# connectfilter: Connect to the filter database. # +# # +# Usage: # +# # +# $dbmodule->connectfilter(missingignore); # +# # +# missingignore Ignore error about database being missing. # +################################################################################# + + $error = ""; + $errorext = ""; + + my $class = shift; + my $ignoremissing = shift; + + # Check if the template database exists. + + my $filterdatabase_exists = main::kiriwrite_fileexists("filters.db.sqlite"); + + if ($filterdatabase_exists eq 1){ + + $filterdb_exists = 0; + + if (!$ignoremissing){ + + $error = "FilterDatabaseDoesNotExist"; + return; + + } + + } + + # Check if the permission settings for the template database are valid. + + my $filterdb_permissions = main::kiriwrite_filepermissions("filters.db.sqlite", 1, 0); + + if ($filterdb_permissions eq 1){ + + # The template database has invalid permissions set + # so return an error value. + + if (!$ignoremissing){ + + $error = "FilterDatabaseInvalidPermissionsSet"; + return; + + } + + } + + # Connect to the template database. + + $filterdb_database_handle = DBI->connect("dbi:SQLite:dbname=filters.db.sqlite"); + $database_handle->{unicode} = 1; + $filterdb_loaded = 1; + +} + +sub disconnectfilter{ +################################################################################# +# disconnectfilter: Disconnect from the filter database. # +# # +# Usage: # +# # +# $dbmodule->disconnectfilter(); # +################################################################################# + + # Disconnect the template database. + + if ($filterdb_loaded eq 1){ + + undef $filterdb_string_handle; + $filterdb_database_handle->disconnect(); + + } + +} + +sub getfilterlist{ +################################################################################# +# getfilterlist: Gets the list of filters in the filter database. # +# # +# Usage: # +# # +# $dbmodule->getfilterlist(); # +################################################################################# + + $error = ""; + $errorext = ""; + + my @filter_list; + my @filter_data; + + # Get the list of filters available. + + $filterdb_string_handle = $filterdb_database_handle->prepare('SELECT id FROM kiriwrite_filters ORDER BY priority ASC') or ( $error = "FilterDatabaseError", $errorext = $filterdb_database_handle->errstr, return ); + $filterdb_string_handle->execute(); + + while (@filter_data = $filterdb_string_handle->fetchrow_array()){ + + # Add the filter to the list of available filters. + + push(@filter_list, $filter_data[0]); + + } + + undef $filterdb_string_handle; + return @filter_list; + +} + +sub getfilterinfo{ +################################################################################# +# getfilterinfo: Gets information about the filter. # +# # +# Usage: # +# # +# $dbmodule->getfilterinfo(options); # +# # +# options Specifies the following options in any order. # +# # +# FilterID Specifies the filter ID number to get information from. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the values passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my %filter_info; + my $filter_exists = 0; + my @filter_data; + + # Get the values that are in the hash. + + my $filter_id = $passedoptions->{"FilterID"}; + + $filterdb_string_handle = $filterdb_database_handle->prepare('SELECT id, priority, findsetting, replacesetting, notes FROM kiriwrite_filters where id = \'' . $class->convert($filter_id) . '\'') or ( $error = "FilterDatabaseError", $errorext = $filterdb_database_handle->errstr, return ); + $filterdb_string_handle->execute(); + + # Get the filter information. + + while (@filter_data = $filterdb_string_handle->fetchrow_array()){ + + $filter_info{"FilterID"} = $filter_data[0]; + $filter_info{"FilterPriority"} = $filter_data[1]; + $filter_info{"FilterFind"} = $filter_data[2]; + $filter_info{"FilterReplace"} = $filter_data[3]; + $filter_info{"FilterNotes"} = $filter_data[4]; + + $filter_exists = 1; + + } + + # Check if the filter exists. + + if (!$filter_exists){ + + # The filter does not exist so return + # an error value. + + $error = "FilterDoesNotExist"; + return; + + } + + # Return the filter information. + + undef $filterdb_string_handle; + return %filter_info; + +} + +sub addfilter{ +################################################################################# +# addfilter: Adds a filter to the filter database. # +# # +# Usage: # +# # +# $dbmodule->addfilter(options); # +# # +# options Specifies the following options in any order. # +# # +# FindFilter Specifies the find filter to add. # +# ReplaceFilter Specifies the replace filter to add. # +# Priority Specifies the filter priority to use. # +# Notes Specifies the notes to use. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the values passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + # Define some variables for later. + + my @database_filters; + my @filterid_list; + my @filterid_check; + my $nofiltertable = 0; + my $filter_found = 0; + my $filter_count = 0; + my $filter_id; + my $new_id; + + # Get the values from the hash. + + my $filter_find = $passedoptions->{"FindFilter"}; + my $filter_replace = $passedoptions->{"ReplaceFilter"}; + my $filter_priority = $passedoptions->{"Priority"}; + my $filter_notes = $passedoptions->{"Notes"}; + + # Check if the filter database permissions are valid. + + my $filterdb_exists = main::kiriwrite_fileexists("filters.db.sqlite", 1, 1); + my $filterdb_permissions = main::kiriwrite_filepermissions("filters.db.sqlite", 1, 1); + + if ($filterdb_permissions eq 1){ + + if ($filterdb_exists eq 0){ + $error = "FilterDatabaseInvalidPermissionsSet"; + return; + } + + } + + # Check if certain values are undefined and if they + # are then set them blank. + + if (!$filter_find){ + + $filter_find = ""; + + } + + if (!$filter_replace){ + + $filter_replace = ""; + + } + + if (!$filter_priority){ + + $filter_priority = 1; + + } + + if (!$filter_notes){ + + $filter_notes = ""; + + } + + my $directory_permissions = main::kiriwrite_filepermissions(".", 1, 1, 0); + + if ($directory_permissions eq 1 && $filterdb_exists){ + + # The template database cannot be created because of invalid directory + # permissions so return an error value. + + $error = "FilterDatabaseFileUncreateable"; + return; + + } + + # Check if the filter table exists. + + $filterdb_string_handle = $filterdb_database_handle->prepare('SELECT id FROM kiriwrite_filters ORDER BY id ASC') or ( $nofiltertable = 1 ); + + # Check if there is really no filter table. + + if ($nofiltertable){ + + # Create the filter database table. + + $filterdb_string_handle = $filterdb_database_handle->prepare('CREATE TABLE kiriwrite_filters ( + id int(7) primary key, + priority int(5), + findsetting varchar(1024), + replacesetting varchar(1024), + notes text + )') or ( $error = "FilterDatabaseError", $errorext = $filterdb_database_handle->errstr, return ); + $filterdb_string_handle->execute(); + + } + + # Find the lowest filter identification number available. + + $filterdb_string_handle = $filterdb_database_handle->prepare('SELECT id FROM kiriwrite_filters ORDER BY id ASC') or ( $error = "FilterDatabaseError", $errorext = $filterdb_database_handle->errstr, return ); + $filterdb_string_handle->execute(); + + while (@database_filters = $filterdb_string_handle->fetchrow_array()){ + + $filter_id = $database_filters[0]; + + # Add the filter identification to the list of filter IDs. + + push(@filterid_list, $filter_id); + + } + + $filter_id = ""; + + # Process each filter looking for a blank available filter. + + foreach $filter_id (@filterid_list){ + + # Check the next filter ID to see if it's blank. + + $new_id = $filter_id + 1; + + $filterdb_string_handle = $filterdb_database_handle->prepare('SELECT id FROM kiriwrite_filters WHERE id = \'' . $class->convert($new_id) . '\'') or ( $error = "FilterDatabaseError", $errorext = $filterdb_database_handle->errstr, return ); + $filterdb_string_handle->execute(); + + # Get the filter identification number. + + while (@filterid_check = $filterdb_string_handle->fetchrow_array()){ + + $filter_found = 1; + + } + + # Check if a filter was found. + + if (!$filter_found){ + + # No filter was found using this ID so exit the loop. + + last; + + } + + # Increment the filter count and reset the filter found value. + + $filter_count++; + $filter_found = 0; + $new_id = 0; + + } + + # Check if there were any filters in the filters database. + + if (!$filter_count && !$new_id){ + + # There were no filters in the filters database so set + # the new filter identification value to 1. + + $new_id = 1; + + } + + # Add the filter to the filter database. + + $filterdb_string_handle = $filterdb_database_handle->prepare('INSERT INTO kiriwrite_filters (id, priority, findsetting, replacesetting, notes) VALUES ( + \'' . $class->convert($new_id) . '\', + \'' . $class->convert($filter_priority) . '\', + \'' . $class->convert($filter_find) . '\', + \'' . $class->convert($filter_replace) .'\', + \'' . $class->convert($filter_notes) . '\' + )') or ( $error = "FilterDatabaseError", $errorext = $filterdb_database_handle->errstr, return ); + $filterdb_string_handle->execute(); + +} + +sub editfilter{ +################################################################################# +# editfilter: Edits a filter in the filter database. # +# # +# Usage: # +# # +# $dbmodule->editfilter(options); # +# # +# options Specifies the following options in any order. # +# # +# FilterID Specifies the filter to edit. # +# NewFindFilter Specifies the new find filter setting. # +# NewReplaceFilter Specifies the new replace filter setting. # +# NewFilterPriority Specifies the new filter priority setting. # +# NewFilterNotes Specifies the new notes for the filter. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the values passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my @filter_data; + my $filter_exists = 1; + my $blankfile = 0; + + # Get the values from the hash. + + my $filter_id = $passedoptions->{"FilterID"}; + my $filter_newfind = $passedoptions->{"NewFindFilter"}; + my $filter_newreplace = $passedoptions->{"NewReplaceFilter"}; + my $filter_newpriority = $passedoptions->{"NewFilterPriority"}; + my $filter_newnotes = $passedoptions->{"NewFilterNotes"}; + + # Check if the filter database permissions are valid. + + my $filterdb_exists = main::kiriwrite_fileexists("filters.db.sqlite", 1, 1); + my $filterdb_permissions = main::kiriwrite_filepermissions("filters.db.sqlite", 1, 1); + + if ($filterdb_permissions eq 1){ + + if ($filterdb_exists eq 0){ + $error = "FilterDatabaseInvalidPermissionsSet"; + return; + } + + } + + # Check if the filter exists before editing it. + + $filterdb_string_handle = $filterdb_database_handle->prepare('SELECT id FROM kiriwrite_filters where id = \'' . $class->convert($filter_id) . '\'') or ( $error = "FilterDatabaseError", $errorext = $filterdb_database_handle->errstr, return ); + $filterdb_string_handle->execute(); + + # Check if the filter exists. + + while (@filter_data = $filterdb_string_handle->fetchrow_array()){ + + $filter_exists = 1; + + } + + # Check if the filter really does exist. + + if (!$filter_exists){ + + # The filter does not exist so return + # an error value. + + $error = "FilterDoesNotExist"; + return; + + } + + # Edit the selected filter. + + $filterdb_string_handle = $filterdb_database_handle->prepare('UPDATE kiriwrite_filters SET + findsetting = \'' . $class->convert($filter_newfind) . '\', + replacesetting = \'' . $class->convert($filter_newreplace) . '\', + priority = \'' . $class->convert($filter_newpriority) . '\', + notes = \'' . $class->convert($filter_newnotes) . '\' + WHERE id = \'' . $class->convert($filter_id) . '\'') or ( $error = "FilterDatabaseError", $errorext = $filterdb_database_handle->errstr, return ); + $filterdb_string_handle->execute(); + + undef $filterdb_string_handle; + return; + +} + +sub deletefilter{ +################################################################################# +# deletefilter: Deletes a filter from the filter database. # +# # +# Usage: # +# # +# $dbmodule->deletefilter(options); # +# # +# options Specifies the following options in any order. # +# # +# FilterID Specifies the filter to delete from the filter database. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the values passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my $filter_exists = 0; + my @filter_data; + + # Get the values from the hash. + + my $filter_id = $passedoptions->{"FilterID"}; + + # Check if the filter exists before deleting. + + $filterdb_string_handle = $filterdb_database_handle->prepare('SELECT id FROM kiriwrite_filters where id = \'' . $class->convert($filter_id) . '\'') or ( $error = "FilterDatabaseError", $errorext = $filterdb_database_handle->errstr, return ); + $filterdb_string_handle->execute(); + + while (@filter_data = $filterdb_string_handle->fetchrow_array()){ + + $filter_exists = 1; + + } + + # Check to see if the filter really does exist. + + if (!$filter_exists){ + + $error = "FilterDoesNotExist"; + return; + + } + + # Delete the filter from the filter database. + + $filterdb_string_handle = $filterdb_database_handle->prepare('DELETE FROM kiriwrite_filters where id = \'' . $class->convert($filter_id) . '\'') or ( $error = "FilterDatabaseError", $errorext = $filterdb_database_handle->errstr, return ); + $filterdb_string_handle->execute(); + + undef $filterdb_string_handle; + +} + +################################################################################# +# Template subroutines. # +################################################################################# + +sub connecttemplate{ +################################################################################# +# connecttemplate: Connect to the template database. # +# # +# Usage: # +# # +# $dbmodule->connecttemplate(missingignore); # +# # +# missingignore Ignore errror about database being missing. # +################################################################################# + + $error = ""; + $errorext = ""; + + my $class = shift; + my $ignoremissing = shift; + + # Check if the template database exists. + + my $templatedatabase_exists = main::kiriwrite_fileexists("templates.db.sqlite"); + + if ($templatedatabase_exists eq 1){ + + $templatedb_exists = 0; + + if (!$ignoremissing){ + + $error = "TemplateDatabaseDoesNotExist"; + return; + + } + + } + + # Check if the permission settings for the template database are valid. + + my $templatedb_permissions = main::kiriwrite_filepermissions("templates.db.sqlite", 1, 0); + + if ($templatedb_permissions eq 1){ + + # The template database has invalid permissions set + # so return an error value. + + if (!$ignoremissing){ + + $error = "TemplateDatabaseInvalidPermissionsSet"; + return; + + } + + } + + # Connect to the template database. + + $template_database_handle = DBI->connect("dbi:SQLite:dbname=templates.db.sqlite"); + $database_handle->{unicode} = 1; + $templatedb_loaded = 1; + +} + +sub disconnecttemplate{ +################################################################################# +# disconnecttemplate: Disconnect from the template database. # +# # +# Usage: # +# # +# $dbmodule->disconnecttemplate(); # +################################################################################# + + # Disconnect the template database. + + if ($templatedb_loaded eq 1){ + + undef $template_string_handle; + $template_database_handle->disconnect(); + + } + +} + +sub gettemplatelist{ +################################################################################# +# gettemplatelist: Gets the list of templates. # +# # +# Usage: # +# # +# $dbmodule->gettemplatelist(); # +################################################################################# + + $error = ""; + $errorext = ""; + + $template_string_handle = $template_database_handle->prepare('SELECT filename FROM kiriwrite_templates ORDER BY filename ASC') or ( $error = "TemplateDatabaseError", $errorext = $template_database_handle->errstr, return ); + $template_string_handle->execute(); + + my @database_template; + my @templates_list; + my $template_filename; + + while (@database_template = $template_string_handle->fetchrow_array()){ + + # Get certain values from the array. + + $template_filename = $database_template[0]; + + # Add the template to the list of templates. + + push(@templates_list, $template_filename); + + } + + return @templates_list; + +} + +sub gettemplateinfo{ +################################################################################# +# gettemplateinfo: Get information on a template. # +# # +# Usage: # +# # +# $dbmodule->gettemplateinfo(options); # +# # +# options Specifies the following options in any order. # +# # +# TemplateFilename Specifies the template filename to use. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the data passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my %page_info; + my @template_data; + + my $template_filename; + my $template_name; + my $template_description; + my $template_datemodified; + my $template_layout; + + my $template_found = 0; + + my $filename = $passedoptions->{"TemplateFilename"}; + + $template_string_handle = $template_database_handle->prepare('SELECT filename, templatename, templatedescription, templatelayout, datemodified FROM kiriwrite_templates WHERE filename = \'' . $class->convert($filename) . '\'') or ( $error = "TemplateDatabaseError", $errorext = $template_database_handle->errstr, return ); + $template_string_handle->execute(); + + while (@template_data = $template_string_handle->fetchrow_array()){ + + # Get certain values from the array. + + $template_filename = $template_data[0]; + $template_name = $template_data[1]; + $template_description = $template_data[2]; + $template_layout = $template_data[3]; + $template_datemodified = $template_data[4]; + + # Process them into the hash. + + %page_info = ( + "TemplateFilename" => $template_filename, + "TemplateName" => $template_name, + "TemplateDescription" => $template_description, + "TemplateLayout" => $template_layout, + "TemplateLastModified" => $template_datemodified + ); + + $template_found = 1; + + } + + if ($template_found eq 0){ + + # The template was not found in the template database so + # write an error value. + + $error = "TemplateDoesNotExist"; + return; + + } + + return %page_info; + +} + +sub addtemplate{ +################################################################################# +# addtemplate: Adds a template to the template database. # +# # +# Usage: # +# # +# $dbmodule->addtemplate(); # +# # +# options Specifies the following options in any order. # +# # +# TemplateFilename Specifies the new template filename. # +# TemplateName Specifies the new template name. # +# TemplateDescription Specifies the new template description. # +# TemplateLayout Specifies the new template layout. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the data passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my @page_exists; + my $notemplatetable; + my $blankfile = 0; + + my $template_filename = $passedoptions->{"TemplateFilename"}; + my $template_name = $passedoptions->{"TemplateName"}; + my $template_description = $passedoptions->{"TemplateDescription"}; + my $template_layout = $passedoptions->{"TemplateLayout"}; + + # Check if the template database permissions are valid. + + my $templatedb_exists = main::kiriwrite_fileexists("templates.db.sqlite", 1, 1); + my $templatedb_permissions = main::kiriwrite_filepermissions("templates.db.sqlite", 1, 1); + + if ($templatedb_permissions eq 1){ + + if ($templatedb_exists eq 0){ + $error = "TemplateDatabaseInvalidPermissionsSet"; + return; + } + + } + + # Check if the template already exists before adding. + + if ($templatedb_exists eq 0){ + + $template_string_handle = $template_database_handle->prepare('SELECT filename FROM kiriwrite_templates WHERE filename = \'' . $class->convert($template_filename) . '\' LIMIT 1') or ($blankfile = 1); + + if ($blankfile eq 0){ + + $template_string_handle->execute(); + + while (@page_exists = $template_string_handle->fetchrow_array()){ + + $error = "TemplatePageExists"; + return; + + } + + } + + } + + # Get the current date. + + my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; + + my $template_date = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; + + # Check if certain values are undefined and if they + # are then set them blank. + + if (!$template_name){ + + $template_name = ""; + + } + + if (!$template_description){ + + $template_description = ""; + + } + + if (!$template_layout){ + + $template_layout = ""; + + } + + my $directory_permissions = main::kiriwrite_filepermissions(".", 1, 1, 0); + + if ($directory_permissions eq 1 && $templatedb_exists){ + + # The template database cannot be created because of invalid directory + # permissions so return an error value. + + $error = "TemplateDatabaseUncreateable"; + return; + + } + + # Check to see if a template can be added. + + $template_string_handle = $template_database_handle->prepare('INSERT INTO kiriwrite_templates (filename, templatename, templatedescription, templatelayout, datemodified) VALUES( + \'' . $class->convert($template_filename) . '\', + \'' . $class->convert($template_name) . '\', + \'' . $class->convert($template_description) . '\', + \'' . $class->convert($template_layout) . '\', + \'' . $class->convert($template_date) . '\' + )') or ( $notemplatetable = 1 ); + + if (!$notemplatetable){ + + $template_string_handle->execute(); + + } + + # Check to see if there is no template table and attempt to create one. + + if ($notemplatetable){ + + # Create a template table. + + my $directory_permissions = main::kiriwrite_filepermissions(".", 1, 1, 0); + + if ($directory_permissions eq 1){ + + # The template database cannot be created because of invalid directory + # permissions so return an error. + + $error = "TemplateDatabaseFileUncreateable"; + return; + + } + + $template_string_handle = $template_database_handle->prepare('create table kiriwrite_templates( + filename varchar(256) primary key, + templatename varchar(512), + templatedescription varchar(512), + templatelayout text, + datemodified datetime + );') or ( $error = "TemplateDatabaseError", $errorext = $template_database_handle->errstr, return ); + $template_string_handle->execute(); + + $template_string_handle = $template_database_handle->prepare('INSERT INTO kiriwrite_templates (filename, templatename, templatedescription, templatelayout, datemodified) VALUES( + \'' . $class->convert($template_filename) . '\', + \'' . $class->convert($template_name) . '\', + \'' . $class->convert($template_description) . '\', + \'' . $class->convert($template_layout) . '\', + \'' . $class->convert($template_date) . '\' + )') or ( $error = "TemplateDatabaseError", $errorext = $template_database_handle->errstr, return ); + $template_string_handle->execute(); + + } + +} + +sub deletetemplate{ +################################################################################# +# deletetemplate: Deletes a template from the template database. # +# # +# Usage: # +# # +# $dbmodule->deletetemplate(options); # +# # +# options Specifies the following options in any order. # +# # +# TemplateFilename Specifies the template filename to delete. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the data passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my @pagedata; + my $template_filename = $passedoptions->{"TemplateFilename"}; + my $template_count = 0; + + # Check if the template exists. + + $template_string_handle = $template_database_handle->prepare('SELECT filename FROM kiriwrite_templates WHERE filename = \'' . $class->convert($template_filename) . '\' LIMIT 1') or ( $error = "TemplateDatabaseError", $errorext = $template_database_handle->errstr, return ); + $template_string_handle->execute(); + + while (@pagedata = $template_string_handle->fetchrow_array()){ + + $template_count++; + + } + + if ($template_count eq 0){ + + # No pages were returned so return an error value. + + $error = "TemplateDoesNotExist"; + return; + + } + + # Delete the template from the template database. + + $template_string_handle = $template_database_handle->prepare('DELETE FROM kiriwrite_templates WHERE filename = \'' . $class->convert($template_filename) . '\'') or ( $error = "TemplateDatabaseError", $errorext = $template_database_handle->errstr, return ); + $template_string_handle->execute(); + +} + +sub edittemplate{ +################################################################################# +# editttemplate: Edits a Kiriwrite template. # +# # +# Usage: # +# # +# $dbmodule->edittemplate(options); # +# # +# options Specifies the following options in any order. # +# # +# TemplateFilename Specifies the template filename to edit. # +# NewTemplateFilename Specifies the new template filename. # +# NewTemplateName Specifies the new template name. # +# NewTemplateDescription Specifies the new template description. # +# NewTemplateLayout Specifies the new template layout. # +################################################################################# + + # Get the values passed. + + my $class = shift; + my ($passedoptions) = @_; + my $template_found = 0; + my @template_info; + + # Process the values passed. + + my $template_filename = $passedoptions->{"TemplateFilename"}; + my $new_template_filename = $passedoptions->{"NewTemplateFilename"}; + my $new_template_name = $passedoptions->{"NewTemplateName"}; + my $new_template_description = $passedoptions->{"NewTemplateDescription"}; + my $new_template_layout = $passedoptions->{"NewTemplateLayout"}; + + # Check if the template database permissions are valid. + + my $templatedb_exists = main::kiriwrite_fileexists("templates.db.sqlite", 1, 1); + my $templatedb_permissions = main::kiriwrite_filepermissions("templates.db.sqlite", 1, 1); + + if ($templatedb_permissions eq 1){ + + if ($templatedb_exists eq 0){ + $error = "TemplateDatabaseInvalidPermissionsSet"; + return; + } + + } + + # Check if the template exists. + + $template_string_handle = $template_database_handle->prepare('SELECT filename FROM kiriwrite_templates WHERE filename = \'' . $class->convert($template_filename) . '\' LIMIT 1') or ( $error = "TemplateDatabaseError", $errorext = $template_database_handle->errstr, return ); + $template_string_handle->execute(); + + while (@template_info = $template_string_handle->fetchrow_array()){ + + $template_found = 1; + + } + + # Check to see if the template was found and set an error value if + # it wasn't. + + if ($template_found eq 0){ + + $error = "TemplateDoesNotExist"; + return; + + } + + # Get the date and time. + + my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; + my $templatenewdate = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; + + # Update the template information. + + $template_string_handle = $template_database_handle->prepare('UPDATE kiriwrite_templates SET + filename = \'' . $class->convert($new_template_filename) . '\', + templatename = \'' . $class->convert($new_template_name) . '\', + templatedescription = \'' . $class->convert($new_template_description) . '\', + templatelayout = \'' . $class->convert($new_template_layout) . '\', + datemodified = \'' . $class->convert($templatenewdate) . '\' + WHERE filename = \'' . $class->convert($template_filename) . '\' + ') or ( $error = "TemplateDatabaseError", $errorext = $template_database_handle->errstr, return ); + $template_string_handle->execute(); + +} + +################################################################################# +# General subroutines. # +################################################################################# + +sub connect{ +################################################################################# +# connect: Connect to the server. # +# # +# Usage: # +# # +# $dbmodule->connect(); # +################################################################################# + + # This function is not needed in this database module. + +} + +sub disconnect{ +################################################################################# +# connect: Disconnect from the server. # +# # +# Usage: # +# # +# $dbmodule->disconnect(); # +################################################################################# + + # This function is not needed in this database module. + + undef $string_handle; + +} + +1; \ No newline at end of file diff --git a/cgi-files/Modules/Presentation/HTML4S.pm b/cgi-files/Modules/Presentation/HTML4S.pm new file mode 100644 index 0000000..74d7004 --- /dev/null +++ b/cgi-files/Modules/Presentation/HTML4S.pm @@ -0,0 +1,2005 @@ +################################################################################# +# Kiriwrite Presentation Module - HTML 4.0 Strict (HTML4S.pm) # +# Output Module for writing pages to the HTML 4.0 Strict Standard # +# # +# Copyright (C) 2007 Steve Brokenshire # +# # +# This module is licensed under the same license as Kiriwrite which is the GPL. # +# # +# This program is free software; you can redistribute it and/or modify it under # +# the terms of the GNU General Public License as published by the Free # +# Software Foundation; as version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.# +# # +# You should have received a copy of the GNU General Public License along with # +# this program; if not, write to the Free Software Foundation, Inc., 51 # +# Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # +################################################################################# + +# Define the package (perl module) name. + +package Kiriwrite::Presentation::HTML4S; + +# Enable strict and use warnings. + +use strict; +use warnings; + +# Set the following values. + +our $VERSION = "0.1.0"; +my $pagedata = ""; +my $tablevel = 0; + +################################################################################# +# Generic Subroutines. # +################################################################################# + +sub new{ +################################################################################# +# new: Create an instance of Kiriwrite::Presentation::HTML4S # +# # +# Usage: # +# # +# $presmodule = Modules::Output::HTML4S->new(); # +################################################################################# + + # Get the perl module name. + + my $class = shift; + my $self = {}; + + return bless($self, $class); + +} + +sub clear{ +################################################################################# +# clear: Clear the current layout created by this module. # +# # +# Usage: # +# # +# $presmodule->clear(); # +################################################################################# + + $pagedata = ""; + return; + +} + +sub grab{ +################################################################################# +# grab: Grab the current layout created by this module. # +# # +# Usage: # +# # +# $presmodule->grab(); # +################################################################################# + + return $pagedata; + +} + +sub convert{ +################################################################################# +# convert: Converts the data passed into data that is compliant with the output # +# format. # +# # +# Usage: # +# # +# $presmodule->convert(data, type); # +# # +# data Specifies the data to be converted. # +# type Specifies the type the data should be converted to. # +################################################################################# + + # Get the data and type passed. + + my $class = shift; + my ($data, $type) = @_; + + # Check if certain values are undefined and if they are + # then set them blank or return an error. + + if (!$data){ + $data = ""; + } + + if (!$type){ + die("No type was specified"); + } + + # Check what type is being used and process the data + # according the type being used. + + if ($type eq "content"){ + + $data =~ s/&/&/g; + $data =~ s/#/#/g; + $data =~ s/\"/"/g; + $data =~ s/'/'/g; + $data =~ s/>/>/g; + $data =~ s//\%3E/g; + $data =~ s/starttable(cssstyle, {options}); # +# # +# cssstyle Specifies the CSS style name to use. # +# options Specifies the following options (in any order): # +# # +# CellPadding The cell padding to be used for each table. # +# CellSpacing The cell spacing to be used for each table. # +################################################################################# + + # Get the CSS style and options. + + my $class = shift; + my ($cssstyle, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + my $cellpadding = $options->{'CellPadding'}; + my $cellspacing = $options->{'CellSpacing'}; + + # Check if the cell padding and cell spacing and + # CSS style values are blank and if they are then + # set them blank. + + if (!$cellpadding){ + $cellpadding = 0; + } + + if (!$cellspacing){ + $cellspacing = 0; + } + + if (!$cssstyle){ + $cssstyle = ""; + } + + # Check if the cell padding and cell spacing values + # are valid and die if it isn't. + + my $cellpadding_validated = $cellpadding; + my $cellspacing_validated = $cellspacing; + + $cellpadding_validated =~ tr/0-9//d; + $cellspacing_validated =~ tr/0-9//d; + + if ($cellpadding_validated ne ""){ + die("Cell padding value given is invalid."); + } + + if ($cellspacing_validated ne ""){ + die("Cell spacing value given is invalid."); + } + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + # Start a table. + + $tagdata = $tagdata . "= 0){ + $tagdata = $tagdata . " cellspacing=\"" . $cellspacing . "\""; + } + + if ($cellpadding > 0){ + $tagdata = $tagdata . " cellpadding=\"" . $cellpadding . "\""; + } + + if ($cssstyle ne ""){ + $tagdata = $tagdata . " class=\"" . $class->convert($cssstyle, "content") . "\""; + } + + $tagdata = $tagdata . ">" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + $tablevel++; + +} + +sub startheader{ +################################################################################# +# startheader: Start a table header. # +# # +# Usage: # +# # +# $presmodule->startheader(); # +################################################################################# + + # Start a table header row. + + my $tagdata = ""; + my $tabcount = $tablevel; + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + $tagdata = $tagdata . "" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + $tablevel++; + +} + +sub addheader{ +################################################################################# +# addheader: Add a table header. # +# # +# Usage: # +# # +# $presmodule->addheader(headername, {options}); # +# # +# headername Specifies the name of the table header to use. # +# options Specifies the following options below (in any order): # +# # +# Style Specifies the CSS Style to use for the table header. # +################################################################################# + + # Get the header name and options. + + my $class = shift; + my ($headername, $options) = @_; + + my $cssstyle = $options->{'Style'}; + + # Check if the CSS Style or header name is undefined and + # if they are then set them blank. + + if (!$headername){ + $headername = ""; + } + + if (!$cssstyle){ + $cssstyle = ""; + } + + my $tagdata = ""; + my $tabcount = $tablevel; + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + $tagdata = $tagdata . "convert($cssstyle, "content") . "\""; + } + + $tagdata = $tagdata . ">" . $class->convert($headername, "content") . "" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub endheader{ +################################################################################# +# endheader: End a table header row # +# # +# Usage: # +# # +# $presmodule->endheader(); # +################################################################################# + + # End a table header row. + + my $tagdata = ""; + $tablevel = ($tablevel - 1); + my $tabcount = $tablevel; + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + $tagdata = $tagdata . "" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub startrow{ +################################################################################# +# startrow: Start a table row. # +# # +# Usage: # +# # +# $presmodule->startrow(); # +################################################################################# + + # Start a table row. + + my $tagdata = ""; + my $tabcount = $tablevel; + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + $tagdata = $tagdata . "" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + $tablevel++; + +} + +sub addcell{ +################################################################################# +# addcell: Add a table cell. # +# # +# Usage: # +# # +# $presmodule->addcell(style); # +# # +# style Specifies which CSS Style to use. # +################################################################################# + + # Get the cell information and options. + + my $class = shift; + my ($cssstyle) = @_; + my $tabcount = $tablevel; + my $tagdata = ""; + + # Check if the cell data and CSS style are undefined + # and if they are then set them blank. + + if (!$cssstyle){ + $cssstyle = ""; + } + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + $tagdata = $tagdata . "convert($cssstyle, "content") . "\""; + } + + $tagdata = $tagdata . ">"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub endcell{ +################################################################################# +# endcell: End a table cell. # +# # +# Usage: # +# # +# $presmodule->endcell(); # +################################################################################# + + # End a table cell. + + my $tagdata = ""; + + $tagdata = $tagdata . "" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub endrow{ +################################################################################# +# endrow: Ends a table row. # +# # +# Usage: # +# # +# $presmodule->endrow(); # +################################################################################# + + # End a table row. + + my $tagdata = ""; + $tablevel = ($tablevel - 1); + my $tabcount = $tablevel; + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + $tagdata = $tagdata . "" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub endtable{ +################################################################################# +# endtable: Ends a table. # +# # +# Usage: # +# # +# $presmodule->endtable(); # +################################################################################# + + # End a table. + + my $tagdata = ""; + $tablevel = ($tablevel - 1); + my $tabcount = $tablevel; + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + $tagdata = $tagdata . "" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +################################################################################# +# Information box. # +################################################################################# + +sub startbox{ +################################################################################# +# startbox: Start an information box. # +# # +# Usage: # +# # +# $presmodule->startbox(cssstyle); # +# # +# cssstyle Specifies the CSS Style to use. # +################################################################################# + + # Get the CSS Style name. + + my $class = shift; + my $cssstyle = shift; + + # Check if the CSS style given is undefined and + # if it is then set it blank. + + if (!$cssstyle){ + $cssstyle = ""; + } + + my $tagdata = ""; + my $tabcount = $tablevel; + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + # Start an information box. + + $tagdata = $tagdata . "convert($cssstyle, "content") . "\""; + } + + $tagdata = $tagdata . ">"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub enterdata{ +################################################################################# +# enterdata: Enter data into a information box. # +# # +# Usage: # +# # +# $presmodule->enterdata(data); # +# # +# data Specifies what data should be entered into the information box. # +################################################################################# + + # Get the data for the information box. + + my $class = shift; + my $data = shift; + + # Append the data to the page data. + + $pagedata = $pagedata . $class->convert($data, "content"); + +} + +sub endbox{ +################################################################################# +# endbox: End an information box. # +# # +# Usage: # +# # +# $presmodule->endbox(); # +################################################################################# + + # End an information box. + + my $tagdata = ""; + $tagdata = $tagdata . "" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +################################################################################# +# Form boxes. # +################################################################################# + +sub startform{ +################################################################################# +# startform: Start a form. # +# # +# Usage: # +# # +# $presmodule->startform(action, method); # +# # +# action Specifies the action (address) the data should be sent to. # +# method Specifies the method to use (POST, GET) # +################################################################################# + + my $class = shift; + my $action = shift; + my $method = shift; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Check if the action and method values given + # are undefined and if they are set default + # values. + + if (!$action){ + $action = ""; + } + + if (!$method){ + # The method is blank so set it to POST. + $method = "POST"; + } + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + $tagdata = $tagdata . "
convert($action, "content") . "\" method=\"" . $class->convert($method, "content") . "\">" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + $tablevel++; + +} + +sub addcheckbox{ +################################################################################# +# addcheckbox: Add a check box. # +# # +# Usage: # +# # +# $presmodule->addcheckbox(checkboxname, {options}); # +# # +# checkboxname Specifies the check box name. # +# options Specifies the following options below (in any order). # +# # +# OptionDescription Specifies a description for the checkbox value. # +# Style Specifies the CSS style to use. # +# Checked Specifies if the checkbox is checked. # +# LineBreak Specifies if a line break should be added. # +################################################################################# + + # Get the options recieved. + + my $class = shift; + my ($checkboxname, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Get certain values from the hash. + + my $optiondescription = $options->{'OptionDescription'}; + my $style = $options->{'Style'}; + my $checked = $options->{'Checked'}; + my $linebreak = $options->{'LineBreak'}; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$checkboxname){ + die("The checkbox name is blank."); + } + + if (!$optiondescription){ + $optiondescription = ""; + } + + if (!$style){ + $style = ""; + } + + if (!$checked){ + $checked = 0; + } + + if (!$linebreak){ + $linebreak = 0; + } + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + # Add a check box. + + $tagdata = $tagdata . "convert($checkboxname, "content") . "\""; + + if ($style ne ""){ + $tagdata = $tagdata . " class=\"" . $class->convert($style, "content") . "\""; + } + + if ($checked eq 1){ + $tagdata = $tagdata . " checked"; + } + + $tagdata = $tagdata . ">"; + + if ($optiondescription ne ""){ + $tagdata = $tagdata . " " . $class->convert($optiondescription, "content"); + } + + if ($linebreak eq 1){ + $tagdata = $tagdata . "
"; + } + + $tagdata = $tagdata . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub addradiobox{ +################################################################################# +# addradiobox: Add a radio box. # +# # +# Usage: # +# # +# $presmodule->addradiobox(radioboxname, {options}); # +# # +# radioboxname The name of the radio box. # +# options Specifies the following options below (in any order). # +# # +# Description Specifies a description for the checkbox value. # +# Style Specifies the CSS style to use. # +# Selected Specifies if the radio box is selected. # +# LineBreak Specifies if a line break should be used. # +# Value Specifies the value of the radio box. # +################################################################################# + + # Get the options recieved. + + my $class = shift; + my ($radioboxname, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Get certain values from the hash. + + my $optiondescription = $options->{'Description'}; + my $style = $options->{'Style'}; + my $selected = $options->{'Selected'}; + my $linebreak = $options->{'LineBreak'}; + my $value = $options->{'Value'}; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$radioboxname){ + die("The radio box name is blank."); + } + + if (!$value){ + $value = ""; + } + + if (!$optiondescription){ + $optiondescription = ""; + } + + if (!$style){ + $style = ""; + } + + if (!$selected){ + $selected = 0; + } + + if (!$linebreak){ + $linebreak = 0; + } + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + # Add a radio box. + + $tagdata = $tagdata . "convert($radioboxname, "content") . "\""; + + if ($style ne ""){ + $tagdata = $tagdata . " class=\"" . $class->convert($style, "content") . "\""; + } + + if ($selected eq 1){ + $tagdata = $tagdata . " checked"; + } + + if ($value ne ""){ + $tagdata = $tagdata . " value=\"" . $class->convert($value, "content") . "\""; + } else { + $tagdata = $tagdata . " value=\"0\""; + } + + $tagdata = $tagdata . ">"; + + if ($optiondescription ne ""){ + $tagdata = $tagdata . " " . $class->convert($optiondescription, "content"); + } + + if ($linebreak eq 1){ + $tagdata = $tagdata . "
"; + } + + $tagdata = $tagdata . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; +} + +sub addselectbox{ +################################################################################# +# addselectbox: Add a select box. # +# # +# Usage: # +# # +# $presmodule->addselectbox(selectname, {options}); # +# # +# selectboxname Specifies the name of the select box. # +# options Specifies the following options (in any order). # +# # +# Style Specifies the CSS style to use. # +################################################################################# + + # Get the options recieved. + + my $class = shift; + my ($selectboxname, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Get certain values from the hash. + + my $style = $options->{'Style'}; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$selectboxname){ + die("The select box name is blank.") + } + + if (!$style){ + $style = ""; + } + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + # Add a select box. + + $tagdata = $tagdata . "" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub addinputbox{ +################################################################################# +# addinputbox: Add a input text box. # +# # +# Usage: # +# # +# $presmodule->addinputbox(inputboxname, options); # +# # +# inputboxname Specifies the name of the input text box. # +# options Specifies the following options (in any order). # +# # +# Size Specifies the size of the input text box. # +# MaxLength Specifies the maximum length of the input text box. # +# Style Specifies the CSS style to use. # +# Value Specifies a value for the input box. # +################################################################################# + + # Get the options recieved. + + my $class = shift; + my ($inputboxname, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Get certain values from the hash. + + my $size = $options->{'Size'}; + my $maxlength = $options->{'MaxLength'}; + my $style = $options->{'Style'}; + my $value = $options->{'Value'}; + my $password = $options->{'Password'}; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$inputboxname){ + die("The input box name given is blank."); + } + + if (!$size){ + $size = 0; + } + + if (!$maxlength){ + $maxlength = 0; + } + + if (!$style){ + $style = ""; + } + + if (!$value){ + $value = ""; + } + + if (!$password){ + $password = 0; + } + + # Check if certain values are valid and return + # an error if they aren't. + + my $size_validated = $size; + my $maxlength_validated = $maxlength; + + $size_validated =~ tr/0-9//d; + $maxlength_validated =~ tr/0-9//d; + + if ($size_validated ne ""){ + die("The size given is invalid."); + } + + if ($maxlength_validated ne ""){ + die("The maximum length given is invalid."); + } + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + # Add an input text box. + + $tagdata = "convert($inputboxname, "content") . "\""; + + if ($size > 0){ + $tagdata = $tagdata . " size=\"" . $class->convert($size, "content") . "\""; + } + + if ($maxlength > 0){ + $tagdata = $tagdata . " maxlength=\"" . $class->convert($maxlength, "content") . "\""; + } + + if ($style ne ""){ + $tagdata = $tagdata . " class=\"" . $class->convert($style, "content") . "\""; + } + + if ($value ne ""){ + $tagdata = $tagdata . " value=\"" . $class->convert($value, "content") . "\""; + } + + $tagdata = $tagdata . ">" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub addtextbox{ +################################################################################# +# addtextbox: Add a multiple line text box. # +# # +# Usage: # +# # +# $presmodule->addtextbox(textboxname, options); # +# # +# textboxname Specifies the name of the multiple line text box. # +# options Specifies the following options (in any order). # +# # +# Columns Specifies the width of the multiple line text box. # +# Rows Specifies the height of the multiple line text box. # +# Style Specifies the CSS style to use. # +# Value Specifies a value for the multiple line text box. # +################################################################################# + + # Get the options recieved. + + my $class = shift; + my ($textboxname, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Get certain values from the hash. + + my $columns = $options->{'Columns'}; + my $rows = $options->{'Rows'}; + my $style = $options->{'Style'}; + my $value = $options->{'Value'}; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$textboxname){ + die("The multiple line text box name is blank."); + } + + if (!$columns){ + $columns = 0; + } + + if (!$rows){ + $rows = 0; + } + + if (!$style){ + $style = ""; + } + + if (!$value){ + $value = ""; + } + + # Check if certain values are valid and return + # an error if they aren't. + + my $columns_validated = $columns; + my $rows_validated = $rows; + + $columns_validated =~ tr/0-9//d; + $rows_validated =~ tr/0-9//d; + + if ($columns_validated ne ""){ + die("The columns value given is invalid."); + } + + if ($rows_validated ne ""){ + die("The rows value given is invalid."); + } + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + # Add a multiple line text box. + + $tagdata = $tagdata . "" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub addsubmit{ +################################################################################# +# addsubmit: Add a submit button. # +# # +# Usage: # +# # +# $pagemodule->addsubmit(submitname, options); # +# # +# submitname Specifies the name (label) of the submit button. # +# options Specifies the following options (in any order). # +# # +# Style Specifies the CSS style to use. # +################################################################################# + + # Get the options recieved. + + my $class = shift; + my ($submitname, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Get certain values from the hash. + + my $style = $options->{'Style'}; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$submitname){ + die("The submit name is blank."); + } + + if (!$style){ + $style = ""; + } + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + # Add a submit button. + + $tagdata = $tagdata . "convert($submitname, "content") . "\""; + + if ($style ne ""){ + $tagdata = $tagdata . " class=\"" . $class->convert($style, "content") . "\""; + } + + $tagdata = $tagdata . ">" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub addreset{ +################################################################################# +# addreset: Add a reset button. # +# # +# Usage: # +# # +# $pagemodule->addreset(resetname, options); # +# # +# resetname Specifies the name (label) of the reset button. # +# options Specifies the following options (in any order). # +# # +# Style Specifies the CSS style to use. # +################################################################################# + + # Get the options recieved. + + my $class = shift; + my ($resetname, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Get certain values from the hash. + + my $style = $options->{'Style'}; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$resetname){ + die("The reset name is blank."); + } + + if (!$style){ + $style = ""; + } + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + # Add a reset button. + + $tagdata = $tagdata . "convert($resetname, "content") . "\""; + + if ($style ne ""){ + $tagdata = $tagdata . " class=\"" . $class->convert($style, "content") . "\""; + } + + $tagdata = $tagdata . ">" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub addhiddendata{ +################################################################################# +# addhiddendata: Adds hidden data to the form. # +# # +# Usage: # +# # +# $presmodule->addhiddendata(name, value); # +# # +# name Specifies the name of the hidden data. # +# value Specifies the value of the hidden data. # +################################################################################# + + # Get the name and value. + + my $class = shift; + my ($name, $value) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$name){ + die("The name for the hidden data is blank."); + } + + if (!$value){ + $value = ""; + } + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + # Add hidden data. + + $tagdata = $tagdata . "convert($name, "content") . "\""; + + if ($value ne ""){ + $tagdata = $tagdata . " value=\"" . $class->convert($value, "content") . "\""; + } + + $tagdata = $tagdata . ">" . "\r\n"; + + # Add the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub addbutton{ +################################################################################# +# addbutton: Add a button. # +# # +# Usage: # +# # +# $presmodule->addbutton(buttonname, options); # +# # +# buttonname Specifies the name of button. # +# options Specifies the following options below (in any order). # +# # +# Value Specifies the value of the button. # +# Description Specifies the description (label) of the button. # +# Style Specifies the CSS style to use. # +################################################################################# + + # Get the options recieved. + + my $class = shift; + my ($buttonname, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Get certain values from the hash. + + my $value = $options->{'Value'}; + my $description = $options->{'Description'}; + my $style = $options->{'Style'}; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$buttonname){ + die("The name for button is blank."); + } + + if (!$value){ + $value = ""; + } + + if (!$description){ + die("The description for the button is blank."); + } + + if (!$style){ + $style = ""; + } + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + # Add a button. + + $tagdata = $tagdata . "\r\n"; + + # Add the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub endform{ +################################################################################# +# endform: Ends a form. # +# # +# Usage: # +# # +# $presmodule->endform(); # +################################################################################# + + # End a form. + + my $tagdata = ""; + $tablevel = ($tablevel - 1); + my $tabcount = $tablevel; + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + $tagdata = $tagdata . "
" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +################################################################################# +# Page Link. # +################################################################################# + +sub addlink{ +################################################################################# +# addlink: Adds a link. # +# # +# Usage: # +# # +# $presmodule->addlink(link, options); # +# # +# Link Specifies the location of the link. # +# options Specifies the following options below (in any order). # +# # +# Target Specifies the target window for the link. # +# Text Specifies the text to use. # +################################################################################# + + # Get the options recieved. + + my $class = shift; + my ($link, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Get certain values from the hash. + + my $target = $options->{'Target'}; + my $name = $options->{'Text'}; + my $embed = $options->{'Embed'}; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$link){ + die("The link specified was blank."); + } + + if (!$target){ + $target = ""; + } + + if (!$embed){ + $embed = 0; + } + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + # Add a link. + + $tagdata = "convert($link, "link") . "\""; + + if ($target ne ""){ + $tagdata = $tagdata . " target=\"" . $class->convert($target, "content") . "\""; + } + + $tagdata = $tagdata . ">" . $class->convert($name, "content") . "" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +################################################################################# +# Image. # +################################################################################# + +sub addimage{ +################################################################################# +# addimage: Adds an image. # +# # +# Usage: # +# # +# $presmodule->addimage(image, options); # +# # +# image Specifies the location of the image. # +# options Specifies the following options below (in any order). # +# # +# Style Specifies the CSS style to use. # +# Description Specifies the description of the image. # +# Width Specifies the width of the image. # +# Height Specifies the height of the image. # +################################################################################# + + # Get the options recieved. + + my $class = shift; + my ($image, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Get certain values from the hash. + + my $style = $options->{'Style'}; + my $width = $options->{'Width'}; + my $height = $options->{'Height'}; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$image){ + die("The link to the image given is blank"); + } + + if (!$style){ + $style = ""; + } + + if (!$width){ + $width = 0; + } + + if (!$height){ + $height = 0; + } + + # Check if certain values are valid and return + # an error if they aren't. + + my $width_validated = $width; + my $height_validated = $height; + + $width_validated =~ tr/0-9//d; + $height_validated =~ tr/0-9//d; + + if (!$width_validated){ + die("The width value given is invalid."); + } + + if (!$height_validated){ + die("The height value given is invalid."); + } + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + # Add an image. + + $tagdata = $tagdata . "convert($image, "content") . "\""; + + if ($style ne ""){ + $tagdata = $tagdata . " class=\"" . $class->convert($style, "content") . "\""; + } + + if ($width ne 0){ + $tagdata = $tagdata . " width=\"" . $class->convert($width, "content") . "\""; + } + + if ($height ne 0){ + $tagdata = $tagdata . " height=\"" . $class->convert($height, "content") . "\""; + } + + $tagdata = $tagdata . ">" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +################################################################################# +# Text. # +################################################################################# + +sub addtext{ +################################################################################# +# addtext: Adds some text. # +# # +# Usage: # +# # +# $presmodule->addtext(text, options); # +# # +# text Specifies the text to add. # +# options Specifies the following options below (in any order). # +# # +# Style Specifies the CSS style to use. # +################################################################################# + + # Get the options recieved. + + my $class = shift; + my ($text, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Get certain values from the hash. + + my $style = $options->{'Style'}; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$style){ + $style = ""; + } + + if (!$text){ + $text = ""; + } + + # Add some text. + + if ($style ne ""){ + $tagdata = $tagdata . "convert($style, "content") . "\">" . $class->convert($text, "content") . ""; + } else { + $tagdata = $tagdata . $class->convert($text, "content"); + } + + # Append the tagdata to the pagedata. + + $pagedata = $pagedata . $tagdata; + +} + +sub addboldtext{ +################################################################################# +# addboldtext: Adds some bold text. # +# # +# Usage: # +# # +# $presmodule->addboldtext(text, options); # +# # +# text Specifies the text to add. # +# options Specifies the following options below (in any order). # +# # +# Style Specifies the CSS style to use. # +################################################################################# + + # Get the options recieved. + + my $class = shift; + my ($text, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Get certain values from the hash. + + my $style = $options->{'Style'}; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$text){ + die("The text given was blank."); + } + + if (!$style){ + $style = ""; + } + + # Add some bold text. + + if ($style ne ""){ + $tagdata = $tagdata . "" . $class->convert($text, "content") . ""; + } else { + $tagdata = $tagdata . "" . $class->convert($text, "content") . ""; + } + + # Append the tagdata to the pagedata. + + $pagedata = $pagedata . $tagdata; + +} + +sub additalictext{ +################################################################################# +# addboldtext: Adds some italic text. # +# # +# Usage: # +# # +# $presmodule->additalictext(text, options); # +# # +# text Specifies the text to add. # +# options Specifies the following options below (in any order). # +# # +# Style Specifies the CSS style to use. # +################################################################################# + + # Get the options recieved. + + my $class = shift; + my ($text, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Get certain values from the hash. + + my $style = $options->{'Style'}; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$text){ + die("The text given was blank."); + } + + if (!$style){ + $style = ""; + } + + # Add some italic text. + + if ($style ne ""){ + $tagdata = $tagdata . "" . $class->convert($text, "content") . ""; + } else { + $tagdata = $tagdata . "" . $class->convert($text, "content") . ""; + } + + # Append the tagdata to the pagedata. + + $pagedata = $pagedata . $tagdata; + +} + +sub addlinebreak{ +################################################################################# +# addlinebreak: Adds a line break specific to the output format. # +# # +# Usage: # +# # +# $presmodule->addlinebreak(); # +################################################################################# + + # Add a line break. + + my $tagdata = ""; + + $tagdata = "
" . "\r\n"; + + # Append the tagdata to the pagedata. + + $pagedata = $pagedata . $tagdata; + +} + +sub addhorizontalline{ +################################################################################# +# addhorizontalline: Adds a horizontal line. # +# # +# Usage: # +# # +# $presmodule->addhorizontalline(); # +################################################################################# + + # Add a horizontal line. + + my $tagdata = ""; + + $tagdata = "
" . "\r\n"; + + # Append the tagdata to the pagedata. + + $pagedata = $pagedata . $tagdata; + +} + +################################################################################# +# Other. # +################################################################################# + +sub startlist{ +################################################################################# +# startlist: Start a list. # +# # +# Usage: # +# # +# $presmodule->startlist(); # +################################################################################# + + # Start a list. + + my $tagdata = ""; + my $tabcount = $tablevel; + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + $tagdata = $tagdata . "
    " . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + $tablevel++; + +} + +sub additem{ +################################################################################# +# additem: Adds an item to the list. # +# # +# Usage: # +# # +# $presmodule->additem(text, options); # +# # +# text Specifies the text to use for the item. # +# options Specifies the following options (in any order). # +# # +# Style Specifies the CSS style to use. # +################################################################################# + + # Get the options recieved. + + my $class = shift; + my ($text, $options) = @_; + + my $tagdata = ""; + my $tabcount = $tablevel; + + # Get certain values from the hash. + + my $style = $options->{'Style'}; + + # Check if certain values are undefined and if they + # are then set them blank or to a default value. + + if (!$text){ + die("The text given was blank."); + } + + if (!$style){ + $style = ""; + } + + # Add an item to the list. + + $tagdata = $tagdata . "
  • convert($style, "content") . "\""; + } + + $tagdata = $tagdata . ">" . $class->convert($text, "content"); + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +sub endlist{ +################################################################################# +# endlist: End a list. # +# # +# Usage: # +# # +# $presmodule-endlist(); # +################################################################################# + + # End a list. + + my $tagdata = ""; + $tablevel = ($tablevel - 1); + my $tabcount = $tablevel; + + while ($tabcount > 0){ + $tagdata = $tagdata . "\t"; + $tabcount = $tabcount - 1; + } + + $tagdata = $tagdata . "
" . "\r\n"; + + # Append the tag data to the page data. + + $pagedata = $pagedata . $tagdata; + +} + +1; \ No newline at end of file diff --git a/cgi-files/lang/en-GB.xml b/cgi-files/lang/en-GB.xml new file mode 100644 index 0000000..a1a3556 --- /dev/null +++ b/cgi-files/lang/en-GB.xml @@ -0,0 +1,527 @@ + + + + + English (British) + Steve Brokenshire + sbrokenshire(ao)xestia(dottie)co(dottie)uk + + + + + View Databases + Add Database + + + Database Name + Database Description + Database Categories + Database Notes + Database Filename + Return to the database list. + + Database List + Database Options + There are no databases that can be used. To create a database click on the Add Database link. + Databases with invalid permissions + The following databases have invalid permissions set: + Databases with errors + The following databases have errors: + + Add Database + Leave the filename blank to automatically generate a filename. + Don't include any extensions as it will be done automatically. + The filename cannot be any more than 32 characters long. + The filename should only contain letters, numbers and no spaces. + Add Database + Clear values + Database '%s' has been created. + + Edit Database + Edit Database '%s' + Edit Database + Edit Database + Database '%s' updated. + + Database Deletion + Are you sure you want to delete '%s'? + Yes, delete the database + No, return to the database list. + Database Deleted + Database '%s' was deleted. + + + + + + Add Page + + + Database + Page Filename + Page Name + Page Description + Page Section + Page Template + Page Content + Page Settings + Last Modified + + Return to the page list for the '%s' database. + View the page list for the '%s' database. + + A database error occurred while getting the page information with the filename '%s': %s + The page with the filename '%s' does not exist. + The page with the filename '%s' does not exist in the database that the page is to be copied from. + A database error has occurred while copying the page with the filename '%s' from the old database: %s + A database error has occurred while copying the page with the filename '%s' to the new database: %s + The page with the filename '%s' does not exist in the database that the page is to be copied from. + The page with the filename '%s' already exists in the database that the page is to be copied to. + A database error has occurred while moving the page with the filename '%s' from the old database: %s + A database error has occurred while moving the page with the filename '%s' to the new database: %s + The page with the filename '%s' does not exist in the database that the page is to be moved from. + The page with the filename '%s' already exists in the database that the page is to be moved to. + The page with the filename '%s' does not exist in the database that the page is to be moved from. + + Don't use a template + Keep current template filename (%s) + + Use page name and section name. + Use the page name only. + Use the section name only. + Don't use page name or section name. + + Template database does not exist. No template will be used. + Template database does not exist. Existing template settings can be kept. + Template database has invalid permissions set. No template will be used. + Template database has invalid permissions set. Existing template settings can be kept. + A database error occurred while trying to get the list of templates: %s + A database error occurred while trying to get the list of templates: '%s'. Existing template settings can be kept. + There are no templates in the template database. No template will be used. + The template database does not exist. Existing template settings for selected pages kept. + The template database has invalid permissions set. Existing template settings for selected pages kept. + A database error occurred while trying to get the list of templates: %s. Existing template settings for selected pages kept. + + Viewing Database + View Pages + Database Selection + No database selected. Please select a database from the drop-down list below and then press the 'View' button to view the pages in the selected database. + View + + Page list for '%s' + No pages exist in this database. To create a page for this database, click on Add Page link at the top of the page. + Delete Selected + Move Selected + Copy Selected + Edit Selected + + Add Page + Add Page + The page called '%s' was added to the '%s' database successfully. + + Edit Page + Editing Page '%s' + Edit Page + Page Edited + The page '%s' has been edited. + + Delete Page + Delete page '%s' + Are you sure you want to delete '%s' from the '%s' database? + Yes, delete the page + Page Deleted + The page named '%s' was deleted from the '%s' database. + + Delete selected pages + Are you sure you want to delete the selected pages below from the '%s' database? + Yes, delete the selected pages + No, return to the page list for the '%s' database. + Selected pages deleted + The following pages were deleted from the '%s' database: + + Move selected pages + Which database do you want to move the following pages from the '%s' database to? + Move pages to: + Move selected pages + The following pages from the '%s' database were moved to the '%s' database: + No pages were moved from the '%s' database to the '%s' database. + The following errors/warnings have occurred while moving the pages: + + Copy selected pages + Which database do you want to copy the following pages from the '%s' database to? + Copy pages to: + Copy selected pages + The following pages from the '%s' database were copied to the '%s' database: + No pages were copied from the '%s' database to the '%s' database. + The following errors/warnings have occurred while copying the pages: + + Edit selected pages + The following pages from the '%s' database will be altered: + Using the values below (click on the checkbox for each value to be edited on the selected pages): + Edit selected pages + No pages were edited in the '%s' database. + The selected pages in the '%s' database have been edited: + The following errors/warnings occurred while editing the selected pages: + + + + + + Show Filters + Add Filter + + + Priority + Find Setting + Replace Setting + + If no filter priority is specified, the filter priority will be set to 1. + Return to the filter list. + + View Filters + There are no filters available in the filters database. To add a filter, click on the Add Filter link. + The filters database does not exist and will be created when a filter is added. + Warning: + One (or more) of your filters has a blank find filter and needs to be fixed. + Blank Find Setting + Blank Replace Setting + + Add Filter + Find... + Replace with... + Notes + Add Filter + Filter Added + The filter was added successfully to the filters list. + + Edit Filter + Edit Filter + Filter edited + The selected filter was edited. + + Delete Filter + Are you sure you want to delete the selected filter? + Yes, delete the selected filter. + No, return to the filter list. + Filter Deleted + The selected filter was deleted from the filters list. + + + + + + + List Databases + Compile All + Clean Output Directory + + + Return to the compile database list. + + Compile Pages + There are no databases that can be used for compiling. + Compile Selected + + Compile All Databases + Do you want to compile all of the databases in the database directory? + Compile All Databases + + Compile Selected Databases + Do you want to compile the following databases? + Compile Selected Databases + + Compile Database + Are you sure you want to compile the '%s' database? + Compile Database + + [Information] + [Error] + [Warning] + + Compile Databases + The filters database does not exist. No filters will be used. + The filters database has invalid permissions set. No filters will be used. + A filter database error has occurred: %s. No filters will be used. + One (or more) of the find filters from the filters database is blank. + Finished processing the filters database. + The templates database does not exist. Pages will be compiled without templates being used. + The templates database has invalid permissions set. Pages will be compiled without templates being used. + A database error occurred while trying to get the list of templates: %s + Finished processing the templates database. + The database with the filename '%s' has invalid characters. Skipping this database... + The database with the filename '%s' is too long. Skipping this database... + The database with the filename '%s' does not exist. Skipping this database... + The database with the filename '%s' has invalid permissions set. Skipping this database... + A database error has occurred on the database with the filename '%s': %s + Compiling pages in the '%s' database... + A database error has occurred on the database with the filename '%s' while getting the list of pages: %s + The page '%s' has an invalid filename. Page skipped. + The template with the filename '%s' for '%s' (%s) does not exist. + The page with the filename '%s' has invalid permissions set. Page not written. + An error occured while writing the page with the filename '%s': %s + (%s) was compiled. + '%s' (%s) was compiled. + Finished compiling pages in the '%s' database... + %s pages compiled, %s errors, %s warnings. + + Clean Output Directory + Are you sure you want to clean the output directory? + Yes, clean output directory + Some of the contents of the directory were removed. However, not all of the files in the output directory were deleted due to invalid permissions. + The contents of the output directory have been removed. + + + + + View Settings + Edit Settings + + + View Settings + The current settings being used are the following: + Directories + Database Directory + Output Directory + Images (URI path) + Date + Date Format + Language + System Language + Modules + Presentation Module + Database Module + To alter the current settings, select the Edit Settings option at the top of the page. + + Edit Settings + Warning: + Settings that have changed take effect after clicking on the 'Change Settings' button and viewing the confirmation message. + D - Show single digit day if day value is less than 10. + DD - Show double digit day if day value is less than 10. + M - Show single digit month if month value is less than 10. + MM - Show double digit month if month value is less than 10. + Y - Show double digit year value. + YY - Show four digit year value. + h - Show single digit hour if hour value is less than 10. + hh - Show double digit hour if hour value is less than 10. + m - Show single digit minute if minute value is less than 10. + mm - Show double digit minute if minute value is less than 10. + s - Show single digit second if second value is less than 10. + ss - Show double digit second if second value is less than 10. + Other Characters: / - < > ; + Database Server + Database Port + Database Protocol + Database Name + Database Username + Database Password + Keep the current password + Table Prefix + Change Settings + Return to the list of settings. + Settings Edited + The page settings have been changed and will take effect on the next page load of Kiriwrite. + + + + Error! + The extended information about the error is: + An error has occurred but not an error that is known to Kiriwrite. + The filename specified was blank. + A blank variable was specified. + A filename specified already exists. + An internal error has occurred within Kiriwrite. + An invalid option was given. + An invalid action was specified. + The filename given contains invalid characters. + An invalid mode was specified. + A UTF-8 string is invalid. + An variable with invalid data has been found. + A variable given is too long. + The compile type specified was blank. + No database was specified when trying to add a page. + The directory name specified was blank. + The find filter was blank. + The date and time format given is blank. + A database connection error has occurred. + The database categories list is too long. + The database that the pages are being copied to is the same database that the pages are copied from. + A database with the filename given already exists. + The database directory is missing. + The database directory has invalid permission settings. + The database description is too long. + The database filename is invalid. + The database filename is too long. + A database error has occurred. + The database has invalid permission settings. + The database name contains invalid characters. + The database name is too long. + The database name is blank. + The database file is missing. + The database that the pages are moving to is missing. + The database cannot be renamed due to invalid permissions set. + The database that the pages are being moved to is the same database that the pages are moving from. + The database module name given is blank. + The database module name given is invalid. + The database directory name given was blank. + The database directory name given was invalid. + The database module with the filename given is missing. + The filters database was not created because of the invalid permissions set. + A database error has occurred while using the filters database. + The filters database has invalid permission settings. + The filters database is missing. + The filter identification number given is blank. + The filter with the identification number given does not exist. + The filter identification number given is invalid. + The filter identification number given is too long. + The find filter given is too long. + The filter priority number given is invalid. + The filter priority given contains invalid characters. + The filter priority given is too long. + The compile type given is invalid. + The page number specified is invalid. + No pages were selected. + The directory name specified was invalid. + The date and time format given is invalid. + An invalid language filename was given. + The language filename given does not exist. + The module name given was blank. + The module name given was invalid. + A database error has occurred in the database that the selected pages are being copied to. + The database that the selected pages are being copied to does not exist. + The database that the selected pages are being copied to has invalid permissions set. + A database error has occurred in the database that the selected pages are being moved to. + The database that the selected pages are moving to does not exist. + The database that the selected pages are moving to has invalid permissions set. + No databases are available for compiling. + No databases were selected for compiling. + No values will be changed on the selected pages as no values for changing were selected. + A database error has occurred in the database that the selected pages are being copied from. + The database that the selected pages are being copied from does not exist. + The database that the selected pages are being copied from has invalid permissions set. + A database error has occurred in the database that the selected pages are being moved from. + The database that the selected pages are moving from does not exist. + The database that the selected pages are moving from has invalid permissions set. + The output directory name given was blank. + The output directory name given was invalid. + The output directory is missing + The output directory has invalid permissions set. + The presentation module name given is blank. + The presentation module name given is invalid. + The presentation module with the filename given is missing. + The page with the filename given does not exist. + The page filename given already exists + The page filename given is invalid. + The page filename given is too long. + The page filename given is blank. + The page title given is too long. + The page description given is too long. + The page section given is too long. + The page database filename given is too long. + The page settings given is too long. + The page settings given are invalid. + The page template filename given was too long. + The replace filter given is too long + The database server name given is invalid. + The database server name given is too long. + The server database name given is invalid. + The server database name given is too long. + The server database username given is invalid. + The server database username given is too long. + The server database password given is too long. + The server database table prefix given is invalid. + The server database table prefix given is too long. + The database port number given is invalid. + The database port number given contains characters other than numbers. + The database port number given is too long. + The database server protocol name given is too long. + An invalid database server protocol was specified. + The template name given is blank. + A template with the given filename already exists. + The template filename given is invalid. + A database error has occurred while using the template database. + The template database has invalid permissions. + The template database is in a invalid format. + The template directory name given was blank. + The template directory name given was invalid. + The template database was not created because of the invalid permissions set. + The template filename given is too long + The template name given is too long + The template description given is too long + The template database is missing. + The template filename given does not exist in the templates database. + The template filename given was blank. + + + + Edit + Delete + Compile + + + No Name + No Description + Blank Database Name + + + Alter + Setting + Value + Restore current settings + Clear values + Select None + Options + + Kiriwrite Tags: + <kiriwrite:pagecontent> - Specifies the page content. + <kiriwrite:pagetitle> - Specifies the page title (and page section depending on page settings). + <kiriwrite:pagename> - Specifies the page name. + <kiriwrite:pagedescription> - Specifies the page description. + <kiriwrite:pagesection> - Specifies the page section. + <kiriwrite:autosection> - Automatic page section name. + <kiriwrite:autotitle> - Automatic page title (and page section depending on page settings). + + + + View Databases + View Pages + View Filters + View Templates + Compile Pages + View Settings + + diff --git a/cgi-files/lang/en-uk.xml b/cgi-files/lang/en-uk.xml deleted file mode 100644 index 2c7fa00..0000000 --- a/cgi-files/lang/en-uk.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - English UK - English UK - - - - -- 2.39.5