X-Git-Url: http://Server1/repobrowser/?p=kiriwrite%2F.git;a=blobdiff_plain;f=cgi-files%2Fkiriwrite.cgi;h=e351c2758aab592206b37bb7a5407826fe89c6a3;hp=2b061b6ea18136b5b5e58db858ea33f5ca915f28;hb=820f8c72b5d3985b5c06b0ffa7def526064ee2d7;hpb=15f5ab9da7cc30829a180c388d2094d9ede29a6d diff --git a/cgi-files/kiriwrite.cgi b/cgi-files/kiriwrite.cgi index 2b061b6..e351c27 100755 --- a/cgi-files/kiriwrite.cgi +++ b/cgi-files/kiriwrite.cgi @@ -1,12 +1,13 @@ #!/usr/bin/perl -Tw ################################################################################# -# Kiriwrite (kiriwrite.cgi) # +# Kiriwrite (kiriwrite.pl/kiriwrite.cgi) # # Main program script # # # -# Version: 0.0.2 # +# Version: 0.5.0 # +# mod_perl 2.x compatabile version # # # -# Copyright (C) 2005-2007 Steve Brokenshire # +# Copyright (C) 2005-2008 Steve Brokenshire # # # # 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 # @@ -21,11907 +22,1096 @@ # Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # ################################################################################# -use strict; # Throw errors if there's something wrong. -use warnings; # Write warnings to the HTTP Server Log file. +use strict; +use warnings; use utf8; -use CGI qw(:standard); -use CGI::Carp('fatalsToBrowser'); # Output errors to the browser. +use CGI::Lite; +use Tie::IxHash; -# Declare global variables for Kiriwrite settings and languages. - -our($kiriwrite_config, %kiriwrite_config, $kiriwrite_lang, %kiriwrite_lang, $kiriwrite_version, %kiriwrite_version); - -# Setup the version information for Kiriwrite. - -%kiriwrite_version = ( - "major" => 0, - "minor" => 0, - "revision" => 2 -); - -################################################################################# -# Begin listing the functions needed. # -################################################################################# - -#sub AUTOLOAD{ -################################################################################# -# AUTOLOAD: Catch-all for subroutines that do not exist. # -################################################################################# - - # A subroutine given does not exist so return an error. - -# kiriwrite_error("internalerror"); - -#} - -sub kiriwrite_page_add{ -################################################################################# -# kiriwrite_page_add: Adds a page to a database # -# # -# Usage: # -# # -# kiriwrite_page_add(database, pagefilename, title, description, section, # -# template, settings, info, confirm); # -# # -# database Specifies the database name. # -# pagefilename Specifies the page filename. # -# title Specifies the page title to be used. # -# description Specifies the short description of the page. # -# section Specifies the section assigned to the page. # -# template Specifies the template to use. # -# settings Specifies the settings to be used on the page. # -# data Specifies the data which consists the page. # -# confirm Confirms action to add an page. # -################################################################################# - - # Fetch the required variables that have been passed to the subroutine. - - my ($pagedatabase, $pagefilename, $pagetitle, $pagedescription, $pagesection, $pagetemplate, $pagesettings, $pagefiledata, $confirm) = @_; - - # Load the required Perl modules. - - use DBI; - - # Check if the action to add a new page has been confirmed (or not). - - my $pagedata = ""; - - if (!$confirm){ - - $confirm = 0; - - } - - kiriwrite_variablecheck($confirm, "maxlength", 1, 0); - - # Check if the database filename is valid and return an error if - # it isn't. - - my $pagedatabase_filename_check = kiriwrite_variablecheck($pagedatabase, "filename", 0, 1); - - if ($pagedatabase_filename_check eq 1){ - - # The database filename is blank, so return an error. - - kiriwrite_error("blankdatabasepageadd"); - - } elsif ($pagedatabase_filename_check eq 2){ - - # The database filename is invalid, so return an error. - - kiriwrite_error("databasefilenameinvalid"); - - } - - # Check the length the database name and return an error if it's - # too long. - - my $pagedatabase_length_check = kiriwrite_variablecheck($pagedatabase, "maxlength", 64, 1); - - if ($pagedatabase_length_check eq 1){ - - # The database name is too long, so return an error. - - kiriwrite_error("databasefilenametoolong"); - - } - - if ($confirm eq "1"){ - - # Check all the variables to see if they UTF8 valid. - - kiriwrite_variablecheck($pagefilename, "utf8", 0, 0); - kiriwrite_variablecheck($pagetitle, "utf8", 0, 0); - kiriwrite_variablecheck($pagedescription, "utf8", 0, 0); - kiriwrite_variablecheck($pagesection, "utf8", 0, 0); - kiriwrite_variablecheck($pagedatabase, "utf8", 0, 0); - kiriwrite_variablecheck($pagesettings, "utf8", 0, 0); - kiriwrite_variablecheck($pagetemplate, "utf8", 0, 0); - kiriwrite_variablecheck($pagefiledata, "utf8", 0, 0); - - # Convert the values into proper UTF8 values. - - $pagefilename = kiriwrite_utf8convert($pagefilename); - $pagetitle = kiriwrite_utf8convert($pagetitle); - $pagedescription = kiriwrite_utf8convert($pagedescription); - $pagesection = kiriwrite_utf8convert($pagesection); - $pagedatabase = kiriwrite_utf8convert($pagedatabase); - $pagesettings = kiriwrite_utf8convert($pagesettings); - $pagetemplate = kiriwrite_utf8convert($pagetemplate); - $pagefiledata = kiriwrite_utf8convert($pagefiledata); - - # Check all the variables (except for the page data, filename and settings - # will be checked more specifically later if needed) that were passed to - # the subroutine. - - my $pagefilename_maxlength_check = kiriwrite_variablecheck($pagefilename, "maxlength", 256, 1); - my $pagetitle_maxlength_check = kiriwrite_variablecheck($pagetitle, "maxlength", 512, 1); - my $pagedescription_maxlength_check = kiriwrite_variablecheck($pagedescription, "maxlength", 512, 1); - my $pagesection_maxlength_check = kiriwrite_variablecheck($pagesection, "maxlength", 256, 1); - my $pagedatabase_maxlength_check = kiriwrite_variablecheck($pagedatabase, "maxlength", 64, 1); - my $pagesettings_maxlength_check = kiriwrite_variablecheck($pagesettings, "maxlength", 1, 1); - my $pagetemplate_maxlength_check = kiriwrite_variablecheck($pagetemplate, "maxlength", 64, 1); - - # Check if an value returned is something else other than 0. - - if ($pagefilename_maxlength_check eq 1){ - - # The page filename given is too long, so return an error. - - kiriwrite_error("pagefilenametoolong"); - - } - - if ($pagetitle_maxlength_check eq 1){ - - # The page title given is too long, so return an error. - - kiriwrite_error("pagetitletoolong"); - - } - - if ($pagedescription_maxlength_check eq 1){ - - # The page description given is too long, so return an error. - - kiriwrite_error("pagedescriptiontoolong"); - - } - - if ($pagesection_maxlength_check eq 1){ - - # The page section given is too long, so return an error. - - kiriwrite_error("pagesectiontoolong"); - - } - - if ($pagedatabase_maxlength_check eq 1){ - - # The page database given is too long, so return an error. - - kiriwrite_error("pagedatabasefilenametoolong"); - - } - - if ($pagesettings_maxlength_check eq 1){ - - # The page settings given is too long, so return an error. - - kiriwrite_error("pagesettingstoolong"); - - } - - if ($pagetemplate_maxlength_check eq 1){ - - # The page template given is too long, so return an error. - - kiriwrite_error("pagetemplatefilenametoolong"); - - } - - # The action to create a new page has been confirmed, so add the page to the - # selected database. - - if (!$pagefilename){ - kiriwrite_error("pagefilenameblank"); - } - - # Check the page filename and page settings. - - my $pagefilename_filename_check = kiriwrite_variablecheck($pagefilename, "page_filename", 0, 1); - my $pagesettings_setting_check = kiriwrite_variablecheck($pagesettings, "pagesetting", 0, 1); - my $pagetemplate_filename_check = 0; - - if ($pagetemplate ne "!none"){ - - # A template is being used so check the filename of the - # template. - - $pagetemplate_filename_check = kiriwrite_variablecheck($pagetemplate, "page_filename", 0, 1); - - } - - if ($pagefilename_filename_check eq 1){ - - # The page filename given is invalid, so return an error. - - kiriwrite_error("pagefilenameinvalid"); - - } - - if ($pagesettings_setting_check eq 1){ - - # The page settings given is invalid, so return an error. - - kiriwrite_error("pagesettingsinvalid"); - - } - - if ($pagetemplate_filename_check eq 1){ - - # The template filename given is invalid, so return an error - - kiriwrite_error("templatefilenameinvalid"); - - } - - # Check the permissions of the page database. - - my $pagedatabase_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $pagedatabase . '.db'); - my $pagedatabase_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $pagedatabase . '.db', 1, 1, 0); - - if ($pagedatabase_exists eq 1){ - - # The page database does not exist, so return an error. - - kiriwrite_error("databasefilemissing"); - - } - - if ($pagedatabase_permissions eq 1){ - - # The page database permissions are invalid, so return - # an error. - - kiriwrite_error("databaseinvalidpermissions"); - - } - - # Load the SQLite database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $pagedatabase . '.db'); - - # Check if the filename used already exists and return - # an error if it is. - - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename . '\' LIMIT 1') or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - - my @database_page; - my $page_exists = 0; - - while (@database_page = $string_handle->fetchrow_array()){ - - # The page exists so set the page exists value to 1. - - $page_exists = 1; - - } - - if ($page_exists eq 1){ - - # The page exists so return an error. - - kiriwrite_error("pagefilenameexists"); - - } - - # Get the database name. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1'); - $string_handle->execute(); - - my @database_info = $string_handle->fetchrow_array(); - - my $database_name = $database_info[0]; - - # Convert the values so they don't cause the SQL query - # to break. - - my $filename_sql = kiriwrite_convert($pagefilename, "kiriwrite"); - my $pagename_sql = kiriwrite_convert($pagetitle, "kiriwrite"); - my $pagedescription_sql = kiriwrite_convert($pagedescription, "kiriwrite"); - my $pagesection_sql = kiriwrite_convert($pagesection, "kiriwrite"); - my $pagetemplate_sql = kiriwrite_convert($pagetemplate, "kiriwrite"); - my $pagesettings_sql = kiriwrite_convert($pagesettings, "kiriwrite"); - my $pagefiledata_sql = kiriwrite_convert($pagefiledata, "kiriwrite"); - - # Create the last modified date. - - my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; - - my $pagelastmodified = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; - - # Add the page to the database. - - $string_handle = $database_handle->prepare('INSERT INTO kiriwrite_database_pages VALUES( - \'' . $filename_sql . '\', - \'' . $pagename_sql . '\', - \'' . $pagedescription_sql . '\', - \'' . $pagesection_sql . '\', - \'' . $pagetemplate_sql . '\', - \'' . $pagefiledata_sql . '\', - \'' . $pagesettings_sql . '\', - \'' . $pagelastmodified . '\' - )'); - $string_handle->execute(); - - # Convert certain variables so that display properly. - - my $pagetitle_display = kiriwrite_convert($pagetitle, "normal_display"); - my $database_name_display = kiriwrite_convert($database_name, "normal_display"); - - $pagedata = "

Add Page

"; - $pagedata = $pagedata . "The page called '" . $pagetitle_display . "' was added to the '" . $database_name_display . "' database successfully.

"; - $pagedata = $pagedata . "Return to the page list for the '" . $database_name . "' database."; - - return $pagedata; - - } elsif ($confirm eq 0) { - - # The action to create a new page has not been confirmed, so print out a form - # for adding a page to a database. - - # Check if the page database and template database exists and has valid permissions - # set and return an error if they don't. - - my $database_page_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $pagedatabase . '.db'); - my $database_page_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $pagedatabase . '.db', 1, 1, 0); - my $database_template_exists = kiriwrite_fileexists("templates.db"); - my $database_template_permissions = kiriwrite_filepermissions("templates.db", 1, 0, 0); - - my $template_data = ""; - - my $database_handle; - my $string_handle; - - my $template_warningmessage; - my $template_warning = 0; - - my @database_template; - my @database_page; - - if ($database_page_exists eq 1){ - - # The page database does not exists so return an - # error. - - kiriwrite_error("databasemissingfile"); - - } - - if ($database_page_permissions eq 1){ - - # The page database permissions are invalid so - # return an error. - - kiriwrite_error("databaseinvalidpermissions"); - - } - - if ($database_template_exists eq 1){ - - # The template database does not exist so - # write a message to say that the template - # database is missing, none assumed. - - $template_warningmessage = "Template database does not exist. No template will be used."; - $template_warning = 1; - - } - - if ($database_template_permissions eq 1 && $database_template_exists ne 1){ - - # The template permissions are invalid so - # write a message saying that the template - # database has invalid permissions set, - # none assumed. - - $template_warningmessage = "Template database has invalid permissions set. No template will be used."; - $template_warning = 1; - - } - - # Check if the template_warning value is set to 1 and - # if it isn't then load the template database. - - if ($template_warning eq 0){ - - # The template_warning value is not set to 1, so - # load the template database. - - my $page_filename = ""; - my $page_name = ""; - my $template_count = 0; - - # Load the SQLite database. - - $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db"); - $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_templates ORDER BY templatename asc") or kiriwrite_error("templatedatabaseinvalidformat"); - $string_handle->execute(); - - $template_data = ""; - - if ($template_count eq 0){ - - # There are no templates in the template database - # so write a message saying that no templates - # are in the template database. - - $template_warningmessage = "There are no templates in the template database. No template will be used."; - $template_warning = 1; - - } - - } - - # Load the page database and get the page database - # name. - - $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $pagedatabase . '.db'); - $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_info limit 1") or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - - @database_page = $string_handle->fetchrow_array(); - - my $database_name = $database_page[0]; - - $database_name = kiriwrite_convert($database_name, "normal_display"); - $pagedatabase = kiriwrite_convert($pagedatabase, "normal_display"); - - $pagedata = $pagedata . "

Add Page

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - - if ($template_warning eq 1){ - - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - - } else { - - $pagedata = $pagedata . ""; - - } - - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "
SettingValue
Database" . $database_name . "
Page Name
Page Description
Page Section
Page Template" . $template_warningmessage . "
Page Template" . $template_data . "
Page Filename
Page Content

"; - $pagedata = $pagedata . "
Kiriwrite tags

<kiriwrite:autosection> - Automatic page section name. (Will be blank if page section name is blank).
- <kiriwrite:autotitle> - Automatic title and section name based on page setting.
- <kiriwrite:pagedata> - Page Content
- <kiriwrite:pagetitle> - Page Title based on page setting.
- <kiriwrite:pagename> - Page Name
- <kiriwrite:pagedescription> - Page Description
- <kiriwrite:pagesection> - Page Section
"; - $pagedata = $pagedata . "
Page Settings Use page name and section name.
Use the page name only.
Use the section name only.
Don't use page name or section name.
"; - $pagedata = $pagedata . "
| | Return to the page list."; - $pagedata = $pagedata . "
"; - - return $pagedata; - - } else { - - # The confirm value is something else than '1' or '0' so - # return an error. - - kiriwrite_error("invalidvalue"); - - } - - - -} - -sub kiriwrite_page_delete{ -################################################################################# -# kiriwrite_page_delete: Deletes a (single) page from a database. # -# # -# Usage: # -# # -# kiriwrite_page_delete(database, page, [confirm]); # -# # -# database Specifies the database to delete from. # -# page Specifies the page to delete. # -# confirm Confirms the action to delete the page. # -################################################################################# - - my ($database, $page, $confirm) = @_; - - # Load the required Perl modules. - - use DBI; - - my $pagedata; - - # Check if the database filename is valid and return an error if - # it isn't. - - my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1); - - if ($pagedatabase_filename_check eq 1){ - - # The database filename is blank, so return an error. - - kiriwrite_error("blankdatabasepageadd"); - - } elsif ($pagedatabase_filename_check eq 2){ - - # The database filename is invalid, so return an error. - - kiriwrite_error("databasefilenameinvalid"); - - } - - # Check the length the database name and return an error if it's - # too long. - - my $pagedatabase_length_check = kiriwrite_variablecheck($database, "maxlength", 64, 1); - - if ($pagedatabase_length_check eq 1){ - - # The database name is too long, so return an error. - - kiriwrite_error("databasefilenametoolong"); - - } - - # Check if the page name is specified is blank and return an error if - # it is. - - if (!$page){ - - # The page name is blank, so return an error. - - kiriwrite_error("blankfilename"); - - } - - # If the confirm value is blank, then set the confirm value to 0. - - if (!$confirm){ - - $confirm = 0; - - } - - if ($confirm eq 1){ - - # The action to delete the selected page from the database - # has been confirmed. - - # Check that the database exists and has the correct permissions - # set. - - my $database_check_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $database_check_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db', 1, 1, 0); - - # Check the results and return an error if needed. - - if ($database_check_exists eq 1){ - - # The database file does not exist, so return an error. - - kiriwrite_error("databasemissingfile"); - - } - - if ($database_check_permissions eq 1){ - - # The database file has invalid permissions set, so - # return an error. - - kiriwrite_error("databaseinvalidpermissions"); - - } - - # Load the SQLite database and get information about the - # database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("databasefileinvalid") or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - - my @database_info; - my $database_name; - @database_info = $string_handle->fetchrow_array(); - $database_name = $database_info[0]; - - my $pagefilename_sql = kiriwrite_convert($page, "kiriwrite"); - - # Check if the filename exists and return an error if it - # isn't. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename_sql . '\' LIMIT 1'); - $string_handle->execute(); - - my @database_page; - my $page_found = 0; - - while (@database_page = $string_handle->fetchrow_array()){ - - $page_found = 1; - - } - - # Check if the page wasn't found and return an error if it - # didn't. - - if ($page_found eq 0){ - - # Page wasn't found in the database so return - # an error. - - kiriwrite_error("pagefilenamedoesnotexist"); - - } - - # Get information about the page (mainly the name). - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename_sql . '\' LIMIT 1'); - $string_handle->execute(); - - my $page_name; - @database_page = $string_handle->fetchrow_array(); - $page_name = $database_page[1]; - - # Delete the page from the database. - - $string_handle = $database_handle->prepare('DELETE FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename_sql . '\''); - $string_handle->execute(); - - # Convert the values before writing them. - - my $database_out = kiriwrite_convert($database, "normal_display"); - my $database_name_out = kiriwrite_convert($database_name, "normal_display"); - my $page_name_out = kiriwrite_convert($page_name, "normal_display"); - - # Write out a message saying that the selected page from - # the database has been deleted. - - $pagedata = "

Page Deleted

"; - $pagedata = $pagedata . "The page named '" . $page_name_out . "' was deleted from the '" . $database_name_out . "' database.

"; - $pagedata = $pagedata . "Return to the '" . $database_name_out . "' database."; - - return $pagedata; - - } elsif ($confirm eq 0){ - - # Check that the database exists and has the correct permissions - # set. - - my $database_check_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $database_check_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db', 1, 1, 0); - - # Check the results and return an error if needed. - - if ($database_check_exists eq 1){ - - # The database file does not exist, so return an error. - - kiriwrite_error("databasemissingfile"); - - } - - if ($database_check_permissions eq 1){ - - # The database file has invalid permissions set, so - # return an error. - - kiriwrite_error("databaseinvalidpermissions"); - - } - - # Load the SQLite database and get information about the - # database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("databasefileinvalid") or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - - my @database_info; - my $database_name; - @database_info = $string_handle->fetchrow_array(); - $database_name = $database_info[0]; - - my $pagefilename_sql = kiriwrite_convert($page, "kiriwrite"); - - # Check if the filename exists and return an error if it - # isn't. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename_sql . '\' LIMIT 1'); - $string_handle->execute(); - - my $page_found = 0; - - my @database_page; - - while (@database_page = $string_handle->fetchrow_array()){ - - $page_found = 1; - - } - - # Check if the page wasn't found and return an error if it - # didn't. - - if ($page_found eq 0){ - - # Page wasn't found in the database so return - # an error. - - kiriwrite_error("pagefilenamedoesnotexist"); - - } - - # Get information about the page (mainly the name). - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename_sql . '\' LIMIT 1'); - $string_handle->execute(); - - my $page_name; - @database_page = $string_handle->fetchrow_array(); - $page_name = $database_page[1]; - - # Convert the values so that they can be displayed properly. - - my $page_name_out = kiriwrite_convert($page_name, "normal_display"); - my $database_out = kiriwrite_convert($database, "normal_display"); - my $database_name_out = kiriwrite_convert($database_name, "normal_display"); - my $page_out = kiriwrite_convert($page, "normal_display"); - - # Write a message asking the user to confirm the deletion of the - # page. - - $pagedata = "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "";; - $pagedata = $pagedata . "

Delete page '" . $page_name_out . "'

"; - $pagedata = $pagedata . "Are you sure you want to delete '" . $page_name_out . "' from the '" . $database_name_out . "' database?

"; - $pagedata = $pagedata . " | No, return to the '" . $database_name_out . "' database."; - $pagedata = $pagedata . "
"; - - - return $pagedata; - - } else { - - # Another page deletion type was specified, so return an error. - - kiriwrite_error("invalidoption"); - - } - -} - -sub kiriwrite_page_edit{ -################################################################################# -# kiriwrite_page_edit: Edits a page from a database. # -# # -# Usage: # -# # -# kiriwrite_page_edit(database, filename, newname, newfilename, newdescription, # -# newsection, newtemplate, newsettings, newpagecontent # -# confirm); # -# # -# database Specifies the database to edit from. # -# filename Specifies the filename to use. # -# newfilename Specifies the new page filename to use. # -# newname Specifies the new page name to use. # -# newdescription Specifies the new description for the page. # -# newsection Specifies the new section name to use. # -# newtemplate Specifies the new template filename to use. # -# newsettings Specifies the new page settings to use. # -# newpagecontent Specifies the new page content to use. # -# confirm Confirms the action to edit the page. # -################################################################################# - - # Get the values that have been passed to the subroutine. - - my ($database, $pagefilename, $pagenewfilename, $pagenewtitle, $pagenewdescription, $pagenewsection, $pagenewtemplate, $pagenewsettings, $pagenewcontent, $confirm) = @_; - - # Load the required Perl modules. - - use DBI; - - my $pagedata = ""; - - # Check if the confirm value is blank and if it is, then set it to '0'. - - if (!$confirm){ - - $confirm = 0; - - } - - # Check if the confirm value is more than one character long and if it - # is then return an error. - - kiriwrite_variablecheck($confirm, "maxlength", 1, 0); - - # Check if the database filename is valid and return an error if - # it isn't. - - my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1); - - if ($pagedatabase_filename_check eq 1){ - - # The database filename is blank, so return an error. - - kiriwrite_error("blankdatabasepageadd"); - - } elsif ($pagedatabase_filename_check eq 2){ - - # The database filename is invalid, so return an error. - - kiriwrite_error("databasefilenameinvalid"); - - } - - # Check the length the database name and return an error if it's - # too long. - - my $pagedatabase_length_check = kiriwrite_variablecheck($database, "maxlength", 64, 1); - - if ($pagedatabase_length_check eq 1){ - - # The database name is too long, so return an error. - - kiriwrite_error("databasefilenametoolong"); - - } - - # Check if the page identification number is blank (which it shouldn't - # be) and if it is, then return an error. - - if (!$pagefilename){ - - kiriwrite_error("blankfilename"); - - } - - # Check if the confirm value is '1' and if it is, edit the specified - # page in the database. - - if ($confirm eq 1){ - - # Check if the new page filename is blank. - - if (!$pagenewfilename){ - - # The page filename is blank so return an error. - - kiriwrite_error("pagefilenameblank"); - - } - - # The action to edit a page has been confirmed so check the - # variables recieved are UTF8 compiliant before converting. - - kiriwrite_variablecheck($database, "utf8", 0, 0); - kiriwrite_variablecheck($pagefilename, "utf8", 0, 0); - kiriwrite_variablecheck($pagenewfilename, "utf8", 0, 0); - kiriwrite_variablecheck($pagenewtitle, "utf8", 0, 0); - kiriwrite_variablecheck($pagenewdescription, "utf8", 0, 0); - kiriwrite_variablecheck($pagenewsection, "utf8", 0, 0); - kiriwrite_variablecheck($pagenewsettings, "utf8", 0, 0); - kiriwrite_variablecheck($pagenewtemplate, "utf8", 0, 0); - kiriwrite_variablecheck($pagenewcontent, "utf8", 0, 0); - - # Convert the variables into proper UTF8 variables. - - $database = kiriwrite_utf8convert($database); - $pagefilename = kiriwrite_utf8convert($pagefilename); - $pagenewfilename = kiriwrite_utf8convert($pagenewfilename); - $pagenewtitle = kiriwrite_utf8convert($pagenewtitle); - $pagenewdescription = kiriwrite_utf8convert($pagenewdescription); - $pagenewsection = kiriwrite_utf8convert($pagenewsection); - $pagenewsettings = kiriwrite_utf8convert($pagenewsettings); - $pagenewtemplate = kiriwrite_utf8convert($pagenewtemplate); - $pagenewcontent = kiriwrite_utf8convert($pagenewcontent); - - # Check the lengths of the variables. - - my $pagenewfilename_maxlength_check = kiriwrite_variablecheck($pagenewfilename, "maxlength", 256, 1); - my $pagenewtitle_maxlength_check = kiriwrite_variablecheck($pagenewtitle, "maxlength", 256, 1); - my $pagenewdescription_maxlength_check = kiriwrite_variablecheck($pagenewdescription, "maxlength", 512, 1); - my $pagenewsection_maxlength_check = kiriwrite_variablecheck($pagenewsection, "maxlength", 256, 1); - my $pagenewsettings_maxlength_check = kiriwrite_variablecheck($pagenewsettings, "maxlength", 1, 1); - my $pagenewtemplate_maxlength_check = kiriwrite_variablecheck($pagenewtemplate, "maxlength", 64, 1); - - # Check each result to see if the length of the variable - # is valid and return an error if it isn't. - - if ($pagenewfilename_maxlength_check eq 1){ - - # The new page filename given is too long, so return an error. - - kiriwrite_error("pagefilenametoolong"); - - } - - if ($pagenewtitle_maxlength_check eq 1){ - - # The new page title given is too long, so return an error. - - kiriwrite_error("pagetitletoolong"); - - } - - if ($pagenewdescription_maxlength_check eq 1){ - - # The new page description given is too long, so return an error. - - kiriwrite_error("pagedescriptiontoolong"); - - } - - if ($pagenewsection_maxlength_check eq 1){ - - # The new page section given is too long, so return an error. - - kiriwrite_error("pagesectiontoolong"); - - } - - if ($pagenewsettings_maxlength_check eq 1){ - - # The new page settings given is too long, so return an error. - - kiriwrite_error("pagesettingstoolong"); - - } - - if ($pagenewtemplate_maxlength_check eq 1){ - - # The new page template given is too long, so return an error. - - kiriwrite_error("pagetemplatefilenametoolong"); - - } - - # Check if the new page filename and new page settings - # are valid. - - my $pagenewfilename_filename_check = kiriwrite_variablecheck($pagenewfilename, "page_filename", 0, 1); - my $pagenewsettings_settings_check = kiriwrite_variablecheck($pagenewsettings, "pagesetting", 0, 1); - my $pagetemplate_filename_check = 0; - - if ($pagenewtemplate ne "!none"){ - - # A template is being used so check the filename of the - # template. - - $pagetemplate_filename_check = kiriwrite_variablecheck($pagenewtemplate, "page_filename", 0, 1); - - } - - # Check each result to see if the variables have passed - # their tests and return an error if they haven't. - - if ($pagenewfilename_filename_check eq 1){ - - # The new page filename is invalid, so return an error. - - kiriwrite_error("pagefilenameinvalid"); - - } - - if ($pagenewsettings_settings_check eq 1){ - - # The new page settings is invalid, so return an error. - - kiriwrite_error("pagesettingsinvalid"); - - } - - if ($pagetemplate_filename_check eq 1){ - - # The template filename given is invalid, so return an error - - kiriwrite_error("templatefilenameinvalid"); - - } - - # Check if the page database exists and the permissions set for - # it are valid. - - my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db', 1, 1, 0); - - if ($database_exists eq 1){ - - # The database does not exist, so return an error. - - kiriwrite_error("databasemissingfile"); - - } - - if ($database_permissions eq 1){ - - # The database permissions are invalid, so return - # an error. - - kiriwrite_error("databaseinvalidpermissions"); - - } - - # Load the SQLite database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - - # Check if the page exists in the page database and return - # an error if it doesn't. - - my $pagefilename_sql = kiriwrite_convert($pagefilename, "kiriwrite"); - - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename . '\' LIMIT 1') or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - - my $page_exists = 0; - my @database_pages; - - # Check if a result has returned (meaning that the - # page with that filename exists. - - while(@database_pages = $string_handle->fetchrow_array()){ - - # The page exists so set the value to 1. - - $page_exists = 1; - - } - - if ($page_exists eq 0){ - - # The page does not exist, so return an error. - - kiriwrite_error("pagefilenamedoesnotexist"); - - } - - # Get the current date and time. - - my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; - - my $pagelastmodified = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; - - # Prepare for the page's values to be changed. - - $pagefilename_sql = kiriwrite_convert($pagefilename, "kiriwrite"); - my $pagenewfilename_sql = kiriwrite_convert($pagenewfilename, "kiriwrite"); - my $pagenewtitle_sql = kiriwrite_convert($pagenewtitle, "kiriwrite"); - my $pagenewdescription_sql = kiriwrite_convert($pagenewdescription, "kiriwrite"); - my $pagenewsection_sql = kiriwrite_convert($pagenewsection, "kiriwrite"); - my $pagenewtemplate_sql = kiriwrite_convert($pagenewtemplate, "kiriwrite"); - my $pagenewsettings_sql = kiriwrite_convert($pagenewsettings, "kiriwrite"); - my $pagenewcontent_sql = kiriwrite_convert($pagenewcontent, "kiriwrite"); - my $pagelastmodified_sql = kiriwrite_convert($pagelastmodified, "kiriwrite"); - - # Edit the page in the database. - - $string_handle = $database_handle->prepare('UPDATE kiriwrite_database_pages SET filename = \'' . $pagenewfilename_sql . '\', pagename = \'' . $pagenewtitle_sql . '\', pagedescription = \'' . $pagenewdescription_sql . '\', pagesection = \'' . $pagenewsection_sql . '\', pagetemplate = \'' . $pagenewtemplate_sql . '\', pagedata = \'' . $pagenewcontent_sql . '\', pagesettings = \'' . $pagenewsettings_sql . '\', lastmodified = \'' . $pagelastmodified_sql . '\' WHERE filename = \'' . $pagefilename_sql . '\''); - $string_handle->execute(); - - # Get the database name. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1'); - $string_handle->execute(); - - my @database_info; - my $database_name; - - @database_info = $string_handle->fetchrow_array(); - $database_name = $database_info[0]; - - # Convert certain values so that they can be displayed - # properly. - - my $pagenewtitle_out = kiriwrite_convert($pagenewtitle, "normal_display"); - my $database_out = kiriwrite_convert($database, "normal_display"); - my $database_name_out = kiriwrite_convert($database_name, "normal_display"); - - # Write out the message to say that the page has been - # edited. - - $pagedata = "

Page Edited

"; - $pagedata = $pagedata . "The page '" . $pagenewtitle_out . "' has been edited.

"; - $pagedata = $pagedata . "Return to the page list for the '" . $database_name_out . "' database"; - - return $pagedata; - - } elsif ($confirm eq 0) { - - # Check if the database exists and that the permissions - # for the database are valid. - - my $database_file_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $database_file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - - if ($database_file_exists eq 1){ - - # The database with the filename given does - # not exist, so return an error. - - kiriwrite_error("databasemissingfile"); - - } - - if ($database_file_permissions eq 1){ - - # The file permissions of the database given - # are invalid so return an error. - - kiriwrite_error("databaseinvalidpermissions"); - - } - - # Load the SQLite database and check if the file exists. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename . '\' LIMIT 1') or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - - my $page_count = 0; - my @database_pages; - my @database_info; - my @database_templates; - my $template_data; - my $template_filename; - my $template_name; - my $template_found = 0; - - while (@database_pages = $string_handle->fetchrow_array()){ - - $page_count = 1; - - } - - if ($page_count eq 0){ - - # The page does not exist in the template database, so - # return an error. - - kiriwrite_error("pagefilenamedoesnotexist"); - - } - - # Get the database name. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - @database_info = $string_handle->fetchrow_array(); - - my $database_name = $database_info[0]; - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename . '\' LIMIT 1'); - $string_handle->execute(); - @database_pages = $string_handle->fetchrow_array(); - - # Get the variables and convert them so that they can be displayed - # properly. - - my $data_filename = kiriwrite_convert($database_pages[0], "normal_display"); - my $data_name = kiriwrite_convert($database_pages[1], "normal_display"); - my $data_description = kiriwrite_convert($database_pages[2], "normal_display"); - my $data_section = kiriwrite_convert($database_pages[3], "normal_display"); - my $data_template = kiriwrite_convert($database_pages[4], "normal_display"); - my $data_content = kiriwrite_convert($database_pages[5], "normal_display"); - my $data_settings = kiriwrite_convert($database_pages[6], "normal_display"); - my $data_lastmodified = kiriwrite_convert(kiriwrite_convert($database_pages[7], "date"), "normal_display"); - - # Get the template list and select the template that is being used by - # the page, check the permissions and if the template database exists. - - my $template_warning; - - my $template_file_exists = kiriwrite_fileexists("templates.db"); - my $template_file_permissions = kiriwrite_filepermissions("templates.db", 1, 0, 0); - - if ($template_file_exists eq 1){ - - # The template database does not exist, so write a warning messsage. - - $template_warning = "The template database does not exist. Existing template settings for page kept."; - - } - - if ($template_file_permissions eq 1 && $template_file_exists ne 1){ - - # The template database has invalid permissions set, so write a warning message. - - $template_warning = "The template database has invalid permissions set. Existing template settings for page kept."; - - } - - # Get the list of templates. - - if (!$template_warning){ - - # Load the templates database and get the templates. - - $database_handle = DBI->connect("dbi:SQLite:templates.db"); - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates') or $template_warning = "The template database is in an invalid format. Existing template settings kept."; - - if (!$template_warning){ - - $string_handle->execute(); - - $template_data = ""; - - } - - # Begin writing out the form for editing the selected page. - - $pagedata = "

Editing Page '" . $data_name . "'

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - - if ($template_warning){ - - $pagedata = $pagedata . ""; - - } else { - - $pagedata = $pagedata . ""; - - } - - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - - } else { - - # The setting is not the one being checked for - # so write the option out as normal. - - $pagedata = $pagedata . " Don't use page name or section name.
"; - - } - - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "
SettingValue
Database" . $database_name . "
Page Name
Page Description
Page Section
Page Template" . $data_template . "
" . $template_warning . "
Page Template" . $template_data . "
Page Filename
Page Content

"; - $pagedata = $pagedata . "
Kiriwrite tags

<kiriwrite:autosection> - Automatic page section name. (Will be blank if page section name is blank).
- <kiriwrite:autotitle> - Automatic title and section name based on page setting.
- <kiriwrite:pagedata> - Page Content
- <kiriwrite:pagetitle> - Page Title based on page setting.
- <kiriwrite:pagename> - Page Name
- <kiriwrite:pagedescription> - Page Description
- <kiriwrite:pagesection> - Page Section
"; - $pagedata = $pagedata . "
Page Settings"; - - # Check the page settings value and set the currently selected - # option to what the settings value is set to. - - if ($data_settings eq 1){ - - # The selected option is to use the page name and - # section name so make sure it is selected. - - $pagedata = $pagedata . " Use page name and section name.
"; - - } else { - - # The setting is not the one being checked for - # so write the option out as normal. - - $pagedata = $pagedata . " Use page name and section name.
"; - - } - - if ($data_settings eq 2){ - - # The selected option is to use the page name - # only so make sure it is selected. - - $pagedata = $pagedata . " Use the page name only.
"; - - } else { - - # The setting is not the one being checked for - # so write the option out as normal. - - $pagedata = $pagedata . " Use the page name only.
"; - - } - - if ($data_settings eq 3){ - - # The selected option is to use the section name - # only so make sure it is selected. - - $pagedata = $pagedata . " Use the section name only.
"; - - } else { - - # The setting is not the one being checked for - # so write the option out as normal. - - $pagedata = $pagedata . " Use the section name only.
"; - - } - - if ($data_settings eq 0){ - - # The selected option is to not use the page name - # or the section name. - - $pagedata = $pagedata . " Don't use page name or section name.
Page Last Modified" . $data_lastmodified . "
"; - $pagedata = $pagedata . "
| | Return to the page list for '" . $database_name . "'"; - $pagedata = $pagedata . "
"; - - return $pagedata; - - } else { - - # The confirm value is a value other than '0' and '1' so - # return an error. - - kiriwrite_error("invalidvalue"); - - } - -} - -sub kiriwrite_page_multidelete{ -################################################################################# -# kiriwrite_page_multidelete: Delete mulitple pages from the database. # -# # -# Usage: # -# # -# kiriwrite_page_multidelete(database, confirm, filelist); # -# # -# database Specifies the database to delete multiple pages from. # -# confirm Confirms the action to delete the selected pages from the # -# database. # -# filelist The list of files to delete from the selected database. # -################################################################################# - - # Get the information passed to the subroutine. - - my ($database, $confirm, @filelist) = @_; - - # Load the needed Perl modules. - - use DBI; - - # Define a variable for later on. - - my $pagedata; - - # Check if the database name is blank and return an error if - # it is. - - if (!$database){ - - # The database name is blank so return an error. - - kiriwrite_error("databasenameblank"); - - } - - # Check if the page database exists and the permissions set for - # it are valid. - - my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db', 1, 1, 0); - - if ($database_exists eq 1){ - - # The database does not exist, so return an error. - - kiriwrite_error("databasemissingfile"); - - } - - if ($database_permissions eq 1){ - - # The database permissions are invalid, so return - # an error. - - kiriwrite_error("databaseinvalidpermissions"); - - } - - # Check if the file list array has any values and return - # an error if it doesn't. - - if (!@filelist){ - - # The page list really is blank so return - # an error. - - kiriwrite_error("nopagesselected"); - } - - # Check if the database filename is valid and return an error if - # it isn't. - - my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1); - - if ($pagedatabase_filename_check eq 1){ - - # The database filename is blank, so return an error. - - kiriwrite_error("blankdatabasepageadd"); - - } elsif ($pagedatabase_filename_check eq 2){ - - # The database filename is invalid, so return an error. - - kiriwrite_error("databasefilenameinvalid"); - - } - - # Check the length the database name and return an error if it's - # too long. - - my $pagedatabase_length_check = kiriwrite_variablecheck($database, "maxlength", 64, 1); - - if ($pagedatabase_length_check eq 1){ - - # The database name is too long, so return an error. - - kiriwrite_error("databasefilenametoolong"); - - } - - # Check if the confirm value is blank and if it is, then - # set it to 0. - - if (!$confirm){ - - # The confirm value is blank so set the confirm value - # to 0. - - $confirm = 0; - - } - - if ($confirm eq 1){ - - # The action to delete multiple pages from the database has - # been confirmed. - - # Load the SQLite Database and get info about the database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - - my @database_info = $string_handle->fetchrow_array(); - my $database_name = $database_info[0]; - - # Define some variables for later. - - my @database_page; - my $filelist_filename; - my $deleted_list; - my $page_name; - my $page_found = 0; - - $deleted_list = ""; - - foreach $filelist_filename (@filelist){ - - # Check if the page exists and skip to the next - # file if it doesn't exist. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $filelist_filename . '\' LIMIT 1'); - $string_handle->execute(); - - while (@database_page = $string_handle->fetchrow_array()){ - $page_found = 1; - } - - if ($page_found eq 0){ - - next; - - } - - # Get the page name. - - $string_handle->execute(); - @database_page = $string_handle->fetchrow_array(); - $page_name = $database_page[1]; - - # Delete the page. - - $string_handle = $database_handle->prepare('DELETE FROM kiriwrite_database_pages WHERE filename = \'' . $filelist_filename . '\''); - $string_handle->execute(); - - # Append the page name and page filename to the list - # of deleted pages. - - $deleted_list = $deleted_list . kiriwrite_convert($page_name, "normal_display") . " (" . $filelist_filename . ")" . "
"; - $page_found = 0; - - } - - $string_handle = $database_handle->prepare('VACUUM'); - $string_handle->execute(); - - my $database_out = kiriwrite_convert($database, "normal_display"); - my $database_name_out = kiriwrite_convert($database_name, "normal_display"); - - $pagedata = "

Selected pages deleted

"; - $pagedata = $pagedata . "The following pages were deleted from the '" . $database_name_out . "' database:

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . $deleted_list; - $pagedata = $pagedata . "

"; - $pagedata = $pagedata . "Return to the page list for the '" . $database_name_out . "' database."; - - return $pagedata; - - } elsif ($confirm eq 0){ - - # The action to delete multiple pages from the database has - # not been confirmed, so write a form asking the user to confirm - # the deletion of those pages. - - # Load the SQLite Database and get info about the database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - - my @database_info = $string_handle->fetchrow_array(); - my $database_name = $database_info[0]; - - # Define some variables for later. - - my @page_info; - my @pagenames; - my @filenames; - my $pagename; - my $filelist_filename; - my $filelist_filename_sql; - my $database_name_out; - my $pagenameslist; - my $pagenameslist_out; - my $pageseek = 0; - my $pagefound = 0; - - # Process each filename given. - - foreach $filelist_filename (@filelist){ - - $filelist_filename_sql = kiriwrite_convert($filelist_filename, "kiriwrite"); - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $filelist_filename . '\' LIMIT 1') or kiriwrite_error("databasefileinvalid"); - - $string_handle->execute(); - - # Check if the filename given exists and if it - # doesn't then skip this filename and go onto - # the next filename. - - while (@page_info = $string_handle->fetchrow_array()){ - - $pagefound = 1; - - } - - if ($pagefound eq 0){ - - next; - - } - - # Get the data again. - - $string_handle->execute(); - @page_info = $string_handle->fetchrow_array(); - - # Add the page name and file name to their seperate - # arrays. - - $pagenames[$pageseek] = $page_info[1]; - $filenames[$pageseek] = $page_info[0]; - - # Increment the page seek counter and reset the - # page found value. - - $pageseek++; - $pagefound = 0; - - } - - $pageseek = 0; - - $pagenameslist = ""; - - foreach $pagename (@pagenames){ - - if (!$pagename){ - - $pagenameslist = $pagenameslist . "No page name (" . $filenames[$pageseek] . ")
"; - - } else { - - $pagenameslist = $pagenameslist . kiriwrite_convert($pagename, "normal_display") . " (" . kiriwrite_convert($filenames[$pageseek], "normal_display") . ")
"; - - } - - $pageseek++; - - } - - # Check if any files were selected and return - # an error if there wasn't. - - if ($pageseek eq 0){ - - # No pages were selected so return an error. - - kiriwrite_error("nopagesselected"); - - } - - # Convert the values so that they display properly. - - $database_name_out = kiriwrite_convert($database_name, "normal_display"); - my $database_out = kiriwrite_convert($database, "normal_display"); - - # Write the form for displaying pages. - - $pagedata = "

Delete multiple pages

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - - $pageseek = 1; - - foreach $filelist_filename (@filenames){ - - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - - $pageseek++; - - } - - - - $pagedata = $pagedata . "Are you sure you want to delete the selected pages below from the '" . $database_name_out . "' database?

"; - $pagedata = $pagedata . "
" . $pagenameslist . "

"; - $pagedata = $pagedata . " | No, return to the list for '" . $database_name_out . "' database."; - $pagedata = $pagedata . "
"; - - return $pagedata; - - } else { - - # A confirm value other than 0 or 1 is given, so - # return an error. - - kiriwrite_error("invaildvalue"); - - } - -} - -sub kiriwrite_page_multimove{ -################################################################################# -# kiriwrite_page_multimove: Move several pages from one database to another # -# database. # -# # -# Usage: # -# # -# kiriwrite_page_multimove(database, newdatabase, confirm, filelist); # -# # -# database Specifies the database to move the selected pages from. # -# newdatabase Specifies the database to move the selected pages to. # -# confirm Confirms the action to move the pages from one database to # -# another. # -# filelist Specifies the list of pages to move. # -################################################################################# - - # Get the values that were passed to the subroutine. - - my ($database, $newdatabase, $confirm, @filelist) = @_; - - # Load the required Perl modules. - - use DBI; - - # Define a variable for later. - - my $pagedata = ""; - - # Check if the file list is blank and return an error - # if it is. - - if (!@filelist){ - - # The file list really is blank so return - # an error. - - kiriwrite_error("nopagesselected"); - - } - - # Check if the file permissions on the original database - # are valid and return an error if they aren't. - - my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db', 1, 1, 0); - - if ($database_exists eq 1){ - - # The database does not exist, so return an error. - - kiriwrite_error("oldmovedatabasedoesnotexist"); - - } - - if ($database_permissions eq 1){ - - # The database permissions are invalid, so return - # an error. - - kiriwrite_error("oldmovedatabasefileinvalidpermissions"); - - } - - # Check if the confirm value is blank and if it is then - # set the confirm value to 0. - - if (!$confirm){ - - $confirm = 0; - - } - - if ($confirm eq 1){ - - # The action to move several pages from one database - # to another has been confirmed. - - # Check if the database that the pages are moving from - # is the same as the database the pages are moving to. - # Return an error if it is. - - if ($database eq $newdatabase){ - - # The database that the pages are moving from - # and the database the pages are moving to - # is the same, so return an error. - - kiriwrite_error("databasemovesame"); - - } - - # Check that the new database exists and the permissions - # for the new database are valid. - - $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $newdatabase . '.db'); - $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $newdatabase . '.db', 1, 1, 0); - - if ($database_exists eq 1){ - - # The database does not exist, so return an error. - - kiriwrite_error("newmovedatabasedoesnotexist"); - - } - - if ($database_permissions eq 1){ - - # The database permissions are invalid, so return - # an error. - - kiriwrite_error("newmovedatabasefileinvalidpermissions"); - - } - - # Define some values for later. - - my @olddatabase_info; - my @olddatabase_page; - my @newdatabase_info; - my @newdatabase_page; - - my $filename; - my $filename_sql; - my $filename_out; - - my $olddatabase_database_handle; - my $olddatabase_string_handle; - my $olddatabase_name; - my $olddatabase_name_out; - my $olddatabase_out; - my $newdatabase_database_handle; - my $newdatabase_string_handle; - my $newdatabase_name; - my $newdatabase_name_out; - my $newdatabase_out; - - my $warninglist = ""; - my $movedlist = ""; - - my $page_filename; - my $page_filename_sql; - my $page_filename_out; - my $page_name; - my $page_name_sql; - my $page_name_out; - my $page_description; - my $page_description_sql; - my $page_section; - my $page_section_sql; - my $page_template; - my $page_template_sql; - my $page_data; - my $page_data_sql; - my $page_settings; - my $page_settings_sql; - my $page_lastmodified; - my $page_lastmodified_sql; - - my $page_found = 0; - - # Check if the database filename is valid and return an error if - # it isn't. - - my $newpagedatabase_filename_check = kiriwrite_variablecheck($newdatabase, "filename", 0, 1); - - if ($newpagedatabase_filename_check eq 1){ - - # The database filename is blank, so return an error. - - kiriwrite_error("blankdatabasepageadd"); - - } elsif ($newpagedatabase_filename_check eq 2){ - - # The database filename is invalid, so return an error. - - kiriwrite_error("databasefilenameinvalid"); - - } - - # Load the old and new SQLite databases. - - $olddatabase_database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - $newdatabase_database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $newdatabase . '.db'); - - # Get the database information from both databases. - - $olddatabase_string_handle = $olddatabase_database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("oldmovedatabasefileinvalid"); - $newdatabase_string_handle = $newdatabase_database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("newmovedatabasefileinvalid"); - $olddatabase_string_handle->execute(); - $newdatabase_string_handle->execute(); - - @olddatabase_info = $olddatabase_string_handle->fetchrow_array(); - @newdatabase_info = $newdatabase_string_handle->fetchrow_array(); - - $olddatabase_name = $olddatabase_info[0]; - $newdatabase_name = $newdatabase_info[0]; - - # Convert the database names so that they can be displayed - # properly. - - $olddatabase_name_out = kiriwrite_convert($olddatabase_name, "normal_display"); - $newdatabase_name_out = kiriwrite_convert($newdatabase_name, "normal_display"); - $olddatabase_out = kiriwrite_convert($database, "normal_display"); - $newdatabase_out = kiriwrite_convert($newdatabase, "normal_display"); - - # Get each file in the old database, get the file values, - # put them into the new database and delete the pages - # from the old database. - - foreach $filename (@filelist){ - - # Check if the filename exists in the old database. - # If the filename does not exist then write - # a warning and process the next file. - - $filename_sql = kiriwrite_convert($filename, "kiriwrite"); - $filename_out = kiriwrite_convert($filename, "normal_display"); - $olddatabase_string_handle = $olddatabase_database_handle->prepare('SELECT * FROM kiriwrite_database_pages where filename = \'' . $filename_sql . '\' LIMIT 1'); - $olddatabase_string_handle->execute(); - - $page_found = 0; - - while (@olddatabase_page = $olddatabase_string_handle->fetchrow_array()){ - - # The page in the old database does exist so - # set the value to 1. - - $page_found = 1; - - } - - # See if the page was found and write a warning if it - # wasn't. - - if ($page_found eq 0){ - - # The page was not found. Write a warning and - # process the next page. - - $filename_out = kiriwrite_convert($filename, "normal_display"); - $warninglist = $warninglist . "The page with the filename '" . $filename_out . "' could not be found in the '" . $olddatabase_name_out . "' database. Page skipped.
"; - next; - - } - - # Check if the filename exists in the new database. - # If the filename does exist then write - # a warning and process the next file. - - $newdatabase_string_handle = $newdatabase_database_handle->prepare('SELECT * FROM kiriwrite_database_pages where filename = \'' . $filename_sql . '\' LIMIT 1'); - $newdatabase_string_handle->execute(); - - $page_found = 0; - - while (@newdatabase_page = $newdatabase_string_handle->fetchrow_array()){ - - # The page in the old database does exist so - # set the value to 1. - - $page_found = 1; - - } - - # See if the page was found and write a warning if it - # wasn't. - - if ($page_found eq 1){ - - # The page was not found. Write a warning and - # process the next page. - - $filename_out = kiriwrite_convert($filename, "normal_display"); - $warninglist = $warninglist . "The page with the filename '" . $filename_out . "' already exists in '" . $olddatabase_name_out . "' database. Page skipped.
"; - next; - - } - - - # Get the information about the page. - - $olddatabase_string_handle->execute(); - @olddatabase_page = $olddatabase_string_handle->fetchrow_array(); - $page_filename = $olddatabase_page[0]; - $page_name = $olddatabase_page[1]; - $page_description = $olddatabase_page[2]; - $page_section = $olddatabase_page[3]; - $page_template = $olddatabase_page[4]; - $page_data = $olddatabase_page[5]; - $page_settings = $olddatabase_page[6]; - $page_lastmodified = $olddatabase_page[7]; - - # Convert the values so that they can be processed - # properly. - - $page_filename_sql = kiriwrite_convert($page_filename, "kiriwrite"); - $page_name_sql = kiriwrite_convert($page_name, "kiriwrite"); - $page_description_sql = kiriwrite_convert($page_description, "kiriwrite"); - $page_section_sql = kiriwrite_convert($page_section, "kiriwrite"); - $page_template_sql = kiriwrite_convert($page_template, "kiriwrite"); - $page_data_sql = kiriwrite_convert($page_data, "kiriwrite"); - $page_settings_sql = kiriwrite_convert($page_settings, "kiriwrite"); - $page_lastmodified_sql = kiriwrite_convert($page_lastmodified, "kiriwrite"); - - $page_filename_out = kiriwrite_convert($page_filename, "normal_display"); - $page_name_out = kiriwrite_convert($page_name, "normal_display"); - - # Add the page to the new database. - - $newdatabase_string_handle = $newdatabase_database_handle->prepare('INSERT INTO kiriwrite_database_pages VALUES( - \'' . $page_filename_sql . '\', - \'' . $page_name_sql . '\', - \'' . $page_description_sql . '\', - \'' . $page_section_sql . '\', - \'' . $page_template_sql . '\', - \'' . $page_data_sql . '\', - \'' . $page_settings_sql . '\', - \'' . $page_lastmodified_sql . '\' - )'); - $newdatabase_string_handle->execute(); - - # Delete the page from the old database. - - $olddatabase_string_handle = $olddatabase_database_handle->prepare('DELETE FROM kiriwrite_database_pages WHERE filename = \'' . $filename_sql . '\''); - $olddatabase_string_handle->execute(); - - # Append the moved page (filename and name) to the list of - # moved pages. - - if (!$page_name_out){ - - $page_name_out = "No Name"; - - } - - $movedlist = $movedlist . $page_name_out . " (" . $filename_out . ")" . "
"; - - } - - # Write out a message saying that the pages were moved (if any) - # to the new database (and any warnings given). - - $pagedata = $pagedata . "

Move multiple pages

"; - - if ($movedlist){ - - $pagedata = $pagedata . "The following pages from the '" . $olddatabase_name_out . "' database were moved to the '" . $newdatabase_name_out . "' database:

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . $movedlist; - $pagedata = $pagedata . "


"; - - } else { - - $pagedata = $pagedata . "No pages were moved from the '" . $olddatabase_name_out . "' database to the '" . $newdatabase_name_out . "' database.

"; - - } - - if ($warninglist){ - - $pagedata = $pagedata . "The following errors/warnings have occured while moving the pages:

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . $warninglist; - $pagedata = $pagedata . "


"; - - } - - $pagedata = $pagedata . "Return to the page list for the '" . $olddatabase_name_out . "' database. | View the page list for the '" . $newdatabase_name_out . "' database."; - - return $pagedata; - - } elsif ($confirm eq 0) { - - # The action to move several pages from one database - # to another has not been confirmed so write a form. - - # Load the SQLite database and get the needed - # information about the database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - - my @database_info = $string_handle->fetchrow_array(); - my $database_name = $database_info[0]; - - # Define some values for later. - - my $database_info; - my @page_info; - my @pagenames; - my @filenames; - my $data_file; - my $data_file_length; - my $database_list; - my $database_filename; - my $filename; - my $filename_out; - my $filelist_filename_sql; - my $filelist_filename; - my $pagelist_formdata; - my $newdatabase_filename; - my $newdatabase_filename_out; - my $newdatabase_name; - my $newdatabase_name_out; - my $pagelist; - my $pagename; - my $pageseek = 0; - my $dbseek = 0; - my $pagefound = 0; - - # Process each filename given. - - foreach $filelist_filename (@filelist){ - - $filelist_filename_sql = kiriwrite_convert($filelist_filename, "kiriwrite"); - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $filelist_filename . '\' LIMIT 1') or kiriwrite_error("databasefileinvalid"); - - $string_handle->execute(); - - # Check if the filename given exists and if it - # doesn't then skip this filename and go onto - # the next filename. - - while (@page_info = $string_handle->fetchrow_array()){ - - $pagefound = 1; - - } - - if ($pagefound eq 0){ - - next; - - } - - # Get the data again. - - $string_handle->execute(); - @page_info = $string_handle->fetchrow_array(); - - # Add the page name and file name to their seperate - # arrays. - - $pagenames[$pageseek] = $page_info[1]; - $filenames[$pageseek] = $page_info[0]; - - # Increment the page seek counter and reset the - # page found value. - - $pageseek++; - $pagefound = 0; - - } - - # Check if any pages exust and return an error if - # there wasn't. - - if ($pageseek eq 0){ - - # None of the selected pages exist, so return - # an error. - - kiriwrite_error("nopagesselected"); - - } - - # Create the page list of files to move. - - $pageseek = 1; - $pagelist = ""; - $pagelist_formdata = ""; - - foreach $filename (@filenames){ - - - - $pagename = $pagenames[$pageseek - 1]; - - # Check if the page name is blank and if it is then say - # no name. - - if (!$pagename){ - - # The page name is blank. - - $pagelist = $pagelist . "No Name" . " (" . $filename . ")
"; - - } else { - - # Append the page name and filename to the page list. - - $pagelist = $pagelist . kiriwrite_convert($pagename, "normal_display") . " (" . $filename . ")
"; - - } - - # Append the form data to the page list form data. - - $filename_out = kiriwrite_convert($filename, "normal_display"); - - $pagelist_formdata = $pagelist_formdata . ""; - $pagelist_formdata = $pagelist_formdata . ""; - - $pageseek++; - - } - - # Get the database filenames and names. - - # Check the directory to make sure the permissions are settings are valid - # and return an error if the permission settings are invalid. - - my $data_directory_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"}, 1, 0); - - if ($data_directory_permissions eq 1){ - - # The data directory has invalid permissions set, so return an error. - - kiriwrite_error("datadirectoryinvalidpermissions"); - - } - - # Open the directory and get the list of all files ending with .xml and - # put them into the data_directory array. - - opendir(DATADIR, $kiriwrite_config{"directory_data_db"}); - my @data_directory = grep /m*\.db/, readdir(DATADIR); - closedir(DATADIR); - - # Process each database to get the database name. - - $database_list = ""; - - # Convert some values so that they display properly. - - my $database_name_out = kiriwrite_convert($database_name, "normal_display"); - my $database_out = kiriwrite_convert($database, "normal_display"); - - # Write out the form. - - $pagedata = "

Move selected pages

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . $pagelist_formdata; - $pagedata = $pagedata . "Which database do you want to move the following pages from the '" . $database_name_out . "' database to?

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . $pagelist; - $pagedata = $pagedata . "

"; - $pagedata = $pagedata . "Move pages to: " . $database_list . "

"; - $pagedata = $pagedata . " | Return to the page list for the '" . $database_name_out . "' database."; - $pagedata = $pagedata . "
"; - - return $pagedata; - - } else { - - # The confirm value is other than 0 or 1, so return - # an error. - - kiriwrite_error("invalidvariable"); - - } - - -} - - -sub kiriwrite_page_multicopy{ -################################################################################# -# kiriwrite_page_multicopy: Copy several pages from one database to another # -# database. # -# # -# Usage: # -# # -# kiriwrite_page_multicopy(database, newdatabase, confirm, filelist); # -# # -# database Specifies the database to copy the selected pages from. # -# newdatabase Specifies the database to copy the selected page to. # -# confirm Confirms the action to copy the pages. # -# filelist A list of filenames to copy in an array. # -################################################################################# - - # Get the values that were passed to the subroutine. - - my ($database, $newdatabase, $confirm, @filelist) = @_; - - # Load the required Perl modules. - - use DBI; - - # Define a variable for later. - - my $pagedata = ""; - - # Check if the file list is blank and return an error - # if it is. - - if (!@filelist){ - - # The file list really is blank so return - # an error. - - kiriwrite_error("nopagesselected"); - - } - - # Check if the file permissions on the original database - # are valid and return an error if they aren't. - - my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db', 1, 0); - - if ($database_exists eq 1){ - - # The database does not exist, so return an error. - - kiriwrite_error("oldcopydatabasedoesnotexist"); - - } - - if ($database_permissions eq 1){ - - # The database permissions are invalid, so return - # an error. - - kiriwrite_error("oldcopydatabasefilenameinvalidpermissions"); - - } - - # Check if the confirm value is blank and if it is then - # set the confirm value to 0. - - if (!$confirm){ - - $confirm = 0; - - } - - # Check if the database filename is valid and return an error if - # it isn't. - - my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1); - - if ($pagedatabase_filename_check eq 1){ - - # The database filename is blank, so return an error. - - kiriwrite_error("blankdatabasepageadd"); - - } elsif ($pagedatabase_filename_check eq 2){ - - # The database filename is invalid, so return an error. - - kiriwrite_error("databasefilenameinvalid"); - - } - - if ($confirm eq 1){ - - # The action to copy several pages from one database - # to another has been confirmed. - - # Check if the database that the pages are copied from - # is the same as the database the pages are copied to. - # Return an error if it is. - - if ($database eq $newdatabase){ - - # The database that the pages are being copied from - # and the database that the pages are copied to - # is the same, so return an error. - - kiriwrite_error("databasecopysame"); - - } - - # Check that the new database exists and the permissions - # for the new database are valid. - - $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $newdatabase . '.db'); - $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $newdatabase . '.db', 1, 1, 0); - - if ($database_exists eq 1){ - - # The database does not exist, so return an error. - - kiriwrite_error("newcopydatabasedoesnotexist"); - - } - - if ($database_permissions eq 1){ - - # The database permissions are invalid, so return - # an error. - - kiriwrite_error("newcopydatabasefileinvalidpermissions"); - - } - - # Define some values for later. - - my @olddatabase_info; - my @olddatabase_page; - my @newdatabase_info; - my @newdatabase_page; - - my $filename; - my $filename_sql; - my $filename_out; - - my $olddatabase_database_handle; - my $olddatabase_string_handle; - my $olddatabase_name; - my $olddatabase_name_out; - my $olddatabase_out; - my $newdatabase_database_handle; - my $newdatabase_string_handle; - my $newdatabase_name; - my $newdatabase_name_out; - my $newdatabase_out; - - my $warninglist = ""; - my $copiedlist = ""; - - my $page_filename; - my $page_filename_sql; - my $page_filename_out; - my $page_name; - my $page_name_sql; - my $page_name_out; - my $page_description; - my $page_description_sql; - my $page_section; - my $page_section_sql; - my $page_template; - my $page_template_sql; - my $page_data; - my $page_data_sql; - my $page_settings; - my $page_settings_sql; - my $page_lastmodified; - my $page_lastmodified_sql; - - my $page_found = 0; - - # Check if the database filename is valid and return an error if - # it isn't. - - my $newpagedatabase_filename_check = kiriwrite_variablecheck($newdatabase, "filename", 0, 1); - - if ($newpagedatabase_filename_check eq 1){ - - # The database filename is blank, so return an error. - - kiriwrite_error("blankdatabasepageadd"); - - } elsif ($newpagedatabase_filename_check eq 2){ - - # The database filename is invalid, so return an error. - - kiriwrite_error("databasefilenameinvalid"); - - } - - # Load the old and new SQLite databases. - - $olddatabase_database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - $newdatabase_database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $newdatabase . '.db'); - - # Get the database information from both databases. - - $olddatabase_string_handle = $olddatabase_database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("oldcopydatabasefileinvalid"); - $newdatabase_string_handle = $newdatabase_database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("newcopydatabasefileinvalid"); - $olddatabase_string_handle->execute(); - $newdatabase_string_handle->execute(); - - @olddatabase_info = $olddatabase_string_handle->fetchrow_array(); - @newdatabase_info = $newdatabase_string_handle->fetchrow_array(); - - $olddatabase_name = $olddatabase_info[0]; - $newdatabase_name = $newdatabase_info[0]; - - # Convert the database names so that they can be displayed - # properly. - - $olddatabase_name_out = kiriwrite_convert($olddatabase_name, "normal_display"); - $newdatabase_name_out = kiriwrite_convert($newdatabase_name, "normal_display"); - $olddatabase_out = kiriwrite_convert($database, "normal_display"); - $newdatabase_out = kiriwrite_convert($newdatabase, "normal_display"); - - # Get each file in the old database, get the file values, - # put them into the new database. - - foreach $filename (@filelist){ - - # Check if the filename exists in the old database. - # If the filename does not exist then write - # a warning and process the next file. - - $filename_sql = kiriwrite_convert($filename, "kiriwrite"); - $filename_out = kiriwrite_convert($filename, "normal_display"); - $olddatabase_string_handle = $olddatabase_database_handle->prepare('SELECT * FROM kiriwrite_database_pages where filename = \'' . $filename_sql . '\' LIMIT 1'); - $olddatabase_string_handle->execute(); - - $page_found = 0; - - while (@olddatabase_page = $olddatabase_string_handle->fetchrow_array()){ - - # The page in the old database does exist so - # set the value to 1. - - $page_found = 1; - - } - - # See if the page was found and write a warning if it - # wasn't. - - if ($page_found eq 0){ - - # The page was not found. Write a warning and - # process the next page. - - $filename_out = kiriwrite_convert($filename, "normal_display"); - $warninglist = $warninglist . "The page with the filename '" . $filename_out . "' could not be found in the '" . $olddatabase_name_out . "' database. Page skipped.
"; - next; - - } - - # Check if the filename exists in the new database. - # If the filename does exist then write - # a warning and process the next file. - - $newdatabase_string_handle = $newdatabase_database_handle->prepare('SELECT * FROM kiriwrite_database_pages where filename = \'' . $filename_sql . '\' LIMIT 1'); - $newdatabase_string_handle->execute(); - - $page_found = 0; - - while (@newdatabase_page = $newdatabase_string_handle->fetchrow_array()){ - - # The page in the old database does exist so - # set the value to 1. - - $page_found = 1; - - } - - # See if the page was found and write a warning if it - # wasn't. - - if ($page_found eq 1){ - - # The page was not found. Write a warning and - # process the next page. - - $filename_out = kiriwrite_convert($filename, "normal_display"); - $warninglist = $warninglist . "The page with the filename '" . $filename_out . "' already exists in '" . $newdatabase_name_out . "' database. Page skipped.
"; - next; - - } - - - # Get the information about the page. - - $olddatabase_string_handle->execute(); - @olddatabase_page = $olddatabase_string_handle->fetchrow_array(); - $page_filename = $olddatabase_page[0]; - $page_name = $olddatabase_page[1]; - $page_description = $olddatabase_page[2]; - $page_section = $olddatabase_page[3]; - $page_template = $olddatabase_page[4]; - $page_data = $olddatabase_page[5]; - $page_settings = $olddatabase_page[6]; - $page_lastmodified = $olddatabase_page[7]; - - # Convert the values so that they can be processed - # properly. - - $page_filename_sql = kiriwrite_convert($page_filename, "kiriwrite"); - $page_name_sql = kiriwrite_convert($page_name, "kiriwrite"); - $page_description_sql = kiriwrite_convert($page_description, "kiriwrite"); - $page_section_sql = kiriwrite_convert($page_section, "kiriwrite"); - $page_template_sql = kiriwrite_convert($page_template, "kiriwrite"); - $page_data_sql = kiriwrite_convert($page_data, "kiriwrite"); - $page_settings_sql = kiriwrite_convert($page_settings, "kiriwrite"); - $page_lastmodified_sql = kiriwrite_convert($page_lastmodified, "kiriwrite"); - - $page_filename_out = kiriwrite_convert($page_filename, "normal_display"); - $page_name_out = kiriwrite_convert($page_name, "normal_display"); - - # Add the page to the new database. - - $newdatabase_string_handle = $newdatabase_database_handle->prepare('INSERT INTO kiriwrite_database_pages VALUES( - \'' . $page_filename_sql . '\', - \'' . $page_name_sql . '\', - \'' . $page_description_sql . '\', - \'' . $page_section_sql . '\', - \'' . $page_template_sql . '\', - \'' . $page_data_sql . '\', - \'' . $page_settings_sql . '\', - \'' . $page_lastmodified_sql . '\' - )'); - $newdatabase_string_handle->execute(); - - # Append the copied page (filename and name) to the list of - # copied pages. - - if (!$page_name_out){ - - $page_name_out = "No page name"; - - } - - $copiedlist = $copiedlist . $page_name_out . " (" . $filename_out . ")" . "
"; - - } - - # Write out a message saying that the pages were moved (if any) - # to the new database (and any warnings given). - - $pagedata = $pagedata . "

Copy multiple pages

"; - - if ($copiedlist){ - - $pagedata = $pagedata . "The following pages from the '" . $olddatabase_name_out . "' database were copied to the '" . $newdatabase_name_out . "' database:

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . $copiedlist; - $pagedata = $pagedata . "


"; - - } else { - - $pagedata = $pagedata . "No pages were copied from the '" . $olddatabase_name_out . "' database to the '" . $newdatabase_name_out . "' database.

"; - - } - - if ($warninglist){ - - $pagedata = $pagedata . "The following errors/warnings have occured while copying the pages:

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . $warninglist; - $pagedata = $pagedata . "


"; - - } - - $pagedata = $pagedata . "Return to the page list for the '" . $olddatabase_name_out . "' database. | View the page list for the '" . $newdatabase_name_out . "' database."; - - return $pagedata; - - } elsif ($confirm eq 0) { - - # The action to copy several pages from one database - # to another has not been confirmed so write a form. - - # Load the SQLite database and get the needed - # information about the database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - - my @database_info = $string_handle->fetchrow_array(); - my $database_name = $database_info[0]; - - # Define some values for later. - - my $database_info; - my @page_info; - my @pagenames; - my @filenames; - my $data_file; - my $data_file_length; - my $database_list; - my $database_filename; - my $filename; - my $filename_out; - my $filelist_filename_sql; - my $filelist_filename; - my $pagelist_formdata; - my $newdatabase_filename; - my $newdatabase_filename_out; - my $newdatabase_name; - my $newdatabase_name_out; - my $pagelist; - my $pagename; - my $pageseek = 0; - my $dbseek = 0; - my $pagefound = 0; - - # Process each filename given. - - foreach $filelist_filename (@filelist){ - - $filelist_filename_sql = kiriwrite_convert($filelist_filename, "kiriwrite"); - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $filelist_filename . '\' LIMIT 1') or kiriwrite_error("databasefileinvalid"); - - $string_handle->execute(); - - # Check if the filename given exists and if it - # doesn't then skip this filename and go onto - # the next filename. - - while (@page_info = $string_handle->fetchrow_array()){ - - $pagefound = 1; - - } - - if ($pagefound eq 0){ - - next; - - } - - # Get the data again. - - $string_handle->execute(); - @page_info = $string_handle->fetchrow_array(); - - # Add the page name and file name to their seperate - # arrays. - - $pagenames[$pageseek] = $page_info[1]; - $filenames[$pageseek] = $page_info[0]; - - # Increment the page seek counter and reset the - # page found value. - - $pageseek++; - $pagefound = 0; - - } - - # Check if any pages exust and return an error if - # there wasn't. - - if ($pageseek eq 0){ - - # None of the selected pages exist, so return - # an error. - - kiriwrite_error("nopagesselected"); - - } - - # Create the page list of files to move. - - $pageseek = 1; - $pagelist = ""; - $pagelist_formdata = ""; - - foreach $filename (@filenames){ - - $pagename = $pagenames[$pageseek - 1]; - - # Check if the - - if (!$pagename){ - - # Write a message saying that there is no page name. - - $pagelist = $pagelist . "No Name" . " (" . $filename . ")
"; - - } else { - - # Append the page name and filename to the page list. - - $pagelist = $pagelist . $pagename . " (" . $filename . ")
"; - - } - - - - # Append the form data to the page list form data. - - $filename_out = kiriwrite_convert($filename, "normal_display"); - - $pagelist_formdata = $pagelist_formdata . ""; - $pagelist_formdata = $pagelist_formdata . ""; - - $pageseek++; - - } - - # Get the database filenames and names. - - # Check the directory to make sure the permissions are settings are valid - # and return an error if the permission settings are invalid. - - my $data_directory_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"}, 1, 0); - - if ($data_directory_permissions eq 1){ - - # The data directory has invalid permissions set, so return an error. - - kiriwrite_error("datadirectoryinvalidpermissions"); - - } - - # Open the directory and get the list of all files ending with .xml and - # put them into the data_directory array. - - opendir(DATADIR, $kiriwrite_config{"directory_data_db"}); - my @data_directory = grep /m*\.db/, readdir(DATADIR); - closedir(DATADIR); - - # Process each database to get the database name. - - $database_list = ""; - - # Convert some values so that they display properly. - - my $database_name_out = kiriwrite_convert($database_name, "normal_display"); - my $database_out = kiriwrite_convert($database, "normal_display"); - - # Write out the form. - - $pagedata = "

Copy selected pages

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . $pagelist_formdata; - $pagedata = $pagedata . "Which database do you want to copy the following pages from the '" . $database_name_out . "' database to?

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . $pagelist; - $pagedata = $pagedata . "

"; - $pagedata = $pagedata . "Copy pages to: " . $database_list . "

"; - $pagedata = $pagedata . " | Return to the page list for the '" . $database_name_out . "' database."; - $pagedata = $pagedata . "
"; - - return $pagedata; - - } else { - - # The confirm value is other than 0 or 1, so return - # an error. - - kiriwrite_error("invalidvariable"); - - } - -} - -sub kiriwrite_page_multiedit{ -################################################################################# -# kiriwrite_page_multiedit: Edit several pages from a database. # -# # -# Usage: # -# # -# kiriwrite_page_multiedit(database, newsection, altersection, newtemplate, # -# altertemplate, newsettings, altersettings # -# confirm, filelist); # -# # -# database Specifies the database to edit the pages from. # -# newsection Specifies the new section name to use on the selected pages. # -# altersection Specifies if the section name should be altered. # -# newtemplate Specifies the new template filename to use on the selected # -# pages. # -# altertemplate Specifies if the template filename should be altered. # -# newsettings Specifies the new settings to use on the selected pages. # -# altersettings Specifies if the settings should be altered. # -# confirm Confirms the action to edit the selected pages. # -# filelist The list of file names to edit. # -################################################################################# - - # Get the values that were passed to the subroutine. - - my ($database, $newsection, $altersection, $newtemplate, $altertemplate, $newsettings, $altersettings, $confirm, @filelist) = @_; - - # Load the required Perl modules. - - use DBI; - - # Define a variable for later. - - my $pagedata = ""; - - # Check if the file list is blank and return an error - # if it is. - - if (!@filelist){ - - # The file list really is blank so return - # an error. - - kiriwrite_error("nopagesselected"); - - } - - # Check if the file permissions on the original database - # are valid and return an error if they aren't. - - my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db', 1, 1, 0); - - if ($database_exists eq 1){ - - # The database does not exist, so return an error. - - kiriwrite_error("databasemissingfile"); - - } - - if ($database_permissions eq 1){ - - # The database permissions are invalid, so return - # an error. - - kiriwrite_error("databaseinvalidpermissions"); - - } - - # Check if certain values are undefined and define them if - # they are. - - if (!$altersection){ - - # The alter section value is blank, so set it to - # off. - - $altersection = "off"; - - } - - if (!$altertemplate){ - - # The alter template value is blank, so set it to - # off. - - $altertemplate = "off"; - - } - - if (!$altersettings){ - - # The alter settings value is blank, so set it to - # off. - - $altersettings = "off"; - - } - - # Check if the database filename is valid and return an error if - # it isn't. - - my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1); - - if ($pagedatabase_filename_check eq 1){ - - # The database filename is blank, so return an error. - - kiriwrite_error("blankdatabasepageadd"); - - } elsif ($pagedatabase_filename_check eq 2){ - - # The database filename is invalid, so return an error. - - kiriwrite_error("databasefilenameinvalid"); - - } - - # Check if the confirm value is blank and if it is then - # set the confirm value to 0. - - if (!$confirm){ - - $confirm = 0; - - } - - if ($confirm eq 1){ - - # The action to edit the template has been confirmed so - # edit the selected pages. - - # Check the values recieved at UTF8 compliant before - # converting. - - kiriwrite_variablecheck($newsection, "utf8", 0, 0); - kiriwrite_variablecheck($newtemplate, "utf8", 0, 0); - kiriwrite_variablecheck($newsettings, "utf8", 0, 0); - - # Convert the values into proper UTF8 values. - - $newsection = kiriwrite_utf8convert($newsection); - $newtemplate = kiriwrite_utf8convert($newtemplate); - $newsettings = kiriwrite_utf8convert($newsettings); - - # Check the length of the variables. - - kiriwrite_variablecheck($altersection, "maxlength", 3, 0); - kiriwrite_variablecheck($altertemplate, "maxlength", 3, 0); - kiriwrite_variablecheck($altersettings, "maxlength", 3, 0); - my $newsection_maxlength_check = kiriwrite_variablecheck($newsection, "maxlength", 256, 1); - my $newtemplate_maxlength_check = kiriwrite_variablecheck($newtemplate, "maxlength", 256, 1); - my $newtemplate_filename_check = kiriwrite_variablecheck($newtemplate, "filename", 0, 1); - my $newsettings_maxlength_check = kiriwrite_variablecheck($newsettings, "maxlength", 1, 1); - my $newsettings_settings_check = kiriwrite_variablecheck($newsettings, "pagesetting", 0, 1); - - # Check the values and return an error if needed. - - if ($newsection_maxlength_check eq 1 && $altersection eq "on"){ - - # The new section name is too long, so return an - # error. - - kiriwrite_error("pagesectiontoolong"); - - } - - if ($newtemplate_maxlength_check eq 1 && $altertemplate eq "on"){ - - # The new template name is too long, so return an - # error. - - kiriwrite_error("templatefilenametoolong"); - - } - - # Check if the template filename is set to !skip or !none - # and skip this check if it is. - - if ($newtemplate eq "!skip" || $newtemplate eq "!none"){ - - # Skip this check as the template filename is - # !skip or !none. - - } else { - if ($newtemplate_filename_check eq 1 && $altertemplate eq "on" || $newtemplate_filename_check eq 2 && $altertemplate eq "on"){ - - # The new template filename is invalid, so return - # an error. - - kiriwrite_error("templatefilenameinvalid"); - - } - } - - if ($newsettings_maxlength_check eq 1 && $altertemplate eq "on"){ - - # The new settings value is too long, so return - # an error. - - kiriwrite_error("pagesettingstoolong"); - - } - - if ($newsettings_settings_check eq 1 && $altertemplate eq "on"){ - - # The new settings value is invalid, so return - # an error. - - kiriwrite_error("pagesettingsinvalid"); - - } - - # Load the SQLite Database and get info about the database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - - # Get the database name. - - my @database_info = $string_handle->fetchrow_array(); - my $database_name = $database_info[0]; - my $database_name_out = kiriwrite_convert($database_name, "normal_display"); - my $database_out = kiriwrite_convert($database, "normal_display"); - - # Define some values for later. - - my @database_page; - my $edited_list = ""; - my $filename; - my $filename_sql; - my $filename_out; - my $sqlquery_options = ""; - my @sqlquery_list; - my $sqlquery_option; - my $page_name; - my $page_name_out; - my $newsection_sql; - my $newtemplate_sql; - my $newsettings_sql; - my $pagefound = 0; - my $pageedited = 0; - my $sqlquery_seek = 0; - my $warninglist; - - # Get the date and time information. - - my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; - - my $pagelastmodified = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; - - - # Check if the template filename is !skip and - # set the alter template value to off if it - # is. - - if ($newtemplate eq "!skip"){ - - $altertemplate = "off"; - - } - - # Check if all values are not selected and return - # an error if they are. - - if ($altersection ne "on" && $altertemplate ne "on" && $altersettings ne "on"){ - - # All values are not selected so return - # an error. - - kiriwrite_error("noeditvaluesselected"); - - } - - # Check if each value is meant to be changed on - # the selected files. Start with the section - # name. - - if ($altersection eq "on"){ - - # Convert the value so that it will work - # when SQL query is made. - - $newsection_sql = kiriwrite_convert($newsection, "kiriwrite"); - - # The section name should be altered so - # prepare the a part of the SQL query. - # Check if this is the first part of - # the SQL query. - - if ($sqlquery_seek eq 0){ - - # This is the first part of the SQL query. - - $sqlquery_list[$sqlquery_seek] = "pagesection = \'" . $newsection_sql . "\'"; - $sqlquery_seek++; - - } else { - - # This isn't the first part of the SQL query. - - $sqlquery_list[$sqlquery_seek] = ", pagesection = \'" . $newsection_sql . "\'"; - $sqlquery_seek++; - - } - - } - - # Check if the template name should be changed. - - if ($altertemplate eq "on"){ - - # Convert the value so that it will work - # when SQL query is made. - - $newtemplate_sql = kiriwrite_convert($newtemplate, "kiriwrite"); - - # The section name should be altered so - # prepare the a part of the SQL query. - # Check if this is the first part of - # the SQL query. - - if ($sqlquery_seek eq 0){ - - # This is the first part of the SQL query. - - $sqlquery_list[$sqlquery_seek] = "pagetemplate = \'" . $newtemplate_sql . "\'"; - $sqlquery_seek++; - - } else { - - # This isn't the first part of the SQL query. - - $sqlquery_list[$sqlquery_seek] = ", pagetemplate = \'" . $newtemplate_sql . "\'"; - $sqlquery_seek++; - - } - - } - - # Check if the page settings should be changed. - - if ($altersettings eq "on"){ - - # Convert the value so that it will work - # when SQL query is made. - - $newsettings_sql = kiriwrite_convert($newsettings, "kiriwrite"); - - # The section name should be altered so - # prepare the a part of the SQL query. - # Check if this is the first part of - # the SQL query. - - if ($sqlquery_seek eq 0){ - - # This is the first part of the SQL query. - - $sqlquery_list[$sqlquery_seek] = "pagesettings = \'" . $newsettings_sql . "\'"; - $sqlquery_seek++; - - } else { - - # This isn't the first part of the SQL query. - - $sqlquery_list[$sqlquery_seek] = ", pagesettings = \'" . $newsettings_sql . "\'"; - $sqlquery_seek++; - - } - - } - - # Add a new modification date. - - $sqlquery_list[$sqlquery_seek] = ", lastmodified = \'" . $pagelastmodified . "\'"; - - # Create the line for the needed SQL query. - - foreach $sqlquery_option (@sqlquery_list){ - - # Add the line to the needed SQL query. - - $sqlquery_options = $sqlquery_options . $sqlquery_option; - - } - - # Edit each filename. - - foreach $filename (@filelist){ - - # Check if the page filename exists in the - # database. - - $filename_sql = kiriwrite_convert($filename, "kiriwrite"); - $filename_out = kiriwrite_convert($filename, "normal_display"); - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $filename_sql . '\'') or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - - # Check if the filename given exists and if it - # doesn't then skip this filename and go onto - # the next filename. - - while (@database_page = $string_handle->fetchrow_array()){ - - $pagefound = 1; - - } - - if ($pagefound eq 0){ - - # The page was not find in the database so - # add a warning saying it could not be - # found in the database and process the - # next file. - - - $warninglist = $warninglist . "The page \'" . $filename_out . "\'could not be found." . "
"; - next; - - } - - # Get the page name. - - $string_handle->execute(); - @database_page = $string_handle->fetchrow_array(); - $page_name = $database_page[1]; - $page_name_out = kiriwrite_convert($page_name, "normal_display"); - - # Alter the values of the page using the values recieved. - - $string_handle = $database_handle->prepare('UPDATE kiriwrite_database_pages SET ' . $sqlquery_options . ' WHERE filename = \'' . $filename_sql . '\''); - $string_handle->execute(); - - # Add the page to the list of edited pages. Check if - # the page name is blank. - - if (!$page_name_out){ - - # The page name is blank so write no name. - - $edited_list = $edited_list . "The page (" . $filename_out . ") was edited." . "
"; - - } else { - - # Add the page to the list of edited pages. - - $edited_list = $edited_list . "The page called '" . $page_name_out . "' (" . $filename_out . ") was edited." . "
"; - - } - - # Increment the counter of edited pages. - - $pageedited++; - - } - - $pagedata = $pagedata . "

Edit selected pages

"; - - # Check if the counter of edited pages is 0 and if it is - # then write a message saying that no pages were edited - # else write a message listing all of the pages edited. - - if ($pageedited eq 0){ - - $pagedata = $pagedata . "No pages were edited in the '" . $database_name_out . "' database.

"; - - } else { - - # Write out the message saying that the selected pages - # were edited. - - $pagedata = $pagedata . "The selected pages in the '" . $database_name_out . "' database have been edited:

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . $edited_list; - $pagedata = $pagedata . "

"; - - } - - # Check if any warnings have occured and write a message - # if any warnings did occur. - - if ($warninglist){ - - # One or several warnings have occured so - # write a message. - - $pagedata = $pagedata . "The following errors/warnings occured while editing the selected pages:

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . $warninglist; - $pagedata = $pagedata . "

"; - - } - - # Write a link going back to the page list for - # the selected database. - - $pagedata = $pagedata . "Return to the page list for the '" . $database_name_out . "' database."; - - return $pagedata; - - } elsif ($confirm eq 0){ - - # The action to edit the template has not been confirmed - # so write a form out instead. - - # Load the SQLite Database and get info about the database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - - # Get the database name. - - my @database_info = $string_handle->fetchrow_array(); - my $database_name = $database_info[0]; - my $database_name_out = kiriwrite_convert($database_name, "normal_display"); - my $database_out = kiriwrite_convert($database, "normal_display"); - - # Define some variables for later. - - my @database_page; - my @database_templates; - my @filenames; - my @page_info; - my @pagenames; - my $filelist_filename; - my $filelist_filename_sql; - my $filelist_filename_out; - my $filename; - my $pagefound; - my $pagelist = ""; - my $pagelistformdata = ""; - my $pageseek = 0; - my $page_name; - my $page_filename; - my $template_data; - my $template_filename; - my $template_name; - my $template_warning; - - # Get the information about each page that is going - # to be edited. - - foreach $filelist_filename (@filelist){ - - $filelist_filename_sql = kiriwrite_convert($filelist_filename, "kiriwrite"); - $filelist_filename_out = kiriwrite_convert($filelist_filename, "normal_display"); - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $filelist_filename . '\' LIMIT 1') or kiriwrite_error("databasefileinvalid"); - - $string_handle->execute(); - - # Check if the filename given exists and if it - # doesn't then skip this filename and go onto - # the next filename. - - while (@page_info = $string_handle->fetchrow_array()){ - - $pagefound = 1; - - } - - if ($pagefound eq 0){ - - next; - - } - - # Get the data again. - - $string_handle->execute(); - @page_info = $string_handle->fetchrow_array(); - - # Add the page name and file name to their seperate - # arrays. - - $pagenames[$pageseek] = $page_info[1]; - $filenames[$pageseek] = $page_info[0]; - - # Add the form data for the page filename. - - # BLEARGH - - $pagelistformdata = $pagelistformdata . ""; - $pagelistformdata = $pagelistformdata . ""; - - # Increment the page seek counter and reset the - # page found value. - - $pageseek++; - $pagefound = 0; - - } - - # Check if any pages were found in the database and return - # an error if not. - - if ($pageseek eq 0){ - - # No pages were found so return an error. - - kiriwrite_error("nopagesselected"); - - } - - # Get the template list and select the template that is being used by - # the page, check the permissions and if the template database exists. - - my $template_file_exists = kiriwrite_fileexists("templates.db"); - my $template_file_permissions = kiriwrite_filepermissions("templates.db", 1, 0, 0); - - if ($template_file_exists eq 1){ - - # The template database does not exist, so write a warning messsage. - - $template_warning = "The template database does not exist. Existing template settings for selected pages kept."; - - } - - if ($template_file_permissions eq 1 && $template_file_exists ne 1){ - - # The template database has invalid permissions set, so write a warning message. - - $template_warning = "The template database has invalid permissions set. Existing template settings for selected pages kept."; - - } - - # Get the list of templates. - - if (!$template_warning){ - - # Load the templates database and get the templates. - - $database_handle = DBI->connect("dbi:SQLite:templates.db"); - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates') or $template_warning = "The template database is in an invalid format. Existing template settings for selected pages kept."; - - if (!$template_warning){ - - $string_handle->execute(); - - $template_data = ""; - - } - - } - - # Process the list of selected pages. - - $pageseek = 1; - foreach $filename (@filenames){ - - # Process each filename. - - $page_name = $pagenames[$pageseek - 1]; - $page_filename = $filenames[$pageseek - 1]; - - # Check if the page name is blank. - - if (!$page_name){ - - # Write a message saying there's no page name. - - $pagelist = $pagelist . "No Name" . " (" . $page_filename . ")" . "
" - - } else { - - # Append the page to the list of pages to edit. - - $pagelist = $pagelist . $page_name . " (" . $page_filename . ")" . "
"; - - } - - $pageseek++; - - } - - # Write a form for editing the selected pages. - - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "

Edit selected pages

"; - $pagedata = $pagedata . "The following pages from the '" . $database_name_out . "' database will be altered:

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . $pagelist; - $pagedata = $pagedata . "

"; - $pagedata = $pagedata . $pagelistformdata; - $pagedata = $pagedata . "Using the values below (click on the checkbox for each value to be edited on the selected pages):

"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - - # Check if a warning for template database has been written - # and return the warning message if it has else write the - # list of templates. - - if ($template_warning){ - - # There is a message in the template warning variable - - $pagedata = $pagedata . ""; - - } else { - - $pagedata = $pagedata . ""; - - } - - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "
AlterSettingValue
Page Section
Page Template" . $template_warning . "
Page Template" . $template_data . "
Page Settings Use page name and section name.
Use the page name only.
Use the section name only.
Don't use page name or section name.

"; - $pagedata = $pagedata . " | Return to the page list for the '" . $database_name_out . "' database."; - $pagedata = $pagedata . "
"; - - return $pagedata; - - } else { - - # The confirm value is something else other than - # 1 or 0, so return an error. - - kiriwrite_error("invalidvariable"); - - } - -} - -sub kiriwrite_page_list{ -################################################################################# -# kiriwrite_page_list: Lists pages from an database. # -# # -# Usage: # -# # -# kiriwrite_page_list([database]); # -# # -# database Specifies the database to retrieve the pages from. # -################################################################################# - - # Get the database file name from what was passed to the subroutine. - - my ($database_file) = @_; - - # Load the required Perl modules. - - my $xsl = XML::Simple->new(); - use DBI; - - # Check if the database_file variable is empty, if it is then print out a - # select box asking the user to select a database from the list. - - if (!$database_file) { - - # Define the variables required for this section. - - my $pagedata = ""; - my $dblistdata = ""; - my $data_file = ""; - my $data_file_length = 0; - my $data_file_friendly = ""; - my $database_handle = ""; - my $string_handle = ""; - my $database_name = ""; - my $file_permissions = ""; - my @database_info; - my @data_directory; - - # Open the data directory and get all of the databases. - - opendir(DATADIR, $kiriwrite_config{"directory_data_db"}); - @data_directory = grep /m*\.db/, readdir(DATADIR); - closedir(DATADIR); - - # Get the information about each database (the short name and friendly name). - - foreach $data_file (@data_directory){ - - # Give the filename a friendly name. - - $data_file_length = length($data_file); - $data_file_friendly = substr($data_file, 0, $data_file_length - 3); - - # Check if the permissions for the database are valid. - - $file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' .$data_file, 1, 0); - - if ($file_permissions ne 0){ - - # The permissions for the database are invalid - # so process the next database. - - next; - - } - - # Load the SQLite database. - - $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $data_file); - $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_info LIMIT 1") or next; - $string_handle->execute(); - @database_info = $string_handle->fetchrow_array(); - - # Get the database name from the results. - - $database_name = $database_info[0]; - $database_name = kiriwrite_convert($database_name, "normal_display"); - - # Append the database to the list of databases available. - - $dblistdata = $dblistdata . ""; - - } - - # Write the page data. - - $pagedata = "

View Pages

\r\n"; - $pagedata = $pagedata . "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.

"; - - $pagedata = $pagedata . "
\r\n"; - $pagedata = $pagedata . "\r\n"; - $pagedata = $pagedata . "\r\n"; - $pagedata = $pagedata . " | "; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "
 
"; - - return $pagedata; - - } else { - - my @database_pages; - my @database_info; - my $tabledata = ""; - my $pagedata = ""; - my $pagemultioptions = ""; - my $database_handle = ""; - my $string_handle = ""; - my $db_friendlyname = ""; - my $tablestyle = ""; - - my $page_filename = ""; - my $page_name = ""; - my $page_description = ""; - my $page_modified = ""; - - my $tablestyletype = 0; - my $page_count = 0; - my $db_file_notblank = 0; - - # The database_file variable is not blank, so print out a list of pages from - # the selected database. - - # Preform a variable check on the database filename to make sure that it is - # valid before using it. - - kiriwrite_variablecheck($database_file, "filename", "", 0); - kiriwrite_variablecheck($database_file, "maxlength", 64, 0); - - # Check if the specified database file exists, - # if it does exist then continue otherwise return an error saying the database - # could not be found. - - if (-e $kiriwrite_config{"directory_data_db"} . '/' . $database_file . '.db'){ - - # Check that the permissions for the database file are valid. - - my $database_db_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_file . '.db', 1, 0, 0); - - if ($database_db_permissions eq 1){ - - kiriwrite_error("databaseinvalidpermissions"); - - } - - # Load the SQLite database. - - $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database_file . '.db'); - - # Get the database name. - - $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_info LIMIT 1") or kiriwrite_error("databasenameinvalid"); - $string_handle->execute(); - - @database_info = $string_handle->fetchrow_array(); - - $db_friendlyname = $database_info[0]; - - $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_pages") or kiriwrite_error("databasenameinvalid"); - $string_handle->execute(); - - # Write the table header into the tabledata string. - - $tabledata = "\r\n\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n"; - - # Write the results out as a list and append it to the - # tabledata string. - - while (@database_pages = $string_handle->fetchrow()){ - - $page_filename = kiriwrite_convert($database_pages[0], "normal_display"); - $page_name = kiriwrite_convert($database_pages[1], "normal_display"); - $page_description = kiriwrite_convert($database_pages[2], "normal_display"); - $page_modified = kiriwrite_convert($database_pages[7], "date"); - $page_modified = kiriwrite_convert($page_modified, "normal_display"); - - if ($database_pages[0]){ - $page_count++; - } else { - next; - } - - if ($tablestyletype eq 0){ - - $tablestyle = "tablecell1"; - $tablestyletype = 1; - - } else { - - $tablestyle = "tablecell2"; - $tablestyletype = 0; - - } - - # Check if the page name and description names - # are blank and if they are write a message saying that - # field contains no data. - - if ($page_name eq ""){ - - $page_name = "No Name"; - - } - - if ($page_description eq ""){ - - $page_description = "No Description"; - - } - - if ($page_modified eq ""){ - - $page_modified = "No Date"; - - } - - $tabledata = $tabledata . ""; - - - - } - - # Check if the page count is more than - - if ($page_count > 0){ - $db_file_notblank = 1; - } - - # Append the closing table part into the tabledata string. - - $tabledata = $tabledata . "
Page LocationPage NamePage DescriptionLast ModifiedOptions
" . $page_filename ."" . $page_name . "" . $page_description . "" . $page_modified . "Edit Delete
"; - - } else { - # Either the database file, the database configuration file or both are missing - # so return an error saying that certain files are missing. - - kiriwrite_error("databasemissingfile"); - } - - # Check if the database really was not blank and if it was, write a message saying that - # no pages existed in the database else write the list of pages in the database. - - $db_friendlyname = kiriwrite_convert($db_friendlyname, "normal_display"); - - if ($db_file_notblank eq 0){ - - $pagedata = "

Page list for '" . $db_friendlyname . "'

"; - $pagedata = $pagedata . "
No pages exist in this database. To create a page for this database, click on Add Page link at the top of the page.
"; - - } else { - - $pagemultioptions = " | | | | "; - - $pagedata = "

Page list for '" . $db_friendlyname . "'

"; - $pagedata = $pagedata . "
\r\n"; - $pagedata = $pagedata . "\r\n"; - $pagedata = $pagedata . "\r\n"; - $pagedata = $pagedata . "\r\n"; - $pagedata = $pagedata . "\r\n"; - $pagedata = $pagedata . $pagemultioptions . "

\r\n"; - $pagedata = $pagedata . $tabledata; - $pagedata = $pagedata . "
" . $pagemultioptions . "

\r\n"; - $pagedata = $pagedata . "

"; - - } - - return $pagedata; - - } - -} - -sub kiriwrite_page_multipleselect{ -################################################################################# -# kiriwrite_page_multipleselect: Gets the multiple page selections from a # -# database and processes them into a single which can be used in the # -# kiriwrite_page_delete. # -# # -# Usage: # -# # -# kiriwrite_page_multipleselect(); # -################################################################################# - - # Load the required perl modules for this subroutine. - - my $query = new CGI; - - # Setup some variables that will be used later on. - - my $page_select_seek = 1; - my $page_current_value = ""; - my $selectionlist = ""; - - # Get the required variables from the HTTP query. - - my $page_count = $query->param('count'); - - do { - - # Get the current value of the selected page's checkbox. - - $page_current_value = $query->param('name[' . $page_select_seek . ']'); - - # If page_current_value is undefinied or blank, set page_current_value - # to off. - - if (!$page_current_value){ - - $page_current_value = "off"; - - } - - # Check if the page_current_value is set to 'on' if it is append the - # current page seek value to the selection list. - - if ($page_current_value eq "on"){ - - # Append the current seek value to the selection list. - - $selectionlist = $selectionlist . $page_select_seek . "|"; - - } - - # Increment the page selection seeking counter. - - $page_select_seek++; - - } until ($page_select_seek eq $page_count); - - return $selectionlist; - -} - -sub kiriwrite_template_add{ -################################################################################# -# kiriwrite_template_add: Add a template to the template folder # -# # -# Usage: # -# # -# kiriwrite_template_add(filename, name, description, layout, confirm); # -# # -# filename The filename of the new template. # -# name The name of the template. # -# description The description of the template. # -# layout The layout of the new template. # -# confirm Confirm the action of creating a new template. # -################################################################################# - - # Get the variables that were passed to the subroutine. - - my ($templatefilename, $templatename, $templatedescription, $templatelayout, $confirm) = @_; - - # Load the needed Perl Modules - - use DBI; - - # Check if the confirm value is blank and if it is then set confirm to 0. - - if (!$confirm){ - - # The confirm value is blank, so set the value of confirm to 0. - - $confirm = 0; - - } - - if ($confirm eq 1){ - - # Check (validate) each of the values. - - kiriwrite_variablecheck($templatename, "utf8", 0, 0); - kiriwrite_variablecheck($templatedescription, "utf8", 0, 0); - kiriwrite_variablecheck($templatelayout, "utf8", 0, 0); - - # Convert the values into proper UTF8 strings that can be used. - - $templatename = kiriwrite_utf8convert($templatename); - $templatedescription = kiriwrite_utf8convert($templatedescription); - $templatelayout = kiriwrite_utf8convert($templatelayout); - - # Check the length of the converted UTF8 strings. - - my $templatefilename_length_check = kiriwrite_variablecheck($templatefilename, "maxlength", 64, 1); - my $templatename_length_check = kiriwrite_variablecheck($templatename, "maxlength", 512, 1); - my $templatedescription_length_check = kiriwrite_variablecheck($templatedescription, "maxlength", 512, 1); - kiriwrite_variablecheck($confirm, "maxlength", 1, 0); - - if ($templatefilename_length_check eq 1){ - - # The template filename length is too long, so return an error. - - kiriwrite_error("templatefilenametoolong"); - - } - - if ($templatename_length_check eq 1){ - - # The template name length is too long, so return an error. - - kiriwrite_error("templatenametoolong"); - - } - - - if ($templatedescription_length_check eq 1){ - - # The template description length is too long, so return an error. - - kiriwrite_error("templatedescriptiontoolong"); - - } - - # Check if the filename specified is a valid filename. - - kiriwrite_variablecheck($templatefilename, "filename", "", 0); - - # Check if the template database file permissions are valid and - # return an error if they aren't. - - my $template_database_permissions = kiriwrite_filepermissions("templates.db", 1, 1, 1); - - if ($template_database_permissions eq 1){ - - # Template database has invalid permissions set, so return - # an error. - - kiriwrite_error("templatedatabasefileinvalidpermissions"); - } - - # Check if the template database exists and if it doesn't then - # create the database and populate it. - - my $template_database_exists = kiriwrite_fileexists("templates.db"); - my $database_handle; - my $string_handle; - - if ($template_database_exists eq 1){ - - # The template database does not exist, so try to create a database. - - # Check if the directory has valid permissions to create files (and - # thus be able create a template database). - - my $directory_permissions = 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. - - kiriwrite_error("templatedatabasefilenotcreated"); - } - - # Create the SQLite database for the templates and populate it. - - $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db"); - $string_handle = $database_handle->prepare('CREATE TABLE kiriwrite_templates( - filename varchar(64) primary key, - templatename varchar(512), - templatedescription varchar(512), - templatelayout text, - datemodified datetime - )') or die(kiriwrite_error("templatedatabaseinvalidformat")); - $string_handle->execute(); - - } - - # Check if the template filename is already used and if it is then - # return an error. - - $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db"); - $string_handle = $database_handle->prepare('select * from kiriwrite_templates where filename = \'' . $templatefilename . '\' limit 1') or die(kiriwrite_error("templatedatabaseinvalidformat")); - $string_handle->execute(); - - my @database_template_check = $string_handle->fetchrow_array(); - my $template_checkname = $database_template_check[0]; - - if ($template_checkname){ - - # A template already exists with the filename given, so return an error. - - kiriwrite_error("templatefilenameexists"); - } - - # 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 $templatedate = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; - - # Convert the values that are going to be added for storing in the database. - - $templatename = kiriwrite_convert($templatename, "kiriwrite"); - $templatedescription = kiriwrite_convert($templatedescription, "kiriwrite"); - $templatelayout = kiriwrite_convert($templatelayout, "kiriwrite"); - - # Add the template to the template database. - - $string_handle = $database_handle->prepare('INSERT INTO kiriwrite_templates values( - \'' . $templatefilename . '\', - \'' . $templatename . '\', - \'' . $templatedescription . '\', - \'' . $templatelayout . '\', - \'' . $templatedate . '\' - )'); - $string_handle->execute(); - - # Print out the confirmation message. - - my $pagedata = "

Template Added

"; - $pagedata = $pagedata . "The template called '" . $templatename ."' was sucessfully created.

"; - $pagedata = $pagedata . "Return to the templates list"; - return $pagedata; - - } else { - # No confirmation was made, so print out a form for adding a template. - - my $pagedata = "

Add Template

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "
SettingValue
Name:
Description:
Filename:
Template Layout:

"; - $pagedata = $pagedata . " | "; - $pagedata = $pagedata . "
"; - - return $pagedata; - - } - - -} - -sub kiriwrite_template_edit{ -################################################################################# -# kiriwrite_template_edit: Edit a template from the template folder. # -# # -# Usage: # -# # -# kiriwrite_template_edit(filename, [newfilename], [newname], [newdescription], # -# [templatelayout], [confirm]); # -# # -# filename The current filename of the template to edit. # -# newfilename The new filename of the template to edit. # -# newname The new name of the template being edited. # -# newdescription The new description of the template being edited. # -# templatelayout The modified/altered template layout. # -# confirm Confirms the action to edit a template and its # -# settings. # -################################################################################# - - # Get all the variables that have been passed to the subroutine. - - my ($templatefilename, $templatenewfilename, $templatenewname, $templatenewdescription, $templatelayout, $confirm) = @_; - - # Load the Perl modules required for this subroutine. - - use DBI; - - # Define the pagedata variable for later on. - - my $pagedata = ""; - - # Check if the confirm variable is blank, if it is then - # set confirm to '0' - - if (!$confirm){ - - # confirm is uninitalised/blank, so set the value of confirm - # to '0' - - $confirm = 0; - - } - - # Check if the template filename is blank and if it is, then return - # an error. - - if (!$templatefilename){ - - kiriwrite_error("templatefilenameblank"); - - } - - if ($confirm eq 1){ - - # Check certain strings to see if they UTF8 compiliant. - - kiriwrite_variablecheck($templatenewname, "utf8", 0, 0); - kiriwrite_variablecheck($templatenewdescription, "utf8", 0, 0); - kiriwrite_variablecheck($templatelayout, "utf8", 0, 0); - - # Convert the values into proper UTF8 strings. - - $templatenewname = kiriwrite_utf8convert($templatenewname); - $templatenewdescription = kiriwrite_utf8convert($templatenewdescription); - $templatelayout = kiriwrite_utf8convert($templatelayout); - - # Check if the filenames recieved are valid filenames. - - kiriwrite_variablecheck($templatenewfilename, "maxlength", 64, 0); - kiriwrite_variablecheck($templatenewdescription, "maxlength", 512, 0); - kiriwrite_variablecheck($templatenewname, "maxlength", 512, 0); - kiriwrite_variablecheck($templatefilename, "maxlength", 64, 0); - kiriwrite_variablecheck($confirm, "maxlength", 1, 0); - - kiriwrite_variablecheck($templatefilename, "filename", "", 0); - kiriwrite_variablecheck($templatenewfilename, "filename", "", 0); - - # Check that the template database file exists and the permissions - # of the template database are valid. - - my $template_database_exists = kiriwrite_fileexists("templates.db"); - my $template_database_permissions = kiriwrite_filepermissions("templates.db", 1, 1, 0); - - if ($template_database_exists eq 1){ - - # the template database does not exist so return an error. - - kiriwrite_error("templatedatabasemissing"); - - } - - if ($template_database_permissions eq 1){ - - # The template database permissions are set incorrectly so - # return an error. - - kiriwrite_error("templatedatabaseinvalidpermissions"); - - } - - # Get the date. - - 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; - - # Convert the values so that they don't break when entering them into the SQL query. - - $templatenewname = kiriwrite_convert($templatenewname, "kiriwrite"); - $templatenewdescription = kiriwrite_convert($templatenewdescription, "kiriwrite"); - $templatelayout = kiriwrite_convert($templatelayout, "kiriwrite"); - - # Load the SQLite database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db"); - my $string_handle = $database_handle->prepare('UPDATE kiriwrite_templates SET - filename = \'' . $templatenewfilename . '\', - templatename = \'' . $templatenewname . '\', - templatedescription = \'' . $templatenewdescription . '\', - templatelayout = \'' . $templatelayout . '\', - datemodified = \'' . $templatenewdate . '\' - WHERE filename = \'' . $templatefilename . '\' - ') or die(kiriwrite_error("templatedatabaseinvalidformat")); - $string_handle->execute(); - - # Convert the following values so that display - - $templatenewname = kiriwrite_convert($templatenewname, "normal_display"); - - # Append a link so that the user can return to the templates list. - - $pagedata = $pagedata . "

Edit Template

"; - $pagedata = $pagedata . "The selected template called '" . $templatenewname . "' was edited.

"; - $pagedata = $pagedata . "Return to the templates list."; - - } else { - - # Load the SQLite database. - - my $templatefilename_sql = kiriwrite_convert($templatefilename, "kiriwrite"); - - my $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db"); - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates where filename = \'' . $templatefilename_sql . '\' limit 1') or die(kiriwrite_error("templatedatabaseinvalidformat")); - $string_handle->execute(); - - # Check if there is a result from the SQL query made (meaning - # that the template exists). - - my $template_found = 0; - my @database_template; - - while (@database_template = $string_handle->fetchrow_array()){ - - # The template has been found, so set the template - # found value to 1 so it doesn't return an error. - - $template_found = 1; - - } - - if ($template_found eq 0){ - - # The template was not found (doesn't exist) so - # return an error. - - kiriwrite_error("templatedoesnotexist"); - - } - - # Execute the query and get the information again. - - $string_handle->execute(); - @database_template = $string_handle->fetchrow_array(); - - # Get the values from the query results. - - my $template_filename = $database_template[0]; - my $template_name = $database_template[1]; - my $template_description = $database_template[2]; - my $template_layout = $database_template[3]; - my $template_modified = $database_template[4]; - - # Convert the values that are going to be displayed. - - $template_filename = kiriwrite_convert($template_filename, "normal_display"); - $template_name = kiriwrite_convert($template_name, "normal_display"); - $template_description = kiriwrite_convert($template_description, "normal_display"); - $template_layout = kiriwrite_convert($template_layout, "normal_display"); - - # Write out the form for editing an template with the current template - # settings put into the correct place. - - $pagedata = $pagedata . "

Edit Template

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "
SettingValue
Name:
Description:
Filename:
Template Layout:

"; - $pagedata = $pagedata . " | | Return to the templates list."; - $pagedata = $pagedata . "
"; - - } - - return $pagedata; - -} - -sub kiriwrite_template_delete{ -################################################################################# -# kiriwrite_template_delete: Delete a template from the template folder. # -# # -# Usage: # -# # -# kiriwrite_template_delete(filename, confirm); # -# # -# filename Specifies the filename of the database to delete. # -# confirm Confirms the action to delete a template. # -################################################################################# - - # Get the parameters that were passed to the subroutine. - - my ($template_filename, $template_confirm) = @_; - - if (!$template_confirm){ - $template_confirm = 0; - } - - # Load the required Perl modules - use DBI; - - # Check the length of the variables. - kiriwrite_variablecheck($template_filename, "maxlength", 64, 0); - kiriwrite_variablecheck($template_confirm, "maxlength", 1, 0); - - # Check if the template_name string is blank and if it is then - # return an error (as the template_name string should not be - # blank. - - if (!$template_filename){ - - # The template_filename string really is blank, - # so return an error saying that an empty - # filename was passed (to the subroutine). - - kiriwrite_error("templatefilenameblank"); - - } - - # Check if the template_confirm string is blank and if it is, write - # out a form asking the user to confirm the deletion. - - if ($template_confirm eq 1){ - - # The action to delete the template from the template database has - # been confirmed so delete the template. - - # Check if the template database exists and the file permissions - # are valid and return an error if they aren't. - - my $template_database_exists = kiriwrite_fileexists("templates.db"); - my $template_database_permissions = kiriwrite_filepermissions("templates.db", 1, 1, 0); - - if ($template_database_exists eq 1){ - - # the template database does not exist so return an error. - - kiriwrite_error("templatedatabasemissing"); - - } - - if ($template_database_permissions eq 1){ - - # The template database permissions are set incorrectly so - # return an error. - - kiriwrite_error("templatedatabaseinvalidpermissions"); - - } - - # Load thw SQLite database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db"); - - # Get the template name. - - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates WHERE filename = \'' . $template_filename . '\' LIMIT 1') or die(kiriwrite_error("templatedatabaseinvalidformat")); - $string_handle->execute(); - - my @database_template_page = $string_handle->fetchrow_array(); - my $database_template_name = $database_template_page[1]; - - $database_template_name = kiriwrite_convert($database_template_name, "normal_display"); - - # Delete the selected template. - - $string_handle = $database_handle->prepare('DELETE FROM kiriwrite_templates WHERE filename = \'' . $template_filename . '\''); - $string_handle->execute(); - - my $pagedata = "

Template Deleted

"; - $pagedata = $pagedata . "The selected template called '" . $database_template_name . "' was deleted."; - $pagedata = $pagedata . "

Return to the templates list"; - - return $pagedata; - - } elsif ($template_confirm eq 0) { - - # The template confirm value is 0 (previously blank and then set to 0), so - # write out a form asking the user to confirm the deletion of the template. - - # Check the templte database file exists and the permissions for the - # template database are valid. - - my $template_database_exists = kiriwrite_fileexists("templates.db"); - my $template_database_permissions = kiriwrite_filepermissions("templates.db", 1, 1, 0); - - if ($template_database_exists eq 1){ - - # The template database does not exist so return an error. - - kiriwrite_error("templatedatabasemissing"); - - } - - if ($template_database_permissions eq 1){ - - # The template database has invalid permissions set so return - # an error. - - kiriwrite_error("templatedatabaseinvalidpermissions"); - - } - - # Load the SQLite database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db"); - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates WHERE filename = \'' . $template_filename . '\' LIMIT 1'); - $string_handle->execute(); - - # Check if a result had returned and return an error if no result - # was returned. - - my @template_data; - my $template_found = 0; - - while(@template_data = $string_handle->fetchrow_array()){ - - # A template has been found so increment the counter. - - $template_found++; - } - - if ($template_found eq 0){ - - # The template does not exist, so return an error. - kiriwrite_error("templatedoesnotexist"); - - } - - # Get the template file information. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates WHERE filename = \'' . $template_filename . '\' LIMIT 1'); - $string_handle->execute(); - @template_data = $string_handle->fetchrow_array(); - - my $template_data_filename = $template_data[0]; - my $template_data_name = $template_data[1]; - - # Check if the template name is blank and if it is - - # Convert the strings so that display properly. - - $template_data_name = kiriwrite_convert($template_data_name, "normal_display"); - $template_data_name = kiriwrite_convert($template_data_name, "normal_display"); - - # Write out the confirmation form. - - my $pagedata = "

Template Deletion

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "Are you sure you want to delete the template called '" . $template_data_name . "' (" . $template_data_filename . ")?

"; - $pagedata = $pagedata . " | No, return to the template list."; - - $pagedata = $pagedata . "
"; - - return $pagedata; - - } else { - - kiriwrite_error("invalidvariable"); - - } - -} - -sub kiriwrite_template_list{ -################################################################################# -# kiriwrite_template_list: List the templates in the template folder. # -# # -# Usage: # -# # -# kiriwrite_template_list(); # -################################################################################# - - # Load the module required for processing the XML configuration files. - - use DBI; - - # Define certain values for later. - - my @database_template; - - my $database_handle; - my $string_handle; - - my $template_filename = ""; - my $template_name = ""; - my $template_description = ""; - my $template_data = ""; - - my $template_count = 0; - - my $template_style = 0; - my $template_stylename = ""; - - my $pagedata = ""; - my $templatedata = ""; - - # Check if the template database exists and the permissions for it are - # valid if the template database doesn't exist then write a message - # saying it will be created when a template is added. - - my $template_database_permissions = kiriwrite_filepermissions("templates.db", 1, 0, 1); - my $template_database_exists = kiriwrite_fileexists("templates.db"); - - if ($template_database_permissions eq 1){ - - # The templates directory has invalid permissions so an - # error will be returned. - - kiriwrite_error("templatedatabaseinvalidpermissions"); - - } - - if ($template_database_exists eq 1){ - - $pagedata = "

View Templates

"; - $pagedata = $pagedata . "
The template database doesn't exist and will be created when a template is added.
"; - - return $pagedata; - - } - - # Place the table cell headings into the templatedata string. - - $templatedata = ""; - - # Check if the database exists first before loading it. - - if ($template_database_exists eq 1){ - - } else { - - # Load the SQLite database. - - $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db"); - $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_templates ORDER BY filename ASC") or die(kiriwrite_error("templatedatabaseinvalidformat")); - $string_handle->execute(); - - # Process each template. - - while (@database_template = $string_handle->fetchrow_array()){ - - # Get certain values from the array. - - $template_filename = $database_template[0]; - $template_name = $database_template[1]; - $template_description = $database_template[2]; - $template_data = $database_template[3]; - - # Convert the data into information that can be displayed. - - $template_filename = kiriwrite_convert($template_filename, "normal_display"); - $template_name = kiriwrite_convert($template_name, "normal_display"); - $template_description = kiriwrite_convert($template_description, "normal_display"); - $template_data = kiriwrite_convert($template_data, "normal_display"); - - # Check what style the row of table cells should be. - - if ($template_style eq 0){ - - $template_stylename = "tablecell1"; - $template_style = 1; - - } else { - - $template_stylename = "tablecell2"; - $template_style = 0; - - } - - # Check if the template name and descriptions are blank and if - # they are then insert a message saying that there's no name - # or no description. - - if (!$template_name){ - $template_name = "No Name"; - } - - if (!$template_description){ - $template_description = "No Description"; - } - - # Check if there is no template data and if there isn't write - # a blank template message. - - if (!$template_data){ - $template_filename = $template_filename . " [Blank Template]"; - } - - # Append the table row to the templatedata string. - - $templatedata = $templatedata . ""; - - # Increment the template counter. - - $template_count++; - - } - - } - - $templatedata = $templatedata . "
Template FilenameTemplate NameTemplate DescriptionOptions
" . $template_filename . "" . $template_name . "" . $template_description . "Edit Delete
"; - - # Check if any templates are in the database and if there isn't - # then write a message saying that there are no templates in the - # database. - - if ($template_count eq 0){ - $templatedata = "
There are no templates in the template database. To add a template click on the Add Template link.
"; - } - - # Process the templatedata into pagedata. - - $pagedata = "

View Templates

"; - $pagedata = $pagedata . $templatedata; - - return $pagedata; - -} - -sub kiriwrite_database_add{ -################################################################################# -# kiriwrite_database_add: Creates a new database. # -# # -# Usage: # -# # -# kiriwrite_database_add(filename, name, description, [confirm]); # -# # -# filename Specifies the filename for the database. # -# name Specifies a (friendly) name for the database. # -# description Specifies a description for the database. # -# confirm Confirms the action to create a database. # -################################################################################# - - # Get the variables passed from the subroutine. - - my ($database_filename, $database_name, $database_description, $database_notes, $database_categories, $database_confirm) = @_; - - # Load the perl modules for this subroutine. - - use DBI; - - # Check if the confirm value is blank and if it is then - # set the confirm value to 0. - - if (!$database_confirm){ - - # The confirm value was blank so set the value to 0. - - $database_confirm = 0; - - } - - - if ($database_confirm eq 1){ - - # The action to create a new database is confirmed. - - # Validate the database name and database descriptions. - - my $database_name_check_utf8 = kiriwrite_variablecheck($database_name, "utf8", 0, 0); - my $database_description_check_utf8 = kiriwrite_variablecheck($database_description, "utf8", 0, 0); - my $database_notes_check_utf8 = kiriwrite_variablecheck($database_notes, "utf8", 0, 0); - my $database_categories_check_utf8 = kiriwrite_variablecheck($database_categories, "utf8", 0, 0); - - # Convert the UTF8 strings before checking the length of the strings. - - $database_name = kiriwrite_utf8convert($database_name); - $database_description = kiriwrite_utf8convert($database_description); - $database_notes = kiriwrite_utf8convert($database_notes); - $database_categories = kiriwrite_utf8convert($database_categories); - - my $database_name_check_blank = kiriwrite_variablecheck($database_name, "blank", 0, 1); - my $database_name_check_length = kiriwrite_variablecheck($database_name, "maxlength", 256, 1); - my $database_description_check_length = kiriwrite_variablecheck($database_description, "maxlength", 512, 1); - my $database_filename_check_length = kiriwrite_variablecheck($database_filename, "maxlength", 64, 1); - my $database_categories_check_length = kiriwrite_variablecheck($database_categories, "maxlength", 512, 1); - - # Check if values returned contains any values that would - # result in a specific error message being returned. - - if ($database_name_check_length eq 1){ - - # The length of the database name is too long, so return an error. - kiriwrite_error("databasenametoolong"); - - } - - if ($database_description_check_length eq 1){ - - # The database description length is too long, so return an error. - kiriwrite_error("databasedescriptiontoolong"); - - } - - if ($database_name_check_blank eq 1){ - - # The database name is blank, so return an error. - kiriwrite_error("databasenameblank"); - - } - - if ($database_filename_check_length eq 1){ - - # The database filename is to long, so return an error. - kiriwrite_error("databasefilenametoolong"); - - } - - if ($database_categories_check_length eq 1){ - - # The database categories is too long, so return an error. - kiriwrite_error("databasecategoriestoolong"); - - } - - # Check if the database filename is blank and if it is then - # generate a filename. - - if ($database_filename eq ""){ - - # Filename is blank so generate a file name from - # the database name. - - $database_filename = kiriwrite_processfilename($database_name); - - # Check to make sure that the database filename really - # is valid. - - kiriwrite_variablecheck($database_filename, "filename", "", 0); - kiriwrite_variablecheck($database_filename, "maxlength", 64, 0); - - # Check if the database and database configuration file does - # not already exist. - - if (-e $kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db'){ - - # A filename exists, so abort the script telling the user that those files exist. - kiriwrite_error("fileexists"); - - } - - } else { - - # Filename is not blank, so check if the filenames are already - # being used and if the actual filename itself is valid. - - # Check the filename to make sure the database and the database configuration file does not already exist. - - if (-e $kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db' ){ - - # A filename exists, so abort the script telling the user that those files exist. - - kiriwrite_error("fileexists"); - - - } - - # Check to make sure the database filename itself really is - # valid. - - kiriwrite_variablecheck($database_filename, "filename", "", 0); - kiriwrite_variablecheck($database_filename, "maxlength", 64, 0); - - } - - # Convert certain data so that the SQL query doesn't break. - - my $database_name_final = $database_name; - $database_name = kiriwrite_convert($database_name, "kiriwrite"); - $database_description = kiriwrite_convert($database_description, "kiriwrite"); - $database_categories = kiriwrite_convert($database_categories, "kiriwrite"); - - # Populate the database with the infomration and page tables. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database_filename . ".db"); - my $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) - )'); - $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 - )'); - $string_handle->execute(); - - # Add an entry to the kiriwrite_database_info table. - - $string_handle = $database_handle->prepare('INSERT INTO kiriwrite_database_info values( - \'' . $database_name . '\', - \'' . $database_description . '\', - \'' . $database_notes . '\', - \'' . $database_categories . '\', - \'' . $kiriwrite_version{"major"} . '\', - \'' . $kiriwrite_version{"minor"} . '\', - \'' . $kiriwrite_version{"revision"} . '\' - )'); - $string_handle->execute(); - - $database_name_final = kiriwrite_convert($database_name_final, "normal_display"); - - my $pagedata = "

Add Database

"; - $pagedata = $pagedata . "Database '" . $database_name_final . "' has been created.

\r\n"; - $pagedata = $pagedata . "Return to database list"; - - return $pagedata; - - } - - # There is confirm value is not 1, so write a form for creating a database to - # store pages in. - - my $pagedata = "

Add Database

\r\n"; - - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . "\t\t\t\r\n"; - $pagedata = $pagedata . "\t\t\r\n"; - $pagedata = $pagedata . "\t\t\r\n"; - $pagedata = $pagedata . "\t\t\r\n"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "\t\t\t
SettingValue
Database name
Database description
Database notes
Database categories
Database filename
-
    -
  • Leave the filename blank to automatically generate a filename.
  • -
  • Don't include .db as it will be appended automatically.
  • -
  • The filename cannot be any more than 64 characters long.
  • -
  • The filename should only contain letters and numbers, no spaces.
  • -
-
\r\n"; - $pagedata = $pagedata . "\t\t\t
\r\n"; - $pagedata = $pagedata . "\t\t\t | "; - $pagedata = $pagedata . "\t\t
\r\n"; - - # Exit the subroutine taking the data in the pagadata variable with it. - - return $pagedata; - -} - -sub kiriwrite_database_edit{ -################################################################################# -# kiriwrite_database_edit: Edits an database. # -# # -# Usage: # -# # -# kiriwrite_database_edit(filename, name, description, newfilename, newname, # -# newdescription, notes, categories, [confirm]); # -# # -# filename Specifies the filename of the database. # -# name Specifies the name of the database. # -# description Specifies the description of the database. # -# newfilename Specifies the new filename of the database. # -# newname Specifies the new name of the database. # -# newdescription Specifies the new description of the database. # -# notes Specifies the new notes of the database. # -# categories Specifies the new categories of the database. # -# confirm Confirms the action to edit a database. # -################################################################################# - - # First, get all the variables passed to the subroutine. - - my ($database_shortname, $database_name, $database_description, $database_newfilename, $database_newname, $database_newdescription, $database_notes, $database_categories, $database_confirm) = @_; - - # Load the needed Perl modules. - - use DBI; - - # Check if the database confirm value is blank and if it is - # set the confirm value to 0. - - if (!$database_confirm){ - - $database_confirm = 0; - - } - - # Check if the confirm variable has a value in it, if it has, check again to make sure it really is the correct value (Perl moans - # if $database_confirm was used directly). - - if ($database_confirm eq 1){ - - # Check if the database exists before trying to edit it. - - my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db'); - - if ($database_exists eq 1){ - - # The database does not exist so return an error. - - kiriwrite_error("databasemissingfile"); - - } - - # Check if the new data passes the validation tests below. First, check the length of the variables. - - my $database_name_check_utf8 = kiriwrite_variablecheck($database_newname, "utf8", 0, 0); - my $database_description_check_utf8 = kiriwrite_variablecheck($database_newdescription, "utf8", 0, 0); - my $database_notes_check_utf8 = kiriwrite_variablecheck($database_notes, "utf8", 0, 0); - my $database_categories_check_utf8 = kiriwrite_variablecheck($database_categories, "utf8", 0, 0); - - # Convert the UTF8 strings to make sure their length is accurate. - - $database_newname = kiriwrite_utf8convert($database_newname); - $database_newdescription = kiriwrite_utf8convert($database_newdescription); - $database_notes = kiriwrite_utf8convert($database_notes); - $database_categories = kiriwrite_utf8convert($database_categories); - - # Check if the database filename given is valid and return an error - # if it isn't. - - kiriwrite_variablecheck($database_shortname, "filename", "", 0); - - # Preform the following tests. - - my $database_filename_check_length = kiriwrite_variablecheck($database_newfilename, "maxlength", 64, 1); - my $database_filename_letnum = kiriwrite_variablecheck($database_newfilename, "filename", 0, 0); - my $database_name_check_length = kiriwrite_variablecheck($database_newname, "maxlength", 256, 1); - my $database_description_check_length = kiriwrite_variablecheck($database_newdescription, "maxlength", 512, 1); - my $database_categories_check_length = kiriwrite_variablecheck($database_categories, "maxlength", 512, 1); - my $database_name_check_blank = kiriwrite_variablecheck($database_newname, "blank", 0, 1); - - # Check if the data is valid and return a specific error if it doesn't. - - if ($database_name_check_length eq 1){ - - # The length of the database name is too long, so return an error. - kiriwrite_error("databasenametoolong"); - - } - - if ($database_description_check_length eq 1){ - - # The database description length is too long, so return an error. - kiriwrite_error("databasedescriptiontoolong"); - - } - - if ($database_name_check_blank eq 1){ - - # The database name is blank, so return an error. - kiriwrite_error("databasenameblank"); - - } - - if ($database_filename_check_length eq 1){ - - # The database filename is too long, so return an error. - kiriwrite_error("databasefilenametoolong"); - - } - - if ($database_categories_check_length eq 1){ - - # The database categories is too long, so return an error. - kiriwrite_error("databasecategoriestoolong"); - - } - - # Check the permissions of the database file to see if it is valid - # and return an error if it isn't. - - my $database_file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db', 1, 1, 1); - - if ($database_file_permissions eq 1){ - - # The database file itself has invalid permissions. - - kiriwrite_error("databaseinvalidpermissions"); - - } - - # Check if the old and new filenames have changed, if they have then rename the database file. - - my $pagedata; - - $pagedata = "

Edit Database

"; - - if ($database_shortname ne $database_newfilename){ - - # Old name does not match with the new filename, so rename the database file. - - # Check if a database with the same shortname already exists, if it does then return with an error. - - if (-e $kiriwrite_config{"directory_data_db"} . '/' . $database_newfilename . '.db'){ - kiriwrite_error("databasealreadyexists"); - } - - # Change the database filename. - - rename($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db', $kiriwrite_config{"directory_data_db"} . '/' . $database_newfilename . '.db'); - unlink($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db'); - - # Set the filename to the new filename. - - $database_shortname = $database_newfilename; - - } - - # Load the SQLite database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . ".db"); - - # Convert the UTF8 strings so that they can be properly updated. - - $database_name = kiriwrite_utf8convert($database_name); - $database_description = kiriwrite_utf8convert($database_description); - - # Convert the strings that are going to put into the database so that - # the database query doesn't break. - - $database_name = kiriwrite_convert($database_name, "kiriwrite"); - $database_newname = kiriwrite_convert($database_newname, "kiriwrite"); - $database_description = kiriwrite_convert($database_description, "kiriwrite"); - $database_newdescription = kiriwrite_convert($database_newdescription, "kiriwrite"); - - my $string_handle = $database_handle->prepare('UPDATE kiriwrite_database_info SET name = \'' . $database_newname . '\', description = \'' . $database_newdescription . '\', notes = \'' . $database_notes . '\', categories = \'' . $database_categories . '\' WHERE name = \'' . $database_name . '\' AND description = \'' . $database_description . '\'') or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - - # Convert a string so that it can be displayed properly. - - $database_newname = kiriwrite_convert($database_newname, "normal_display"); - - # Write out a message saying that the database has been updated. - - $pagedata = $pagedata . "Database '" . $database_newname . "' updated.
"; - $pagedata = $pagedata . "
\r\nReturn to database list."; - - return $pagedata; - - } else { - - # Check if the database filename given is valid and return an error - # if it isn't. - - kiriwrite_variablecheck($database_shortname, "filenameindir", "", 0); - - # Check if the database exists before trying to edit it. - - my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db'); - - if ($database_exists eq 1){ - - # The database does not exist so return an error. - - kiriwrite_error("databasemissingfile"); - - } - - - # Check the permissions of the database file to see if it is valid - # and return an error if it isn't. - - my $database_file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db', 1, 0, 1); - - if ($database_file_permissions eq 1){ - - # The database file itself has invalid permissions. - - kiriwrite_error("databaseinvalidpermissions"); - - } - - # Load the SQLite database. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . ".db"); - my $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_info LIMIT 1") or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); - my @database_info = $string_handle->fetchrow_array(); - - # Get the values needed from the kiriwrite_database_info table. - - my $database_oldname = $database_info[0]; - my $database_olddescription = $database_info[1]; - my $database_notes = $database_info[2]; - my $database_categories = $database_info[3]; - - # Convert the values in the kieiwrite format into the format that can be understood - # with a web browser. - - $database_oldname = kiriwrite_convert($database_oldname, "normal_display"); - $database_olddescription = kiriwrite_convert($database_olddescription, "normal_display"); - $database_notes = kiriwrite_convert($database_notes, "normal_display"); - $database_categories = kiriwrite_convert($database_categories, "normal_display"); - - # Print out the form for editing a database's settings. - - my $pagedata = "

Edit Database '" . $database_oldname . "'

"; - $pagedata = $pagedata . "
\r\n"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "\r\n"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "
SettingValue
Database name
Database description
Database notes
Database categories
Database filename

"; - - $pagedata = $pagedata . " | "; - $pagedata = $pagedata . "

"; - return $pagedata; - - } - - # The interpreter should not be here. So return an error saying invalid variable. - - kiriwrite_error("invalidvariable"); - -} - -sub kiriwrite_database_delete{ -################################################################################# -# kiriwrite_database_delete: Deletes an database. # -# # -# Usage: # -# # -# kiriwrite_database_delete(filename, [confirm]); # -# # -# filename Specifies the filename for the database to be deleted. # -# confirm Confirms the action to delete a database. # -################################################################################# - - my ($database_filename, $database_confirm) = @_; - - # Load the CGI module and the XML::Simple module for this subroutine. - - use DBI; - - # Check if the confirm value is blank and if it is then set the - # confirm value to 0. - - if (!$database_confirm){ - - $database_confirm = 0; - - } - - # Check if the database exists before trying to edit it. - - my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db'); - - if ($database_exists eq 1){ - - # The database does not exist so return an error. - - kiriwrite_error("databasemissingfile"); - - } - - # Check if the database filename given is valid and return an error - # if it isn't. - - kiriwrite_variablecheck($database_filename, "filename", "", 0); - - # Check if the request to delete a database has been confirmed. If it has, - # then delete the database itself. - - if ($database_confirm eq 1){ - # There is a value in the confirm variable of the HTTP query. - - # Before deleting, check the permissions of the database file. - - my $deleted_database_file_permissions = 0; - - my $pagedata = ""; - - $deleted_database_file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db', 1, 1, 1); - - if ($deleted_database_file_permissions eq 1){ - - # The database file itself has invalid permissions. - - kiriwrite_error("databaseinvalidpermissions"); - - } - - # Load the SQLite database to get the database name. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db'); - my $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_info LIMIT 1"); - $string_handle->execute; - my @database_info = $string_handle->fetchrow_array(); - - my $database_name = $database_info[0]; - $database_name = kiriwrite_convert($database_name, "normal_display"); - - # Untaint the database filename given. - - ($database_filename) = $database_filename =~ /^([a-zA-Z0-9.]+)$/; - - # Delete the database file. - - unlink($kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db'); - - # Write a message saying that the database has been deleted. - - $pagedata = "

Database Deleted

"; - $pagedata = $pagedata . "Database '" . $database_name . "' was deleted.
\r\n"; - - $pagedata = $pagedata . "
Return to database list."; - - return $pagedata; - - } - - # The action has not been confirmed, so write out a form asking the - # user to confirm. - - # Check the permissions of the database file to see if they are valid - # and return an error if it isn't. - - my $delete_database_file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db', 1, 1, 1); - - if ($delete_database_file_permissions eq 1){ - - # The database file itself has invalid permissions. - - kiriwrite_error("databaseinvalidpermissions"); - - } - - # Load the SQLite database to get the database name. - - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db'); - my $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_info LIMIT 1"); - $string_handle->execute; - my @database_info = $string_handle->fetchrow_array(); - - # Convert the database name so that it can be displayed properly. - - my $database_name = $database_info[0]; - $database_filename = kiriwrite_convert($database_filename, "normal_display"); - $database_name = kiriwrite_convert($database_name, "normal_display"); - - # Write out the form to ask the user to confirm the deletion of the - # selected database. - - my $pagedata = "

Database Deletion

"; - $pagedata = $pagedata . "\t\tAre you sure you want to delete '". $database_name . "'\?

"; - $pagedata = $pagedata . "\t\t
\r\n"; - $pagedata = $pagedata . "\t\t"; - $pagedata = $pagedata . "\t\t"; - $pagedata = $pagedata . "\t\t"; - $pagedata = $pagedata . "\t\t"; - $pagedata = $pagedata . "\t\t | Return to database list."; - $pagedata = $pagedata . "\t\t
\r\n"; - - return $pagedata; - -} - -sub kiriwrite_database_list{ -################################################################################# -# kiriwrite_database_list: Lists the databases available. # -# # -# Usage: # -# # -# kiriwrite_database_list(); # -################################################################################# - - # Load the following Perl modules. - use DBI; - - # Check the directory to make sure the permissions are settings are valid - # and return an error if the permission settings are invalid. - - my $data_directory_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"}, 1, 0); - - if ($data_directory_permissions eq 1){ - - # The data directory has invalid permissions set, so return an error. - - kiriwrite_error("datadirectoryinvalidpermissions"); - - } - - # Open the directory and get the list of all files ending with .xml and - # put them into the data_directory array. - - opendir(DATADIR, $kiriwrite_config{"directory_data_db"}); - my @data_directory = grep /m*\.db/, readdir(DATADIR); - closedir(DATADIR); - - # Declare the following variables that are going to be used before using - # the foreach function. - - my $pagedata = ""; - my $database_count = 0; - my $database_handle = ""; - my $database_filename = ""; - my $database_filename_friendly = ""; - my $database_filename_length = 0; - my $database_permissions = ""; - my $data_file = ""; - my $string_handle = ""; - my @database_info; - my $table_style = 0; - my $table_style_name = ""; - my $permissions_warning = 0; - my $permissions_list = ""; - my $invalid_warning = 0; - my $invalid_list = ""; - - # Begin creating the table for the list of databases. - - $pagedata = "

Database List

\r\n"; - - $pagedata = $pagedata . "\r\n"; - - foreach $data_file (@data_directory){ - # Check the database file permissions before opening it. - - $database_filename = $kiriwrite_config{"directory_data_db"} . '/' . $data_file; - $database_permissions = kiriwrite_filepermissions($database_filename, 1, 0, 0); - - if ($database_permissions eq 1){ - $permissions_warning = 1; - $permissions_list = $permissions_list . $data_file . "
\r\n"; - next; - } - - # Load the SQLite database. - - $database_handle = DBI->connect("dbi:SQLite:dbname=" . $database_filename); - - # Query the SQLite database or return an error (meaning that the database is in - # a invalid format). - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or ( - $invalid_list = $invalid_list . $data_file . "
\r\n", - $invalid_warning = 1, - next - ); - - $string_handle->execute(); - @database_info = $string_handle->fetchrow_array(); - - # Check the style to be used with. - - if ($table_style eq 0){ - - # Use the first style and set the style value - # to use the next style, the next time the - # if statement is checked. - - $table_style_name = "tablecell1"; - $table_style = 1; - } else { - - # Use the second style and set the style - # value to use the first style, the next - # time if statement is checked. - - $table_style_name = "tablecell2"; - $table_style = 0; - } - - $database_info[0] = kiriwrite_convert($database_info[0], "normal_display"); - $database_info[1] = kiriwrite_convert($database_info[1], "normal_display"); - - # Create a friendly name for the database. - - $database_filename_length = length($data_file); - $database_filename_friendly = substr($data_file, 0, $database_filename_length - 3); - - # Append the database information to the table. - - $pagedata = $pagedata . "\r\n"; - - $database_count++; - - } - - $pagedata = $pagedata . "
Database NameDatabase DescriptionOptions
" . $database_info[0] . "" . $database_info[1] . "Edit Delete Compile
\r\n
"; - - # Check if there are no valid databases are if there is no - # valid databases then write a message saying that no - # valid databases are available. - - if ($database_count eq 0){ - - # - - $pagedata = "

Database List

"; - $pagedata = $pagedata . "

There are no databases that can be used. To create a database click on the Add Database link.

"; - - } - - # Check if any databases with problems have appeared and if they - # have, print out a message saying which databases have problems. - - if ($permissions_warning eq 1){ - - $pagedata = $pagedata . "

Databases with invalid permissions

"; - $pagedata = $pagedata . "The following databases have invalid permissions set:

"; - $pagedata = $pagedata . $permissions_list; - - } - - if ($invalid_warning eq 1){ - - $pagedata = $pagedata . "

Databases with invalid formats

"; - $pagedata = $pagedata . "The following databases are in a invalid format:

"; - $pagedata = $pagedata . $invalid_list; - - } - - return $pagedata; # Return to the main part of the script with the processed information. - -} - - -sub kiriwrite_filter_list{ -################################################################################# -# kiriwrite_filter_list: Lists the filters that will be used when compiling a # -# webpage. # -# # -# Usage: # -# # -# kiriwrite_filter_list(); # -################################################################################# - - # Load the needed Perl modules. - - use DBI; - - # Check if the filters database exists and the - # permissions for the filters database are - # valid. - - my $database_exists = kiriwrite_fileexists("filters.db"); - my $database_permissions = kiriwrite_filepermissions("filters.db", 1, 0, 0); - my $filtersdb_notexist = 0; - - if ($database_exists eq 1){ - - # The filters database does not exist so - # set the value for the filters database - # not existing to 1. - - $filtersdb_notexist = 1; - - } - - if ($database_permissions eq 1 && $database_exists ne 1){ - - # The filters database has invalid - # permissions set, so return an error. - - kiriwrite_error("filtersdbpermissions"); - - } - - # Define some variables required for processing the filters list. - - my @database_filters; - my $database_handle; - my $string_handle; - my $pagedata = ""; - my $filterdata = ""; - my $filterswarning = ""; - my $filter_id; - my $filter_id_out; - my $filter_find; - my $filter_find_out; - my $filter_replace; - my $filter_replace_out; - my $filter_count = 0; - my $filter_priority; - my $filter_priority_out; - my $filter_style = 0; - my $filter_find_blank = 0; - my $filter_style_name = ""; - - $pagedata = $pagedata . "

View Filters

"; - - # If the filters database exists then get the list of filters, - # otherwise write a message saying that the filters database - # does not exist and will be created when a filter is added. - - if ($filtersdb_notexist eq 0){ - - # Get the SQLite database and get the filters ordered - # by priority. - - $database_handle = DBI->connect("dbi:SQLite:dbname=filters.db"); - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters ORDER BY priority ASC') or kiriwrite_error("filtersdbinvalidformat"); - $string_handle->execute(); - - $filterdata = $filterdata . ""; - $filterdata = $filterdata . ""; - - while (@database_filters = $string_handle->fetchrow_array()){ - - # Get the values from the from the array. - - $filter_id = $database_filters[0]; - $filter_priority = $database_filters[1]; - $filter_find = $database_filters[2]; - $filter_replace = $database_filters[3]; - - # Convert the values into values that can be displayed. - - $filter_id_out = kiriwrite_convert($filter_id, "normal_display"); - $filter_priority_out = kiriwrite_convert($filter_priority, "normal_display"); - $filter_find_out = kiriwrite_convert($filter_find, "normal_display"); - $filter_replace_out = kiriwrite_convert($filter_replace, "normal_display"); - - # Check which style should be used. - - if ($filter_style eq 0){ - - $filter_style_name = "tablecell1"; - $filter_style = 1; - - } else { - - $filter_style_name = "tablecell2"; - $filter_style = 0; - - } - - # Check if the replace filter is blank and if it is - # then say no replace setting is given. - - if (!$filter_replace){ - - # No replace filter is specified, so write a message - # saying that there is no replace filter. - - $filter_replace_out = "Replace filter is blank."; - - } - - # Check if the find filter is blank. - - if (!$filter_find && $filter_find_blank eq 0){ - - # No find filter is specified, So write a message saying - # that one of your find filters is blank and needs to be - # fixed. - - $filterdata = "Warning: One (or more) of your filters has a blank find filter and needs to be fixed.

" . $filterdata; - - } - - # Add the filter to the list of filters in the database. - - $filterdata = $filterdata . ""; - - $filter_count++; - - } - - $filterdata = $filterdata . "
PriorityFind SettingReplace SettingOptions
" . $filter_priority_out . "" . $filter_find_out . "" . $filter_replace_out . "Edit Delete
"; - - # Check if there are filters in the filters database and - # write a message if there isn't. - - if ($filter_count eq 0){ - - # There are no filters in the filters database. - - $filterswarning = "There are no filters available in the filters database. To add a filter, click on the Add Filter link."; - - } - - } - - # Check if the database wasn't found and if it - # wasn't then write a message saying that the - # database will be created when a filter is - # added. - - if ($filtersdb_notexist eq 1){ - - # The filters database doesn't exist so write - # a message. - - $filterswarning = "The filters database does not exist and will be created when a filter is added."; - - - } - - # Check if there is a warning message and if - # there is then write that warning message - # else write the list of filters. - - if ($filterswarning){ - - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . $filterswarning; - $pagedata = $pagedata . "
"; - - } else { - - # The filters database exists so write out the - # list of filters. - - $pagedata = $pagedata . $filterdata; - - } - - return $pagedata; - -} - -sub kiriwrite_filter_add{ -################################################################################# -# kiriwrite_filter_add: Adds a filter to the filter list. # -# # -# Usage: # -# # -# kiriwrite_filter_add(filterfind, filterreplace, filterpriority, # -# filternotes, [confirm]); # -# # -# filterfind Specifies the new word(s) to find. # -# filterreplace Specifies the new word(s) to replace. # -# filterpriority Specifies the new priority to use. # -# filternotes Specifies the new notes to use. # -# confirm Confirms the action to add a filter. # -################################################################################# - - # Get the values that have been passed to the subroutine. - - my ($filter_new_find, $filter_new_replace, $filter_new_priority, $filter_new_notes, $confirm) = @_; - - # Load the needed Perl modules. - - use DBI; - - # Check the confirm value to make sure it is no more than - # one character long. - - kiriwrite_variablecheck($confirm, "maxlength", 1, 0); - - # Define the page data value for later. - - my $pagedata = ""; - - if (!$confirm){ - - # The confirm value is undefined, so set the - # value of the confirm integer to '0'. - - $confirm = 0; - - } - - if ($confirm eq 1){ - - # The confirm integer is '1', so add the word - # to the filter list. - - # First, check the variables recieved are UTF8 - # copliant. - - kiriwrite_variablecheck($filter_new_find, "utf8", 0, 0); - kiriwrite_variablecheck($filter_new_replace, "utf8", 0, 0); - kiriwrite_variablecheck($filter_new_priority, "utf8", 0, 0); - - # Convert the UTF8 values so that the length can - # checked properly. - - $filter_new_find = kiriwrite_utf8convert($filter_new_find); - $filter_new_replace = kiriwrite_utf8convert($filter_new_replace); - $filter_new_priority = kiriwrite_utf8convert($filter_new_priority); - - # Check if the find filter is blank and return an error - # if it is. - - if (!$filter_new_find){ - - # The find filter given is blank so return an - # error. - - kiriwrite_error("blankfindfilter"); - - } - - if (!$filter_new_priority){ - - # The filter priority is blank so set it - # to 1. - - $filter_new_priority = 1; - - } - - # Check the length and contents of the values given - # to make sure they are valid. - - my $filterfind_maxlength_check = kiriwrite_variablecheck($filter_new_find, "maxlength", 1024, 1); - my $filterreplace_maxlength_check = kiriwrite_variablecheck($filter_new_replace, "maxlength", 1024, 1); - my $filterpriority_maxlength_check = kiriwrite_variablecheck($filter_new_priority, "maxlength", 5, 1); - my $filterpriority_numbers_check = kiriwrite_variablecheck($filter_new_priority, "numbers", 0, 1); - - # Check if the result of the tests to see if they - # are valid. - - if ($filterfind_maxlength_check eq 1){ - - # The find filter is too long, so return - # an error. - - kiriwrite_error("findfiltertoolong"); - - } - - if ($filterreplace_maxlength_check eq 1){ - - # The replace filter is too long, so - # return an error. - - kiriwrite_error("replacefiltertoolong"); - - } - - if ($filterpriority_maxlength_check eq 1){ - - # The length of the filter priority - # given is too long, so return an - # error. - - kiriwrite_error("filterprioritytoolong"); - - } - - if ($filterpriority_numbers_check eq 1){ - - # The priority of the filter given - # contains characters other than - # numbers. - - kiriwrite_error("filterpriorityinvalidchars"); - - } - - # Check if the filter priority is less than 1 - # and more than 10000 and return an error - # if it is. - - if ($filter_new_priority < 1 || $filter_new_priority > 50000){ - - # The filter priority is less than 1 and - # more than 10000, so return an error. - - kiriwrite_error("filterpriorityinvalid"); - - } - - # Define some variables for later on. - - my @database_filters; - my @database_check; - - my $database_handle; - my $string_handle; - my $chk_database_handle; - my $chk_string_handle; - - my $filters_exist; - my $filters_permissions; - my $filters_count = 0; - my $blankid_found = 0; - my $current_id = 0; - my $next_id = 0; - my $filter_exists = 0; - - my $first_filter = 0; - - my $new_id; - - # Check if the filters database exists, has valid - # permission settings and if it doesn't create - # the database first. - - $filters_exist = kiriwrite_fileexists("filters.db"); - - if ($filters_exist eq 0){ - - # The filters database does exist, so don't - # bother trying to create another one. - - $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 1, 1); - - if ($filters_permissions eq 1){ - - # The filters database has invalid permissions so - # return an error. - - kiriwrite_error("filtersdbpermissions"); - - } - - # Load the SQLite database. - - $database_handle = DBI->connect("dbi:SQLite:dbname=filters.db"); - - } else { - - # The filters database does not exist, so create - # the filters database. - - # Check if the filters database can really be - # created. - - my $directory_permissions = kiriwrite_filepermissions(".", 1, 1, 0); - - if ($directory_permissions eq 1){ - - # The filters database cannot be created because of invalid directory - # permissions so return an error. - - kiriwrite_error("filtersdatabasefilenotcreated"); - } - - # Create the filters database. - - $database_handle = DBI->connect("dbi:SQLite:dbname=filters.db"); - $string_handle = $database_handle->prepare('create table kiriwrite_filters( - id int(7) primary key, - priority int(5), - findsetting varchar(1024), - replacesetting varchar(1024), - notes text - ); - '); - $string_handle->execute(); - - } - - $chk_database_handle = DBI->connect("dbi:SQLite:dbname=filters.db"); - - # Find the lowest identification number available. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters ORDER BY id ASC') or kiriwrite_error("filtersdbinvalidformat");; - $string_handle->execute(); - - # Process each filter to find a blank identification - # number. - - while(@database_filters = $string_handle->fetchrow_array()){ - - # Check the next filter identification number to see - # if it exists and use that identification number if - # it doesn't exist. - - $current_id = $database_filters[0]; - $next_id = $current_id + 1; - $chk_string_handle = $chk_database_handle->prepare('SELECT * FROM kiriwrite_filters WHERE id = \'' . $next_id . '\' LIMIT 1'); - $chk_string_handle->execute(); - - while(@database_check = $chk_string_handle->fetchrow_array()){ - - $filter_exists = 1; - - - } - - if ($filter_exists eq 0 && $blankid_found eq 0){ - - $new_id = $next_id; - $blankid_found = 1; - - } - - # Check if this is the first filter and the current - # identification number is more than 1 and if it - # is then set the new identification number to 1. - - if ($first_filter eq 0 && $current_id > 1 && $blankid_found eq 0){ - - # The first filter has an identification - # number more than 1, so set the new - # identification number to 1. - - $new_id = 1; - $blankid_found = 1; - $first_filter = 1; - - - } - - # Set the next identification number as the - # current identification number add one and - # increment the filters count. - - $first_filter = 1; - $filters_count++; - $filter_exists = 0; - - } - - # Check if there are any filters in the database - # and if not set the identification number to 1. - - if ($filters_count eq 0){ - - # No filters were really in the filters - # database. - - $new_id = 1; - - } - - # Convert the values so that they can be processed - # properly. - - my $filter_new_id_sql = kiriwrite_convert($new_id, "kiriwrite"); - my $filter_new_priority_sql = kiriwrite_convert($filter_new_priority, "kiriwrite"); - my $filter_new_find_sql = kiriwrite_convert($filter_new_find, "kiriwrite"); - my $filter_new_replace_sql = kiriwrite_convert($filter_new_replace, "kiriwrite"); - my $filter_new_notes_sql = kiriwrite_convert($filter_new_notes, "kiriwrite"); - - # Add the new filter to the filters database. - - $string_handle = $database_handle->prepare('INSERT INTO kiriwrite_filters VALUES( - \'' . $filter_new_id_sql . '\', - \'' . $filter_new_priority_sql . '\', - \'' . $filter_new_find_sql . '\', - \'' . $filter_new_replace_sql . '\', - \'' . $filter_new_notes_sql . '\' - )'); - $string_handle->execute(); - - # Write out a message saying that the filter was added to the - # filters database. - - $pagedata = $pagedata . "

Filter Added

"; - $pagedata = $pagedata . "The filter was added sucessfully to the filters list.

"; - $pagedata = $pagedata . "Return to the filters list."; - - return $pagedata; - - } elsif ($confirm ne 0) { - - # The confirm integer is another value (which - # it shouldn't be) so return an error. - - kiriwrite_error("invalidvalue"); - - } - - # The confirm integer was blank so print out a form - # for adding a new filter. - - $pagedata = "

Add Filter

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "
SettingValue
Find...
Replace with...
Filter Priority
  • If no filter priority is specified, the filter priority will be set to 1.
Filter Notes
"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . " | "; - $pagedata = $pagedata . "
"; - - return $pagedata; - -} - -sub kiriwrite_filter_edit{ -################################################################################# -# kiriwrite_filter_edit: Edits a filter from the filter list. # -# # -# Usage: # -# # -# kiriwrite_filter_edit(filternumber, newfilterfind, newfilterreplace, # -# newfilterpriority, newfilternotes, confirm); # -# # -# filterid Specifies the filter number (line number) in the # -# filters database. # -# newfilterfind Specifies the new word to find. # -# newfilterreplace Specifies the new word to replace. # -# newfilterpriority Specifies the new filter priority. # -# newfilternotes Specifies the new filter notes. # -# confirm Confirms the action to edit a filter. # -################################################################################# - - # Get the values that have been passed to the subroutine. - - my ($filter_id, $filter_new_find, $filter_new_replace, $filter_new_priority, $filter_new_notes, $confirm) = @_; - - # Load the needed Perl modules. - - use DBI; - - # Check the confirm value to make sure it is no more than - # one character long. - - kiriwrite_variablecheck($confirm, "maxlength", 1, 0); - - # Define the page data value for later. - - my $pagedata = ""; - - # Check if the confirm value is blank and if it is - # srt the confirm value to 0. - - if (!$confirm){ - - # The confirm value does not have any value - # set so set it to 0. - - $confirm = 0; - - } - - # Check if the filter identification number is blank, - # contains characters other than numbers and is more - # than seven characters long. - - if (!$filter_id){ - - # The filter identification number is blank, - # so return an error. - - kiriwrite_error("filteridblank"); - - } - - my $filter_id_numbers_check = kiriwrite_variablecheck($filter_id, "numbers", 0, 1); - - if ($filter_id_numbers_check eq 1){ - - # The filter identification number contains - # characters other than numbers, so return - # an error. - - kiriwrite_error("filteridinvalid"); - - } - - my $filter_id_maxlength_check = kiriwrite_variablecheck($filter_id, "maxlength", 7, 1); - - if ($filter_id_maxlength_check eq 1){ - - # The filter identification number given - # is more than seven characters long, so - # return an error. - - kiriwrite_error("filteridtoolong"); - - } - - # Check if the filters database exists and the - # permissions for it are valid. - - my $filters_exists = kiriwrite_fileexists("filters.db"); - - if ($filters_exists eq 1){ - - # The filters database does not exist, so - # return an error. - - kiriwrite_error("filtersdbmissing"); - - } - - my $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 0); - - if ($filters_permissions eq 1){ - - # The filters database has invalid permissions - # set, so return an error. - - kiriwrite_error("filtersdbpermissions"); - - } - - # Define some variables for later. - - my $database_handle; - my $string_handle; - my $filter_id_sql = kiriwrite_convert($filter_id, "kiriwrite"); - my $filter_id_out = kiriwrite_convert($filter_id, "normal_display"); - my $filter_priority; - my $filter_priority_sql; - my $filter_priority_out; - my $filter_find; - my $filter_find_sql; - my $filter_find_out; - my $filter_replace; - my $filter_replace_sql; - my $filter_replace_out; - my $filter_notes; - my $filter_notes_sql; - my $filter_notes_out; - - # Check if the action to edit a filter has been - # confirmed. - - # Load the SQLite database. - - $database_handle = DBI->connect("dbi:SQLite:dbname=filters.db"); - - if ($confirm eq 1){ - - # The action to edit a filter has been confirmed so - # edit the selected filter. - - # Check if changes to the database can be written to. - - $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 1); - - if ($filters_permissions eq 1){ - - # The filters database has invalid permissions - # set, so return an error. - - kiriwrite_error("filtersdbpermissions"); - - } - - # Define some variables for later. - - my @database_filter; - my $filter_exists = 0; - - # Check if the filter exists. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters WHERE id = \'' . $filter_id_sql . '\' LIMIT 1') or kiriwrite_error("filtersdbinvalidformat"); - $string_handle->execute(); - - while (@database_filter = $string_handle->fetchrow_array()){ - - # The filter exists. - - $filter_exists = 1; - - } - - # Check if the filter really doesn't exist. - - if ($filter_exists eq 0){ - - # The filter really does not exist so - # return an error. - - kiriwrite_error("filterdoesnotexist"); - - } - - # First, check the variables recieved are UTF8 - # copliant. - - kiriwrite_variablecheck($filter_new_find, "utf8", 0, 0); - kiriwrite_variablecheck($filter_new_replace, "utf8", 0, 0); - kiriwrite_variablecheck($filter_new_priority, "utf8", 0, 0); - kiriwrite_variablecheck($filter_new_notes, "utf8", 0, 0); - - # Convert the UTF8 values so that the length can - # checked properly. - - $filter_find = kiriwrite_utf8convert($filter_new_find); - $filter_replace = kiriwrite_utf8convert($filter_new_replace); - $filter_priority = kiriwrite_utf8convert($filter_new_priority); - $filter_notes = kiriwrite_utf8convert($filter_new_notes); - - # Check if the find filter is blank and return an error - # if it is. - - if (!$filter_new_find){ - - # The find filter given is blank so return an - # error. - - kiriwrite_error("blankfindfilter"); - - } - - if (!$filter_new_priority){ - - # The filter priority is blank so set it - # to 1. - - $filter_new_priority = 1; - - } - - # Check the length and contents of the values given - # to make sure they are valid. - - my $filterfind_maxlength_check = kiriwrite_variablecheck($filter_new_find, "maxlength", 1024, 1); - my $filterreplace_maxlength_check = kiriwrite_variablecheck($filter_new_replace, "maxlength", 1024, 1); - my $filterpriority_maxlength_check = kiriwrite_variablecheck($filter_new_priority, "maxlength", 5, 1); - my $filterpriority_numbers_check = kiriwrite_variablecheck($filter_new_priority, "numbers", 0, 1); - - # Check if the result of the tests to see if they - # are valid. - - if ($filterfind_maxlength_check eq 1){ - - # The find filter is too long, so return - # an error. - - kiriwrite_error("findfiltertoolong"); - - } - - if ($filterreplace_maxlength_check eq 1){ - - # The replace filter is too long, so - # return an error. - - kiriwrite_error("replacefiltertoolong"); - - } - - if ($filterpriority_maxlength_check eq 1){ - - # The length of the filter priority - # given is too long, so return an - # error. - - kiriwrite_error("filterprioritytoolong"); - - } - - if ($filterpriority_numbers_check eq 1){ - - # The priority of the filter given - # contains characters other than - # numbers. - - kiriwrite_error("filterpriorityinvalidchars"); - - } - - # Check if the filter priority is less than 1 - # and more than 10000 and return an error - # if it is. - - if ($filter_new_priority < 1 || $filter_new_priority > 50000){ - - # The filter priority is less than 1 and - # more than 10000, so return an error. - - kiriwrite_error("filterpriorityinvalid"); - - } - - # Convert the new information about the filter given - # so that it can be added to the SQL query properly. - - $filter_find_sql = kiriwrite_convert($filter_find, "kiriwrite"); - $filter_replace_sql = kiriwrite_convert($filter_replace, "kiriwrite"); - $filter_priority_sql = kiriwrite_convert($filter_priority, "kiriwrite"); - $filter_notes_sql = kiriwrite_convert($filter_notes, "kiriwrite"); - - # Edit the filter using the information provided. - - $string_handle = $database_handle->prepare('UPDATE kiriwrite_filters SET priority = \'' . $filter_priority_sql . '\', findsetting = \'' . $filter_find_sql . '\', replacesetting = \'' . $filter_replace_sql . '\', notes = \'' . $filter_notes_sql . '\' WHERE id = \'' . $filter_id_sql . '\''); - $string_handle->execute(); - - # Write a message saying that the filter was edited. - - $pagedata = $pagedata . "

Filter edited

"; - $pagedata = $pagedata . "The selected filter was edited.

"; - $pagedata = $pagedata . "Return to the list of filters."; - - return $pagedata; - - } elsif ($confirm eq 0){ - - # The action to edit a filter has not been confirmed - # so write a form for editing the filter with. - - # Define some variables for later. - - my @database_filter; - my $filter_exists = 0; - - # Check if the filter exists. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters WHERE id = \'' . $filter_id_sql . '\' LIMIT 1') or kiriwrite_error("filtersdbinvalidformat"); - $string_handle->execute(); - - while (@database_filter = $string_handle->fetchrow_array()){ - - # The filter exists. - - $filter_exists = 1; - - } - - # Check if the filter really doesn't exist. - - if ($filter_exists eq 0){ - - # The filter really does not exist so - # return an error. - - kiriwrite_error("filterdoesnotexist"); - - } - - # Get the filter information. - - $string_handle->execute(); - - @database_filter = $string_handle->fetchrow_array(); - - # Get the required information. - - $filter_priority = $database_filter[1]; - $filter_find = $database_filter[2]; - $filter_replace = $database_filter[3]; - $filter_notes = $database_filter[4]; - - $filter_priority_out = kiriwrite_convert($filter_priority, "normal_display"); - $filter_find_out = kiriwrite_convert($filter_find, "normal_display"); - $filter_replace_out = kiriwrite_convert($filter_replace, "normal_display"); - $filter_notes_out = kiriwrite_convert($filter_notes, "normal_display"); - - # Write out the form. - - $pagedata = $pagedata . "

Edit Filter

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "
SettingValue
Find...
Replace With...
Filter Priority
  • If no filter priority is specified, the filter priority will be set to 1.
Filter Notes

"; - $pagedata = $pagedata . " | | Return to the filter database."; - $pagedata = $pagedata . "
"; - - return $pagedata; - - } else { - - # A confirm value other than 0 or 1 has been - # specified, so return an error. - - kiriwrite_error("invalidvalue"); - - } - -} - -sub kiriwrite_filter_delete{ -################################################################################# -# kiriwrite_filter_delete: Deletes a filter from the filter list. # -# # -# Usage: # -# # -# kiriwrite_filter_delete(number, confirm); # -# # -# number Specifies the filter line number to delete. # -# confirm Confirms the deletion of the selected filter. # -################################################################################# - - # Get the values that were passed to this subroutine. - - my ($filter_id, $confirm) = @_; - - # Load the needed Perl modules. - - use DBI; - - # Check the confirm value to make sure it is no more than - # one character long. - - kiriwrite_variablecheck($confirm, "maxlength", 1, 0); - - # Define the page data value for later. - - my $pagedata = ""; - - # Check if the confirm value is blank and if it is - # srt the confirm value to 0. - - if (!$confirm){ - - # The confirm value does not have any value - # set so set it to 0. - - $confirm = 0; - - } - - # Check if the filter identification number is blank, - # contains characters other than numbers and is more - # than seven characters long. - - if (!$filter_id){ - - # The filter identification number is blank, - # so return an error. - - kiriwrite_error("filteridblank"); - - } - - my $filter_id_numbers_check = kiriwrite_variablecheck($filter_id, "numbers", 0, 1); - - if ($filter_id_numbers_check eq 1){ - - # The filter identification number contains - # characters other than numbers, so return - # an error. - - kiriwrite_error("filteridinvalid"); - - } - - my $filter_id_maxlength_check = kiriwrite_variablecheck($filter_id, "maxlength", 7, 1); - - if ($filter_id_maxlength_check eq 1){ - - # The filter identification number given - # is more than seven characters long, so - # return an error. - - kiriwrite_error("filteridtoolong"); - - } - - # Check if the filters database exists and the - # permissions for it are valid. - - my $filters_exists = kiriwrite_fileexists("filters.db"); - - if ($filters_exists eq 1){ - - # The filters database does not exist, so - # return an error. - - kiriwrite_error("filtersdbmissing"); - - } - - my $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 0); - - if ($filters_permissions eq 1){ - - # The filters database has invalid permissions - # set, so return an error. - - kiriwrite_error("filtersdbpermissions"); - - } - - # Define some values for later. - - my @database_filter; - my $filterid_sql = kiriwrite_convert($filter_id, "kiriwrite"); - my $filterid_out = kiriwrite_convert($filter_id, "normal_display"); - my $database_handle; - my $string_handle; - my $filter_exists = 0; - - # Load the SQLite database. - - $database_handle = DBI->connect("dbi:SQLite:dbname=filters.db"); - - # Check if the confirm integer has a value of '1'. - - if ($confirm eq 1){ - - # The action to delete a filter has been confirmed. - - # Check the permissions of the filters database is - # valid (for writing). - - $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 1); - - if ($filters_permissions eq 1){ - - # The filters database has invalid permissions - # set, so return an error. - - kiriwrite_error("filtersdbpermissions"); - - } - - # Check if the filter exists. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters WHERE id = \'' . $filterid_sql . '\' LIMIT 1') or kiriwrite_error("filtersdbinvalidformat"); - $string_handle->execute(); - - while (@database_filter = $string_handle->fetchrow_array()){ - - # The filter exists. - - $filter_exists = 1; - - } - - # Check if the filter really doesn't exist. - - if ($filter_exists eq 0){ - - # The filter really does not exist so - # return an error. - - kiriwrite_error("filterdoesnotexist"); - - } - - # Delete the filter from the filters database. - - $string_handle = $database_handle->prepare('DELETE FROM kiriwrite_filters where id = \'' . $filterid_sql . '\'') or kiriwrite_error("filtersdbinvalidformat"); - $string_handle->execute(); - - # Write a message saying that the filter was deleted - # from the filters database. - - $pagedata = $pagedata . "

Delete Filter

"; - $pagedata = $pagedata . "The selected filter was deleted from the filters database.

"; - $pagedata = $pagedata . "Return to the filters database."; - - } elsif ($confirm eq 0) { - - # The action to delete a filter has not been confirmed so write - # a form asking for the user to confirm the deletion of the - # filter. - - # Check if the filter exists. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters WHERE id = \'' . $filterid_sql . '\' LIMIT 1') or kiriwrite_error("filtersdbinvalidformat"); - $string_handle->execute(); - - while (@database_filter = $string_handle->fetchrow_array()){ - - # The filter exists. - - $filter_exists = 1; - - } - - # Check if the filter really doesn't exist. - - if ($filter_exists eq 0){ - - # The filter really does not exist so - # return an error. - - kiriwrite_error("filterdoesnotexist"); - - } - - # The confirm integer is '0', so continue write out - # a form asking the user to confirm the deletion - # pf the filter. - - $pagedata = $pagedata . "

Confirm deletion

"; - $pagedata = $pagedata . "Are you sure you want to delete the selected filter?

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . " | No, return to the filters list."; - $pagedata = $pagedata . "
"; - - } else { - - kiriwrite_error("invalidvalue"); - - } - - return $pagedata; - -} - -sub kiriwrite_compile_makepages{ -################################################################################# -# kiriwrite_compile_makepages: Compile the selected pages and place them in the # -# specified output directory. # -# # -# Usage: # -# # -# kiriwrite_compile_makepages(type, selectedlist, confirm); # -# # -# type Specifies if single or multiple databases are to be compiled. # -# confirm Specifies if the action to compile the databases should really # -# be done. # -# selectedlist Specifies the databases to compile from as an array. # -################################################################################# - - # Get the values that have been passed to the subroutine. - - my ($type, $confirm, @selectedlist) = @_; - - # Check if the confirm value is more than one - # character long. - - kiriwrite_variablecheck($confirm, "maxlength", 1, 0); - - # Check if the confirm value is blank and if it - # is then set the confirm value to 0. - - if (!$confirm){ - - # The confirm value is blank, so set the - # confirm value to 0. - - $confirm = 0; - - } - - # Check if there are any databases selected - # and return an error if there isn't. - - if (!@selectedlist){ - - # There are no databases in the array - # so return an error. - - kiriwrite_error("nodatabaseselected"); - - } - - # Check if the type given is no more than - # 7 characters long. - - my $type_maxlength_check = kiriwrite_variablecheck($type, "maxlength", 8, 1); - - if ($type_maxlength_check eq 1){ - - # The type length given is too long so - # return an error. - - kiriwrite_error("variabletoolong"); - - } - - # Define the following values for later. - - my $pagedata = ""; - - # Check if the action to compile the databases - # has been confirmed. - - if ($confirm eq 1){ - - # The action to compile the datavases has - # been confirmed. - - # Define some variables for later. - - my %templatefiles; - my @databaseinfo; - my @databasepages; - my @filterslist; - my @findfilter; - my @replacefilter; - my @templateslist; - my @pagedirectories; - my $messages = ""; - my $warning_count = 0; - my $error_count = 0; - my $pages_count = 0; - my $filters_count = 0; - my $filters_find_blank_warning = 0; - my $database_handle; - my $string_handle; - my $filter_find; - my $filter_replace; - my $database; - my $database_out; - my $database_name; - my $database_name_out; - my $page_filename; - my $page_filename_out; - my $page_filename_check; - my $page_filename_char = ""; - my $page_filename_directory; - my $page_filename_length = 0; - my $page_filename_seek = 0; - my $page_filename_dircount = 0; - my $page_directory_name; - my $page_directory_path; - my $page_name; - my $page_name_out; - my $page_description; - my $page_section; - my $page_template; - my $page_template_out; - my $page_content; - my $page_settings; - my $page_lastmodified; - my $page_title; - my $page_final; - my $page_autosection; - my $page_autotitle; - my $database_filename_check = 0; - my $database_maxlength_check = 0; - my $output_exists = 0; - my $output_permissions = 0; - my $filters_exists = 0; - my $filters_permissions = 0; - my $filters_skip = 0; - my $templates_exists = 0; - my $templates_permissions = 0; - my $templates_skip = 0; - my $database_exists = 0; - my $database_permissions = 0; - my $information_prefix = "[Information] "; - my $error_prefix = "[Error] "; - my $warning_prefix = "[Warning] "; - - # Check if the output directory exists and has - # valid permissions set. - - $output_exists = kiriwrite_fileexists($kiriwrite_config{'directory_data_output'}); - - if ($output_exists ne 0){ - - # The output directory does not exist so - # return an error. - - kiriwrite_error("outputdirectorymissing"); - - } - - $output_permissions = kiriwrite_filepermissions($kiriwrite_config{'directory_data_output'}, 1, 1); - - if ($output_permissions ne 0){ - - # The output directory has invalid - # permissions set so return an error. - - kiriwrite_error("outputdirectoryinvalidpermissions"); - - } - - # Check if the filters database exists and has valid - # permissions set. - - $filters_exists = kiriwrite_fileexists("filters.db"); - - if ($filters_exists ne 0){ - - # The filters database does not exist - # so write a warning. - - $messages = $messages . $warning_prefix . "The filters database does not exist. No filters will be used." . "
"; - $filters_skip = 1; - $warning_count++; - - } - - $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 0); - - if ($filters_permissions ne 0 && $filters_exists eq 0){ - - # The filters database has invalid - # permissions set so write a warning. - - $messages = $messages . $warning_prefix . "The filters database has invalid permissions set. No filters will be used." . "
"; - $filters_skip = 1; - $warning_count++; - - } - - # Load the filters database (if the filters skip - # value isn't set to 1). - - if ($filters_skip eq 0){ - - # Load the filters database. - - $database_handle = DBI->connect("dbi:SQLite:dbname=filters.db"); - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters ORDER BY priority ASC') or $messages = $messages . $error_prefix . "The filters database is in an invalid format. No filters will be used." . "
", $error_count++, $filters_skip = 1; - - # Check if the filters skip value is set to 0 - # before executing the query. - - if ($filters_skip eq 0){ - - # Get the filters. - - $string_handle->execute(); - while (@filterslist = $string_handle->fetchrow_array()){ - - # Check if the find filter is blank and - # if it is then write a warning message. - - if (!$filterslist[2]){ - - if ($filters_find_blank_warning ne 1){ - - $messages = $messages . $warning_prefix . "One (or more) of the find filters from the filters database is blank." . "
"; - $filters_find_blank_warning = 1; - } - next; - - } else { - - # Add each find and replace filter. - - $findfilter[$filters_count] = $filterslist[2]; - $replacefilter[$filters_count] = $filterslist[3]; - - } - - $filters_count++; - - } - $messages = $messages . $information_prefix . "The filters database has been loaded." . "
"; - - } - - } - - # Check if the templates database exists and has - # valid permissions set. - - $templates_exists = kiriwrite_fileexists("templates.db"); - - if ($templates_exists ne 0){ - - # The template database does not exist - # so write a warning. - - $messages = $messages . $warning_prefix . "The templates database does not exist. Pages will be compiled without templates being used." . "
"; - $templates_skip = 1; - $warning_count++; - - } - - $templates_permissions = kiriwrite_filepermissions("templates.db", 1, 0); - - if ($templates_permissions ne 0 && $templates_exists eq 0){ - - # The template database has invalid - # permissions set so write a warning. - - $messages = $messages . $warning_prefix . "The templates database has invalid permissions set. Pages will be compiled without templates being used." . "
"; - $templates_skip = 1; - $warning_count++; - - } - - # Load the templates database (if the template - # skip value isn't set to 1). - - if ($templates_skip eq 0){ - - # Load the templates database. - - $database_handle = DBI->connect('dbi:SQLite:dbname=templates.db'); - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates') or $messages = $messages . $error_prefix . "The templates database is in an invalid format. Pages will be compiled without templates being used." . "
", $error_count++, $templates_skip = 1; - - # Check if the templates skip value is set to - # 0 before executing the query. - - if ($templates_skip eq 0){ - - # Get the templates and place them into the - # template files hash. - - $string_handle->execute(); - while(@templateslist = $string_handle->fetchrow_array()){ - - # Place each template file into the hash. - - $templatefiles{$templateslist[0]}{template} = $templateslist[3]; - $templatefiles{$templateslist[0]}{valid} = 1; - - } - $messages = $messages . $information_prefix . "The templates database has been loaded." . "
"; - - } - - } - - # Process each database. - - foreach $database (@selectedlist){ - - # Check if the database filename and length - # are valid. - - $messages = $messages . "
"; - - $database_out = kiriwrite_convert($database, "normal_display"); - $database_filename_check = kiriwrite_variablecheck($database, "page_filename", "", 1); - $database_maxlength_check = kiriwrite_variablecheck($database, "maxlength", 64, 1); - - if ($database_filename_check ne 0){ - - # The database filename is invalid, so process - # the next database. - - $messages = $messages . $error_prefix . "The database filename '" . $database_out . ".db' is invalid. Skipping this database..." . "
"; - $error_count++; - next; - - } - - if ($database_maxlength_check ne 0){ - - # The database file is too long, so process the - # next database. - - $messages = $messages . $error_prefix . "The database with the filename '" . $database_out . ".db' is too long. Skipping this database..." . "
"; - $error_count++; - next; - - } - - # Check if the database exists and has valid - # permissions set. - - $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - - if ($database_exists ne 0){ - - # The database does not exist so process - # the next database. - - $messages = $messages . $error_prefix . "The database with the filename '" . $database_out . ".db' does not exist. Skipping this database..." . "
"; - $error_count++; - next; - - } - - $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db', 1, 0); - - if ($database_permissions ne 0){ - - # The permissions for the database are invalid - # so process the next database. - - $messages = $messages . $error_prefix . "The database with the filename '" . $database_out . ".db' has invalid permissions set. Skipping this database..." . "
"; - $error_count++; - next; - - } - - # Load the SQLite database. - - $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - - # Get the database name. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or $messages = $messages . $error_prefix . "The database with the filename '" . $database_out . ".db' is in an invalid format. Skipping this database..." . "
", next; - $string_handle->execute(); - @databaseinfo = $string_handle->fetchrow_array(); - $database_name = $databaseinfo[0]; - $database_name_out = kiriwrite_convert($database_name, "normal_display"); - $messages = $messages . $information_prefix . "Compiling pages in the '" . $database_name_out . "' database..." . "
"; - - # Get the pages in the database. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages') or $messages = $messages . $error_prefix . "The database with the filename '" . $database_out . ".db' is in an invalid format. Skipping this database..." . "
", next; - $string_handle->execute(); - - while(@databasepages = $string_handle->fetchrow_array()){ - - # Convert the values so that they can be - # used in the messages list. - - $page_filename = $databasepages[0]; - $page_name = $databasepages[1]; - $page_description = $databasepages[2]; - $page_section = $databasepages[3]; - $page_template = $databasepages[4]; - $page_content = $databasepages[5]; - $page_settings = $databasepages[6]; - $page_lastmodified = $databasepages[7]; - - $page_filename_out = kiriwrite_convert($page_filename, "normal_display"); - $page_name_out = kiriwrite_convert($page_name, "normal_display"); - $page_template_out = kiriwrite_convert($page_template, "normal_display"); - - # Check if the filename is valid. - - $page_filename_check = kiriwrite_variablecheck($page_filename, "page_filename"); - - if ($page_filename_check ne 0){ - - # The file name is not valid so write a - # error and process the next page. - - $messages = $messages . $error_prefix . "The page '" . $page_name_out . "' has an invalid filename. Page skipped." . "
"; - next; - - } - - # Check if the template with the filename does not exist - # in the template files hash and write a message and - # process the next page. - - if (!$templatefiles{$page_template}{valid} && $page_template ne "!none" && $templates_skip eq 0){ - - $messages = $messages . $error_prefix . "The template with the filename '" . $page_template_out . "' for '" . $page_name_out . "' (" . $page_filename_out . ") does not exist." . "
"; - $error_count++; - next; - - $page_final = $page_content; - - } elsif ($page_template eq "!none"){ - - $page_final = $page_content; - - } else { - - $page_final = $templatefiles{$page_template}{template}; - $page_final =~ s//$page_content/g; - - } - - # Create the combined page title (if needed). - - if ($page_settings eq 0){ - - # Don't use page name or section name. - - $page_final =~ s///g; - - } elsif ($page_settings eq 1){ - - # Use the page name and section name. - - $page_autotitle = "(" . $page_section . " - " . $page_name . ")"; - $page_title = $page_section . " - " . $page_name; - $page_final =~ s//$page_title/g; - - } elsif ($page_settings eq 2){ - - # Use the page name only. - - $page_autotitle = "(" . $page_name . ")"; - $page_final =~ s//$page_name/g; - - } elsif ($page_settings eq 3){ - - # Use the section name only. - - if ($page_section){ - $page_autotitle = "(" . $page_section . ")"; - } - $page_final =~ s//$page_section/g; - - } - - # Check if the section name is not blank and - # place brackets inbetween if it is. - - if ($page_section){ - - $page_autosection = "(" . $page_section . ")"; - - } - - # Replace each value with the apporiate page - # values. - - $page_final =~ s//$page_name/g; - $page_final =~ s//$page_description/g; - $page_final =~ s//$page_section/g; - $page_final =~ s//$page_autosection/g; - $page_final =~ s//$page_autotitle/g; - - # Process the filters on the page data. - - if ($filters_skip eq 0){ - - $filters_count = 0; - - foreach $filter_find (@findfilter){ - - # Get the replace filter and process each - # filter on the page. - - $filter_replace = $replacefilter[$filters_count]; - $page_final =~ s/$filter_find/$filter_replace/g; - $filters_count++; - - } - - } - - # Process the page filename and check what directories - # need to be created. - - $page_filename_length = int(length($page_filename)); - - do { - - $page_filename_char = substr($page_filename, $page_filename_seek, 1); - - # Check if a forward slash appears and add it to - # the list of directories array. - - if ($page_filename_char eq '/'){ - - # Append the directory name to the list of - # directories array. - - $pagedirectories[$page_filename_dircount] = $page_filename_directory; - $page_filename_directory = ""; - $page_filename_char = ""; - $page_filename_dircount++; - - } else { - - # Append the character to the directory/filename. - - $page_filename_directory = $page_filename_directory . $page_filename_char; - - } - - $page_filename_seek++; - - } until ($page_filename_length eq $page_filename_seek); - - foreach $page_directory_name (@pagedirectories){ - - # Check if the directory exists and create - # the directory if it doesn't exist. - - $page_directory_path = $page_directory_path . '/' . $page_directory_name; - - mkdir($kiriwrite_config{"directory_data_output"} . '/' . $page_directory_path); - - } - - # Write the file to the output directory. - - open(PAGE, "> " . $kiriwrite_config{"directory_data_output"} . '/' . $page_filename); - print PAGE $page_final; - close(PAGE); - - # Write a message saying the page has been compiled. - - $messages = $messages . $information_prefix . "'" . $page_name_out . "' (" . $page_filename_out . ") was compiled." . "
"; - $pages_count++; - - # Reset certain values. - - $page_autotitle = ""; - $page_autosection = ""; - $page_filename_seek = 0; - $page_filename_dircount = 0; - - $page_filename_directory = ""; - $page_directory_path = ""; - $page_directory_name = ""; - @pagedirectories = (); - - } - - # Write a message saying that the database has - # been processed. - - $messages = $messages . $information_prefix . "Finished compiling pages in the '" . $database_name_out . "' database..." . "
"; - - } - - $messages = $messages . "
"; - $messages = $messages . $pages_count . " pages compiled, " . $error_count . " errors, " . $warning_count . " warnings."; - $pagedata = $pagedata . "

Compile databases

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . $messages; - $pagedata = $pagedata . "
"; - - return $pagedata; - - } elsif ($confirm eq 0){ - - # The action to compile the databases has - # not been confirmed so check what type - # is being used. - - if ($type eq "single"){ - - # The type is a single database selected so - # process that database. - - # Define some variables for later. - - my $database_handle; - my $string_handle; - my @database_info; - my $database_filename_check; - my $database_maxlength_check; - my $databasefilename; - my $databasefilename_out; - my $database_name; - my $database_name_out; - - # Check that the database name and length are - # valid and return an error if they aren't. - - $databasefilename = $selectedlist[0]; - $databasefilename_out = kiriwrite_convert($databasefilename, "normal_display"); - $database_filename_check = kiriwrite_variablecheck($databasefilename, "filename", "", 1); - $database_maxlength_check = kiriwrite_variablecheck($databasefilename, "maxlength", 64, 1); - - if ($database_filename_check ne 0){ - - # The database filename is invalid, so - # return an error. - - kiriwrite_error("databasefilenameinvalid"); - - } - - if ($database_maxlength_check ne 0){ - - # The database filename is too long, so - # return an error. - - kiriwrite_error("databasefilenametoolong"); - - } - - # Check if the database exists and has valid permissions - # set and skip them if they don't. - - my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $databasefilename . '.db'); - my $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $databasefilename . '.db', 1, 0); - - if ($database_exists ne 0){ - - # The database filename does not exist, so - # return an error. - - kiriwrite_error("databasemissingfile"); - - } - - if ($database_permissions ne 0){ - - # The database permissions are invalid, so - # return an error. - - kiriwrite_error("databaseinvalidpermissions"); - - } - - # Load the SQLite database. - - $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $databasefilename . '.db'); - - # Get the database name. - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1'); - $string_handle->execute(); - @database_info = $string_handle->fetchrow_array(); - $database_name = $database_info[0]; - $database_name_out = kiriwrite_convert($database_name, "normal_display"); - - # Write out a form asking the user to confirm if the - # user wants to compile the selected database. - - $pagedata = $pagedata . "

Compile database

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "Are you sure you want to compile the '" . $database_name_out . "' database?

"; - $pagedata = $pagedata . " | Return to the list of databases for compiling."; - $pagedata = $pagedata . "
"; - - return $pagedata; - - } elsif ($type eq "multiple"){ - - # The type is multiple databases selected - # so process each database. - - # Define some variables for later. - - my $database_handle; - my $databasename; - my $databasename_out; - my @database_info; - my $database_filename_check; - my $database_maxlength_check; - my $database_exists; - my $database_permissions; - my $database_count = 0; - my $string_handle; - my $database_info_name; - my $database_info_name_out; - my $databaselist = ""; - - foreach $databasename (@selectedlist){ - - # Check if the database is in the database - # directory and skip it if it isn't. - - $database_filename_check = kiriwrite_variablecheck($databasename, "filename", "", 1); - $database_maxlength_check = kiriwrite_variablecheck($databasename, "maxlength", 64, 1); - - if ($database_filename_check ne 0 || $database_maxlength_check ne 0){ - - # The database filename given is invalid or - # the database filename given is too long - # so process the next database. - - next; - - } - - # Check if the database exists and has valid permissions - # set and skip them if they don't. - - $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $databasename . '.db'); - $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $databasename . '.db', 1, 0); - - if ($database_exists ne 0 || $database_permissions ne 0){ - - # The database does not exist or the permissions - # for the database are invalid so process the - # next database. - - next; - - } - - # Get the database name. - - $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $databasename . '.db'); - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or next; - $string_handle->execute(); - - # Increment the amount of databases to compile. - - $database_count++; - - # Get the database name, convert it so that it can - # be displayed properly and add it to the list of - # databases to be compiled. - - @database_info = $string_handle->fetchrow_array(); - $database_info_name = $database_info[0]; - $database_info_name_out = kiriwrite_convert($database_info_name, "normal_display"); - $databasename_out = kiriwrite_convert($databasename, "normal_display"); - - $databaselist = $databaselist . "" . $database_info_name_out . "
"; - - } - - # Check if any databases are available to be compiled. - - if ($database_count eq 0){ - - # No databases are available to be compiled. - - kiriwrite_error("nodatabaseselected"); - - } - - # Write out the form for compiling the database. - - $pagedata = $pagedata . "

Compile selected databases

"; - $pagedata = $pagedata . "Do you want to compile the following databases?

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . $databaselist; - $pagedata = $pagedata . "

"; - $pagedata = $pagedata . " | Return to the database list."; - $pagedata = $pagedata . "
"; - - return $pagedata; - - } else { - - # The type is something else other than - # single or multiple, so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } else { - - # The confirm value is neither 0 or 1, so - # return an error. - - kiriwrite_error("invalidvariable"); - - } - -} - -sub kiriwrite_compile_all{ -################################################################################# -# kiriwrite_compile_all: Compile all of the databases in the database # -# directory. # -# # -# Usage: # -# # -# kiriwrite_compile_all(); # -################################################################################# - - # Get the list of databases to compile. - - opendir(DATABASE, $kiriwrite_config{"directory_data_db"}); - my @database_list = grep /m*\.db/, readdir(DATABASE); - closedir(DATABASE); - - # Define some variables for later. - - my $databaseformdata; - my $database_name = ""; - my $database_name_filename_check; - my $database_name_length = 0; - my $database_name_final_length = 0; - my $database_name_final = ""; - my $database_count = 1; - - foreach $database_name (@database_list){ - - # Check if the database filename is valid before - # using the database. - - $database_name_filename_check = kiriwrite_variablecheck($database_name, "filename", 0, 1); - - if ($database_name_filename_check ne 0){ - - # The database filename is invalid so process - # the next database. - - next; - - } - - # Get the database name without the extension. - - $database_name_length = length($database_name); - $database_name_final_length = $database_name_length - 3; - $database_name_final = substr($database_name, 0, $database_name_final_length); - - # Process the final database name into form values. - - $databaseformdata = $databaseformdata . ""; - $databaseformdata = $databaseformdata . ""; - - $database_count++; - - } - - # Check the list of databases to compile to see if it is blank, - # if it is then return an error. - - if ($database_count eq 0){ - - # The list of database is blank so return an error. - - kiriwrite_error("nodatabasesavailable"); - - } - - # Write out a form for confirming the action to compile all of the databases. - - my $pagedata = "

Compile all databases

"; - $pagedata = $pagedata . "Do you want to compile all of the databases in the database directory?

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . $databaseformdata; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . " | Return to the compile database list."; - $pagedata = $pagedata . "
"; - - return $pagedata; - -} - -sub kiriwrite_selectedlist{ -################################################################################# -# kiriwrite_page_selectedlist: Get the list of selected pages to use. # -# # -# Usage: # -# # -# kiriwrite_page_selectedlist(); # -################################################################################# - - # Load the required Perl modules. - - my $query = new CGI; - - my $count = $query->param('count'); - - # Check if the list of files has a value and if not set it 0. - - if (!$count){ - - $count = 0; - - } - - # Define some values for later. - - my @filename_list; - my @selected_list; - my @final_list; - - my $filename; - my $selected; - - my $final_count = 0; - my $seek = 0; - - # Get the list of filenames. - - do { - - # Get the values from id[] - - $seek++; - - $filename = $query->param('id[' . $seek . ']'); - $filename_list[$seek] = $filename; - - } until ($seek eq $count || $count eq 0); - - # Get the list of selected filenames. - - $seek = 0; - - do { - - # Get the values from name[] - - $seek++; - - $selected = $query->param('name[' . $seek . ']'); - - if (!$selected){ - - $selected = 'off'; - - } - - $selected_list[$seek] = $selected; - - } until ($seek eq $count || $count eq 0); - - # Create a final list of filenames to be used for - # processing. - - $seek = 0; - - do { - - # Check if the selected value is on and include - # the filename in the final list. - - $seek++; - - $selected = $selected_list[$seek]; - - if ($selected eq "on"){ - - $filename = $filename_list[$seek]; - $final_list[$final_count] = $filename; - $final_count++; - - } - - } until ($seek eq $count || $count eq 0); - - return @final_list; - -} - -sub kiriwrite_compile_list{ -################################################################################# -# kiriwrite_compile_list: Shows a list of databases that can be compiled. # -# # -# Usage: # -# # -# kiriwrite_compile_list(); # -################################################################################# - - # Load the required Perl modules. - - use DBI; - - # Check the directory to make sure the permissions are settings are valid - # and return an error if the permission settings are invalid. - - my $data_directory_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"}, 1, 0); - - if ($data_directory_permissions eq 1){ - - # The data directory has invalid permissions set, so return an error. - - kiriwrite_error("datadirectoryinvalidpermissions"); - - } - - # Open the directory and get the list of all files ending with .xml and - # put them into the data_directory array. - - opendir(DATADIR, $kiriwrite_config{"directory_data_db"}); - my @data_directory = grep /m*\.db/, readdir(DATADIR); - closedir(DATADIR); - - # Declare the following variables that are going to be used before using - # the foreach function. - - my $pagedata = ""; - my $database_count = 0; - my $database_handle = ""; - my $database_filename = ""; - my $database_filename_friendly = ""; - my $database_filename_length = 0; - my $database_permissions = ""; - my $database_name_out = ""; - my $database_description_out = ""; - my $data_file = ""; - my $string_handle = ""; - my @database_info; - my $table_style = 0; - my $table_style_name = ""; - my $tabledata = ""; - my $permissions_warning = 0; - my $permissions_list = ""; - my $select_menu = ""; - my $invalid_warning = 0; - my $invalid_list = ""; - - # Begin creating the table for the list of databases. - - $pagedata = "

Compile Pages

\r\n"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - - $select_menu = " | "; - - foreach $data_file (@data_directory){ - # Check the database file permissions before opening it. - - $database_filename = $kiriwrite_config{"directory_data_db"} . '/' . $data_file; - $database_permissions = kiriwrite_filepermissions($database_filename, 1, 0, 0); - - if ($database_permissions eq 1){ - $permissions_warning = 1; - $permissions_list = $permissions_list . $data_file . "
\r\n"; - next; - } - - # Load the SQLite database. - - $database_handle = DBI->connect("dbi:SQLite:dbname=" . $database_filename); - - # Query the SQLite database or return an error (meaning that the database is in - # a invalid format). - - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or ( - $invalid_list = $invalid_list . $data_file . "
\r\n", - $invalid_warning = 1, - next - ); - - $string_handle->execute(); - @database_info = $string_handle->fetchrow_array(); - - # Check the style to be used with. - - if ($table_style eq 0){ - - # Use the first style and set the style value - # to use the next style, the next time the - # if statement is checked. - - $table_style_name = "tablecell1"; - $table_style = 1; - } else { - - # Use the second style and set the style - # value to use the first style, the next - # time if statement is checked. - - $table_style_name = "tablecell2"; - $table_style = 0; - } - - $database_name_out = kiriwrite_convert($database_info[0], "normal_display"); - $database_description_out = kiriwrite_convert($database_info[1], "normal_display"); - - # Create a friendly name for the database. - - $database_filename_length = length($data_file); - $database_filename_friendly = substr($data_file, 0, $database_filename_length - 3); - - $database_count++; - - # Append the database information to the table. - - $tabledata = $tabledata . "" . $database_name_out . "" . $database_description_out . "Compile\r\n"; - - } - - $pagedata = $pagedata . ""; - - $pagedata = $pagedata . $select_menu . "

"; - - $pagedata = $pagedata . "\r\n"; - - $pagedata = $pagedata . $tabledata; - - $pagedata = $pagedata . "
Database NameDatabase DescriptionOptions
\r\n
"; - - $pagedata = $pagedata . $select_menu; - $pagedata = $pagedata . "
"; - - # Check if there are no valid databases are if there is no - # valid databases then write a message saying that no - # valid databases are available. - - if ($database_count eq 0){ - - # - - $pagedata = "

Database List

"; - $pagedata = $pagedata . "

There are no databases that can be used for compiling.

"; - - } - - # Check if any databases with problems have appeared and if they - # have, print out a message saying which databases have problems. - - if ($permissions_warning eq 1){ - - $pagedata = $pagedata . "

Databases with invalid permissions

"; - $pagedata = $pagedata . "The following databases have invalid permissions set:

"; - $pagedata = $pagedata . $permissions_list; - - } - - if ($invalid_warning eq 1){ - - $pagedata = $pagedata . "

Databases with invalid formats

"; - $pagedata = $pagedata . "The following databases are in a invalid format:

"; - $pagedata = $pagedata . $invalid_list; - - } - - return $pagedata; - -} - -sub kiriwrite_compile_clean{ -################################################################################# -# kiriwrite_compile_clean: Deletes the contents of the output directory. # -# # -# Usage: # -# # -# kiriwrite_compile_clean(confirm); # -# # -# confirm Confirms the deletion of files from the output directory. # -################################################################################# - - # Get the values passed to the subroutine. - - my ($confirm) = @_; - - # Define some variables for later. - - my $file_permissions; - my $output_directory_exists; - my $output_directory_permissions; - my $warning_message; - my $pagedata = ""; - - # Check if the output directory exists. - - $output_directory_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_output"}); - - if ($output_directory_exists eq 1){ - - # The output directory does not exist so return - # an error. - - kiriwrite_error("outputdirectorymissing"); - - } - - # Check if the output directory has invalid - # permissions set. - - $output_directory_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_output"}); - - if ($output_directory_permissions eq 1){ - - # The output directory has invalid permissions - # set, so return an error. - - kiriwrite_error("outputdirectoryinvalidpermissions"); - - } - - if ($confirm) { - - if ($confirm eq 1){ - - # The action to clean the output directory has been - # confirmed. - - # Remove the list of files and directories from the - # output directory. - - $file_permissions = kiriwrite_compile_clean_helper($kiriwrite_config{"directory_data_output"}, 1); - - if ($file_permissions eq 1){ - - # One of the files or directories has invalid - # permissions set so write a warning message. - - } - - $pagedata = "

Clean Output Directory

"; - - if ($file_permissions eq 1){ - - $pagedata = $pagedata . "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.

"; - - } else { - - $pagedata = $pagedata . "The contents of the output directory have been removed.

"; - - } - - $pagedata = $pagedata . "Return to the compile databases list."; - - return $pagedata; - - } else { - - # A value other than 1 is set for the confirm value - # (which it shouldn't be) so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } - - # Print out a form for cleaning the output directory. - - $pagedata = "

Clean Output Directory

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "Are you sure you want to clean the output directory?

"; - $pagedata = $pagedata . " | Return to compile list."; - $pagedata = $pagedata . "
"; - - return $pagedata; - -} - -sub kiriwrite_compile_clean_helper{ -################################################################################# -# kiriwrite_compile_clean_helper: Helper for cleaning out the output directory. # -# This command sometimes is called recursively (when a directory is found). # -# # -# Usage: # -# # -# kiriwrite_compile_clean_helper(directory, removedirectory, [permissions]); # -# # -# directory Specifies the directory to remove files (and # -# sub-directories) from. # -# keepdirectory Keeps the directory itself after all files have been # -# removed. # -# permissions Used recursively for error checking. # -################################################################################# - - # Get the values passed to the subroutine. - - my ($directory, $directory_keep, $permissions) = @_; - - # Check if the directory_keep is only one charater long. - - my $directory_file = ""; - my @directory_list; - my $file_permissions = 0; - my $debug = 0; - - # Check if the file permissions value is blank. - - if (!$permissions){ - - # The file permissions value is blank. - - $permissions = 0; - - } - - # Open the directory specified, read the contents of - # the directory and then close the directory. - - opendir(DIRECTORY, $directory); - @directory_list = readdir(DIRECTORY); - closedir(DIRECTORY); - - # Remove each file and directory. - - foreach $directory_file (@directory_list){ - - # Check if the filename is '.' or '..' and if it - # is skip those files. - - if ($directory_file eq "." || $directory_file eq ".."){ - - # The filename is '.' or '..' so skip processing - # these files. - - } else { - - # Check if the permissions on the file or directory has - # valid permissions set. - - $file_permissions = kiriwrite_filepermissions($directory . '/' . $directory_file, 1, 1); - - if ($file_permissions eq 1){ - - # The file or directory has invalid permissions set. - - $permissions = 1; - next; - - } - - # Check if the filename is a directory. - - if (-d $directory . '/' . $directory_file){ - - # The filename is a directory so send the directory name - # and this subroutine again (recursively). - - kiriwrite_compile_clean_helper($directory . '/' . $directory_file, 0, $permissions); - - } else { - - # The file is not a directory but an actual file so - # remove as normal (in terms of the Perl language). - - ($directory) = $directory =~ m/^([a-zA-Z0-9\/.]+)$/ig; - ($directory_file) = $directory_file =~ m/^([a-zA-Z0-9.]+)$/ig; - - unlink($directory . '/' . $directory_file); - - } - - } - - } - - # Check if the directory should be kept. - - if ($directory_keep eq 1){ - - # The directory_keep value is set as 1 so the directory - # specified should be kept. - - } elsif ($directory_keep eq 0) { - - # The directory_keep value is set as 0 so remove the - # directory specified. - - ($directory) = $directory =~ m/^([a-zA-Z0-9\/.]+)$/ig; - rmdir($directory); - - } else { - - # A value other than 0 or 1 was specified so return - # an error, - - kiriwrite_error('invalidvalue'); - - } - - return $permissions; - -} - -sub kiriwrite_settings_view{ -################################################################################# -# kiriwrite_options_view: Writes out the list of options and variables. # -# # -# Usage: # -# # -# kiriwrite_settings_view(); # -################################################################################# - - # Get the settings. - - my $settings_directory_db = $kiriwrite_config{"directory_data_db"}; - my $settings_directory_output = $kiriwrite_config{"directory_data_output"}; - my $settings_noncgi_images = $kiriwrite_config{"directory_noncgi_images"}; - my $settings_system_datetime = $kiriwrite_config{"system_datetime"}; - my $settings_system_language = $kiriwrite_config{"system_language"}; - my $settings_system_output = $kiriwrite_config{"system_output"}; - - # CONTINUE: Write out convert things. - - my $settings_directory_db_out = kiriwrite_convert($settings_directory_db, "normal_display"); - my $settings_directory_output_out = kiriwrite_convert($settings_directory_output, "normal_display"); - my $settings_noncgi_images_out = kiriwrite_convert($settings_noncgi_images, "normal_display"); - my $settings_system_datetime_out = kiriwrite_convert($settings_system_datetime, "normal_display"); - my $settings_system_language_out = kiriwrite_convert($settings_system_language, "normal_display"); - my $settings_system_output_out = kiriwrite_convert($settings_system_output, "normal_display"); - - my $pagedata = "

View Settings

"; - - $pagedata = $pagedata . "The current settings being used are the following:"; - - $pagedata = $pagedata . "

"; - $pagedata = $pagedata . ""; - - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "
SettingValue
Directories
Database Directory" . $settings_directory_db_out . "
Output Directory" . $settings_directory_output_out . "
Images (URI path)" . $settings_noncgi_images_out . "
Date
Date format" . $settings_system_datetime_out . "
Language
System Language" . $settings_system_language_out . "
Output
Output System" . $settings_system_output_out . "

"; - - $pagedata = $pagedata . "To alter the current settings, select the Edit Settings option at the top of the page."; - - return $pagedata; - -} - -sub kiriwrite_settings_edit{ -################################################################################# -# kiriwrite_options_edit: Edits the options. # -# # -# Usage: # -# # -# kiriwrite_options_edit(dbdirectory, outputdirectory, imagesuri, # -# languagesystem, outputsystem, confirm); # -# # -# dbdirectory Specifies the new database directory to use. # -# outputdirectory Specifies the new output directory to use. # -# imagesuri Specifies the new URI path for images. # -# datetimeformat Specifies the new date and time format. # -# languagesystem Specifies the new language to use for Kiriwrite. # -# outputsystem Specifies the new output system to use for Kiriwrite. # -# confirm Confirms the action to edit the settings. # -################################################################################# - - # Get the values that have been passed to the subroutine. - - my ($settings_dbdirectory, $settings_outputdirectory, $settings_imagesuri, $settings_datetimeformat, $settings_languagesystem, $settings_outputsystem, $confirm) = @_; - - # Load the required Perl modules. - - my $xsl = XML::Simple->new(); - - if (!$confirm){ - - # If the confirm value is blank, then set the confirm - # value to 0. - - $confirm = 0; - - } - - if ($confirm eq "1"){ - - # The action to edit the settings has been confirmed. - # Start by checking each variable about to be placed - # in the settings file is valid. - - # Deinfe some variables for later. - - my @kiriwrite_new_settings; - - # Check the length of the directory names. - - kiriwrite_variablecheck($settings_dbdirectory, "maxlength", 64, 0); - kiriwrite_variablecheck($settings_outputdirectory, "maxlength", 64, 0); - kiriwrite_variablecheck($settings_imagesuri, "maxlength", 512, 0); - kiriwrite_variablecheck($settings_datetimeformat, "maxlength", 32, 0); - - kiriwrite_variablecheck($settings_languagesystem, "language_filename", "", 0); - kiriwrite_variablecheck($settings_outputsystem, "outputmodule", 0, 1); - - # Check if the directory names only contain letters and numbers and - # return a specific error if they don't. - - my $kiriwrite_dbdirectory_check = kiriwrite_variablecheck($settings_dbdirectory, "directory", 0, 1); - my $kiriwrite_outputdirectory_check = kiriwrite_variablecheck($settings_outputdirectory, "directory", 0, 1); - kiriwrite_variablecheck($settings_datetimeformat, "datetime", 0, 0); - - if ($kiriwrite_dbdirectory_check eq 1){ - - # The database directory name is blank, so return - # an error. - - kiriwrite_error("dbdirectoryblank"); - - } elsif ($kiriwrite_dbdirectory_check eq 2){ - - # The database directory name is invalid, so return - # an error. - - kiriwrite_error("dbdirectoryinvalid"); - - } - - if ($kiriwrite_outputdirectory_check eq 1){ - - # The output directory name is blank, so return - # an error. - - kiriwrite_error("outputdirectoryblank"); - - } elsif ($kiriwrite_outputdirectory_check eq 2){ - - # The output directory name is invalid, so return - # an error. - - kiriwrite_error("outputdirectoryinvalid"); - - } - - # Place the settings into the array. - - $kiriwrite_new_settings[0] = $settings_dbdirectory; - $kiriwrite_new_settings[1] = $settings_outputdirectory; - $kiriwrite_new_settings[2] = $settings_imagesuri; - $kiriwrite_new_settings[3] = $settings_datetimeformat; - $kiriwrite_new_settings[4] = $settings_languagesystem; - $kiriwrite_new_settings[5] = $settings_outputsystem; - - # Write the new settings to the XML file. - - kiriwrite_output_xml("kiriwrite.xml", "config", @kiriwrite_new_settings); - - # Write a confirmation message. - - my $pagedata = "

Edit Settings

"; - $pagedata = $pagedata . "The page settings have been changed and will take effect on the next page load of Kiriwrite.

"; - $pagedata = $pagedata . "Return to the list of settings."; - - return $pagedata; - - } - - # Get the list of languages available. - - my @language_directory = ""; - my $language_filename = ""; - my $language_file_xml = ""; - my $language_file_systemname = ""; - my $language_file_localname = ""; - my $language_file_localname_out = ""; - my $language_file_seek = 0; - my $language_flie_dot = 0; - my $language_file_length = 0; - my $language_file_char = ""; - my $language_file_friendly = ""; - my $language_selectlist = ""; - - opendir(LANGUAGEDIR, "lang"); - @language_directory = grep /m*\.xml/, readdir(LANGUAGEDIR); - closedir(LANGUAGEDIR); - - # Process each language by loading the XML configuration file - # used for each language and then get the System name and - # the local name of the language. - - $language_selectlist = ""; - - # Get the list of output systems available. - - my @outputsys_directory = ""; - my $outputsys_file = ""; - my $outputsys_char = ""; - my $outputsys_dot = 0; - my $outputsys_firstdot = 0; - my $outputsys_firstdotfound = ""; - my $outputsys_seek = 0; - my $outputsys_length = 0; - my $outputsys_friendly = ""; - my $outputsys_selectlist = ""; - my $outputsys_config = $kiriwrite_config{"system_output"}; - - # Open and get the list of output systems (perl modules) by filtering - # out the - - opendir(OUTPUTSYSTEMDIR, "Modules/Output"); - @outputsys_directory = grep /m*\.pm/, readdir(OUTPUTSYSTEMDIR); - closedir(OUTPUTSYSTEMDIR); - - $outputsys_selectlist = ""; - - # Get the directory settings. - - my $directory_settings_database = $kiriwrite_config{"directory_data_db"}; - my $directory_settings_output = $kiriwrite_config{"directory_data_output"}; - my $directory_settings_imagesuri = $kiriwrite_config{"directory_noncgi_images"}; - my $datetime_setting = $kiriwrite_config{"system_datetime"}; - - my $directory_settings_database_out = kiriwrite_convert($directory_settings_database, "normal_display"); - my $directory_settings_output_out = kiriwrite_convert($directory_settings_output, "normal_display"); - my $directory_settings_imagesuri_out = kiriwrite_convert($directory_settings_imagesuri, "normal_display"); - my $datetime_setting_out = kiriwrite_convert($datetime_setting, "normal_display"); - - # Print out a form for editing the settings. - - my $pagedata = "

Edit Settings

"; - $pagedata = $pagedata . "Warning: Settings that have changed take effect after clicking on the 'Change Settings' button and viewing the confirmation message.

"; - - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . "
Directories
Database Directory
Output Directory
Images (URI path)
Date
Date format

"; - $pagedata = $pagedata . "
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: / - ( ) : -
"; - $pagedata = $pagedata . "
Languages
System Language" . $language_selectlist . "
Output
Output System" . $outputsys_selectlist . "

"; - $pagedata = $pagedata . " | "; - $pagedata = $pagedata . "
"; - - return $pagedata; - -} - -sub kiriwrite_settings_load{ -################################################################################# -# kiriwrite_settings_load: Load the configuration settings into the global # -# variables. # -# # -# Usage: # -# # -# kiriwrite_settings_load(); # -################################################################################# - - # Load the required Perl modules. - - use XML::Simple; - my $xsl = XML::Simple->new(); - - # Check if the Kiriwrite configuration file exists before using it and - # return a critical error if it doesn't exist. - - my $kiriwrite_conf_exist = kiriwrite_fileexists("kiriwrite.xml"); - - if ($kiriwrite_conf_exist eq 1){ - - # The configuration really does not exist so return an critical error. - - kiriwrite_critical("configfilemissing"); - - } - - # Check if the Kiriwrite configuration file has valid permission settings - # before using it and return a critical error if it doesn't have the - # valid permission settings. - - my $kiriwrite_conf_permissions = kiriwrite_filepermissions("kiriwrite.xml", 1, 0); - - if ($kiriwrite_conf_permissions eq 1){ - - # The permission settings for the Kiriwrite configuration file are - # invalid, so return an critical error. - - kiriwrite_critical("configfileinvalidpermissions"); - - } - - # Converts the XML file into meaningful data for later on in this subroutine. - - my $kiriwrite_conf_file = 'kiriwrite.xml'; - my $kiriwrite_conf_data = $xsl->XMLin($kiriwrite_conf_file, SuppressEmpty => 1); - - # Go and fetch the settings and place them into a hash (that is global). - - %kiriwrite_config = ( - - "directory_data_db" => $kiriwrite_conf_data->{settings}->{directories}->{database}, - "directory_data_output" => $kiriwrite_conf_data->{settings}->{directories}->{output}, - "directory_noncgi_images" => $kiriwrite_conf_data->{settings}->{directories}->{images}, - - "system_language" => $kiriwrite_conf_data->{settings}->{language}->{type}, - "system_output" => $kiriwrite_conf_data->{settings}->{system}->{output}, - "system_datetime" => $kiriwrite_conf_data->{settings}->{system}->{datetime} - - ); - - # Do a validation check on all of the variables that were loaded into the global configuration hash. - - kiriwrite_variablecheck($kiriwrite_config{"directory_data_db"}, "maxlength", 64, 0); - kiriwrite_variablecheck($kiriwrite_config{"directory_data_output"}, "maxlength", 64, 0); - kiriwrite_variablecheck($kiriwrite_config{"directory_noncgi_images"}, "maxlength", 512, 0); - kiriwrite_variablecheck($kiriwrite_config{"directory_data_template"}, "maxlength", 64, 0); - - kiriwrite_variablecheck($kiriwrite_config{"system_language"}, "language_filename", "", 0); - kiriwrite_variablecheck($kiriwrite_config{"system_output"}, "outputmodule", 0, 0); - - # Check if the output system module does exist before loading it and return an critical error - # if the output system module does not exist. - - my $kiriwrite_config_systemoutput_fileexists = kiriwrite_fileexists("Modules/Output/" . $kiriwrite_config{"system_output"} . ".pm"); - - if ($kiriwrite_config_systemoutput_fileexists eq 1){ - - # Output system module does not exist so return an critical error. - - kiriwrite_critical("outputsystemmissing"); - - } - - # Check if the output system module does have the valid permission settings and return an - # critical error if the output system module contains invalid permission settings. - - my $kiriwrite_config_systemoutput_permissions = kiriwrite_filepermissions("Modules/Output/" . $kiriwrite_config{"system_output"} . ".pm", 1, 0); - - if ($kiriwrite_config_systemoutput_permissions eq 1){ - - # Output system contains invalid permissions so return an critical error. - - kiriwrite_critical("outputsysteminvalidpermissions"); - - } - - return; - -} - -sub kiriwrite_variablecheck{ -################################################################################# -# kiriwrite_variablecheck: Checks the variables for any invalid characters. # -# # -# Usage: # -# # -# kiriwrite_variablecheck(variablename, type, length, noerror); # -# # -# variablename Specifies the variable to be checked. # -# type Specifies what type the variable is. # -# option Specifies the maximum/minimum length of the variable # -# (if minlength/maxlength is used) or if the filename should be # -# checked to see if it is blank. # -# noerror Specifies if Kiriwrite should return an error or not on # -# certain values. # -################################################################################# - - # Get the values that were passed to the subroutine. - - my ($variable_data, $variable_type, $variable_option, $variable_noerror) = @_; - - if ($variable_type eq "numbers"){ - - # Check for numbers and return an error if there is anything else than numebrs. - - my $variable_data_validated = $variable_data; # Copy the variable_data to variable_data_validated. - $variable_data_validated =~ tr/0-9//d; # Take away all of the numbers and from the variable. - # If it only contains numbers then it should be blank. - - if ($variable_data_validated eq ""){ - # The validated variable is blank. So continue to the end of this section where the return function should be. - } else { - # The variable is not blank, so check if the no error value is set - # to 1 or not. - - if ($variable_noerror eq 1){ - - # The validated variable is not blank and the noerror - # value is set to 1. So return an value of 1. - # (meaning that the data is invalid). - - return 1; - - } elsif ($variable_noerror eq 0) { - - # The validated variable is not blank and the noerror - # value is set to 0. - - kiriwrite_error("invalidvariable"); - - } else { - - # The variable noerror value is something else - # pther than 1 or 0. So return an error. - - kiriwrite_error("invalidvariable"); - - } - - } - - return 0; - - } elsif ($variable_type eq "lettersnumbers"){ - - # Check for letters and numbers and return an error if there is anything else other - # than letters and numbers. - - my $variable_data_validated = $variable_data; # Copy the variable_data to variable_data_validated - $variable_data_validated =~ tr/a-zA-Z0-9.//d; - $variable_data_validated =~ s/\s//g; - - if ($variable_data_validated eq ""){ - # The validated variable is blank. So continue to the end of this section where the return function should be. - } else { - # The variable is not blank, so check if the no error value is set - # to 1 or not. - - if ($variable_noerror eq 1){ - - # The validated variable is not blank and the noerror - # value is set to 1. So return an value of 1. - # (meaning that the data is invalid). - - return 1; - - } elsif ($variable_noerror eq 0) { - - # The validated variable is not blank and the noerror - # value is set to 0. - - kiriwrite_error("invalidvariable"); - - } else { - - # The variable noerror value is something else - # pther than 1 or 0. So return an error. - - kiriwrite_error("invalidvariable"); - - } - - } - - return 0; - - } elsif ($variable_type eq "maxlength"){ - # Check for the length of the variable, return an error if it is longer than the length specified. - - # Check if the variable_data string is blank, if it is then set the variable_data_length - # to '0'. - - my $variable_data_length = 0; - - if (!$variable_data){ - - # Set variable_data_length to '0'. - $variable_data_length = 0; - - } else { - - # Get the length of the variable recieved. - $variable_data_length = length($variable_data); - - } - - - - if ($variable_data_length > $variable_option){ - - # The variable length is longer than it should be so check if - # the no error value is set 1. - - if ($variable_noerror eq 1){ - - # The no error value is set to 1, so return an - # value of 1 (meaning tha the variable is - # too long to be used). - - return 1; - - } elsif ($variable_noerror eq 0){ - - # The no error value is set to 0, so return - # an error. - - kiriwrite_error("variabletoolong"); - - } else { - - # The no error value is something else other - # than 0 or 1, so return an error. - - kiriwrite_error("variabletoolong"); - - } - - } else { - - # The variable length is exactly or shorter than specified, so continue to end of this section where - # the return function should be. - - } - - return 0; - - } elsif ($variable_type eq "blank"){ - # Check if the variable is blank and if it is blank, then return an error. - - if (!$variable_data){ - - # The variable data really is blank, so check what - # the no error value is set. - - if ($variable_noerror eq 1){ - - # The no error value is set to 1, so return - # a value of 1 (saying that the variable was - # blank). - - return 1; - - } elsif ($variable_noerror eq 0){ - - # The no error value is set to 0, so return - # an error. - - kiriwrite_error("blankvariable"); - - } else { - - # The no error value is something else other - # than 0 or 1, so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } - - return 0; - - } elsif ($variable_type eq "filename"){ - # Check for letters and numbers, if anything else than letters and numbers is there (including spaces) return - # an error. - - # Check if the filename passed is blank, if it is then return with an error. - - if ($variable_data eq ""){ - - # The filename specified is blank, so check what the - # noerror value is set. - - if ($variable_noerror eq 1){ - - # The no error value is set to 1 so return - # a value of 1 (meaning that the filename - # was blank). - - return 1; - - } elsif ($variable_noerror eq 0){ - - # The no error value is set to 1 so return - # an error. - - kiriwrite_error("blankfilename"); - - } else { - - # The no error value is something else other - # than 0 or 1, so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } else { - - - } - - my $variable_data_validated = $variable_data; - $variable_data_validated =~ tr/a-zA-Z0-9\.//d; - - # Check if the validated data variable is blank, if it is - # then continue to the end of this section where the return - # function should be, otherwise return an error. - - if ($variable_data_validated eq ""){ - - # The validated data variable is blank, meaning that - # it only contained letters and numbers. - - } else { - - # The validated data variable is not blank, meaning - # that it contains something else, so return an error - # (or a value). - - if ($variable_noerror eq 1){ - - # The no error value is set to 1 so return - # an value of 2. (meaning that the filename - # is invalid). - - - return 2; - - } elsif ($variable_noerror eq 0){ - - # The no error value is set to 0 so return - # an error. - - kiriwrite_error("invalidfilename"); - - } else { - - # The no error value is something else other - # than 0 or 1 so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } - - return 0; - - } elsif ($variable_type eq "filenameindir"){ - # Check if the filename is in the directory and return an - # error if it isn't. - - if ($variable_data eq ""){ - - # The filename specified is blank, so check what the - # noerror value is set. - - if ($variable_noerror eq 1){ - - # The no error value is set to 1 so return - # a value of 1 (meaning that the filename - # was blank). - - return 1; - - } elsif ($variable_noerror eq 0){ - - # The no error value is set to 1 so return - # an error. - - kiriwrite_error("blankfilename"); - - } else { - - # The no error value is something else other - # than 0 or 1, so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } else { - - - } - - # Set the following variables for later on. - - my $variable_data_length = 0; - my $variable_data_char = ""; - my $variable_data_validated = ""; - my $variable_data_seek = 0; - my $variable_data_directory = ""; - my $variable_data_directorycurrent = ""; - my $variable_data_firstlevel = 1; - - # Get the length of the variable recieved. - - $variable_data_length = length($variable_data); - - # Check if the database filename contains the directory command - # for up a directory level and if it is, return an error - # or return with a number. - - do { - - # Get a character from the filename passed to this subroutine. - - $variable_data_char = substr($variable_data, $variable_data_seek, 1); - - # Check if the current character is the forward slash character. - - if ($variable_data_char eq "/"){ - - # Check if the current directory is blank (and on the first level), or if the - # current directory contains two dots or one dot, if it does return an error. - - if ($variable_data_directorycurrent eq "" && $variable_data_firstlevel eq 1 || $variable_data_directorycurrent eq ".." || $variable_data_directorycurrent eq "."){ - - # Check if the noerror value is set to 1, if it is return an - # number, else return an proper error. - - if ($variable_noerror eq 1){ - - # Page filename contains invalid characters and - # the no error value is set to 1 so return a - # value of 2 (meaning that the page filename - # is invalid). - - return 2; - - } elsif ($variable_noerror eq 0) { - - # Page filename contains invalid characters and - # the no error value is set to 0 so return an - # error. - - kiriwrite_error("invalidfilename"); - - } else { - - # The no error value is something else other - # than 0 or 1 so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } - - # Append the forward slash, clear the current directory name and set - # the first directory level value to 0. - - $variable_data_directory = $variable_data_directory . $variable_data_char; - $variable_data_directorycurrent = ""; - $variable_data_firstlevel = 0; - - } else { - - # Append the current character to the directory name and to the current - # directory name. - - $variable_data_directory = $variable_data_directory . $variable_data_char; - $variable_data_directorycurrent = $variable_data_directorycurrent . $variable_data_char; - - } - - # Increment the seek counter. - - $variable_data_seek++; - - } until ($variable_data_seek eq $variable_data_length); - - return 0; - - } elsif ($variable_type eq "datetime"){ - # Check if the date and time setting format is valid. - - if ($variable_data eq ""){ - - if ($variable_noerror eq 1){ - - # The no error value is set to 1 so return - # a value of 1 (meaning that the date and - # time format was blank). - - return 1; - - } elsif ($variable_noerror eq 0){ - - # The no error value is set to 1 so return - # an error. - - kiriwrite_error("blankdatetimeformat"); - - } else { - - # The no error value is something else other - # than 0 or 1, so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } - - my $variable_data_validated = $variable_data; - $variable_data_validated =~ tr|dDmMyYhms/():[ ]||d; - - if ($variable_data_validated eq ""){ - - # The date and time format is valid. So - # skip this bit. - - } else { - - # The validated data variable is not blank, meaning - # that it contains something else, so return an error - # (or a value). - - if ($variable_noerror eq 1){ - - # The no error value is set to 1 so return - # an value of 2. (meaning that the date and - # time format was invalid). - - return 2; - - } elsif ($variable_noerror eq 0){ - - # The no error value is set to 0 so return - # an error. - - kiriwrite_error("invaliddatetimeformat"); - - } else { - - # The no error value is something else other - # than 0 or 1 so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } - - return 0; - - } elsif ($variable_type eq "directory"){ - # Check if the directory only contains letters and numbers and - # return an error if anything else appears. - - my $variable_data_validated = $variable_data; - $variable_data_validated =~ tr/a-zA-Z0-9//d; - - if ($variable_data eq ""){ - - if ($variable_noerror eq 1){ - - # The no error value is set to 1 so return - # a value of 1 (meaning that the directory - # name was blank). - - return 1; - - } elsif ($variable_noerror eq 0){ - - # The no error value is set to 1 so return - # an error. - - kiriwrite_error("blankdirectory"); - - } else { - - # The no error value is something else other - # than 0 or 1, so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } - - if ($variable_data_validated eq ""){ - - # The validated data variable is blank, meaning that - # it only contains letters and numbers. - - } else { - - # The validated data variable is not blank, meaning - # that it contains something else, so return an error - # (or a value). - - if ($variable_noerror eq 1){ - - # The no error value is set to 1 so return - # an value of 2. (meaning that the directory - # name is invalid). - - return 2; - - } elsif ($variable_noerror eq 0){ - - # The no error value is set to 0 so return - # an error. - - kiriwrite_error("invaliddirectory"); - - } else { - - # The no error value is something else other - # than 0 or 1 so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } - - return 0; - - } elsif ($variable_type eq "language_filename"){ - - # The variable type is a language filename type. - # Check if the language file name is blank and - # if it is then return an error (or value). - - if ($variable_data eq ""){ - - # The language filename is blank so check the - # no error value and return an error (or value). - - if ($variable_noerror eq 1){ - - # Language filename is blank and the no error value - # is set as 1, so return a value of 1 (saying that - # the language filename is blank). - - return 1; - - } elsif ($variable_noerror eq 0) { - - # Language filename is blank and the no error value - # is not set as 1, so return an error. - - kiriwrite_error("emptylanguagefilename"); - - } else { - - # The noerror value is something else other - # than 0 or 1 so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } - - # Set the following variables for later on. - - my $variable_data_length = 0; - my $variable_data_char = ""; - my $variable_data_seek = 0; - - # Get the length of the language file name. - - $variable_data_length = length($variable_data); - - do { - - # Get a character from the language filename passed to this - # subroutine and the character the seek counter value is set - # to. - - $variable_data_char = substr($variable_data, $variable_data_seek, 1); - - # Check if the language filename contains a forward slash or a dot, - # if the selected character is a forward slash then return an error - # (or value). - - if ($variable_data_char eq "/" || $variable_data_char eq "."){ - - # The language filename contains a forward slash or - # a dot so depending on the no error value, return - # an error or a value. - - if ($variable_noerror eq 1){ - - # Language filename contains a forward slash or a dot - # and the no error value has been set to 1, so return - # an value of 2 (saying that the language file name is - # invalid). - - return 2; - - } elsif ($variable_noerror eq 0) { - - # Language filename contains a forward slash and the no - # error value has not been set to 1, so return an error. - - kiriwrite_error("invalidlanguagefilename"); - - } else { - - # The noerror value is something else other than - # 1 or 0 so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } - - # Increment the seek counter. - - $variable_data_seek++; - - } until ($variable_data_seek eq $variable_data_length); - - return 0; - - } elsif ($variable_type eq "pagesetting"){ - - # The variable type is a page setting, so check if the page - # setting has one of the valid options. - - if ($variable_data eq 0 || $variable_data eq 1 || $variable_data eq 2 || $variable_data eq 3){ - - # The variable is one of the options above, so continue - # to the end of this section. - - } else { - - # The variable is not one of the options above, so check - # and see if a error or a value should be returned. - - if ($variable_noerror eq 1){ - - # The page setting is invalid and the no error - # value is set 1, so return a value of 1 - # (saying that the page setting value is - # invalid). - - return 1; - - } elsif ($variable_noerror eq 0) { - - # Page setting is invalid and the no error value - # is not 1, so return an error. - - kiriwrite_error("invalidvariable"); - - } else { - - # The no error value is something else other - # than 0 or 1 so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } - - return 0; - - } elsif ($variable_type eq "page_filename"){ - - # The variable type is a page filename type. Check - # if the data is empty and if it is then return an - # error (or value). - - if ($variable_data eq ""){ - - # The filename is blank so check the no error - # value and depending on it return an value - # or an error. - - if ($variable_noerror eq 1){ - - # Page filename is blank and the no error value - # is set as 1, so return a value of 1 (saying - # the filename is blank). - - return 1; - - } elsif ($variable_noerror eq 0) { - - # Page filename is blank and the no error value - # is not 1, so return an error. - - kiriwrite_error("emptypagefilename"); - - } else { - - # The no error value is something else other - # than 0 or 1 so return an error. - - kiriwrite_error("invalidvariable"); - - } - } - - # Set the following variables for later on. - - my $variable_data_length = 0; - my $variable_data_char = ""; - my $variable_data_validated = ""; - my $variable_data_seek = 0; - my $variable_data_directory = ""; - my $variable_data_directorycurrent = ""; - my $variable_data_firstlevel = 1; - - # Get the length of the filename. - - $variable_data_length = length($variable_data); - - # Check that only valid characters should be appearing in - # the filename. - - $variable_data_validated = $variable_data; - $variable_data_validated =~ tr|a-zA-Z0-9\.\/||d; - - if ($variable_data_validated ne ""){ - - # The validated variable is not blank, meaning the - # variable contains invalid characters, so return - # an error. - - kiriwrite_error("invalidfilename"); - - } - - # Check if the page filename contains the directory command - # for up a directory level and if it is, return an error - # or return with a number. - - do { - - # Get a character from the filename passed to this subroutine. - - $variable_data_char = substr($variable_data, $variable_data_seek, 1); - - # Check if the current character is the forward slash character. - - if ($variable_data_char eq "/"){ - - # Check if the current directory is blank (and on the first level), or if the - # current directory contains two dots or one dot, if it does return an error. - - if ($variable_data_directorycurrent eq "" && $variable_data_firstlevel eq 1 || $variable_data_directorycurrent eq ".." || $variable_data_directorycurrent eq "."){ - - # Check if the noerror value is set to 1, if it is return an - # number, else return an proper error. - - if ($variable_noerror eq 1){ - - # Page filename contains invalid characters and - # the no error value is set to 1 so return a - # value of 2 (meaning that the page filename - # is invalid). - - return 2; - - } elsif ($variable_noerror eq 0) { - - # Page filename contains invalid characters and - # the no error value is set to 0 so return an - # error. - - kiriwrite_error("invalidfilename"); - - } else { - - # The no error value is something else other - # than 0 or 1 so return an error. - - kiriwrite_error("invalidvariable"); - - } - - } - - # Append the forward slash, clear the current directory name and set - # the first directory level value to 0. - - $variable_data_directory = $variable_data_directory . $variable_data_char; - $variable_data_directorycurrent = ""; - $variable_data_firstlevel = 0; - - } else { - - # Append the current character to the directory name and to the current - # directory name. - - $variable_data_directory = $variable_data_directory . $variable_data_char; - $variable_data_directorycurrent = $variable_data_directorycurrent . $variable_data_char; - - } - - # Increment the seek counter. - - $variable_data_seek++; - - } until ($variable_data_seek eq $variable_data_length); - - return 0; - - } elsif ($variable_type eq "outputmodule"){ - - # The variable type is a output module filename. - - # Check if the variable_data is blank and if it is - # return an error. - - if ($variable_data eq ""){ - - # The output module is blank so check if an error - # value should be returned or a number should be - # returned. - - } else { - - } - - my $variable_data_validated = $variable_data; - $variable_data_validated =~ tr/a-zA-Z0-9//d; - - if ($variable_data_validated eq ""){ - - } else { - - kiriwrite_error("outputmoduleinvalid"); - - } - - return 0; - - } elsif ($variable_type eq "utf8"){ - - # The variable type is a UTF8 string. - - # Check if the string is a valid UTF8 string. - - if ($variable_data =~ m/^( - [\x09\x0A\x0D\x20-\x7E] # ASCII - | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte - | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs - | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte - | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates - | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 - | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 - | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 - )*$/x){ - - # The UTF-8 string is valid. - - } else { - - # The UTF-8 string is not valid, check if the no error - # value is set to 1 and return an error if it isn't. - - if ($variable_noerror eq 1){ - - # The no error value has been set to 1, so return - # a value of 1 (meaning that the UTF-8 string is - # invalid). - - return 1; - - } elsif ($variable_noerror eq 0) { - - # The no error value has been set to 0, so return - # an error. - - kiriwrite_error("invalidutf8"); - - } else { - - # The no error value is something else other than 0 - # or 1, so return an error. - - kiriwrite_error("invalidoption"); - - } - - } - - return 0; - - } else { - # Another type than the valid ones above has been specified so return an error specifying an invalid option. - kiriwrite_error("invalidoption"); - } - -} - -sub kiriwrite_convert{ -################################################################################# -# kiriwrite_convert: Converts certain characters. # -# # -# Usage; # -# # -# kiriwrite_convert(data, type); # -# # -# data Specifies the data to be used with # -# type The type of conversion to make (convert from or to kiriwrite # -# values. # -################################################################################# - - # Get the data that was passed to the subroutine. - my ($data, $type) = @_; - - if ($type eq "kiriwrite"){ - - # Convert to into the Kiriwrite format. - - $data =~ s/'/''/g; - $data =~ s/\b//g; - - } elsif ($type eq "normal_display"){ - - # Convert into a viewable format. - - $data =~ s/&/&/g; - $data =~ s/\"/"/g; - $data =~ s/'/'/g; - $data =~ s/>/>/g; - $data =~ s/ 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 = $kiriwrite_config{"system_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; - - } - - } else { - kiriwrite_error("invalidoption"); - } - - return $data; - -} - -sub kiriwrite_output_header{ -################################################################################# -# kiriwrite_output_header: Outputs the header to the browser/stdout/console. # -# # -# Usage: # -# # -# kiriwrite_output_header(mimetype); # -# # -# mimetype Specifies the mime type of the header. # -################################################################################# - - # Print a header saying that the page expires immediately since the - # date is set in the past. - - #print "Expires: Sunday, 01-Jan-06 00:00:00 GMT\n"; - #print "Content-Type: text/html; charset=utf-8\n"; - #print header(); - print header(-Expires=>'Sunday, 01-Jan-06 00:00:00 GMT', -charset=>'utf-8'); - return; -} - -sub kiriwrite_processfilename{ -################################################################################# -# kiriwrite_processfilename: Processes a name and turns it into a filename that # -# can be used by Kiriwrite. # -# # -# Usage: # -# # -# kiriwrite_processfilename(text); # -# # -# text Specifies the text to be used in the process for creating a new # -# filename. # -################################################################################# - - # Get the values that have been passed to the subroutine. - - my ($process_text) = @_; - - # Define some variables that will be used later on. - - my $processed_stageone = ""; - my $processed_stagetwo = ""; - my $processed_length = ""; - my $processed_char = ""; - my $processed_seek = 0; - my $processed_filename = ""; - - # Set the first stage value of the processed filename to the - # process filename and then filter it out to only contain - # numbers and letters (no spaces) and then convert the - # capitals to small letters. - - $processed_stageone = $process_text; - $processed_stageone =~ tr#a-zA-Z0-9##cd; - $processed_stageone =~ tr/A-Z/a-z/; - - # Now set the second stage value of the processed filename - # to the first stage value of the processed filename and - # then limit the filename down to 64 characters. - - $processed_stagetwo = $processed_stageone; - $processed_length = length($processed_stagetwo); - - # Process the second stage filename into the final - # filename and do so until the seek counter is 64 - # or reaches the length of the second stage filename. - - do { - - # Get the character that is the seek counter - # is set at. - - $processed_char = substr($processed_stagetwo, $processed_seek, 1); - - # Append to the final processed filename. - - $processed_filename = $processed_filename . $processed_char; - - # Increment the seek counter. - - $processed_seek++; - - } until ($processed_seek eq 64 || $processed_seek eq $processed_length); - - return $processed_filename; - -} - -sub kiriwrite_error{ -################################################################################# -# kiriwrite_error: Prints out an error message. # -# # -# Usage: # -# # -# kiriwrite_error(errortype); # -# # -# errortype Specifies the type of error that occured. # -################################################################################# - - # Get the error type from the subroutine. - - my ($error_type) = @_; - - # Load the list of error messages. - - my ($kiriwrite_error, %kiriwrite_error); - - %kiriwrite_error = ( - # Catch all error message. - "generic" => "An error has occured but not an error that is known to Kiriwrite.", - - # Standard error messages. - "blankfilename" => "The filename specified was blank.", - "blankvariable" => "A blank variable was specified.", - "fileexists" => "A filename specified already exists.", - "internalerror" => "An internal error has occured within Kiriwrite.", - "invalidoption" => "An invalid option was given.", - "invalidaction" => "An invalid action was specified.", - "invalidfilename" => "The filename given contains invalid characters.", - "invalidmode" => "An invalid mode was specified.", - "invalidutf8" => "A UTF-8 string is invalid.", - "invalidvariable" => "An variable with invalid data has been found.", - "variabletoolong" => "A variable given is too long.", - - # Specific error messages. - "blankcompiletype" => "The compile type specified is blank", - "blankdatabasepageadd" => "No database was specified when trying to add a page.", - "blankdirectory" => "The directory name specified was blank.", - "blankfindfilter" => "The find filter was blank.", - "blankdatetimeformat" => "The date and time format given is blank.", - "databasecategoriestoolong" => "The database categories list is too long.", - "databasecopysame" => "The database that the pages are being copied to is the same database that the pages are copied from.", - "datadirectoryinvalidpermissions" => "The database directory has invalid permission settings.", - "databasedescriptiontoolong" => "The database description is too long.", - "databasefilenameinvalid" => "The database filename is invalid.", - "databasefilenametoolong" => "The database filename is too long.", - "databasefileinvalid" => "The database file is in an invalid format.", - "databaseinvalidpermissions" => "The database has invalid permission settings.", - "databasenameinvalid" => "The database name contains invalid characters.", - "databasenametoolong" => "The database name is too long.", - "databasenameblank" => "The database name is blank.", - "databasemissingfile" => "The database file is missing.", - "databasemovemissingfile" => "The database that the pages are moving to is missing.", - "databasemovesame" => "The database that the pages are being moved to is the same database that the pages are moving from.", - "dbdirectoryblank" => "The database directory name given was blank.", - "dbdirectoryinvalid" => "The database directory name given was invalid.", - "filtersdatabasefilenotcreated" => "The filters database was not created because of the invalid permissions set for directory where Kiriwrite is being run from.", - "filtersdbinvalidformat" => "The filters database is an invalid format.", - "filtersdbpermissions" => "The filters database has invalid permission settings.", - "filtersdbmissing" => "The filters database is missing.", - "filteridblank" => "The filter identification number given is blank.", - "filterdoesnotexist" => "The filter with the identification number given does not exist.", - "filteridinvalid" => "The filter identification number given is invalid.", - "filteridtoolong" => "The filter identification number given is too long.", - "findfiltertoolong" => "The find filter given is too long.", - "filterpriorityinvalid" => "The filter priority number given is invalid.", - "filterpriorityinvalidchars" => "The filter priority given contains invalid characters.", - "filterprioritytoolong" => "The filter priority given is too long.", - "invalidcompiletype" => "The compile type given is invalid.", - "invalidpagenumber" => "The page number specified is invalid.", - "nopagesselected" => "No pages were selected.", - "invaliddirectory" => "The directory name specified was invalid.", - "invaliddatetimeformat" => "The date and time format given is invalid.", - "invalidlanguagefilename" => "An invalid language filename was given.", - "newcopydatabasedoesnotexist" => "The database that the selected pages are being copied to does not exist.", - "newcopydatabasefileinvalidpermissions" => "The database that the selected pages are being copied has invalid permissions set.", - "newcopydatabasefileinvalid" => "The database that the selected pages are being copied to is in an invalid format.", - "newmovedatabasedoesnotexist" => "The database that the selected pages are moving to does not exist.", - "newmovedatabasefileinvalidpermissions" => "The database that the selected pages are moving to has invalid permissions set.", - "newmovedatabasefileinvalid" => "The database that the selected pages are moving to is in an invalid format.", - "nodatabasesavailable" => "No databases are available for compiling.", - "nodatabaseselected" => "No databases were selected for compiling.", - "noeditvaluesselected" => "No values will be changed on the selected pages as no values for changing were selected.", - "oldcopydatabasedoesnotexist" => "The database that the selected pages are being copied to does not exist.", - "oldcopydatabasefileinvalidpermissions" => "The database that the selected pages are being copied to has invalid permissions set.", - "oldcopydatabasefileinvalid" => "The database that the selected pages are being copied to is in an invalid format.", - "oldmovedatabasedoesnotexist" => "The database that the selected pages are moving from does not exist.", - "oldmovedatabasefileinvalidpermissions" => "The database that the selected pages are moving from has invalid permissions set.", - "oldmovedatabasefileinvalid" => "The database that the selected pages are moving from is in an invalid format.", - "outputdirectoryblank" => "The output directory name given was blank.", - "outputdirectoryinvalid" => "The output directory name given was invalid.", - "outputdirectorymissing" => "The output directory is missing", - "outputdirectoryinvalidpermissions" => "The output directory has invalid permissions set.", - "outputmoduleblank" => "The output module name given is blank.", - "outputmoduleinvalid" => "The output module name given is invalid.", - "pagefilenamedoesnotexist" => "The page with the filename given does not exist.", - "pagefilenameexists" => "The page filename given already exists", - "pagefilenameinvalid" => "The page filename given is invalid.", - "pagefilenametoolong" => "The page filename given is too long.", - "pagefilenameblank" => "The page filename given is blank.", - "pagetitletoolong" => "The page title given is too long.", - "pagedescriptiontoolong" => "The page description given is too long.", - "pagesectiontoolong" => "The page section given is too long.", - "pagedatabasefilenametoolong" => "The page database filename given is too long.", - "pagesettingstoolong" => "The page settings given is too long.", - "pagesettingsinvalid" => "The page settings given are invalid.", - "pagetemplatefilenametoolong" => "The page template filename given was too long.", - "replacefiltertoolong" => "The replace filter given is too long", - "templatenameblank" => "The template name given is blank.", - "templatefilenameexists" => "A template with the given filename already exists.", - "templatefilenameinvalid" => "The template filename given is invalid.", - "templatedatabaseinvalidpermissions" => "The template database has invalid permissions.", - "templatedatabaseinvalidformat" => "The template database is in a invalid format.", - "templatedirectoryblank" => "The template directory name given was blank.", - "templatedirectoryinvalid" => "The template directory name given was invalid.", - "templatedatabasefilenotcreated" => "The template database was not created because of the invalid permissions set for the directory where Kiriwrite is being run from.", - "templatefilenametoolong" => "The template filename given is too long", - "templatenametoolong" => "The template name given is too long", - "templatedescriptiontoolong" => "The template description given is too long", - "templatedatabasemissing" => "The template database is missing.", - "templatedoesnotexist" => "The template filename given does not exist in the templates database.", - "templatefilenameblank" => "The template filename given was blank.", - ); - - # Check if the specified error is blank and if it is - # use the generic error messsage. - - if (!$kiriwrite_error{$error_type}){ - $error_type = "generic"; - } - - my $pagedata = "
Error!
" . $kiriwrite_error{$error_type} . "
"; - - kiriwrite_output_header; - kiriwrite_output_page("Error!", $pagedata, "none"); - - exit; - -} - -sub kiriwrite_get_templates{ -################################################################################# -# kiriwrite_get_templates: Get the list of templates available (and valid) from # -# the template directory. # -# # -# Usage: # -# # -# kiriwrite_get_templates(); # -################################################################################# - - # Open the template folder and get the list of database configuration files. - - opendir(TEMPLATEDIR, $kiriwrite_config{"directory_data_template"}); - my @templatedir = grep /m*\.xml/, readdir(TEMPLATEDIR); - closedir(TEMPLATEDIR); - - # Get the actual filename of the template by removing the .xml part from - # the filename. - - my $templatedir_filename = ""; - my $templatedir_filename_originallength = ""; - my $templatedir_filename_char = ""; - my $templatedir_filename_processed = ""; - my $templatedir_filename_seek = 0; - my $templatedir_filename_length = 0; - my $templatedir_filename_finallength = 0; - my @templatelist_processed; - my $templatedir_processed_filename = ""; - my @templatelist_final; - my $templatelist_final_count = 0; - - foreach $templatedir_filename (@templatedir){ - - # Get the length of the original filename. - - $templatedir_filename_length = length($templatedir_filename); - $templatedir_filename_finallength = $templatedir_filename_length - 4; - - # Get the filename minus the last four characters and put the processed - # filename into the array of processed filenames. - - $templatedir_filename_processed = substr($templatedir_filename, 0, $templatedir_filename_finallength); - - $templatelist_processed[$templatedir_filename_seek] = $templatedir_filename_processed; - - # Increment the counter. - - $templatedir_filename_seek++; - - # Clear certain variables before using them again. - - $templatedir_filename_processed = ""; - $templatedir_filename_length = 0; - $templatedir_filename_finallength = 0; - - } - - # Check that each template really does exist and put each valid - # template into the final list. - - foreach $templatedir_processed_filename (@templatelist_processed){ - - if (-e $kiriwrite_config{"directory_data_template"} . '/' . $templatedir_processed_filename){ - - # The template does exist, so add the template to the list of valid templates. - - $templatelist_final[$templatelist_final_count] = $templatedir_processed_filename; - $templatelist_final_count++; - - } - - } - - # Return the list of valid templates. - - return @templatelist_final; - -} - -sub kiriwrite_fileexists{ -################################################################################# -# kiriwrite_fileexists: Check if a file exists and returns a value depending on # -# if the file exists or not. # -# # -# Usage: # -# # -# kiriwrite_fileexists(filename); # -# # -# filename Specifies the file name to check if it exists or not. # -################################################################################# - - # Get the value that was passed to the subroutine. - - 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. +binmode STDOUT, ':utf8'; - if (-e $filename){ +# This is commented out because it uses a fair bit of CPU usage. - # Specified file does exist so return a value of 1. +#use CGI::Carp('fatalsToBrowser'); # Output errors to the browser. - return 0; - - } else { - - # Specified file does not exist so return a value of 0. - - return 1; - - } - -} - -sub kiriwrite_filepermissions{ -################################################################################# -# kiriwrite_filepermissions: Check if the file permissions of a file and return # -# either a 1 saying that the permissions are valid or return a 0 saying that # -# the permissions are invalid. # -# # -# Usage: # -# # -# kiriwrite_filepermissions(filename, [read], [write], [filemissingskip]); # -# # -# filename Specifies the filename to check for permissions. # -# read Preform check that the file is readable. # -# write Preform check that the file is writeable. # -# filemissingskip Skip the check of seeing if it can read or write if the # -# file is missing. # -################################################################################# - - # Get the values that was passed to the subroutine. - - my ($filename, $readpermission, $writepermission, $ignorechecks) = @_; - - # Check to make sure that the read permission and write permission values - # are only 1 character long. - - kiriwrite_variablecheck($readpermission, "maxlength", 1, 0); - kiriwrite_variablecheck($writepermission, "maxlength", 1, 0); - kiriwrite_variablecheck($ignorechecks, "maxlength", 1, 0); - - my $ignorechecks_result = 0; - - # Check if the file should be ignored for read and write checking if - # it doesn't exist. - - if ($ignorechecks){ - - if (-e $filename){ - - # The file exists so the checks are to be done. - - $ignorechecks_result = 0; - - } else { - - # The file does not exist so the checks don't need to - # be done to prevent false positives. - - $ignorechecks_result = 1; - - } - - } else { - - $ignorechecks_result = 0; - - } - - # Check if the file should be checked to see if it can be read. - - if ($readpermission && $ignorechecks_result eq 0){ - - # The file should be checked to see if it does contain read permissions - # and return a 0 if it is invalid. - - if (-r $filename){ - - # The file is readable, so do nothing. - - } else { - - # The file is not readable, so return 1. - - return 1; - - } - - } - - # Check if the file should be checked to see if it can be written. - - if ($writepermission && $ignorechecks_result eq 0){ - - # The file should be checked to see if it does contain write permissions - # and return a 0 if it is invalid. - - if (-w $filename){ - - # The file is writeable, so do nothing. - - } else { - - # The file is not writeable, so return 1. - - return 1; - - } - - } - - # No problems have occured, so return 0. - - return 0; - -} - -sub kiriwrite_utf8convert{ -################################################################################# -# kiriwrite_utf8convert: Properly converts values into UTF-8 and make sure # -# that the size of the string is correct when doing input validation. # -# # -# Usage: # -# # -# utfstring # The UTF-8 string to convert. # -################################################################################# - - # Get the values passed to the subroutine. - - my ($utfstring) = @_; - - # Load the Encode perl module. - - use Encode; - - # Convert the string. - - my $finalutf8 = Encode::decode_utf8( $utfstring ); - - return $finalutf8; - -} - -sub kiriwrite_critical{ -################################################################################# -# kiriwrite_critical: Displays a critical error message that cannot be # -# normally by the kiriwrite_error subroutine. # -# # -# Usage: # -# # -# errortype Specifies the type of critical error that has occured. # -################################################################################# - - # Get the value that was passed to the subroutine. - - my ($error_type) = @_; - - # Get the error type from the errortype string. - - if ($error_type eq "configfilemissing"){ - - # The error is that the Kiriwrite configuration file is missing. - # Print the header, error message and then end the script. - - print header(); - print "Critical Error: The Kiriwrite configuration file is missing! Running the setup script for Kiriwrite is recommended."; - exit; - - } elsif ($error_type eq "configfileinvalidpermissions") { - - # The error is that the Kiriwrite configuration file has invalid - # permission settings. Print the header, error messsage and then - # end the script. - - print header(); - print "Critical Error: The Kiriwrite configuration file contains invalid permission settings! Please set the valid permission settings for the configuration file."; - exit; - - } elsif ($error_type eq "outputsystemmissing") { - - # The error is that the output system module is missing. Print the - # header, error message and then end the script. - - print header(); - print "Critical Error: The output system module is missing! Running the setup script for Kiriwrite is recommended."; - exit; - - } elsif ($error_type eq "outputsysteminvalidpermissions"){ - - # The error is that the output system module has invalid permissions - # set. Print the header, error message and then end the script. - - print header(); - print "Critical Error: The output system module contains invalid permission settings! Please set the valid permission settings for the output module."; - exit; - - }else { - - # The error type is unspecified, so return a generic error message. - - print header(); - print "Critical Error: An unspecified critical error has occured."; - exit; - - } - -} - -sub kiriwrite_output_page{ -################################################################################# -# kiriwrite_output_page: Outputs the page to the browser/stdout/console. # -# # -# Usage: # -# # -# kiriwrite_output_page(pagetitle, pagedata, menutype); # -# # -# pagetitle Specifies the page title. # -# pagedata Specifies the page data. # -# menutype Prints out which menu to use. # -################################################################################# - - my ($pagetitle, $pagedata, $menutype) = @_; - - # Open the script page template and load it into the scriptpage variable, - # while declaring the variable. +# Declare global variables for Kiriwrite settings and languages. - open (SCRIPTPAGE, 'page.html'); - my @scriptpage = ; - close (SCRIPTPAGE); - - # Define the variables required. - - my $scriptpageline = ""; - my $pageoutput = ""; - my $menuoutput = ""; - - # Print out the main menu for Kiriwrite. - - $menuoutput = "View Databases | View Pages | View Filters | View Templates | Compile Pages | View Settings\r\n
"; - - # Check what menu is going to be printed along with the default 'top' menu. - - if ($menutype eq "database"){ - # If the menu type is database then print out the database sub-menu. - $menuoutput = $menuoutput . "Show Databases | Add Database"; - - } elsif ($menutype eq "pages"){ - # If the menu type is pages then print out the pages sub-menu. - - # First, fetch the database name from the HTTP query string. - - my $query = new CGI; - my $db_filename = $query->param('database'); - - # Check if a value has been placed in the db_filename string. - - if (!$db_filename){ - - # As the database filename is blank, don't add an option to add a page. - - } else { - - # A database file has been specified so add an option to add a page to - # the selected database. - - $menuoutput = $menuoutput . "Add Page"; - - } - - } elsif ($menutype eq "filter"){ - - # If the menu type is filters then print out the filter sub-menu. - $menuoutput = $menuoutput . "Show Filters | Add Filter"; - - } elsif ($menutype eq "settings"){ - - # If the menu type is options then print out the options sub-menu. - $menuoutput = $menuoutput . "Show Settings | Edit Settings"; - - } elsif ($menutype eq "template"){ - - # If the menu type is template then print out the template sub-menu. - $menuoutput = $menuoutput . "Show Templates | Add Template"; - - } elsif ($menutype eq "compile"){ - - # If the menu type is compile then print out the compile sub-menu. - $menuoutput = $menuoutput . "Compile All | Clean Output Directory"; - - } - - # Find tages and replace with the apporiate variables. - - foreach $scriptpageline (@scriptpage){ - - $scriptpageline =~ s//$menuoutput/g; - $scriptpageline =~ s//$pagedata/g; - - - # Check if page title specified is blank, otherwise add a page title - # to the title. - - if ($pagetitle eq ""){ - $scriptpageline =~ s///g; - } else { - $scriptpageline =~ s// ($pagetitle)/g; - } +our ($kiriwrite_config, %kiriwrite_config, %kiriwrite_lang, $kiriwrite_lang, $kiriwrite_version, %kiriwrite_version, $kiriwrite_env, %kiriwrite_env, $kiriwrite_presmodule, $kiriwrite_dbmodule, $kiriwrite_script_name, $kiriwrite_env_path); +our ($form_data, %form_data); - # Append processed line to the pageoutput variable. - - $pageoutput = $pageoutput . $scriptpageline; - - } - - # Print out the page to the browser/console/stdout. - - print $pageoutput; - - return; +# If you are using mod_perl please change these settings to the correct +# directory where this script is being run from. -} +use lib '.'; +chdir('.'); -sub kiriwrite_output_xml{ -################################################################################# -# kiriwrite_output_xml: Outputs several types of data to an XML file # -# # -# Usage: # -# # -# kiriwrite_output_xml(filename, type, data); # -# # -# filename Specifies the filename of the XML file. # -# type Specifies the type of the XML file to be written. # -# newsettings Specifies the new settings for the XML file. # -################################################################################# +# Load the common functions module. - # Get the variables passed from the subroutine. +use Modules::System::Common; - my ($xml_filename, $xml_type, @newsettings) = @_; - - # Check if filename is blank, if it is then return an error. - - if ($xml_filename eq ""){ - # Filename is blank, return an error. - kiriwrite_error("blankfilename"); - } - - # Validate the XML filename to make sure nothing supicious is being passed. - - kiriwrite_variablecheck($xml_filename, "maxlength", 64, 0); - kiriwrite_variablecheck($xml_filename, "filename", "", 0); - - # Check what type of XML data to output. - - if ($xml_type eq "config") { - - # The type of XML data to output is a Kiriwrite configuration file. - - # Get the data that has been passed to xml_data from the subroutine and - # split them into seperate values. - - my ($xml_config_databasedir, $xml_config_outputdir, $xml_config_imagesuri, $xml_config_datetime, $xml_config_systemlanguage, $xml_config_outputsystem) = @newsettings; - - # Create the XML data layout. - - my $xmldata = "\r\n\r\n\r\n"; - - $xmldata = $xmldata . "\r\n"; - $xmldata = $xmldata . "\t\r\n\t\t\r\n"; - - $xmldata = $xmldata . "\t\t\t" . $xml_config_databasedir . "\r\n"; - $xmldata = $xmldata . "\t\t\t" . $xml_config_outputdir . "\r\n"; - $xmldata = $xmldata . "\t\t\t" . $xml_config_imagesuri . "\r\n"; - $xmldata = $xmldata . "\t\t\r\n"; - - $xmldata = $xmldata . "\t\t\r\n"; - $xmldata = $xmldata . "\t\t\t" . $xml_config_systemlanguage . "\r\n"; - $xmldata = $xmldata . "\t\t\r\n"; - - $xmldata = $xmldata . "\t\t\r\n"; - $xmldata = $xmldata . "\t\t\t" . $xml_config_outputsystem . "\r\n"; - $xmldata = $xmldata . "\t\t\t" . $xml_config_datetime . "\r\n"; - $xmldata = $xmldata . "\t\t\r\n"; - - $xmldata = $xmldata . "\t\r\n"; - - $xmldata = $xmldata . ""; +# Setup the version information for Kiriwrite. - # Open the Kiriwrite XML configuration file and write the new settings to the - # configuration file. - - open(XMLCONFIG, "> kiriwrite.xml"); - print XMLCONFIG $xmldata; - close(XMLCONFIG); - - } else { - - # The type of XML data is something else that is not supported by - # Kiriwrite, so return an error. - - kiriwrite_error("invalidoption"); - - } - - return; +%kiriwrite_version = ( + "major" => 0, + "minor" => 5, + "revision" => 0 +); -} +kiriwrite_initalise; # Initalise the Kiriwrite enviroment. +kiriwrite_settings_load; # Load the configuration options. -################################################################################# -# End listing the functions needed. # -################################################################################# +my $query_lite = new CGI::Lite; -################################################################################# -# Begin proper script execution. # -################################################################################# +# Check if a mode has been specified and if a mode has been specified, continue +# and work out what mode has been specified. -kiriwrite_settings_load; # Load the configuration options. +$form_data = $query_lite->parse_form_data(); -my $query = new CGI; # Easily fetch variables from the HTTP string. +if ($form_data->{'mode'}){ + my $http_query_mode = $form_data->{'mode'}; + if ($http_query_mode eq "db"){ + use Modules::System::Database; -# Check if a mode has been specified and if a mode has been specified, continue -# and work out what mode has been specified. + if ($form_data->{'action'}){ + # An action has been specified, so find out what action has been specified. -if ($query->param('mode')){ - my $http_query_mode = $query->param('mode'); - - if ($http_query_mode eq "db"){ - - # If mode is 'db' (database), then check what action is required. + my $http_query_action = $form_data->{'action'}; - if ($query->param('action')){ - # An action has been specified, so find out what action has been specified. - - my $http_query_action = $query->param('action'); - if ($http_query_action eq "edit"){ # The edit action (which mean edit the settings for the selected database) has been specified, # get the database name and check if the action to edit an database has been confirmed. - - if ($query->param('database')){ + + if ($form_data->{'database'}){ # If there is a value in the database variable check if it is a valid database. Otherwise, # return an error. - - my $http_query_database = $query->param('database'); - + + my $http_query_database = $form_data->{'database'}; + # Check if a value for confirm has been specified, if there is, check if it is the correct # value, otherwise return an error. - - if ($query->param('confirm')){ + + if ($form_data->{'confirm'}){ # A value for confirm has been specified, find out what value it is. If the value is correct # then edit the database settings, otherwise return an error. - - my $http_query_confirm = $query->param('confirm'); - - if ($http_query_confirm eq "yes"){ + + my $http_query_confirm = $form_data->{'confirm'}; + + if ($http_query_confirm eq 1){ # Value is correct, collect the variables to pass onto the database variable. - - # Load the XML::Simple module. - - use XML::Simple; - my $xsl = XML::Simple->new(); - + # Get the variables from the HTTP query. - - my $newdatabasename = $query->param('databasename'); - my $newdatabasedescription = $query->param('databasedescription'); - my $newdatabasefilename = $query->param('databasefilename'); - my $databasename = $query->param('olddatabasename'); - my $databasedescription = $query->param('olddatabasedescription'); - my $databaseshortname = $query->param('database'); - my $databasenotes = $query->param('databasenotes'); - my $databasecategories = $query->param('databasecategories'); - - # Check the permissions of the database configuration file and return - # an error if the database permissions are invalid. - + + my $newdatabasename = $form_data->{'databasename'}; + my $newdatabasedescription = $form_data->{'databasedescription'}; + my $newdatabasefilename = $form_data->{'databasefilename'}; + my $databaseshortname = $form_data->{'database'}; + my $databasenotes = $form_data->{'databasenotes'}; + my $databasecategories = $form_data->{'databasecategories'}; + # Pass the variables to the database editing subroutine. - - my $pagedata = kiriwrite_database_edit($databaseshortname, $databasename, $databasedescription, $newdatabasefilename, $newdatabasename, $newdatabasedescription, $databasenotes, $databasecategories, 1); - + + my $pagedata = kiriwrite_database_edit($databaseshortname, $newdatabasefilename, $newdatabasename, $newdatabasedescription, $databasenotes, $databasecategories, 1); + kiriwrite_output_header; - kiriwrite_output_page("Database Edited", $pagedata, "database"); + kiriwrite_output_page($kiriwrite_lang{database}{editdatabasetitle}, $pagedata, "database"); exit; - + } else { # Value is incorrect, return and error. kiriwrite_error("invalidvariable"); } - + } - + # Display the form for editing an database. my $pagedata = kiriwrite_database_edit($http_query_database); - + kiriwrite_output_header; - kiriwrite_output_page("Edit Database", $pagedata, "database"); + kiriwrite_output_page($kiriwrite_lang{database}{editdatabasetitle}, $pagedata, "database"); exit; - + } else { - + # If there is no value in the database variable, then return an error. kiriwrite_error("invalidvariable"); - - } - + + } + } elsif ($http_query_action eq "delete"){ - + # Action equested is to delete a database, find out if the user has already confirmed deletion of the database # and if the deletion of the database has been confirmed, delete the database. - - if ($query->param('confirm')){ - + + if ($form_data->{'confirm'}){ + # User has confirmed to delete a database, pass the parameters to the kiriwrite_database_delete # subroutine. - - my $database_filename = $query->param('database'); - my $database_confirm = $query->param('confirm'); + + my $database_filename = $form_data->{'database'}; + my $database_confirm = $form_data->{'confirm'}; my $pagedata = kiriwrite_database_delete($database_filename, $database_confirm); - + kiriwrite_output_header; - kiriwrite_output_page("Delete Database", $pagedata, "database"); - + kiriwrite_output_page($kiriwrite_lang->{database}->{deleteddatabase}, $pagedata, "database"); + exit; - + } - + # User has clicked on the delete link (thus hasn't confirmed the action to delete a database). - - my $database_filename = $query->param('database'); + + my $database_filename = $form_data->{'database'}; my $pagedata = kiriwrite_database_delete($database_filename); - + kiriwrite_output_header; - kiriwrite_output_page("Delete Database", $pagedata, "database"); - + kiriwrite_output_page($kiriwrite_lang->{database}->{deletedatabase}, $pagedata, "database"); + exit; - + } elsif ($http_query_action eq "new"){ - + # Action requested is to create a new database, find out if the user has already entered the information needed # to create a database and see if the user has confirmed the action, otherwise printout a form for adding a # database. - - my $http_query_confirm = $query->param('confirm'); - + + my $http_query_confirm = $form_data->{'confirm'}; + # Check if the confirm value is correct. - + if ($http_query_confirm){ if ($http_query_confirm eq 1){ - + # User has confirmed to create a database, pass the parameters to the # kiriwrite_database_add subroutine. - - my $http_query_confirm = $query->param('confirm'); - - my $database_name = $query->param('databasename'); - my $database_description = $query->param('databasedescription'); - my $database_filename = $query->param('databasefilename'); - my $database_notes = $query->param('databasenotes'); - my $database_categories = $query->param('databasecategories'); - + + my $http_query_confirm = $form_data->{'confirm'}; + + my $database_name = $form_data->{'databasename'}; + my $database_description = $form_data->{'databasedescription'}; + my $database_filename = $form_data->{'databasefilename'}; + my $database_notes = $form_data->{'databasenotes'}; + my $database_categories = $form_data->{'databasecategories'}; + my $pagedata = kiriwrite_database_add($database_filename, $database_name, $database_description, $database_notes, $database_categories, $http_query_confirm); - + kiriwrite_output_header; - kiriwrite_output_page("Add Database", $pagedata, "database"); + kiriwrite_output_page($kiriwrite_lang{database}{adddatabase}, $pagedata, "database"); exit; - + } else { - + # The confirm value is something else other than 1 (which it shouldn't be), so # return an error. - + } } - + # User has clicked on the 'Add Database' link. - - my $pagedata = kiriwrite_database_add; - + + my $pagedata = kiriwrite_database_add(); + kiriwrite_output_header; - kiriwrite_output_page("Add Database", $pagedata, "database"); + kiriwrite_output_page($main::kiriwrite_lang{database}{adddatabase}, $pagedata, "database"); exit; - + } else { # Another option has been specified, so return an error. - - kiriwrite_error("invalidaction"); - } - } - # No action has been specified, do the default action of displaying a list - # of databases. + kiriwrite_error("invalidaction"); + } + + } else { + + # No action has been specified, do the default action of displaying a list + # of databases. - my $pagedata = kiriwrite_database_list; - - kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("", $pagedata, "database"); # Output the page to browser/console/stdout. - exit; # End the script. - + my $pagedata = kiriwrite_database_list(); + + kiriwrite_output_header; # Output the header to browser/console/stdout. + kiriwrite_output_page("", $pagedata, "database"); # Output the page to browser/console/stdout. + exit; # End the script. + + } + } elsif ($http_query_mode eq "page"){ - - # If mode is 'page', then check what action is required. - - if ($query->param('action')){ - my $http_query_action = $query->param('action'); + + use Modules::System::Page; + + if ($form_data->{'action'}){ + my $http_query_action = $form_data->{'action'}; # Check if the action requested matches with one of the options below. If it does, # go to that section, otherwise return an error. - + if ($http_query_action eq "view"){ - + # The action selected was to view pages from a database, - - my $database_name = $query->param('database'); - my $pagedata = kiriwrite_page_list($database_name); - + + my $http_query_database = $form_data->{'database'}; + my $http_query_browsenumber = $form_data->{'browsenumber'}; + my $pagedata = kiriwrite_page_list($http_query_database, $http_query_browsenumber); + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Viewing Database", $pagedata, "pages"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang->{pages}->{viewingdatabase}, $pagedata, "pages", $http_query_database); # Output the page to browser/console/stdout. exit; # End the script. - + } elsif ($http_query_action eq "add"){ - + # The action selected was to add a page to the selected database. - - my $http_query_confirm = $query->param('confirm'); - + + my $http_query_confirm = $form_data->{'confirm'}; + if (!$http_query_confirm){ - + $http_query_confirm = 0; - + } - + if ($http_query_confirm eq 1){ - - my $http_query_database = $query->param('database'); - my $http_query_filename = $query->param('pagefilename'); - my $http_query_name = $query->param('pagename'); - my $http_query_description = $query->param('pagedescription'); - my $http_query_section = $query->param('pagesection'); - my $http_query_template = $query->param('pagetemplate'); - my $http_query_settings = $query->param('pagesettings'); - my $http_query_content = $query->param('pagecontent'); - + + my $http_query_database = $form_data->{'database'}; + my $http_query_filename = $form_data->{'pagefilename'}; + my $http_query_name = $form_data->{'pagename'}; + my $http_query_description = $form_data->{'pagedescription'}; + my $http_query_section = $form_data->{'pagesection'}; + my $http_query_template = $form_data->{'pagetemplate'}; + my $http_query_settings = $form_data->{'pagesettings'}; + my $http_query_content = $form_data->{'pagecontent'}; + my $pagedata = kiriwrite_page_add($http_query_database, $http_query_filename, $http_query_name, $http_query_description, $http_query_section, $http_query_template, $http_query_settings, $http_query_content, $http_query_confirm); - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Add Page", $pagedata, "pages"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{pages}{addpage}, $pagedata, "pages"); # Output the page to browser/console/stdout. exit; # End the script. - + } - - my $http_query_database = $query->param('database'); + + my $http_query_database = $form_data->{'database'}; my $pagedata = kiriwrite_page_add($http_query_database); - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Add Page", $pagedata, "pages"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{pages}{addpage}, $pagedata, "pages"); # Output the page to browser/console/stdout. exit; # End the script. - - } elsif ($http_query_action eq "edit"){ - - # The action selected was to edit a page from a database. - - my $http_query_confirm = $query->param('confirm'); + + } elsif ($http_query_action eq "edit"){ + # The action selected was to edit a page from a database. + + my $http_query_confirm = $form_data->{'confirm'}; + if (!$http_query_confirm){ - + $http_query_confirm = 0; - + } - + if ($http_query_confirm eq 1){ - + # Get the needed values from the HTTP query. - - my $http_query_database = $query->param('database'); - my $http_query_filename = $query->param('page'); - my $http_query_newfilename = $query->param('pagefilename'); - my $http_query_name = $query->param('pagename'); - my $http_query_description = $query->param('pagedescription'); - my $http_query_section = $query->param('pagesection'); - my $http_query_template = $query->param('pagetemplate'); - my $http_query_settings = $query->param('pagesettings'); - my $http_query_content = $query->param('pagecontent'); - + + my $http_query_database = $form_data->{'database'}; + my $http_query_filename = $form_data->{'page'}; + my $http_query_newfilename = $form_data->{'pagefilename'}; + my $http_query_name = $form_data->{'pagename'}; + my $http_query_description = $form_data->{'pagedescription'}; + my $http_query_section = $form_data->{'pagesection'}; + my $http_query_template = $form_data->{'pagetemplate'}; + my $http_query_settings = $form_data->{'pagesettings'}; + my $http_query_content = $form_data->{'pagecontent'}; + # Pass the values to the editing pages subroutine. - + my $pagedata = kiriwrite_page_edit($http_query_database, $http_query_filename, $http_query_newfilename, $http_query_name, $http_query_description, $http_query_section, $http_query_template, $http_query_settings, $http_query_content, $http_query_confirm); - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Edit Page", $pagedata, "pages"); # Output the page to browser/console/stdout. - exit; # End the script. - + kiriwrite_output_page($kiriwrite_lang{pages}{editpagetitle}, $pagedata, "pages"); # Output the page to browser/console/stdout. + exit; # End the script. + } - + # Get the needed values from the HTTP query. - - my $http_query_database = $query->param('database'); - my $http_query_filename = $query->param('page'); - + + my $http_query_database = $form_data->{'database'}; + my $http_query_filename = $form_data->{'page'}; + # Pass the values to the editing pages subroutine. - + my $pagedata = kiriwrite_page_edit($http_query_database, $http_query_filename); - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Edit Page", $pagedata, "pages"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{pages}{editpagetitle}, $pagedata, "pages"); # Output the page to browser/console/stdout. exit; # End the script. - - - } elsif ($http_query_action eq "delete"){ + } elsif ($http_query_action eq "delete"){ + # The action selected was to delete a page from a database. - - my $http_query_database = $query->param('database'); - my $http_query_page = $query->param('page'); - my $http_query_confirm = $query->param('confirm'); - + + my $http_query_database = $form_data->{'database'}; + my $http_query_page = $form_data->{'page'}; + my $http_query_confirm = $form_data->{'confirm'}; + my $pagedata = ""; my $selectionlist = ""; - + if ($http_query_confirm){ - + # The action has been confirmed, so try to delete the selected page # from the database. - + $pagedata = kiriwrite_page_delete($http_query_database, $http_query_page, $http_query_confirm); - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Delete Page", $pagedata, "pages"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{pages}{deletepagetitle}, $pagedata, "pages"); # Output the page to browser/console/stdout. exit; # End the script. - + } - + $pagedata = kiriwrite_page_delete($http_query_database, $http_query_page); - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Delete Page", $pagedata, "pages"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{pages}{deletepagetitle}, $pagedata, "pages"); # Output the page to browser/console/stdout. exit; # End the script. - - + } elsif ($http_query_action eq "multidelete"){ # The action selected was to delete multiple pages from a # database. - - my $http_query_database = $query->param('database'); - my $http_query_confirm = $query->param('confirm'); - + + my $http_query_database = $form_data->{'database'}; + my $http_query_confirm = $form_data->{'confirm'}; + my @filelist; my $pagedata; - if ($http_query_confirm){ - + if ($http_query_confirm eq 1){ + # The action to delete multiple pages from the selected # database has been confirmed. - - @filelist = kiriwrite_selectedlist(); + + @filelist = kiriwrite_selectedlist($form_data); $pagedata = kiriwrite_page_multidelete($http_query_database, $http_query_confirm, @filelist); - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Delete selected pages", $pagedata, "pages"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{pages}{deletemultiplepages}, $pagedata, "pages"); # Output the page to browser/console/stdout. exit; # End the script. - + } - + # Get the list of selected pages and pass them to the # multiple page delete subroutine. - - @filelist = kiriwrite_selectedlist(); + + @filelist = kiriwrite_selectedlist($form_data); $pagedata = kiriwrite_page_multidelete($http_query_database, $http_query_confirm, @filelist); - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Delete selected pages", $pagedata, "pages"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{pages}{deletemultiplepages}, $pagedata, "pages"); # Output the page to browser/console/stdout. exit; # End the script. } elsif ($http_query_action eq "multimove"){ # The action selected was to move multiple pages from a # database. - - my $http_query_database = $query->param('database'); - my $http_query_newdatabase = $query->param('newdatabase'); - my $http_query_confirm = $query->param('confirm'); - - my @filelist; - my $pagedata; - - if ($http_query_confirm){ - - # The action to move multiple pages from the selected - # database has been confirmed. - - @filelist = kiriwrite_selectedlist(); - $pagedata = kiriwrite_page_multimove($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist); - - kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Move selected pages", $pagedata, "pages"); # Output the page to browser/console/stdout. - exit; # End the script. - - } - - # Get the list of selected pages and pass them to the - # multiple page move subroutine. - - @filelist = kiriwrite_selectedlist(); - $pagedata = kiriwrite_page_multimove($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist); - - kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Move selected pages", $pagedata, "pages"); # Output the page to browser/console/stdout. - exit; # End the script. - - } elsif ($http_query_action eq "multicopy"){ - - # The action selected was to copy multiple pages from a - # database. - - my $http_query_database = $query->param('database'); - my $http_query_newdatabase = $query->param('newdatabase'); - my $http_query_confirm = $query->param('confirm'); - - my @filelist; - my $pagedata; - - if ($http_query_confirm){ - - # The action to copy multiple pages from the selected - # database has been confirmed. - - @filelist = kiriwrite_selectedlist(); - $pagedata = kiriwrite_page_multicopy($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist); - - kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Copy selected pages", $pagedata, "pages"); # Output the page to browser/console/stdout. - exit; # End the script. - - } - - # Get the list of selected pages and pass them to the - # multiple page copy subroutine. - - @filelist = kiriwrite_selectedlist(); - $pagedata = kiriwrite_page_multicopy($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist); - - kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Copy selected pages", $pagedata, "pages"); # Output the page to browser/console/stdout. - exit; # End the script. - - } elsif ($http_query_action eq "multiedit"){ - - # The action selected was to edit multiple pages from a - # database. - - my $http_query_database = $query->param('database'); - my $http_query_newsection = $query->param('newsection'); - my $http_query_altersection = $query->param('altersection'); - my $http_query_newtemplate = $query->param('newtemplate'); - my $http_query_altertemplate = $query->param('altertemplate'); - my $http_query_newsettings = $query->param('newsettings'); - my $http_query_altersettings = $query->param('altersettings'); - my $http_query_confirm = $query->param('confirm'); - - my @filelist; - my $pagedata; - - if (!$http_query_confirm){ - - @filelist = kiriwrite_selectedlist(); - $pagedata = kiriwrite_page_multiedit($http_query_database, $http_query_newsection, $http_query_altersection, $http_query_newtemplate, $http_query_altertemplate, $http_query_newsettings, $http_query_altersettings, $http_query_confirm, @filelist); - - kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Edit selected pages", $pagedata, "pages"); # Output the page to browser/console/stdout. - exit; - - } - - # Get the list of selected pages and pass them to the - # multiple page edit subroutine. - - @filelist = kiriwrite_selectedlist(); - $pagedata = kiriwrite_page_multiedit($http_query_database, $http_query_newsection, $http_query_altersection, $http_query_newtemplate, $http_query_altertemplate, $http_query_newsettings, $http_query_altersettings, $http_query_confirm, @filelist); - - kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Edit selected pages", $pagedata, "pages"); # Output the page to browser/console/stdout. - exit; # End the script. - - } else { - kiriwrite_error("invalidaction"); - } - - } else { - - # If there the action option is left blank, then print out a form where the database - # can be selected to view pages from. - - my $pagedata = kiriwrite_page_list; - - kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Database Selection", $pagedata, "pages"); # Output the page to browser/console/stdout. - exit; # End the script. - - } - - # No action has been specified, do the default action of listing pages from - # the first database found in the directory. - - } elsif ($http_query_mode eq "filter"){ - - # If there's a value for action in the HTTP query, then - # get that value that is in the HTTP query. - if ($query->param('action')){ + my $http_query_database = $form_data->{'database'}; + my $http_query_newdatabase = $form_data->{'newdatabase'}; + my $http_query_confirm = $form_data->{'confirm'}; - # There is a value for action in the HTTP query, - # so get the value from it. - - my $http_query_action = $query->param('action'); - - if ($http_query_action eq "add"){ + my @filelist; + my $pagedata; - # The action the user requested is to add a filter to the - # filters database. - - # Check if there is a value in confirm and if there is - # then pass it on to the new find and replace words - # to add to the filter database. - - my $http_query_confirm = $query->param('confirm'); - if ($http_query_confirm){ - - # There is a value in http_query_confirm, so pass on the - # new find and replace words so that they can be added - # to the filters database. - - my $http_query_findwords = $query->param('findword'); - my $http_query_replacewords = $query->param('replaceword'); - my $http_query_priority = $query->param('priority'); - my $http_query_notes = $query->param('notes'); - - my $pagedata = kiriwrite_filter_add($http_query_findwords, $http_query_replacewords, $http_query_priority, $http_query_notes, $http_query_confirm); - + + # The action to move multiple pages from the selected + # database has been confirmed. + + @filelist = kiriwrite_selectedlist($form_data); + $pagedata = kiriwrite_page_multimove($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist); + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Add Filters", $pagedata, "filter"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{pages}{movepages}, $pagedata, "pages"); # Output the page to browser/console/stdout. exit; # End the script. - + } - - my $pagedata = kiriwrite_filter_add(); - + + # Get the list of selected pages and pass them to the + # multiple page move subroutine. + + @filelist = kiriwrite_selectedlist($form_data); + $pagedata = kiriwrite_page_multimove($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist); + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Add Filters", $pagedata, "filter"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{pages}{movepages}, $pagedata, "pages"); # Output the page to browser/console/stdout. exit; # End the script. - - } elsif ($http_query_action eq "edit"){ - # The action the user requested is to edit an filter from - # the filters database. - - my $http_query_number = $query->param('filter'); - my $http_query_confirm = $query->param('confirm'); - + } elsif ($http_query_action eq "multicopy"){ + + # The action selected was to copy multiple pages from a + # database. + + my $http_query_database = $form_data->{'database'}; + my $http_query_newdatabase = $form_data->{'newdatabase'}; + my $http_query_confirm = $form_data->{'confirm'}; + + my @filelist; + my $pagedata; + if ($http_query_confirm){ - - # There is a value in http_query_confirm, so pass on the - # new find and replace words so that the filters database - # can be edited. - - my $http_query_findwords = $query->param('filterfind'); - my $http_query_replacewords = $query->param('filterreplace'); - my $http_query_priority = $query->param('priority'); - my $http_query_notes = $query->param('notes'); - - my $pagedata = kiriwrite_filter_edit($http_query_number, $http_query_findwords, $http_query_replacewords, $http_query_priority, $http_query_notes, $http_query_confirm); - + + # The action to copy multiple pages from the selected + # database has been confirmed. + + @filelist = kiriwrite_selectedlist($form_data); + $pagedata = kiriwrite_page_multicopy($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist); + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Edit Filter", $pagedata, "filter"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{pages}{copypages}, $pagedata, "pages"); # Output the page to browser/console/stdout. exit; # End the script. - + } - - my $pagedata = kiriwrite_filter_edit($http_query_number); + + # Get the list of selected pages and pass them to the + # multiple page copy subroutine. + + @filelist = kiriwrite_selectedlist($form_data); + $pagedata = kiriwrite_page_multicopy($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist); + + kiriwrite_output_header; # Output the header to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{pages}{copypages}, $pagedata, "pages"); # Output the page to browser/console/stdout. + exit; # End the script. - kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Edit Filter", $pagedata, "filter"); # Output the page to browser/console/stdout. - exit; # End the script. - - } elsif ($http_query_action eq "delete"){ + } elsif ($http_query_action eq "multiedit"){ + + # The action selected was to edit multiple pages from a + # database. + + my $http_query_database = $form_data->{'database'}; + my $http_query_newsection = $form_data->{'newsection'}; + my $http_query_altersection = $form_data->{'altersection'}; + my $http_query_newtemplate = $form_data->{'newtemplate'}; + my $http_query_altertemplate = $form_data->{'altertemplate'}; + my $http_query_newsettings = $form_data->{'newsettings'}; + my $http_query_altersettings = $form_data->{'altersettings'}; + my $http_query_confirm = $form_data->{'confirm'}; + + my @filelist; + my $pagedata; + + if (!$http_query_confirm){ + + @filelist = kiriwrite_selectedlist($form_data); + $pagedata = kiriwrite_page_multiedit($http_query_database, $http_query_newsection, $http_query_altersection, $http_query_newtemplate, $http_query_altertemplate, $http_query_newsettings, $http_query_altersettings, $http_query_confirm, @filelist); + + kiriwrite_output_header; # Output the header to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{pages}{multiedit}, $pagedata, "pages"); # Output the page to browser/console/stdout. + exit; - # The action the user requested is to delete an filter - # from the filters database. - - my $http_query_number = $query->param('filter'); - my $http_query_confirm = $query->param('confirm'); - - if ($http_query_confirm){ - - my $pagedata = kiriwrite_filter_delete($http_query_number, $http_query_confirm); - - kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Delete Filter", $pagedata, "filter"); # Output the page to browser/console/stdout. - exit; # End the script - } - - my $pagedata = kiriwrite_filter_delete($http_query_number); - - kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Delete Filter", $pagedata, "filter"); # Output the page to browser/console/stdout. - exit; # End the script. - } else { + # Get the list of selected pages and pass them to the + # multiple page edit subroutine. - # Another action was requested that was not one of - # the ones prcedding this catch all, so return - # an error saying that an invalid option was - # specified. - - kiriwrite_error("invalidaction"); + @filelist = kiriwrite_selectedlist($form_data); + $pagedata = kiriwrite_page_multiedit($http_query_database, $http_query_newsection, $http_query_altersection, $http_query_newtemplate, $http_query_altertemplate, $http_query_newsettings, $http_query_altersettings, $http_query_confirm, @filelist); + kiriwrite_output_header; # Output the header to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{pages}{multiedit}, $pagedata, "pages"); # Output the page to browser/console/stdout. + exit; # End the script. + + } else { + kiriwrite_error("invalidaction"); } - + } else { + + # If there the action option is left blank, then print out a form where the database + # can be selected to view pages from. + + my $pagedata = kiriwrite_page_list(); - my $pagedata = kiriwrite_filter_list(); - kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("View Filters", $pagedata, "filter"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{pages}{databaseselecttitle}, $pagedata, ""); # Output the page to browser/console/stdout. exit; # End the script. - + } - - - + } elsif ($http_query_mode eq "template"){ - - # Check if an action has been specified in the HTTP query. - - if ($query->param('action')){ - + + use Modules::System::Template; + + if ($form_data->{'action'}){ + # An action has been specified in the HTTP query. - my $http_query_action = $query->param('action'); - + my $http_query_action = $form_data->{'action'}; + if ($http_query_action eq "delete"){ # Get the required parameters from the HTTP query. - - my $http_query_template = $query->param('template'); - my $http_query_confirm = $query->param('confirm'); - + + my $http_query_template = $form_data->{'template'}; + my $http_query_confirm = $form_data->{'confirm'}; + # Check if a value for confirm has been specified (it shouldn't) # be blank. - - if ($http_query_confirm eq ""){ + + if (!$http_query_confirm){ # The confirm parameter of the HTTP query is blank, so # write out a form asking the user to confirm the deletion # of the selected template. - + my $pagedata = kiriwrite_template_delete($http_query_template); - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Delete Template", $pagedata, "template"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{template}{deletetemplate}, $pagedata, "template"); # Output the page to browser/console/stdout. exit; # End the script. - + } else { - + my $pagedata = kiriwrite_template_delete($http_query_template, $http_query_confirm); - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Delete Template", $pagedata, "template"); # Output the page to browser/console/stdout. - exit; # End the script. - + kiriwrite_output_page($kiriwrite_lang{template}{deletetemplate}, $pagedata, "template"); # Output the page to browser/console/stdout. + exit; # End the script. + } - + } elsif ($http_query_action eq "add") { - + # Get the variables from the HTTP query in preperation for processing. - - my $http_query_confirm = $query->param('confirm'); - my $http_query_templatelayout = $query->param('templatelayout'); - my $http_query_templatename = $query->param('templatename'); - my $http_query_templatedescription = $query->param('templatedescription'); - my $http_query_templatefilename = $query->param('templatefilename'); - + + my $http_query_confirm = $form_data->{'confirm'}; + my $http_query_templatelayout = $form_data->{'templatelayout'}; + my $http_query_templatename = $form_data->{'templatename'}; + my $http_query_templatedescription = $form_data->{'templatedescription'}; + my $http_query_templatefilename = $form_data->{'templatefilename'}; + # Check if there is a confirmed value in the http_query_confirm variable. - + if (!$http_query_confirm){ - + # Since there is no confirm value, print out a form for creating a new # template. - + my $pagedata = kiriwrite_template_add(); - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Add Template", $pagedata, "template"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{template}{addtemplate}, $pagedata, "template"); # Output the page to browser/console/stdout. exit; # End the script. - + } else { - + # A value in the http_query_confirm value is specified, so pass the # variables onto the kiriwrite_template_add subroutine. - + my $pagedata = kiriwrite_template_add($http_query_templatefilename, $http_query_templatename, $http_query_templatedescription, $http_query_templatelayout, $http_query_confirm); - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Add Template", $pagedata, "template"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{template}{addtemplate}, $pagedata, "template"); # Output the page to browser/console/stdout. exit; # End the script. - + } - + } elsif ($http_query_action eq "edit") { - - # Get the required parameters from the HTTP query. - - my $http_query_templatefile = $query->param('template'); - my $http_query_confirm = $query->param('confirm'); - + + # Get the required parameters from the HTTP query. + + my $http_query_templatefile = $form_data->{'template'}; + my $http_query_confirm = $form_data->{'confirm'}; + # Check to see if http_query_confirm has a value of '1' in it and # if it does, edit the template using the settings providied. - + if (!$http_query_confirm){ - + # Since there is no confirm value, open the template configuration # file and the template file itself then print out the data on to # the form. - + my $pagedata = kiriwrite_template_edit($http_query_templatefile); kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Edit Template", $pagedata, "template"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{template}{edittemplate}, $pagedata, "template"); # Output the page to browser/console/stdout. exit; # End the script. - + } elsif ($http_query_confirm eq 1) { - + # Since there is a confirm value of 1, the user has confirm the # action of editing of a template so get the other variables # that were also sent and pass the variables to the subroutine. - - my $http_query_newfilename = $query->param('newfilename'); - my $http_query_newname = $query->param('newname'); - my $http_query_newdescription = $query->param('newdescription'); - my $http_query_newlayout = $query->param('newlayout'); - + + my $http_query_newfilename = $form_data->{'newfilename'}; + my $http_query_newname = $form_data->{'newname'}; + my $http_query_newdescription = $form_data->{'newdescription'}; + my $http_query_newlayout = $form_data->{'newlayout'}; + my $pagedata = kiriwrite_template_edit($http_query_templatefile, $http_query_newfilename, $http_query_newname, $http_query_newdescription, $http_query_newlayout, $http_query_confirm); kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Edit Template", $pagedata, "template"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{template}{edittemplate}, $pagedata, "template"); # Output the page to browser/console/stdout. + exit; # End the script. + + } else { + + # Another confirm value is there instead of '0' or '1'. Return + # an error saying it is invalid. + + kiriwrite_error("invalidvariable"); + + } + + } elsif ($http_query_action eq "view"){ + + # Get the required parameters from the HTTP query. + + my $http_query_browsenumber = $form_data->{'browsenumber'}; + + my $pagedata = kiriwrite_template_list($http_query_browsenumber); + + kiriwrite_output_header; # Output the header to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{template}{viewtemplates}, $pagedata, "template"); # Output the page to browser/console/stdout. + exit; # End the script. + + } else { + + # Another action was specified and was not one of the ones above, so + # return an error. + + kiriwrite_error("invalidaction"); + + } + + } else { + + # If the action option is left blank, then print out a form where the list + # of templates are available. + + my $pagedata = kiriwrite_template_list(); + + kiriwrite_output_header; # Output the header to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{template}{viewtemplates}, $pagedata, "template"); # Output the page to browser/console/stdout. + exit; # End the script. + + } + + } elsif ($http_query_mode eq "filter"){ + + use Modules::System::Filter; + + if ($form_data->{'action'}){ + + # There is a value for action in the HTTP query, + # so get the value from it. + + my $http_query_action = $form_data->{'action'}; + + if ($http_query_action eq "add"){ + + # The action the user requested is to add a filter to the + # filter database. + + # Check if there is a value in confirm and if there is + # then pass it on to the new find and replace words + # to add to the filter database. + + my $http_query_confirm = $form_data->{'confirm'}; + + if ($http_query_confirm){ + + # There is a value in http_query_confirm, so pass on the + # new find and replace words so that they can be added + # to the filter database. + + my $http_query_findwords = $form_data->{'findword'}; + my $http_query_replacewords = $form_data->{'replaceword'}; + my $http_query_priority = $form_data->{'priority'}; + my $http_query_enabled = $form_data->{'enabled'}; + my $http_query_notes = $form_data->{'notes'}; + + my $pagedata = kiriwrite_filter_add({ FindFilter => $http_query_findwords, ReplaceFilter => $http_query_replacewords, Priority => $http_query_priority, Enabled => $http_query_enabled, Notes => $http_query_notes, Confirm => $http_query_confirm }); + #my $pagedata = kiriwrite_filter_add($http_query_findwords, $http_query_replacewords, $http_query_priority, $http_query_notes, $http_query_confirm); + + kiriwrite_output_header; # Output the header to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{filter}{addfilter}, $pagedata, "filter"); # Output the page to browser/console/stdout. + exit; # End the script. + + } + + my $pagedata = kiriwrite_filter_add(); + + kiriwrite_output_header; # Output the header to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{filter}{addfilter}, $pagedata, "filter"); # Output the page to browser/console/stdout. + exit; # End the script. + + } elsif ($http_query_action eq "edit"){ + + # The action the user requested is to edit an filter from + # the filter database. + + my $http_query_number = $form_data->{'filter'}; + my $http_query_confirm = $form_data->{'confirm'}; + + if ($http_query_confirm){ + + # There is a value in http_query_confirm, so pass on the + # new find and replace words so that the filter database + # can be edited. + + my $http_query_findwords = $form_data->{'filterfind'}; + my $http_query_replacewords = $form_data->{'filterreplace'}; + my $http_query_priority = $form_data->{'priority'}; + my $http_query_notes = $form_data->{'notes'}; + my $http_query_enabled = $form_data->{'enabled'}; + + my $pagedata = kiriwrite_filter_edit({ FilterID => $http_query_number, NewFindFilter => $http_query_findwords, NewReplaceFilter => $http_query_replacewords, NewPriority => $http_query_priority, NewEnabled => $http_query_enabled, NewFilterNotes => $http_query_notes, Confirm => $http_query_confirm }); + + kiriwrite_output_header; # Output the header to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{filter}{editfilter}, $pagedata, "filter"); # Output the page to browser/console/stdout. exit; # End the script. - - } else { - - # Another confirm value is there instead of '0' or '1'. Return - # an error saying it is invalid. - - kiriwrite_error("invalidvariable"); - + } - + + my $pagedata = kiriwrite_filter_edit({ FilterID => $http_query_number }); + + kiriwrite_output_header; # Output the header to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{filter}{editfilter}, $pagedata, "filter"); # Output the page to browser/console/stdout. + exit; # End the script. + + } elsif ($http_query_action eq "delete"){ + + # The action the user requested is to delete an filter + # from the filter database. + + my $http_query_number = $form_data->{'filter'}; + my $http_query_confirm = $form_data->{'confirm'}; + + if ($http_query_confirm){ + + my $pagedata = kiriwrite_filter_delete($http_query_number, $http_query_confirm); + + kiriwrite_output_header; # Output the header to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{filter}{deletefilter}, $pagedata, "filter"); # Output the page to browser/console/stdout. + exit; # End the script + + } + + my $pagedata = kiriwrite_filter_delete($http_query_number); + + kiriwrite_output_header; # Output the header to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{filter}{deletefilter}, $pagedata, "filter"); # Output the page to browser/console/stdout. + exit; # End the script. + + } elsif ($http_query_action eq "view"){ + + # The action the user requested is to view the list + # filters on the filter database. + + my $http_query_browsenumber = $form_data->{'browsenumber'}; + + my $pagedata = kiriwrite_filter_list($http_query_browsenumber); + + kiriwrite_output_header; # Output the header to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{filter}{viewfilters}, $pagedata, "filter"); # Output the page to browser/console/stdout. + exit; # End the script. + } else { - - # Another action was specified and was not one of the ones above, so - # return an error. - + + # Another action was requested that was not one of + # the ones prcedding this catch all, so return + # an error saying that an invalid option was + # specified. + kiriwrite_error("invalidaction"); - + } - + } else { - # If the action option is left blank, then print out a form where the list - # of templates are available. - - my $pagedata = kiriwrite_template_list; - + my $pagedata = kiriwrite_filter_list(); + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("View Templates", $pagedata, "template"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{filter}{viewfilters}, $pagedata, "filter"); # Output the page to browser/console/stdout. exit; # End the script. } - + } elsif ($http_query_mode eq "compile"){ + + use Modules::System::Compile; + + if ($form_data->{'action'}){ - # The mode selected is to compile pages from databases. - - # If the action option is left blank, then print out a form where the list - # of databases to compile are available. - - if ($query->param('action')){ - - my $http_query_action = $query->param('action'); + my $http_query_action = $form_data->{'action'}; if ($http_query_action eq "compile"){ - + # The specified action is to compile the pages, check if the # action to compile the page has been confirmed. - - my $http_query_confirm = $query->param('confirm'); - my $http_query_type = $query->param('type'); - + + my $http_query_confirm = $form_data->{'confirm'}; + my $http_query_type = $form_data->{'type'}; + # If it is blank, set the confirm value to 0. - + if (!$http_query_confirm){ - + # The http_query_confirm variable is uninitalised, so place a # '0' (meaning an unconfirmed action). - + $http_query_confirm = 0; - + } - + # If the compile type is blank then return an error. - + if (!$http_query_type){ - + # Compile type is blank so return an error. - + kiriwrite_error("blankcompiletype"); - + } - - if ($http_query_type eq "multiple"){ - + + if ($http_query_type eq "multiple"){ + if ($http_query_confirm eq 1){ - + # The action to compile the pages has been confirmed so # compile the pages. - - my @selectedlist = kiriwrite_selectedlist(); - my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, @selectedlist); - + + my $http_query_override = $form_data->{'enableoverride'}; + my $http_query_overridetemplate = $form_data->{'overridetemplate'}; + my $http_query_outputmodule = $form_data->{'outputmodule'}; + + my @selectedlist = kiriwrite_selectedlist($form_data); + my %form_data_hash = $query_lite->parse_form_data; + kiriwrite_compile_loadhash(%form_data_hash); + my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, $http_query_override, $http_query_overridetemplate, $http_query_outputmodule, @selectedlist); + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Compiled Pages", $pagedata, "compile"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{compile}{compilepages}, $pagedata, "compile"); # Output the page to browser/console/stdout. exit; # End the script. - + } else { - + # The action to compile the pages has not been confirmed # so write a form asking the user to confirm the action # of compiling the pages. - - my @selectedlist = kiriwrite_selectedlist(); - my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, @selectedlist); - + + my $http_query_outputmodule = $form_data->{'outputmodule'}; + + my @selectedlist = kiriwrite_selectedlist($form_data); + my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, "", "", $http_query_outputmodule, @selectedlist); + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Compile mulitple databases", $pagedata, "compile"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{compile}{compileselecteddatabases}, $pagedata, "compile"); # Output the page to browser/console/stdout. exit; # End the script. - + } - + } elsif ($http_query_type eq "single"){ - - my $http_query_database = $query->param('database'); + + my $http_query_database = $form_data->{'database'}; + my $http_query_outputmodule = $form_data->{'outputmodule'}; my @selectedlist; $selectedlist[0] = $http_query_database; - my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, @selectedlist); - + my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, "", "", $http_query_outputmodule, @selectedlist); + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Compile one database", $pagedata, "compile"); + kiriwrite_output_page($kiriwrite_lang{compile}{compiledatabase}, $pagedata, "compile"); exit; # End the script. - + } else { - + kiriwrite_error("invalidcompiletype"); - + } - + } elsif ($http_query_action eq "all"){ - + # The selected action is to compile all of the databases # in the database directory. Check if the action to # compile all of the databases has been confirmed. - - my $http_query_confirm = $query->param('confirm'); - + + my $http_query_confirm = $form_data->{'confirm'}; + my $http_query_outputmodule = $form_data->{'outputmodule'}; + if (!$http_query_confirm){ - + # The http_query_confirm variable is uninitalised, so place a # '0' (meaning an unconfirmed action). - + $http_query_confirm = 0; - - } - - if ($http_query_confirm eq 1){ - - # The action to compile all the databases has been confirmed. - + } - - my $pagedata = kiriwrite_compile_all(); - + + my $pagedata = kiriwrite_compile_all($http_query_outputmodule); + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Compile All Databases", $pagedata, "compile"); + kiriwrite_output_page($kiriwrite_lang{compile}{compilealldatabases}, $pagedata, "compile"); exit; - + } elsif ($http_query_action eq "clean") { - + # The selected action is to clean the output directory. # Check if the action to clean the output directory # has been confirmed. - - my $http_query_confirm = $query->param('confirm'); - + + my $http_query_confirm = $form_data->{'confirm'}; + if (!$http_query_confirm){ - + # The http_query_confirm variable is uninitalised, so place a # '0' (meaning an unconfirmed action). - + $http_query_confirm = 0; - + } - + if ($http_query_confirm eq 1){ - + # The action to clean the output directory has been confirmed. - + my $pagedata = kiriwrite_compile_clean($http_query_confirm); - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Clean Output Directory", $pagedata, "compile"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{compile}{cleanoutputdirectory}, $pagedata, "compile"); # Output the page to browser/console/stdout. exit; # End the script. - + } - + # The action to clean the output directory is not # confirmed, so write a page asking the user # to confirm cleaning the output directory. - + my $pagedata = kiriwrite_compile_clean(); - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Clean Output Directory", $pagedata, "compile"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{compile}{cleanoutputdirectory}, $pagedata, "compile"); # Output the page to browser/console/stdout. exit; # End the script. - + } else { - + # The action specified was something else other than those # above, so return an error. - + kiriwrite_error("invalidaction"); - + } } - my $pagedata = kiriwrite_compile_list; + my $pagedata = kiriwrite_compile_list(); kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Compile Pages", $pagedata, "compile"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{compile}{compilepages}, $pagedata, "compile"); # Output the page to browser/console/stdout. exit; # End the script. } elsif ($http_query_mode eq "settings"){ - - # The mode selected is view (and change settings). - - # If the action value has been left blank, then view the list of - # current settings. + + use Modules::System::Settings; + + if ($form_data->{'action'}){ + my $http_query_action = $form_data->{'action'}; - if ($query->param('action')){ - my $http_query_action = $query->param('action'); - if ($http_query_action eq "edit"){ - + # The action specified is to edit the settings. Check if the action # to edit the settings has been confirmed. - - my $http_query_confirm = $query->param('confirm'); - + + my $http_query_confirm = $form_data->{'confirm'}; + if (!$http_query_confirm){ - + # The confirm value is blank, so set it to 0. - + $http_query_confirm = 0; - + } - + if ($http_query_confirm eq 1){ - + # The action to edit the settings has been confirmed. Get the # required settings from the HTTP query. - - my $http_query_database = $query->param('databasedir'); - my $http_query_output = $query->param('outputdir'); - my $http_query_imagesuri = $query->param('imagesuripath'); - my $http_query_datetimeformat = $query->param('datetime'); - my $http_query_systemlanguage = $query->param('language'); - my $http_query_outputsystem = $query->param('outputsys'); - - my $pagedata = kiriwrite_settings_edit($http_query_database, $http_query_output, $http_query_imagesuri, $http_query_datetimeformat, $http_query_systemlanguage, $http_query_outputsystem, $http_query_confirm); - + + my $http_query_database = $form_data->{'databasedir'}; + my $http_query_output = $form_data->{'outputdir'}; + my $http_query_imagesuri = $form_data->{'imagesuripath'}; + my $http_query_datetimeformat = $form_data->{'datetime'}; + my $http_query_systemlanguage = $form_data->{'language'}; + my $http_query_presmodule = $form_data->{'presmodule'}; + my $http_query_dbmodule = $form_data->{'dbmodule'}; + my $http_query_outputmodule = $form_data->{'outputmodule'}; + my $http_query_textareacols = $form_data->{'textareacols'}; + my $http_query_textarearows = $form_data->{'textarearows'}; + my $http_query_pagecount = $form_data->{'pagecount'}; + my $http_query_filtercount = $form_data->{'filtercount'}; + my $http_query_templatecount = $form_data->{'templatecount'}; + + my $http_query_database_server = $form_data->{'database_server'}; + my $http_query_database_port = $form_data->{'database_port'}; + my $http_query_database_protocol = $form_data->{'database_protocol'}; + my $http_query_database_sqldatabase = $form_data->{'database_sqldatabase'}; + my $http_query_database_username = $form_data->{'database_username'}; + my $http_query_database_passwordkeep = $form_data->{'database_password_keep'}; + my $http_query_database_password = $form_data->{'database_password'}; + my $http_query_database_tableprefix = $form_data->{'database_tableprefix'}; + + my $pagedata = kiriwrite_settings_edit({ DatabaseDirectory => $http_query_database, OutputDirectory => $http_query_output, ImagesURIPath => $http_query_imagesuri, DateTimeFormat => $http_query_datetimeformat, SystemLanguage => $http_query_systemlanguage, PresentationModule => $http_query_presmodule, OutputModule => $http_query_outputmodule, TextAreaCols => $http_query_textareacols, TextAreaRows => $http_query_textarearows, PageCount => $http_query_pagecount, FilterCount => $http_query_filtercount, TemplateCount => $http_query_templatecount, DatabaseModule => $http_query_dbmodule, DatabaseServer => $http_query_database_server, DatabasePort => $http_query_database_port, DatabaseProtocol => $http_query_database_protocol, DatabaseSQLDatabase => $http_query_database_sqldatabase, DatabaseUsername => $http_query_database_username, DatabasePasswordKeep => $http_query_database_passwordkeep, DatabasePassword => $http_query_database_password, DatabaseTablePrefix => $http_query_database_tableprefix, Confirm => 1 }); + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Edit Settings", $pagedata, "settings"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{setting}{editsettings}, $pagedata, "settings"); # Output the page to browser/console/stdout. exit; # End the script. - + } - + # The action to edit the settings has not been confirmed. - - my $pagedata = kiriwrite_settings_edit; - + + my $pagedata = kiriwrite_settings_edit(); + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Edit Settings", $pagedata, "settings"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{setting}{editsettings}, $pagedata, "settings"); # Output the page to browser/console/stdout. exit; # End the script. - + } else { - + # The action specified was something else other than those # above, so return an error. - + kiriwrite_error("invalidaction"); - + } - + } - + # No action has been specified, so print out the list of settings currently being used. - my $pagedata = kiriwrite_settings_view; + my $pagedata = kiriwrite_settings_view(); kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("View Settings", $pagedata, "settings"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang{setting}{viewsettings}, $pagedata, "settings"); # Output the page to browser/console/stdout. exit; # End the script. - + } else { - # Another mode has been specified than the ones above, so return an error saying that - # an invalid option was specified. - + + # An invalid mode has been specified so return + # an error. + kiriwrite_error("invalidmode"); + } - + } else { # No mode has been specified, so print the default "first-run" view of the # database list. - my $pagedata = kiriwrite_database_list; - - kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("", $pagedata, "database"); # Output the page to browser/console/stdout. - exit; # End the script. - -} - -__END__ - -=head1 NAME - -Kiriwrite - -=head1 DESCRIPTION - -Web-based webpage compiler. + use Modules::System::Database; -=head1 AUTHOR + my $pagedata = kiriwrite_database_list(); -Steve Brokenshire - -=head1 USAGE - -This perl script is intended to be used on a web server which has CGI with Perl support or with mod_perl support. - -=head1 DOCUMENTATION - -For more information on how to use Kiriwrite, please see the documentation that was included with Kiriwrite. - -- From the Xestia Documentation website: http://documentation.xestia.co.uk and click on the Kiriwrite link on the page. + kiriwrite_output_header; # Output the header to browser/console/stdout. + kiriwrite_output_page("", $pagedata, "database"); # Output the page to browser/console/stdout. + exit; # End the script. -- From the Documentation directory from the Kiriwrite source packages (.tar/.tar.gz/.tar.bz2). +} -- In the /usr/share/doc/kiriwrite directory if you installed the distribution-specific packages (and also have access to the server itself). \ No newline at end of file +__END__ \ No newline at end of file