From: kirinji Date: Sun, 5 Aug 2007 01:55:33 +0000 (+0000) Subject: Very major changes to Kiriwrite have been made to make it modular so it X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=5c83799dbb0ae75ceb5f6fc6feaa8030f1fb87aa;p=kiriwrite%2F.git Very major changes to Kiriwrite have been made to make it modular so it can support different types of database formats, output formats and languages. - Database support for MySQL databases and file-based database support with the SQLite database mmodule. - Presentation support for HTML 4.0 Strict. - Language support implemented with the hardcoded language seperated and put into a language file (English (British)). - Installer script also created to help with installing Kiriwrite. --- diff --git a/cgi-files/kiriwrite.cgi b/cgi-files/kiriwrite.cgi index 2b061b6..3cf6c47 100755 --- a/cgi-files/kiriwrite.cgi +++ b/cgi-files/kiriwrite.cgi @@ -25,35 +25,61 @@ use strict; # Throw errors if there's something wrong. use warnings; # Write warnings to the HTTP Server Log file. use utf8; -use CGI qw(:standard); +use CGI qw(:standard); use CGI::Carp('fatalsToBrowser'); # Output errors to the browser. +use Tie::IxHash; # Declare global variables for Kiriwrite settings and languages. -our($kiriwrite_config, %kiriwrite_config, $kiriwrite_lang, %kiriwrite_lang, $kiriwrite_version, %kiriwrite_version); +my ($kiriwrite_config, %kiriwrite_config, $kiriwrite_lang, $kiriwrite_version, %kiriwrite_version, $kiriwrite_env, %kiriwrite_env, $kiriwrite_presmodule, $kiriwrite_dbmodule); # Setup the version information for Kiriwrite. %kiriwrite_version = ( "major" => 0, - "minor" => 0, - "revision" => 2 + "minor" => 1, + "revision" => 0 ); +sub BEGIN{ ################################################################################# -# Begin listing the functions needed. # +# BEGIN: Get the enviroment stuff # ################################################################################# -#sub AUTOLOAD{ -################################################################################# -# AUTOLOAD: Catch-all for subroutines that do not exist. # -################################################################################# + # Get the script filename. + + my $env_script_name = $ENV{'SCRIPT_NAME'}; + + # Process the script filename until there is only the + # filename itself. + + my $env_script_name_length = length($env_script_name); + my $filename_seek = 0; + my $filename_char = ""; + my $filename_last = 0; + + do { + $filename_char = substr($env_script_name, $filename_seek, 1); + if ($filename_char eq "/"){ + $filename_last = $filename_seek + 1; + } + $filename_seek++; + } until ($filename_seek eq $env_script_name_length || $env_script_name_length eq 0); + + my $env_script_name_finallength = $env_script_name_length - $filename_last; + my $script_filename = substr($env_script_name, $filename_last, $env_script_name_finallength); - # A subroutine given does not exist so return an error. + # Setup the needed enviroment variables for Kiriwrite. + + %kiriwrite_env = ( + "script_filename" => $script_filename, + ); -# kiriwrite_error("internalerror"); +} -#} +################################################################################# +# Begin listing the functions needed. # +################################################################################# sub kiriwrite_page_add{ ################################################################################# @@ -78,17 +104,11 @@ sub kiriwrite_page_add{ # 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; } @@ -117,7 +137,7 @@ sub kiriwrite_page_add{ # 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); + my $pagedatabase_length_check = kiriwrite_variablecheck($pagedatabase, "maxlength", 32, 1); if ($pagedatabase_length_check eq 1){ @@ -126,7 +146,7 @@ sub kiriwrite_page_add{ kiriwrite_error("databasefilenametoolong"); } - + if ($confirm eq "1"){ # Check all the variables to see if they UTF8 valid. @@ -154,12 +174,12 @@ sub kiriwrite_page_add{ # 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 $pagedatabase_maxlength_check = kiriwrite_variablecheck($pagedatabase, "maxlength", 32, 1); my $pagesettings_maxlength_check = kiriwrite_variablecheck($pagesettings, "maxlength", 1, 1); my $pagetemplate_maxlength_check = kiriwrite_variablecheck($pagetemplate, "maxlength", 64, 1); @@ -223,9 +243,9 @@ sub kiriwrite_page_add{ # The action to create a new page has been confirmed, so add the page to the # selected database. - + if (!$pagefilename){ - kiriwrite_error("pagefilenameblank"); + kiriwrite_error("pagefilenameblank"); } # Check the page filename and page settings. @@ -233,7 +253,7 @@ sub kiriwrite_page_add{ 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 @@ -243,7 +263,7 @@ sub kiriwrite_page_add{ } - if ($pagefilename_filename_check eq 1){ + if ($pagefilename_filename_check ne 0){ # The page filename given is invalid, so return an error. @@ -267,289 +287,465 @@ sub kiriwrite_page_add{ } - # Check the permissions of the page database. + # Check if the database has write permissions. - 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); + my $database_permissions = $kiriwrite_dbmodule->dbpermissions($pagedatabase, 1, 1); - if ($pagedatabase_exists eq 1){ + if ($database_permissions eq 1){ - # The page database does not exist, so return an error. + # The database permissions are invalid so return an error. - kiriwrite_error("databasefilemissing"); + kiriwrite_error("databaseinvalidpermissions"); } - if ($pagedatabase_permissions eq 1){ + # Connect to the database server. + + $kiriwrite_dbmodule->connect(); - # The page database permissions are invalid, so return + # Check if any errors occured while connecting to the database server. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ + + # A database connection error has occured so return # an error. - kiriwrite_error("databaseinvalidpermissions"); + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); } - - # 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. + # Select the database to add the page to. - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename . '\' LIMIT 1') or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); + $kiriwrite_dbmodule->selectdb({ DatabaseName => $pagedatabase }); - my @database_page; - my $page_exists = 0; + # Check if any errors had occured while selecting the database. + + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ + + # The database does not exist, so return an error. + + kiriwrite_error("databasemissingfile"); - while (@database_page = $string_handle->fetchrow_array()){ + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - # The page exists so set the page exists value to 1. + # The database has invalid permissions set, so return + # an error. - $page_exists = 1; + kiriwrite_error("databaseinvalidpermissions"); } - if ($page_exists eq 1){ + # Get information about the database. - # The page exists so return an error. + my %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - kiriwrite_error("pagefilenameexists"); + # Check if any error occured while getting the database information. - } + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # Get the database name. + # A database error has occured so return an error and + # also the extended error information. - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1'); - $string_handle->execute(); + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - 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. + # Add the page to the selected database. - 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"); + $kiriwrite_dbmodule->addpage({ PageFilename => $pagefilename, PageName => $pagetitle, PageDescription => $pagedescription, PageSection => $pagesection, PageTemplate => $pagetemplate, PageContent => $pagefiledata, PageSettings => $pagesettings }); - # Create the last modified date. + # Check if any errors occured while adding the page. - my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; + if ($kiriwrite_dbmodule->geterror eq "PageExists"){ - my $pagelastmodified = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; + # A page with the filename given already exists so + # return an error. - # Add the page to the database. + kiriwrite_error("pagefilenameexists"); - $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(); + } elsif ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # Convert certain variables so that display properly. + # A database error has occured so return an error + # with extended error information. - my $pagetitle_display = kiriwrite_convert($pagetitle, "normal_display"); - my $database_name_display = kiriwrite_convert($database_name, "normal_display"); + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); + + } + + my $database_name = $database_info{"DatabaseName"}; + + # Disconnect from the database server. + + $kiriwrite_dbmodule->disconnect(); + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{addpage}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{pageaddedmessage}, $pagetitle, $database_name)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $pagedatabase, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name) }); + + return $kiriwrite_presmodule->grab(); - $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_list; + my %template_info; + my @templates_list; + my %database_info; + my $template_filename; + my $template_name; my $template_data = ""; - - my $database_handle; - my $string_handle; - my $template_warningmessage; my $template_warning = 0; + my $template_count = 0; + my $template; - my @database_template; - my @database_page; + tie(%template_list, 'Tie::IxHash'); - if ($database_page_exists eq 1){ + # Connect to the database server. - # The page database does not exists so return an - # error. + $kiriwrite_dbmodule->connect(); - kiriwrite_error("databasemissingfile"); + # Check if any errors occured while connecting to the database server. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ + + # A database connection error has occured so return + # an error. + + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); } - if ($database_page_permissions eq 1){ + # Select the database. - # The page database permissions are invalid so - # return an error. + $kiriwrite_dbmodule->selectdb({ DatabaseName => $pagedatabase }); + + # Check if any errors had occured while selecting the database. + + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ + + # The database does not exist, so return an error. + + kiriwrite_error("databasemissingfile"); + + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ + + # The database has invalid permissions set, so return + # an error. kiriwrite_error("databaseinvalidpermissions"); } - if ($database_template_exists eq 1){ + # Check if the database has write permissions. + + my $database_permissions = $kiriwrite_dbmodule->dbpermissions($pagedatabase, 1, 1); + + if ($database_permissions eq 1){ - # The template database does not exist so - # write a message to say that the template - # database is missing, none assumed. + # The database permissions are invalid so return an error. - $template_warningmessage = "Template database does not exist. No template will be used."; - $template_warning = 1; + kiriwrite_error("databaseinvalidpermissions"); } - if ($database_template_permissions eq 1 && $database_template_exists ne 1){ + # Get information about the database. - # The template permissions are invalid so - # write a message saying that the template - # database has invalid permissions set, - # none assumed. + %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - $template_warningmessage = "Template database has invalid permissions set. No template will be used."; - $template_warning = 1; + # Check if any error occured while getting the database information. - } + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # Check if the template_warning value is set to 1 and - # if it isn't then load the template database. + # A database error has occured so return an error and + # also the extended error information. - if ($template_warning eq 0){ + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - # The template_warning value is not set to 1, so - # load the template database. + }; - my $page_filename = ""; - my $page_name = ""; - my $template_count = 0; + # Connect to the template database. - # Load the SQLite database. + $kiriwrite_dbmodule->connecttemplate(); - $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(); + # Check if any errors occured while connecting to the template database. - $template_data = ""; + # Get the list of templates available. - if ($template_count eq 0){ + @templates_list = $kiriwrite_dbmodule->gettemplatelist(); - # There are no templates in the template database - # so write a message saying that no templates - # are in the template database. + # Check if any errors had occured. - $template_warningmessage = "There are no templates in the template database. No template will be used."; + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ + + # A database error occured while getting the list + # of templates so return a warning message with the + # extended error information. + + $template_warningmessage = kiriwrite_language($kiriwrite_lang->{pages}->{templatedatabaseerror}, $kiriwrite_dbmodule->geterror(1)); $template_warning = 1; } - } + if ($template_warning eq 0){ - # Load the page database and get the page database - # name. + # Check to see if there are any templates in the templates + # list array. + + my $template_filename = ""; + my $template_name = ""; + + foreach $template (@templates_list){ + + # Get information about the template. + + %template_info = $kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template }); + + # Check if any error occured while getting the template information. + + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ + + # A database error has occured, so return an error. + + kiriwrite_error("templatedatabaseerror", $kiriwrite_dbmodule->geterror(1)); + + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){ + + # The template does not exist, so process the next template. + + next; - $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(); + } + + # Get the template filename and name. + + $template_filename = $template_info{"TemplateFilename"}; + $template_name = $template_info{"TemplateName"}; + + $template_list{$template_count}{Filename} = $template_filename; + $template_list{$template_count}{Name} = $template_name; + + $template_count++; + + } + + # Check if the final template list is blank. - @database_page = $string_handle->fetchrow_array(); + if (!%template_list){ - my $database_name = $database_page[0]; + # The template list is blank so write the template + # warning message. - $database_name = kiriwrite_convert($database_name, "normal_display"); - $pagedatabase = kiriwrite_convert($pagedatabase, "normal_display"); + $template_warningmessage = $kiriwrite_lang->{pages}->{notemplatesavailable}; - $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 . ""; + } + + } + + } + + my $database_name = $database_info{"DatabaseName"}; + + # Disconnect from the template database. + + $kiriwrite_dbmodule->disconnecttemplate(); + + # Disconnect from the database server. + + $kiriwrite_dbmodule->disconnect(); + + # write out the form for adding a page. + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{addpage}, { Style => "pageheader" }); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "page"); + $kiriwrite_presmodule->addhiddendata("action", "add"); + $kiriwrite_presmodule->addhiddendata("database", $pagedatabase); + $kiriwrite_presmodule->addhiddendata("confirm", "1"); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 }); + + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{setting}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{value}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endheader(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{database}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtext($database_name); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagename}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("pagename", { Size => 64, MaxLength => 512 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagedescription}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("pagedescription", { Size => 64, MaxLength => 512 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagesection}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("pagesection", { Size => 64, MaxLength => 256 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagetemplate}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + + # Check if the template warning value has been set + # and write the error message in place of the templates + # list if it is. if ($template_warning eq 1){ - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; + $kiriwrite_presmodule->addhiddendata("pagetemplate", "!none"); + $kiriwrite_presmodule->addtext($template_warningmessage); } else { - $pagedata = $pagedata . ""; + my $template_file; + my $page_filename; + my $page_name; - } + $kiriwrite_presmodule->addselectbox("pagetemplate"); + + foreach $template_file (keys %template_list){ + + $page_filename = $template_list{$template_file}{Filename}; + $page_name = $template_list{$template_file}{Name}; + $kiriwrite_presmodule->addoption($page_name . " (" . $page_filename . ")", { Value => $page_filename }); + $template_count++; + + $template_count = 0; + } + + $kiriwrite_presmodule->addoption($kiriwrite_lang->{pages}->{usenotemplate}, { Value => "!none", Selected => 1 }); + $kiriwrite_presmodule->endselectbox(); + + } + + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagefilename}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("pagefilename", { Size => 64, MaxLength => 256 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagecontent}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtextbox("pagecontent", { Columns => 50, Rows => 10 }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); + $kiriwrite_presmodule->addboldtext($kiriwrite_lang->{common}->{tags}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagetitle}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagename}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagedescription}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagesection}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pageautosection}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pageautotitle}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->endbox(); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagesettings}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepageandsection}, Value => "1", Selected => 1, LineBreak => 1}); + $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepagename}, Value => "2", Selected => 0, LineBreak => 1}); + $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usesectionname}, Value => "3", Selected => 0, LineBreak => 1}); + $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{nopagesection}, Value => "0", Selected => 0, LineBreak => 1}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->endtable(); + + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{addpagebutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addreset($kiriwrite_lang->{common}->{clearvalues}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $pagedatabase, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name) }); + $kiriwrite_presmodule->endform(); + + return $kiriwrite_presmodule->grab(); - $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"); - + } - + } @@ -569,12 +765,6 @@ sub kiriwrite_page_delete{ 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. @@ -597,7 +787,7 @@ sub kiriwrite_page_delete{ # 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); + my $pagedatabase_length_check = kiriwrite_variablecheck($database, "maxlength", 32, 1); if ($pagedatabase_length_check eq 1){ @@ -617,223 +807,255 @@ sub kiriwrite_page_delete{ 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. + # Connect to the database server. - 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); + $kiriwrite_dbmodule->connect(); - # Check the results and return an error if needed. + # Check if any errors occured while connecting to the database server. - if ($database_check_exists eq 1){ + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - # The database file does not exist, so return an error. + # A database connection error has occured so return + # an error. - kiriwrite_error("databasemissingfile"); + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); } - if ($database_check_permissions eq 1){ + # Select the database to delete the page from. - # The database file has invalid permissions set, so - # return an error. + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database }); + + # Check if any errors had occured while selecting the database. + + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ + + # The database does not exist, so return an error. + + kiriwrite_error("databasemissingfile"); + + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ + + # The database has invalid permissions set, so return + # an error. kiriwrite_error("databaseinvalidpermissions"); } - # Load the SQLite database and get information about the - # database. + # Check if the database has write permissions. - 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_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1); - my @database_info; - my $database_name; - @database_info = $string_handle->fetchrow_array(); - $database_name = $database_info[0]; + if ($database_permissions eq 1){ + + # The database permissions are invalid so return an error. + + kiriwrite_error("databaseinvalidpermissions"); - my $pagefilename_sql = kiriwrite_convert($page, "kiriwrite"); + } - # Check if the filename exists and return an error if it - # isn't. + # Get the information about the database. - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename_sql . '\' LIMIT 1'); - $string_handle->execute(); + my %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - my @database_page; - my $page_found = 0; + # Check if any error occured while getting the database information. - while (@database_page = $string_handle->fetchrow_array()){ + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - $page_found = 1; + # A database error has occured so return an error and + # also the extended error information. + + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); } - # Check if the page wasn't found and return an error if it - # didn't. + # Get the information about the page that is going to be deleted. - if ($page_found eq 0){ + my %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $page }); - # Page wasn't found in the database so return - # an error. + # Check if any errors occured while getting the page information. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ + + # A database error has occured so return an error and + # also the extended error information. + + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); + + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ + + # The page does not exist, so return an error. kiriwrite_error("pagefilenamedoesnotexist"); } - # Get information about the page (mainly the name). + # Delete the page from the database. - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename_sql . '\' LIMIT 1'); - $string_handle->execute(); + $kiriwrite_dbmodule->deletepage({ PageFilename => $page }); - my $page_name; - @database_page = $string_handle->fetchrow_array(); - $page_name = $database_page[1]; + # Check if any errors occured while deleting the page from the database. - # Delete the page from the database. + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ + + # A database error has occured so return an error and + # also the extended error information. + + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); + + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ + + # The page does not exist, so return an error. - $string_handle = $database_handle->prepare('DELETE FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename_sql . '\''); - $string_handle->execute(); + kiriwrite_error("pagefilenamedoesnotexist"); + + } + + # Get the database name and page name. - # Convert the values before writing them. + my $database_name = $database_info{"DatabaseName"}; + my $page_name = $page_info{"PageName"}; - 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"); + # Disconnect from the database server. + + $kiriwrite_dbmodule->disconnect(); # 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."; + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagedeleted}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{pagedeletedmessage}, $page_name, $database_name)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name)}); - return $pagedata; + return $kiriwrite_presmodule->grab(); } elsif ($confirm eq 0){ - # Check that the database exists and has the correct permissions - # set. + # Connect to the database server. - 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); + $kiriwrite_dbmodule->connect(); - # Check the results and return an error if needed. + # Check if any errors occured while connecting to the database server. - if ($database_check_exists eq 1){ + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - # The database file does not exist, so return an error. + # A database connection error has occured so return + # an error. - kiriwrite_error("databasemissingfile"); + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); } - if ($database_check_permissions eq 1){ + # Select the database. - # The database file has invalid permissions set, so - # return an error. + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database }); + + # Check if any errors had occured while selecting the database. + + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ + + # The database does not exist, so return an error. + + kiriwrite_error("databasemissingfile"); + + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ + + # The database has invalid permissions set, so return + # an error. kiriwrite_error("databaseinvalidpermissions"); } - # Load the SQLite database and get information about the - # database. + # 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 = $kiriwrite_dbmodule->getdatabaseinfo(); - my @database_info; - my $database_name; - @database_info = $string_handle->fetchrow_array(); - $database_name = $database_info[0]; + # Check if any errors occured while getting the database information. - my $pagefilename_sql = kiriwrite_convert($page, "kiriwrite"); + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # Check if the filename exists and return an error if it - # isn't. + # A database error has occured so return an error and + # also the extended error information. - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename_sql . '\' LIMIT 1'); - $string_handle->execute(); + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - my $page_found = 0; + } - my @database_page; + # Get information about the page that is going to be deleted. - while (@database_page = $string_handle->fetchrow_array()){ + my %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $page }); - $page_found = 1; + # Check if any errors occured while getting the page information. - } + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # Check if the page wasn't found and return an error if it - # didn't. + # A database error has occured so return an error and + # also the extended error information. - if ($page_found eq 0){ + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - # Page wasn't found in the database so return - # an error. + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ + + # The page does not exist, 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 $database_name = $database_info{"DatabaseName"}; + my $page_name = $page_info{"PageName"}; - my $page_name; - @database_page = $string_handle->fetchrow_array(); - $page_name = $database_page[1]; - - # Convert the values so that they can be displayed properly. + # Disconnect from the database server. - 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"); + $kiriwrite_dbmodule->disconnect(); # 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; + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{deletepage}, $page_name), { Style => "pageheader" }); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "page"); + $kiriwrite_presmodule->addhiddendata("action", "delete"); + $kiriwrite_presmodule->addhiddendata("database", $database); + $kiriwrite_presmodule->addhiddendata("page", $page); + $kiriwrite_presmodule->addhiddendata("confirm", "1"); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{deletepagemessage}, $page_name, $database_name)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{deletepagebutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{deletepagesreturnlink}, $database_name)}); + $kiriwrite_presmodule->endform(); + + return $kiriwrite_presmodule->grab(); } else { - + # Another page deletion type was specified, so return an error. - + kiriwrite_error("invalidoption"); - + } } @@ -864,25 +1086,19 @@ sub kiriwrite_page_edit{ 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. @@ -901,11 +1117,11 @@ sub kiriwrite_page_edit{ 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); + my $pagedatabase_length_check = kiriwrite_variablecheck($database, "maxlength", 32, 1); if ($pagedatabase_length_check eq 1){ @@ -917,18 +1133,18 @@ sub kiriwrite_page_edit{ # 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){ @@ -967,7 +1183,7 @@ sub kiriwrite_page_edit{ # 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 $pagenewtitle_maxlength_check = kiriwrite_variablecheck($pagenewtitle, "maxlength", 512, 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); @@ -1030,7 +1246,7 @@ sub kiriwrite_page_edit{ 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 @@ -1043,7 +1259,7 @@ sub kiriwrite_page_edit{ # 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){ + if ($pagenewfilename_filename_check ne 0){ # The new page filename is invalid, so return an error. @@ -1067,416 +1283,554 @@ sub kiriwrite_page_edit{ } - # Check if the page database exists and the permissions set for - # it are valid. + # Connect to the database server. + + $kiriwrite_dbmodule->connect(); + + # Check if any errors occured while connecting to the database server. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ + + # A database connection error has occured so return + # an error. + + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); + + } + + # Select the database. + + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database }); - 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); + # Check if any errors had occured while selecting the database. - if ($database_exists eq 1){ + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ # The database does not exist, so return an error. kiriwrite_error("databasemissingfile"); + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ + + # The database has invalid permissions set, so return + # an error. + + kiriwrite_error("databaseinvalidpermissions"); + } - + + # Check if the database has write permissions. + + my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1); + if ($database_permissions eq 1){ - # The database permissions are invalid, so return - # an error. + # The database permissions are invalid so return an error. kiriwrite_error("databaseinvalidpermissions"); } - # Load the SQLite database. + # Get the database information. - 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 %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - my $pagefilename_sql = kiriwrite_convert($pagefilename, "kiriwrite"); + # Check if any errors had occured while getting the database information. - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename . '\' LIMIT 1') or kiriwrite_error("databasefileinvalid"); - $string_handle->execute(); + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - my $page_exists = 0; - my @database_pages; + # A database error has occured so return an error and + # also the extended error information. - # Check if a result has returned (meaning that the - # page with that filename exists. + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - while(@database_pages = $string_handle->fetchrow_array()){ + }; - # The page exists so set the value to 1. + my $database_name = $database_info{"DatabaseName"}; - $page_exists = 1; + # Edit the selected page. - } + $kiriwrite_dbmodule->editpage({ PageFilename => $pagefilename, PageNewFilename => $pagenewfilename, PageNewName => $pagenewtitle, PageNewDescription => $pagenewdescription, PageNewSection => $pagenewsection, PageNewTemplate => $pagenewtemplate, PageNewContent => $pagenewcontent, PageNewSettings => $pagenewsettings }); - if ($page_exists eq 0){ + # Check if any errors occured while editing the page. - # The page does not exist, so return an error. + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ + + # A database error has occured so return an error and + # also the extended error information. + + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); + + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ + + # The pages does not exist in the database. kiriwrite_error("pagefilenamedoesnotexist"); } - # Get the current date and time. + # Disconnect from the database server. - my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; + $kiriwrite_dbmodule->disconnect(); - my $pagelastmodified = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{editedpage}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{editedpagemessage}, $pagenewtitle)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name) }); - # Prepare for the page's values to be changed. + return $kiriwrite_presmodule->grab(); - $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"); + } elsif ($confirm eq 0) { - # Edit the page in the database. + # Connect to the database server. - $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(); + $kiriwrite_dbmodule->connect(); - # Get the database name. + # Check if any errors occured while connecting to the database server. - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1'); - $string_handle->execute(); + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - my @database_info; - my $database_name; + # A database connection error has occured so return + # an error. - @database_info = $string_handle->fetchrow_array(); - $database_name = $database_info[0]; + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - # 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"); + # Select the database. - # Write out the message to say that the page has been - # edited. + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database }); - $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"; + # Check if any errors had occured while selecting the database. - return $pagedata; - - } elsif ($confirm eq 0) { - - # Check if the database exists and that the permissions - # for the database are valid. + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ + + # The database does not exist, so return an error. - 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'); + kiriwrite_error("databasemissingfile"); - if ($database_file_exists eq 1){ + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - # The database with the filename given does - # not exist, so return an error. + # The database has invalid permissions set, so return + # an error. - kiriwrite_error("databasemissingfile"); + kiriwrite_error("databaseinvalidpermissions"); } - if ($database_file_permissions eq 1){ + # Get the information about the database. - # The file permissions of the database given - # are invalid so return an error. + my %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - kiriwrite_error("databaseinvalidpermissions"); + # Check if any errors had occured while getting the database information. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ + + # A database error has occured so return an error and + # also the extended error information. + + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); + + }; + + my $database_name = $database_info{"DatabaseName"}; + + # Get the page info. + + my %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $pagefilename }); + + # Check if any errors occured while getting the page information. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ + + # A database error has occured so return an error and + # also the extended error information. + + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); + + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ + + # The page does not exist, so return an error. + + kiriwrite_error("pagefilenamedoesnotexist"); } - # Load the SQLite database and check if the file exists. + # Get the values from the hash. - 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 $data_filename = $page_info{"PageFilename"}; + my $data_name = $page_info{"PageName"}; + my $data_description = $page_info{"PageDescription"}; + my $data_section = $page_info{"PageSection"}; + my $data_template = $page_info{"PageTemplate"}; + my $data_content = $page_info{"PageContent"}; + my $data_settings = $page_info{"PageSettings"}; + my $data_lastmodified = $page_info{"PageLastModified"}; + my $template_warning; my $page_count = 0; + my %template_list; + my %template_info; my @database_pages; my @database_info; my @database_templates; - my $template_data; + my @template_filenames; + my $template_file; my $template_filename; my $template_name; + my $template_count = 0; my $template_found = 0; - while (@database_pages = $string_handle->fetchrow_array()){ - - $page_count = 1; - - } - - if ($page_count eq 0){ + tie(%template_list, 'Tie::IxHash'); - # The page does not exist in the template database, so - # return an error. + # Connect to the template database. - kiriwrite_error("pagefilenamedoesnotexist"); + $kiriwrite_dbmodule->connecttemplate(); - } + # Check if any errors occured while connecting to the template database. - # Get the database name. + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){ - $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(); + # The template database does not exist so set the template + # warning message. - my $database_name = $database_info[0]; + $template_warning = $kiriwrite_lang->{pages}->{notemplatedatabasekeep}; - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $pagefilename . '\' LIMIT 1'); - $string_handle->execute(); - @database_pages = $string_handle->fetchrow_array(); + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){ - # Get the variables and convert them so that they can be displayed - # properly. + # The template database has invalid permissions set so write + # the template warning message. - 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"); + $template_warning = $kiriwrite_lang->{pages}->{templatepermissionserrorkeep}; - # 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; + if (!$template_warning){ - my $template_file_exists = kiriwrite_fileexists("templates.db"); - my $template_file_permissions = kiriwrite_filepermissions("templates.db", 1, 0, 0); + # Get the list of available templates. - if ($template_file_exists eq 1){ + @template_filenames = $kiriwrite_dbmodule->gettemplatelist(); - # The template database does not exist, so write a warning messsage. + # Check if any errors had occured. - $template_warning = "The template database does not exist. Existing template settings for page kept."; + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ - } + # A database error occured while getting the list + # of templates so return an error with the + # extended error information. - if ($template_file_permissions eq 1 && $template_file_exists ne 1){ + $template_warning = kiriwrite_language($kiriwrite_lang->{pages}->{templatedatabaseerrorkeep} , $kiriwrite_dbmodule->geterror(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."; + if (!$template_warning){ - } + foreach $template_filename (@template_filenames){ - # Get the list of templates. + # Get the information about each template. - if (!$template_warning){ + %template_info = $kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_filename }); - # Load the templates database and get the templates. + # Check if any errors occured while getting the template information. - $database_handle = DBI->connect("dbi:SQLite:templates.db"); + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ - $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){ + # A template database error has occured so return a warning message + # with the extended error information. - $string_handle->execute(); + $template_warning = kiriwrite_language($kiriwrite_lang->{pages}->{templatedatabaseerrorkeep} , $kiriwrite_dbmodule->geterror(1)); + last; - $template_data = ""; + if (!$data_settings){ + $data_settings = ""; + } + if (!$data_lastmodified){ + $data_lastmodified = ""; } # 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 . ""; + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{editpage}, $data_name), { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "page"); + $kiriwrite_presmodule->addhiddendata("action", "edit"); + $kiriwrite_presmodule->addhiddendata("database", $database); + $kiriwrite_presmodule->addhiddendata("page", $pagefilename); + $kiriwrite_presmodule->addhiddendata("confirm", 1); + + $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 }); + + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{setting}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{value}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->endheader(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{database}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtext($database_name); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagename}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("pagename", { Size => 64, MaxLength => 256, Value => $data_name }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagedescription}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("pagedescription", { Size => 64, MaxLength => 256, Value => $data_description }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagesection}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("pagesection", { Size => 64, MaxLength => 256, Value => $data_section }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagetemplate}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + + # Check if any template warnings have occured. if ($template_warning){ - $pagedata = $pagedata . ""; + $kiriwrite_presmodule->addtext($template_warning); + $kiriwrite_presmodule->addlinebreak(); - } else { + } - $pagedata = $pagedata . ""; + $kiriwrite_presmodule->addselectbox("pagetemplate"); - } + # Process the list of templates, select one if the + # template filename for the page matches, else give + # an option for the user to keep the current template + # filename. - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; + # Check if the page settings value is set to a + # certain number and select that option based + # on the number else set the value to 0. + if ($data_settings eq 1){ + $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepageandsection}, Value => "1", Selected => 1, LineBreak => 1}); } else { + $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepageandsection}, Value => "1", LineBreak => 1}); + } - # The setting is not the one being checked for - # so write the option out as normal. + if ($data_settings eq 2){ + $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepagename}, Value => "2", Selected => 1, LineBreak => 1}); + } else { + $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepagename}, Value => "2", LineBreak => 1}); + } - $pagedata = $pagedata . " Don't use page name or section name.
"; + if ($data_settings eq 3){ + $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usesectionname}, Value => "3", Selected => 1, LineBreak => 1}); + } else { + $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usesectionname}, Value => "3", LineBreak => 1}); + } + if ($data_settings eq 0 || ($data_settings ne 1 && $data_settings ne 2 && $data_settings ne 3)){ + $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{nopagesection}, Value => "0", Selected => 1, LineBreak => 1}); + } else { + $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{nopagesection}, Value => "0", LineBreak => 1}); } - $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"; + $template_count = 0; - # Check the page settings value and set the currently selected - # option to what the settings value is set to. + foreach $template_file (keys %template_list){ - if ($data_settings eq 1){ + if ($template_list{$template_count}{Selected}){ - # The selected option is to use the page name and - # section name so make sure it is selected. + $kiriwrite_presmodule->addoption($template_list{$template_count}{Name} . " (" . $template_list{$template_count}{Filename} . ")", { Value => $template_list{$template_count}{Filename}, Selected => 1 }); - $pagedata = $pagedata . " Use page name and section name.
"; + } else { - } else { + $kiriwrite_presmodule->addoption($template_list{$template_count}{Name} . " (" . $template_list{$template_count}{Filename} . ")", { Value => $template_list{$template_count}{Filename} }); - # The setting is not the one being checked for - # so write the option out as normal. + } - $pagedata = $pagedata . " Use page name and section name.
"; + $template_count++; } - if ($data_settings eq 2){ - - # The selected option is to use the page name - # only so make sure it is selected. + if ($data_template eq "!none"){ - $pagedata = $pagedata . " Use the page name only.
"; + $kiriwrite_presmodule->addoption($kiriwrite_lang->{pages}->{usenotemplate}, { Value => "!none", Selected => 1 }); + $template_found = 1; } else { - # The setting is not the one being checked for - # so write the option out as normal. + $kiriwrite_presmodule->addoption($kiriwrite_lang->{pages}->{usenotemplate}, { Value => "!none" }); + + } + + if ($template_found eq 0 && $data_template ne "!none"){ - $pagedata = $pagedata . " Use the page name only.
"; + # The template with the filename given was not found. + + $kiriwrite_presmodule->addoption(kiriwrite_language($kiriwrite_lang->{pages}->{keeptemplatefilename}, $data_template), { Value => $data_template, Selected => 1, Style => "warningoption" }); } - if ($data_settings eq 3){ + # Disconnect from the template database. - # The selected option is to use the section name - # only so make sure it is selected. + $kiriwrite_dbmodule->disconnecttemplate(); - $pagedata = $pagedata . " Use the section name only.
"; + # Disconnect from the database server. - } else { + $kiriwrite_dbmodule->disconnect(); - # The setting is not the one being checked for - # so write the option out as normal. + $kiriwrite_presmodule->endselectbox(); - $pagedata = $pagedata . " Use the section name only.
"; + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); - } + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagefilename}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("pagefilename", { Size => 64, MaxLength => 256, Value => $data_filename }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); - if ($data_settings eq 0){ + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagecontent}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtextbox("pagecontent", { Columns => 50, Rows => 10, Value => $data_content }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); + $kiriwrite_presmodule->addboldtext($kiriwrite_lang->{common}->{tags}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagetitle}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagename}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagedescription}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagesection}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pageautosection}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pageautotitle}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->endbox(); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); - # The selected option is to not use the page name - # or the section name. + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagesettings}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); - $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 . "
"; + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + $kiriwrite_presmodule->endtable(); + + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{editpagebutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{common}->{clearvalues}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name) } ); - return $pagedata; + $kiriwrite_presmodule->endform(); + + return $kiriwrite_presmodule->grab(); } else { - + # The confirm value is a value other than '0' and '1' so # return an error. - + kiriwrite_error("invalidvalue"); - + } } @@ -1499,14 +1853,6 @@ sub kiriwrite_page_multidelete{ 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. @@ -1518,29 +1864,6 @@ sub kiriwrite_page_multidelete{ } - # 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. @@ -1570,11 +1893,11 @@ sub kiriwrite_page_multidelete{ 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); + my $pagedatabase_length_check = kiriwrite_variablecheck($database, "maxlength", 32, 1); if ($pagedatabase_length_check eq 1){ @@ -1601,6505 +1924,7898 @@ sub kiriwrite_page_multidelete{ # The action to delete multiple pages from the database has # been confirmed. - # Load the SQLite Database and get info about the database. + # Connect to the database server. - 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(); + $kiriwrite_dbmodule->connect(); - my @database_info = $string_handle->fetchrow_array(); - my $database_name = $database_info[0]; + # Check if any errors occured while connecting to the database server. - # Define some variables for later. + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - my @database_page; - my $filelist_filename; - my $deleted_list; - my $page_name; - my $page_found = 0; + # A database connection error has occured so return + # an error. - $deleted_list = ""; + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - foreach $filelist_filename (@filelist){ + } - # Check if the page exists and skip to the next - # file if it doesn't exist. + # Select the database. - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $filelist_filename . '\' LIMIT 1'); - $string_handle->execute(); + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database }); - while (@database_page = $string_handle->fetchrow_array()){ - $page_found = 1; - } + # Check if any errors occured while selecting the database. - if ($page_found eq 0){ + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - next; + # The database does not exist, so return an error. - } + kiriwrite_error("databasemissingfile"); - # Get the page name. + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - $string_handle->execute(); - @database_page = $string_handle->fetchrow_array(); - $page_name = $database_page[1]; + # The database has invalid permissions set, so return + # an error. - # Delete the page. + kiriwrite_error("databaseinvalidpermissions"); - $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. + # Check if the database has read and write permissions. - $deleted_list = $deleted_list . kiriwrite_convert($page_name, "normal_display") . " (" . $filelist_filename . ")" . "
"; - $page_found = 0; + my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1); - } + if ($database_permissions eq 1){ - $string_handle = $database_handle->prepare('VACUUM'); - $string_handle->execute(); + # The database permissions are invalid so return an error. - my $database_out = kiriwrite_convert($database, "normal_display"); - my $database_name_out = kiriwrite_convert($database_name, "normal_display"); + kiriwrite_error("databaseinvalidpermissions"); - $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; + # Get information about the database. - } elsif ($confirm eq 0){ + my %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - # 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. + # Check if any errors had occured while getting the database + # information. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ + + # A database error has occured so return an error and + # also the extended error information. - # Load the SQLite Database and get info about the database. + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - 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]; + my $database_name = $database_info{"DatabaseName"}; # Define some variables for later. - my @page_info; - my @pagenames; - my @filenames; - my $pagename; + my @database_page; + my %page_info; my $filelist_filename; - my $filelist_filename_sql; - my $database_name_out; - my $pagenameslist; - my $pagenameslist_out; - my $pageseek = 0; - my $pagefound = 0; + my %deleted_list; + my $page; + my $page_name; + my $page_found = 0; + my $page_count = 0; - # Process each filename given. + tie (%deleted_list, 'Tie::IxHash'); - foreach $filelist_filename (@filelist){ + my $deleted_list = ""; - $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"); + foreach $filelist_filename (@filelist){ - $string_handle->execute(); + # Get the page information. - # Check if the filename given exists and if it - # doesn't then skip this filename and go onto - # the next filename. + %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filelist_filename }); - while (@page_info = $string_handle->fetchrow_array()){ + # Check if any errors occured. - $pagefound = 1; + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - } - - if ($pagefound eq 0){ + # A database error has occured so return an error and + # also the extended error information. - next; + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - } + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ - # Get the data again. + # The page does not exist, so process the next page. - $string_handle->execute(); - @page_info = $string_handle->fetchrow_array(); + next; - # Add the page name and file name to their seperate - # arrays. + } - $pagenames[$pageseek] = $page_info[1]; - $filenames[$pageseek] = $page_info[0]; + # Add the page to the list of deleted pages. - # Increment the page seek counter and reset the - # page found value. + $deleted_list{$page_count}{Filename} = $page_info{"PageFilename"}; + $deleted_list{$page_count}{Name} = $page_info{"PageName"}; - $pageseek++; - $pagefound = 0; + # Delete the page. - } + $kiriwrite_dbmodule->deletepage({ PageFilename => $filelist_filename }); - $pageseek = 0; + # Check if any errors occured while deleting the page from the database. - $pagenameslist = ""; + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - foreach $pagename (@pagenames){ + # A database error has occured so return an error and + # also the extended error information. - if (!$pagename){ + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - $pagenameslist = $pagenameslist . "No page name (" . $filenames[$pageseek] . ")
"; + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ - } else { + # The page does not exist, so process the next page. - $pagenameslist = $pagenameslist . kiriwrite_convert($pagename, "normal_display") . " (" . kiriwrite_convert($filenames[$pageseek], "normal_display") . ")
"; + next; } - $pageseek++; + $page_found = 0; + $page_count++; } - # Check if any files were selected and return - # an error if there wasn't. + # Disconnect from the database server. - if ($pageseek eq 0){ + $kiriwrite_dbmodule->disconnect(); - # No pages were selected so return an error. + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{selectedpagesdeleted}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{selectedpagesdeletedmessage}, $database_name)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); - kiriwrite_error("nopagesselected"); + foreach $page (keys %deleted_list){ - } + if (!$deleted_list{$page}{Name}){ + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname}); + $kiriwrite_presmodule->addtext(" (" . $deleted_list{$page}{Filename} . ")"); - # Convert the values so that they display properly. + } else { + $kiriwrite_presmodule->addtext($deleted_list{$page}{Name} . " (" . $deleted_list{$page}{Filename} . ")"); + } - $database_name_out = kiriwrite_convert($database_name, "normal_display"); - my $database_out = kiriwrite_convert($database, "normal_display"); + $kiriwrite_presmodule->addlinebreak(); + } - # Write the form for displaying pages. + $kiriwrite_presmodule->endbox(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name)}); + $kiriwrite_presmodule->endform(); - $pagedata = "

Delete multiple pages

"; - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; + return $kiriwrite_presmodule->grab(); - $pageseek = 1; + } elsif ($confirm eq 0){ - foreach $filelist_filename (@filenames){ + # 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. - $pagedata = $pagedata . ""; - $pagedata = $pagedata . ""; + # Connect to the database server. - $pageseek++; + $kiriwrite_dbmodule->connect(); - } + # Check if any errors occured while connecting to the database server. - + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - $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 . "
"; + # A database connection error has occured so return + # an error. - return $pagedata; + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - } else { + } - # A confirm value other than 0 or 1 is given, so - # return an error. + # Select the database. - kiriwrite_error("invaildvalue"); + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database }); - } + # Check if any errors occured while selecting the database. -} + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ -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. # -################################################################################# + # The database does not exist, so return an error. - # Get the values that were passed to the subroutine. + kiriwrite_error("databasemissingfile"); - my ($database, $newdatabase, $confirm, @filelist) = @_; + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - # Load the required Perl modules. + # The database has invalid permissions set, so return + # an error. - use DBI; + kiriwrite_error("databaseinvalidpermissions"); - # Define a variable for later. - - my $pagedata = ""; + } - # Check if the file list is blank and return an error - # if it is. + # Check if the database has read and write permissions. - if (!@filelist){ + my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1); - # The file list really is blank so return - # an error. + if ($database_permissions eq 1){ - kiriwrite_error("nopagesselected"); + # The database permissions are invalid so return an error. - } + kiriwrite_error("databaseinvalidpermissions"); - # 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); + # Get information about the database. - if ($database_exists eq 1){ + my %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - # The database does not exist, so return an error. + # Check if any errors had occured while getting the database + # information. - kiriwrite_error("oldmovedatabasedoesnotexist"); + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - } - - if ($database_permissions eq 1){ + # A database error has occured so return an error and + # also the extended error information. - # The database permissions are invalid, so return - # an error. + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - kiriwrite_error("oldmovedatabasefileinvalidpermissions"); + }; - } + my $database_name = $database_info{"DatabaseName"}; - # Check if the confirm value is blank and if it is then - # set the confirm value to 0. + # Define some variables for later. - if (!$confirm){ + my %page_info; + my %delete_list; + my $pagename; + my $page = ""; + my $filelist_filename; + my $filelist_filename_sql; + my $pageseek = 0; - $confirm = 0; + tie(%delete_list, 'Tie::IxHash'); - } + # Process each filename given. - if ($confirm eq 1){ + foreach $filelist_filename (@filelist){ - # The action to move several pages from one database - # to another has been confirmed. + # Get the page information. - # 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. + %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filelist_filename }); - if ($database eq $newdatabase){ + # Check if any errors occured. - # The database that the pages are moving from - # and the database the pages are moving to - # is the same, so return an error. + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - kiriwrite_error("databasemovesame"); + # A database error has occured so return an error and + # also the extended error information. - } + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - # Check that the new database exists and the permissions - # for the new database are valid. + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ - $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); + # The page does not exist, so process the next page. - if ($database_exists eq 1){ + next; - # The database does not exist, so return an error. + } - kiriwrite_error("newmovedatabasedoesnotexist"); + # Add the page file name and name to the list + # of pages to delete. - } - - if ($database_permissions eq 1){ + $delete_list{$pageseek}{Filename} = $page_info{"PageFilename"}; + $delete_list{$pageseek}{Name} = $page_info{"PageName"}; - # The database permissions are invalid, so return - # an error. + # Increment the page seek counter and reset the + # page found value. - kiriwrite_error("newmovedatabasefileinvalidpermissions"); + $pageseek++; } - # 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; + # Disconnect from the database server. - 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; + $kiriwrite_dbmodule->disconnect(); - my $warninglist = ""; - my $movedlist = ""; + # Check if any files were selected and return + # an error if there wasn't. - 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; + if ($pageseek eq 0){ - my $page_found = 0; + # No pages were selected so return an error. - # Check if the database filename is valid and return an error if - # it isn't. + kiriwrite_error("nopagesselected"); - my $newpagedatabase_filename_check = kiriwrite_variablecheck($newdatabase, "filename", 0, 1); + } - if ($newpagedatabase_filename_check eq 1){ + # Write the form for displaying pages. - # The database filename is blank, so return an error. + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{deletemultiplepages}, { Style => "pageheader" }); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "page"); + $kiriwrite_presmodule->addhiddendata("action", "multidelete"); + $kiriwrite_presmodule->addhiddendata("database", $database); + $kiriwrite_presmodule->addhiddendata("confirm", "1"); + $kiriwrite_presmodule->addhiddendata("count", $pageseek); - kiriwrite_error("blankdatabasepageadd"); + $pageseek = 1; - } elsif ($newpagedatabase_filename_check eq 2){ + foreach $page (keys %delete_list){ - # The database filename is invalid, so return an error. + $kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on"); + $kiriwrite_presmodule->addhiddendata("id[" . $pageseek . "]", $delete_list{$page}{Filename}); - kiriwrite_error("databasefilenameinvalid"); + $pageseek++; } - # 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'); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{deletemultiplemessage}, $database_name)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); - # Get the database information from both databases. + foreach $page (keys %delete_list){ - $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(); + if (!$delete_list{$page}{Name}){ + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname}); + $kiriwrite_presmodule->addtext(" (" . $delete_list{$page}{Filename} . ")"); + } else { + $kiriwrite_presmodule->addtext($delete_list{$page}{Name} . " (" . $delete_list{$page}{Filename} . ")"); + } + $kiriwrite_presmodule->addlinebreak(); - $olddatabase_name = $olddatabase_info[0]; - $newdatabase_name = $newdatabase_info[0]; + } - # Convert the database names so that they can be displayed - # properly. + $kiriwrite_presmodule->endbox(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{deletepagesbutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{deletepagesreturnlink}, $database_name)}); + $kiriwrite_presmodule->endform(); - $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"); + return $kiriwrite_presmodule->grab(); - # 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. + } else { - foreach $filename (@filelist){ + # A confirm value other than 0 or 1 is given, so + # return an error. - # Check if the filename exists in the old database. - # If the filename does not exist then write - # a warning and process the next file. + kiriwrite_error("invaildvalue"); - $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()){ +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. # +################################################################################# - # The page in the old database does exist so - # set the value to 1. + # Get the values that were passed to the subroutine. - $page_found = 1; + my ($database, $newdatabase, $confirm, @filelist) = @_; - } + # Check if the database filename is valid and return + # an error if it isn't. - # See if the page was found and write a warning if it - # wasn't. + my $newpagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1); - if ($page_found eq 0){ + if ($newpagedatabase_filename_check eq 1){ - # The page was not found. Write a warning and - # process the next page. + # The database filename is blank, so return an error. - $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; + kiriwrite_error("blankdatabasepageadd"); - } + } elsif ($newpagedatabase_filename_check eq 2){ - # Check if the filename exists in the new database. - # If the filename does exist then write - # a warning and process the next file. + # The database filename is invalid, so return an error. - $newdatabase_string_handle = $newdatabase_database_handle->prepare('SELECT * FROM kiriwrite_database_pages where filename = \'' . $filename_sql . '\' LIMIT 1'); - $newdatabase_string_handle->execute(); + kiriwrite_error("databasefilenameinvalid"); - $page_found = 0; + } - while (@newdatabase_page = $newdatabase_string_handle->fetchrow_array()){ + # Check if the file list is blank and return an error + # if it is. - # The page in the old database does exist so - # set the value to 1. + if (!@filelist){ - $page_found = 1; + # The file list really is blank so return + # an error. - } + kiriwrite_error("nopagesselected"); - # See if the page was found and write a warning if it - # wasn't. + } - if ($page_found eq 1){ + # Check if the confirm value is blank and if it is then + # set the confirm value to 0. - # The page was not found. Write a warning and - # process the next page. + if (!$confirm){ - $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; + $confirm = 0; - } + } + if ($confirm eq 1){ - # Get the information about the page. + # The action to move several pages from one database + # to another has been confirmed. - $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]; + # 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. - # Convert the values so that they can be processed - # properly. + if ($database eq $newdatabase){ - $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"); + # The database that the pages are moving from + # and the database the pages are moving to + # is the same, so return an error. - $page_filename_out = kiriwrite_convert($page_filename, "normal_display"); - $page_name_out = kiriwrite_convert($page_name, "normal_display"); + kiriwrite_error("databasemovesame"); - # 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(); + # Check if the new database filename is valid and return an error if + # it isn't. - # Delete the page from the old database. + my $newpagedatabase_filename_check = kiriwrite_variablecheck($newdatabase, "filename", 0, 1); - $olddatabase_string_handle = $olddatabase_database_handle->prepare('DELETE FROM kiriwrite_database_pages WHERE filename = \'' . $filename_sql . '\''); - $olddatabase_string_handle->execute(); + if ($newpagedatabase_filename_check eq 1){ - # Append the moved page (filename and name) to the list of - # moved pages. + # The database filename is blank, so return an error. - if (!$page_name_out){ + kiriwrite_error("blankdatabasepageadd"); - $page_name_out = "No Name"; + } elsif ($newpagedatabase_filename_check eq 2){ - } + # The database filename is invalid, so return an error. - $movedlist = $movedlist . $page_name_out . " (" . $filename_out . ")" . "
"; + kiriwrite_error("databasefilenameinvalid"); } - # 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

"; + # Connect to the database server. - 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 { + $kiriwrite_dbmodule->connect(); - $pagedata = $pagedata . "No pages were moved from the '" . $olddatabase_name_out . "' database to the '" . $newdatabase_name_out . "' database.

"; + # Check if any errors occured while connecting to the database server. - } + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - if ($warninglist){ + # A database connection error has occured so return + # an error. - $pagedata = $pagedata . "The following errors/warnings have occured while moving the pages:

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


"; + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); } - $pagedata = $pagedata . "Return to the page list for the '" . $olddatabase_name_out . "' database. | View the page list for the '" . $newdatabase_name_out . "' database."; + # Select the database the pages are going to be moved from. - return $pagedata; + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database }); - } elsif ($confirm eq 0) { + # Check if any errors had occured while selecting the database. - # The action to move several pages from one database - # to another has not been confirmed so write a form. + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - # Load the SQLite database and get the needed - # information about the database. + # The database does not exist, so return an error. - 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(); + kiriwrite_error("oldmovedatabasedoesnotexist"); - my @database_info = $string_handle->fetchrow_array(); - my $database_name = $database_info[0]; + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - # Define some values for later. + # The database has invalid permissions set, so return + # an error. - 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; + kiriwrite_error("oldmovedatabasefileinvalidpermissions"); - # Process each filename given. + } - foreach $filelist_filename (@filelist){ + # Check if the database has read and write permissions. - $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"); + my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1); - $string_handle->execute(); + if ($database_permissions eq 1){ - # Check if the filename given exists and if it - # doesn't then skip this filename and go onto - # the next filename. + # The database permissions are invalid so return an error. - while (@page_info = $string_handle->fetchrow_array()){ + kiriwrite_error("databaseinvalidpermissions"); - $pagefound = 1; + } - } - - if ($pagefound eq 0){ + # Select the database the pages are going to be moved to. - next; + $kiriwrite_dbmodule->selectseconddb({ DatabaseName => $newdatabase }); - } + # Check if any errors had occured while selecting the database. - # Get the data again. + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - $string_handle->execute(); - @page_info = $string_handle->fetchrow_array(); + # The database does not exist, so return an error. - # Add the page name and file name to their seperate - # arrays. + kiriwrite_error("newmovedatabasedoesnotexist"); - $pagenames[$pageseek] = $page_info[1]; - $filenames[$pageseek] = $page_info[0]; + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - # Increment the page seek counter and reset the - # page found value. + # The database has invalid permissions set, so return + # an error. - $pageseek++; - $pagefound = 0; + kiriwrite_error("newmovedatabasefileinvalidpermissions"); } - # Check if any pages exust and return an error if - # there wasn't. + # Check if the database has read and write permissions. - if ($pageseek eq 0){ + $database_permissions = $kiriwrite_dbmodule->dbpermissions($newdatabase, 1, 1); - # None of the selected pages exist, so return - # an error. + if ($database_permissions eq 1){ - kiriwrite_error("nopagesselected"); + # The database permissions are invalid so return an error. + + kiriwrite_error("databaseinvalidpermissions"); } - # Create the page list of files to move. + # Define some values for later. - $pageseek = 1; - $pagelist = ""; - $pagelist_formdata = ""; + my %moved_list; + my %warning_list; + my %page_info; - foreach $filename (@filenames){ + my $filename; + my $olddatabase_name; + my $newdatabase_name; + my $page; + my $warning; - $pagename = $pagenames[$pageseek - 1]; + my $page_found = 0; + my $move_count = 0; + my $warning_count = 0; - # Check if the page name is blank and if it is then say - # no name. + tie(%moved_list, 'Tie::IxHash'); + tie(%warning_list, 'Tie::IxHash'); - if (!$pagename){ + # Get information about the database that the selected pages are moving from. - # The page name is blank. + my %olddatabase_info = $kiriwrite_dbmodule->getdatabaseinfo(); - $pagelist = $pagelist . "No Name" . " (" . $filename . ")
"; + # Check if any errors had occured while getting the database + # information. - } else { + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # Append the page name and filename to the page list. + # A database error has occured so return an error and + # also the extended error information. - $pagelist = $pagelist . kiriwrite_convert($pagename, "normal_display") . " (" . $filename . ")
"; + kiriwrite_error("oldmovedatabasedatabaseerror", $kiriwrite_dbmodule->geterror(1)); - } + }; - # Append the form data to the page list form data. + $olddatabase_name = $olddatabase_info{"DatabaseName"}; - $filename_out = kiriwrite_convert($filename, "normal_display"); + # Get information about the database that the selected pages are moving to. - $pagelist_formdata = $pagelist_formdata . ""; - $pagelist_formdata = $pagelist_formdata . ""; + my %newdatabase_info = $kiriwrite_dbmodule->getseconddatabaseinfo(); - $pageseek++; + # Check if any errors had occured while getting the database + # information. - } + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # Get the database filenames and names. + # A database error has occured so return an error and + # also the extended error information. - # Check the directory to make sure the permissions are settings are valid - # and return an error if the permission settings are invalid. + kiriwrite_error("newmovedatabasedatabaseerror", $kiriwrite_dbmodule->geterror(1)); - my $data_directory_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"}, 1, 0); + }; - if ($data_directory_permissions eq 1){ + $newdatabase_name = $newdatabase_info{"DatabaseName"}; - # The data directory has invalid permissions set, so return an error. + # Get each file in the old database, get the page values, + # put them into the new database and delete the pages + # from the old database. - kiriwrite_error("datadirectoryinvalidpermissions"); + foreach $filename (@filelist){ - } + # Get the page information. - # Open the directory and get the list of all files ending with .xml and - # put them into the data_directory array. + %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filename }); - opendir(DATADIR, $kiriwrite_config{"directory_data_db"}); - my @data_directory = grep /m*\.db/, readdir(DATADIR); - closedir(DATADIR); + # Check if any errors occured. - # Process each database to get the database name. + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ + + # A database error has occured so write a warning message and + # also the extended error information. - $database_list = ""; + } - # Convert some values so that they display properly. + $moved_list{$move_count}{Filename} = $page_info{"PageFilename"}; + $moved_list{$move_count}{Name} = $page_info{"PageName"}; - my $database_name_out = kiriwrite_convert($database_name, "normal_display"); - my $database_out = kiriwrite_convert($database, "normal_display"); + $move_count++; - # 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; + # Disconnect from the database server. - } else { + $kiriwrite_dbmodule->disconnect(); - # The confirm value is other than 0 or 1, so return - # an error. + # Write out a message saying that the pages were moved (if any) + # to the new database (and any warnings given). - kiriwrite_error("invalidvariable"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{movepages}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); - } + if (%moved_list){ + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{movedpagesmessage}, $olddatabase_name, $newdatabase_name)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); -} + $kiriwrite_presmodule->startbox("datalist"); + foreach $page (keys %moved_list){ + if (!$moved_list{$page}{Name}){ + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname}); + $kiriwrite_presmodule->addtext(" (" . $moved_list{$page}{Filename} . ")"); + } else { + $kiriwrite_presmodule->addtext($moved_list{$page}{Name} . " (" . $moved_list{$page}{Filename} . ")"); + } + $kiriwrite_presmodule->addlinebreak(); + } + $kiriwrite_presmodule->endbox(); -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. # -################################################################################# + } else { - # Get the values that were passed to the subroutine. + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{nopagesmoved}, $olddatabase_name, $newdatabase_name)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); - my ($database, $newdatabase, $confirm, @filelist) = @_; + } - # Load the required Perl modules. + if (%warning_list){ - use DBI; + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{errormessages}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); + foreach $warning (keys %warning_list){ + $kiriwrite_presmodule->addtext($warning_list{$warning}{Message}); + $kiriwrite_presmodule->addlinebreak(); + } + $kiriwrite_presmodule->endbox(); - # Define a variable for later. + } - my $pagedata = ""; + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $olddatabase_name)}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $newdatabase, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{viewpagelist}, $newdatabase_name)}); - # Check if the file list is blank and return an error - # if it is. + return $kiriwrite_presmodule->grab(); - if (!@filelist){ + } elsif ($confirm eq 0) { - # The file list really is blank so return - # an error. + # The action to move several pages from one database + # to another has not been confirmed so write a form. - kiriwrite_error("nopagesselected"); + # Connect to the database server. - } + $kiriwrite_dbmodule->connect(); - # Check if the file permissions on the original database - # are valid and return an error if they aren't. + # Check if any errors occured while connecting to the database server. - 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 ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - if ($database_exists eq 1){ + # A database connection error has occured so return + # an error. - # The database does not exist, so return an error. + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - kiriwrite_error("oldcopydatabasedoesnotexist"); + } - } - - if ($database_permissions eq 1){ + # Select the database. - # The database permissions are invalid, so return - # an error. + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database }); - kiriwrite_error("oldcopydatabasefilenameinvalidpermissions"); + # Check if any errors occured while selecting the database. - } + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - # Check if the confirm value is blank and if it is then - # set the confirm value to 0. + # The database does not exist, so return an error. - if (!$confirm){ + kiriwrite_error("databasemissingfile"); - $confirm = 0; + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - } + # The database has invalid permissions set, so return + # an error. - # Check if the database filename is valid and return an error if - # it isn't. + kiriwrite_error("databaseinvalidpermissions"); - my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1); + } - if ($pagedatabase_filename_check eq 1){ + # Check if the database has read and write permissions. - # The database filename is blank, so return an error. + my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1); - kiriwrite_error("blankdatabasepageadd"); + if ($database_permissions eq 1){ - } elsif ($pagedatabase_filename_check eq 2){ + # The database permissions are invalid so return an error. - # The database filename is invalid, so return an error. + kiriwrite_error("databaseinvalidpermissions"); - kiriwrite_error("databasefilenameinvalid"); + } - } + # Get information about the database. - if ($confirm eq 1){ + my %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - # The action to copy several pages from one database - # to another has been confirmed. + # Check if any errors had occured while getting the database + # information. - # 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 ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - if ($database eq $newdatabase){ + # A database error has occured so return an error and + # also the extended error information. - # 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("databaseerror", $kiriwrite_dbmodule->geterror(1)); - kiriwrite_error("databasecopysame"); + }; - } + my $database_name = $database_info{"DatabaseName"}; - # Check that the new database exists and the permissions - # for the new database are valid. + # Define some values for later. - $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); + my %db_list; + my %move_list; + my %page_info; + my $page; + my $data_file; + my $db_name; + my $filename; + my $filelist_filename; + my $pagename; + my $pageseek = 0; + my $dbseek = 0; - if ($database_exists eq 1){ + # Process each filename given. - # The database does not exist, so return an error. + tie (%move_list, 'Tie::IxHash'); + tie (%db_list, 'Tie::IxHash'); - kiriwrite_error("newcopydatabasedoesnotexist"); + foreach $filelist_filename (@filelist){ - } - - if ($database_permissions eq 1){ + # Get the page information. - # The database permissions are invalid, so return - # an error. + %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filelist_filename }); - kiriwrite_error("newcopydatabasefileinvalidpermissions"); + # Check if any errors occured. - } + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # Define some values for later. + # A database error has occured so return an error and + # also the extended error information. - my @olddatabase_info; - my @olddatabase_page; - my @newdatabase_info; - my @newdatabase_page; + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - my $filename; - my $filename_sql; - my $filename_out; + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ - 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; + # The page does not exist, so process the next page. - my $warninglist = ""; - my $copiedlist = ""; + next; - 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; + # Add the page name and file name to the list of + # pages to move. - # Check if the database filename is valid and return an error if - # it isn't. + $move_list{$pageseek}{Filename} = $page_info{"PageFilename"}; + $move_list{$pageseek}{Name} = $page_info{"PageName"}; - my $newpagedatabase_filename_check = kiriwrite_variablecheck($newdatabase, "filename", 0, 1); + # Increment the page seek counter and reset the + # page found value. - if ($newpagedatabase_filename_check eq 1){ + $pageseek++; - # The database filename is blank, so return an error. + } - kiriwrite_error("blankdatabasepageadd"); + # Check if any pages exust and return an error if + # there wasn't. - } elsif ($newpagedatabase_filename_check eq 2){ + if ($pageseek eq 0){ - # The database filename is invalid, so return an error. + # None of the selected pages exist, so return + # an error. - kiriwrite_error("databasefilenameinvalid"); + kiriwrite_error("nopagesselected"); } - # 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 list of databases. - # Get the database information from both databases. + my @database_list = $kiriwrite_dbmodule->getdblist(); - $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(); + # Check if any errors occured while trying to get the list of databases. - @olddatabase_info = $olddatabase_string_handle->fetchrow_array(); - @newdatabase_info = $newdatabase_string_handle->fetchrow_array(); + if ($kiriwrite_dbmodule->geterror eq "DataDirMissing"){ - $olddatabase_name = $olddatabase_info[0]; - $newdatabase_name = $newdatabase_info[0]; + # The database directory is missing so return an error. - # Convert the database names so that they can be displayed - # properly. + kiriwrite_error("datadirectorymissing"); - $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"); + } elsif ($kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){ - # Get each file in the old database, get the file values, - # put them into the new database. + # The database directory has invalid permissions set so return + # an error. - foreach $filename (@filelist){ + kiriwrite_error("datadirectoryinvalidpermissions"); - # 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(); + # Get the information about each database (the short name and friendly name). - $page_found = 0; + foreach $data_file (@database_list){ - while (@olddatabase_page = $olddatabase_string_handle->fetchrow_array()){ + $kiriwrite_dbmodule->selectdb({ DatabaseName => $data_file }); - # The page in the old database does exist so - # set the value to 1. + # Check if any errors occured while selecting the database. - $page_found = 1; + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - } + # The database does not exist, so process the next + # database. - # See if the page was found and write a warning if it - # wasn't. + next; - if ($page_found eq 0){ + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - # The page was not found. Write a warning and - # process the next page. + # The database has invalid permissions set, so process + # the next database. - $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. + # Get the database information. - $newdatabase_string_handle = $newdatabase_database_handle->prepare('SELECT * FROM kiriwrite_database_pages where filename = \'' . $filename_sql . '\' LIMIT 1'); - $newdatabase_string_handle->execute(); + %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - $page_found = 0; + # Check if any errors had occured while getting the database + # information. - while (@newdatabase_page = $newdatabase_string_handle->fetchrow_array()){ + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # The page in the old database does exist so - # set the value to 1. + # A database error has occured so process the next + # database. - $page_found = 1; + next; - } + }; - # See if the page was found and write a warning if it - # wasn't. + # Check if the database name is undefined and if it is + # then set it blank. - if ($page_found eq 1){ + if (!$database_name){ + $database_name = ""; + } - # The page was not found. Write a warning and - # process the next page. + # Append the database to the list of databases available. - $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; + $db_list{$dbseek}{Filename} = $data_file; + $db_list{$dbseek}{Name} = $database_info{"DatabaseName"}; - } + $dbseek++; + } - # 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(); + # Disconnect from the database server. - # Append the copied page (filename and name) to the list of - # copied pages. + $kiriwrite_dbmodule->disconnect(); - if (!$page_name_out){ + # Write out the form. - $page_name_out = "No page name"; + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{movepages}, { Style => "pageheader" }); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "page"); + $kiriwrite_presmodule->addhiddendata("action", "multimove"); + $kiriwrite_presmodule->addhiddendata("database", $database); + $kiriwrite_presmodule->addhiddendata("count", $pageseek); + $kiriwrite_presmodule->addhiddendata("confirm", "1"); - } + # Write the page form data. - $copiedlist = $copiedlist . $page_name_out . " (" . $filename_out . ")" . "
"; + $pageseek = 1; + foreach $page (keys %move_list){ + $kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on"); + $kiriwrite_presmodule->addhiddendata("id[" . $pageseek . "]", $move_list{$page}{Filename}); + $pageseek++; } - # Write out a message saying that the pages were moved (if any) - # to the new database (and any warnings given). + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{movepagesmessage}, $database_name)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); - $pagedata = $pagedata . "

Copy multiple pages

"; + foreach $page (keys %move_list){ + if (!$move_list{$page}{Name}){ + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname}); + $kiriwrite_presmodule->addtext(" (" . $move_list{$page}{Filename} . ")"); + } else { + $kiriwrite_presmodule->addtext($move_list{$page}{Name} . " (" . $move_list{$page}{Filename} . ")"); + } + $kiriwrite_presmodule->addlinebreak(); + } - 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 { + $kiriwrite_presmodule->endbox(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{movepagesto}); - $pagedata = $pagedata . "No pages were copied from the '" . $olddatabase_name_out . "' database to the '" . $newdatabase_name_out . "' database.

"; + $kiriwrite_presmodule->addselectbox("newdatabase"); + foreach $db_name (keys %db_list){ + $kiriwrite_presmodule->addoption($db_list{$db_name}{Name} . " (" . $db_list{$db_name}{Filename} . ")", { Value => $db_list{$db_name}{Filename}}); } - if ($warninglist){ + $kiriwrite_presmodule->endselectbox(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{movepagesbutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name)}); + $kiriwrite_presmodule->endform(); - $pagedata = $pagedata . "The following errors/warnings have occured while copying the pages:

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


"; + return $kiriwrite_presmodule->grab(); - } + } else { - $pagedata = $pagedata . "Return to the page list for the '" . $olddatabase_name_out . "' database. | View the page list for the '" . $newdatabase_name_out . "' database."; + # The confirm value is other than 0 or 1, so return + # an error. - return $pagedata; + kiriwrite_error("invalidvariable"); - } 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]; +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. # +################################################################################# - # Define some values for later. + # Get the values that were passed to the subroutine. - 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; + my ($database, $newdatabase, $confirm, @filelist) = @_; - # Process each filename given. + # Check if the file list is blank and return an error + # if it is. - foreach $filelist_filename (@filelist){ + if (!@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"); + # The file list really is blank so return + # an error. - $string_handle->execute(); + kiriwrite_error("nopagesselected"); - # 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()){ + # Check if the confirm value is blank and if it is then + # set the confirm value to 0. - $pagefound = 1; + if (!$confirm){ - } - - if ($pagefound eq 0){ + $confirm = 0; - next; + } - } + # Check if the database filename is valid and return an error if + # it isn't. - # Get the data again. + my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1); - $string_handle->execute(); - @page_info = $string_handle->fetchrow_array(); + if ($pagedatabase_filename_check eq 1){ - # Add the page name and file name to their seperate - # arrays. + # The database filename is blank, so return an error. - $pagenames[$pageseek] = $page_info[1]; - $filenames[$pageseek] = $page_info[0]; + kiriwrite_error("blankdatabasepageadd"); - # Increment the page seek counter and reset the - # page found value. + } elsif ($pagedatabase_filename_check eq 2){ - $pageseek++; - $pagefound = 0; + # The database filename is invalid, so return an error. - } + kiriwrite_error("databasefilenameinvalid"); - # Check if any pages exust and return an error if - # there wasn't. + } - if ($pageseek eq 0){ + if ($confirm eq 1){ - # None of the selected pages exist, so return - # an error. + # The action to copy several pages from one database + # to another has been confirmed. - kiriwrite_error("nopagesselected"); + # 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){ - # Create the page list of files to move. + # 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. - $pageseek = 1; - $pagelist = ""; - $pagelist_formdata = ""; + kiriwrite_error("databasecopysame"); - foreach $filename (@filenames){ + } - $pagename = $pagenames[$pageseek - 1]; + # Check if the new database filename is valid and return an error if + # it isn't. - # Check if the + my $pagedatabase_filename_check = kiriwrite_variablecheck($newdatabase, "filename", 0, 1); - if (!$pagename){ + if ($pagedatabase_filename_check eq 1){ - # Write a message saying that there is no page name. + # The database filename is blank, so return an error. - $pagelist = $pagelist . "No Name" . " (" . $filename . ")
"; + kiriwrite_error("blankdatabasepageadd"); - } else { + } elsif ($pagedatabase_filename_check eq 2){ - # Append the page name and filename to the page list. + # The database filename is invalid, so return an error. - $pagelist = $pagelist . $pagename . " (" . $filename . ")
"; + kiriwrite_error("databasefilenameinvalid"); - } + } + # Connect to the database server. + $kiriwrite_dbmodule->connect(); - # Append the form data to the page list form data. + # Check if any errors occured while connecting to the database server. - $filename_out = kiriwrite_convert($filename, "normal_display"); + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - $pagelist_formdata = $pagelist_formdata . ""; - $pagelist_formdata = $pagelist_formdata . ""; + # A database connection error has occured so return + # an error. - $pageseek++; + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); } - # 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){ + # Select the database the pages are going to be copied from. - # The data directory has invalid permissions set, so return an error. + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database }); - kiriwrite_error("datadirectoryinvalidpermissions"); - - } + # Check if any errors had occured while selecting the database. - # Open the directory and get the list of all files ending with .xml and - # put them into the data_directory array. + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - opendir(DATADIR, $kiriwrite_config{"directory_data_db"}); - my @data_directory = grep /m*\.db/, readdir(DATADIR); - closedir(DATADIR); + # The database does not exist, so return an error. - # Process each database to get the database name. + kiriwrite_error("oldcopydatabasedoesnotexist"); - $database_list = ""; + my @olddatabase_info; + my @olddatabase_page; + my @newdatabase_info; + my @newdatabase_page; - # Convert some values so that they display properly. + my $filename; + my $filename_sql; + my $filename_out; - my $database_name_out = kiriwrite_convert($database_name, "normal_display"); - my $database_out = kiriwrite_convert($database, "normal_display"); + my $olddatabase_database_handle; + my $olddatabase_string_handle; + my $olddatabase_name; + my $newdatabase_database_handle; + my $newdatabase_string_handle; + my $newdatabase_name; - # Write out the form. + my $page; + my $warning; + my $page_filename; + my $page_filename_sql; + my $page_name; + my $page_name_sql; + 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; - $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; + my $page_seek = 0; + my $warning_count = 0; - } else { + my $page_found = 0; - # The confirm value is other than 0 or 1, so return - # an error. + tie(%copied_list, 'Tie::IxHash'); + tie(%warning_list, 'Tie::IxHash'); - kiriwrite_error("invalidvariable"); + # Get information about the database that the selected pages are moving from. - } + my %olddatabase_info = $kiriwrite_dbmodule->getdatabaseinfo(); -} + # Check if any errors had occured while getting the database + # information. -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. # -################################################################################# + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # Get the values that were passed to the subroutine. + # A database error has occured so return an error and + # also the extended error information. - my ($database, $newsection, $altersection, $newtemplate, $altertemplate, $newsettings, $altersettings, $confirm, @filelist) = @_; + kiriwrite_error("oldcopydatabasedatabaseerror", $kiriwrite_dbmodule->geterror(1)); - # Load the required Perl modules. + }; - use DBI; + $olddatabase_name = $olddatabase_info{"DatabaseName"}; - # Define a variable for later. + # Get information about the database that the selected pages are moving to. - my $pagedata = ""; + my %newdatabase_info = $kiriwrite_dbmodule->getseconddatabaseinfo(); - # Check if the file list is blank and return an error - # if it is. + # Check if any errors had occured while getting the database + # information. - if (!@filelist){ + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # The file list really is blank so return - # an error. + # A database error has occured so return an error and + # also the extended error information. - kiriwrite_error("nopagesselected"); + kiriwrite_error("newcopydatabasedatabaseerror", $kiriwrite_dbmodule->geterror(1)); - } + }; - # Check if the file permissions on the original database - # are valid and return an error if they aren't. + $newdatabase_name = $newdatabase_info{"DatabaseName"}; - 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); + # Check if the database filename is valid and return an error if + # it isn't. - if ($database_exists eq 1){ + my $newpagedatabase_filename_check = kiriwrite_variablecheck($newdatabase, "filename", 0, 1); - # The database does not exist, so return an error. + if ($newpagedatabase_filename_check eq 1){ - kiriwrite_error("databasemissingfile"); + # The database filename is blank, so return an error. - } - - if ($database_permissions eq 1){ + kiriwrite_error("blankdatabasepageadd"); - # The database permissions are invalid, so return - # an error. + } elsif ($newpagedatabase_filename_check eq 2){ - kiriwrite_error("databaseinvalidpermissions"); + # The database filename is invalid, so return an error. - } + kiriwrite_error("databasefilenameinvalid"); - # Check if certain values are undefined and define them if - # they are. + } - if (!$altersection){ + foreach $filename (@filelist){ - # The alter section value is blank, so set it to - # off. + # Get the page information. - $altersection = "off"; + %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filename }); - } + # Check if any errors occured. - if (!$altertemplate){ + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # The alter template value is blank, so set it to - # off. + # A database error has occured so return an error and + # also the extended error information. - $altertemplate = "off"; + $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasepageerror}, $filename, $kiriwrite_dbmodule->geterror(1)); + $warning_count++; + next; - } + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ - if (!$altersettings){ + # The page does not exist, so process the next page. - # The alter settings value is blank, so set it to - # off. + $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasecopyfrompageerror}, $filename); + $warning_count++; + next; - $altersettings = "off"; + } - } + $kiriwrite_dbmodule->copypage({ PageFilename => $filename }); - # Check if the database filename is valid and return an error if - # it isn't. + # Check if any errors occured while copying the page. - my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1); + if ($kiriwrite_dbmodule->geterror eq "OldDatabaseError"){ - if ($pagedatabase_filename_check eq 1){ + # A database error has occured while copying the pages from + # the old database, so write a warning message. - # The database filename is blank, so return an error. + $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasecopyfromdatabaseerror}, $filename, $kiriwrite_dbmodule->geterror(1)); + $warning_count++; + next; - kiriwrite_error("blankdatabasepageadd"); + } elsif ($kiriwrite_dbmodule->geterror eq "NewDatabaseError"){ - } elsif ($pagedatabase_filename_check eq 2){ + # A database error has occured while copying the pages to + # the new database, so write a warning message. - # The database filename is invalid, so return an error. + $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasecopytodatabaseerror}, $filename, $kiriwrite_dbmodule->geterror(1)); + $warning_count++; + next; - kiriwrite_error("databasefilenameinvalid"); + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ - } + # The page with the filename given in the database that + # the page is to be copied from doesn't exist so write + # a warning message. - # Check if the confirm value is blank and if it is then - # set the confirm value to 0. + $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasecopyfrompagenotexist}, $filename); + $warning_count++; + next; - if (!$confirm){ + } elsif ($kiriwrite_dbmodule->geterror eq "PageAlreadyExists"){ - $confirm = 0; + # The page with the filename given in the database that + # the page is to be copied to already exists so write a + # warning message. - } + $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasecopytopageexists}, $filename); + $warning_count++; + next; - if ($confirm eq 1){ + } - # The action to edit the template has been confirmed so - # edit the selected pages. + # Append the copied page (filename and name) to the list of + # copied pages. - # Check the values recieved at UTF8 compliant before - # converting. + $copied_list{$page_seek}{Filename} = $filename; + $copied_list{$page_seek}{Name} = $page_info{"PageName"}; + $page_seek++; - 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. + # Disconnect from the database server. - $newsection = kiriwrite_utf8convert($newsection); - $newtemplate = kiriwrite_utf8convert($newtemplate); - $newsettings = kiriwrite_utf8convert($newsettings); + $kiriwrite_dbmodule->disconnect(); - # Check the length of the variables. + # Write out a message saying that the pages were moved (if any) + # to the new database (and any warnings given). - 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); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{copypages}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); - # Check the values and return an error if needed. + if (%copied_list){ - if ($newsection_maxlength_check eq 1 && $altersection eq "on"){ + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{copypagesresultmessage}, $olddatabase_name, $newdatabase_name)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); + foreach $page (keys %copied_list){ + if (!$copied_list{$page}{Name}){ + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname}); + $kiriwrite_presmodule->addtext(" (" . $copied_list{$page}{Filename} . ")"); + } else { + $kiriwrite_presmodule->addtext($copied_list{$page}{Name} . " (" . $copied_list{$page}{Filename} . ")"); + } + $kiriwrite_presmodule->addlinebreak(); + } + $kiriwrite_presmodule->endbox(); - # The new section name is too long, so return an - # error. + } else { - kiriwrite_error("pagesectiontoolong"); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{nopagescopied}, $olddatabase_name, $newdatabase_name)); } - if ($newtemplate_maxlength_check eq 1 && $altertemplate eq "on"){ - - # The new template name is too long, so return an - # error. + if (%warning_list){ - kiriwrite_error("templatefilenametoolong"); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{copypageswarnings}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); + foreach $warning (keys %warning_list){ + $kiriwrite_presmodule->addtext($warning_list{$warning}{Message}); + $kiriwrite_presmodule->addlinebreak(); + } + $kiriwrite_presmodule->endbox(); } - # Check if the template filename is set to !skip or !none - # and skip this check if it is. + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $olddatabase_name)}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $newdatabase, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{viewpagelist}, $newdatabase_name)}); + $kiriwrite_presmodule->endform(); - if ($newtemplate eq "!skip" || $newtemplate eq "!none"){ + return $kiriwrite_presmodule->grab(); - # Skip this check as the template filename is - # !skip or !none. + } elsif ($confirm eq 0) { - } else { - if ($newtemplate_filename_check eq 1 && $altertemplate eq "on" || $newtemplate_filename_check eq 2 && $altertemplate eq "on"){ + # The action to copy several pages from one database + # to another has not been confirmed so write a form. - # The new template filename is invalid, so return - # an error. + # Connect to the database server. - kiriwrite_error("templatefilenameinvalid"); + $kiriwrite_dbmodule->connect(); - } - } + # Check if any errors occured while connecting to the database server. - if ($newsettings_maxlength_check eq 1 && $altertemplate eq "on"){ + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - # The new settings value is too long, so return + # A database connection error has occured so return # an error. - kiriwrite_error("pagesettingstoolong"); + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); } - if ($newsettings_settings_check eq 1 && $altertemplate eq "on"){ + # Select the database to copy the pages from. - # The new settings value is invalid, so return - # an error. + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database }); - kiriwrite_error("pagesettingsinvalid"); + # Check if any errors occured while selecting the database. - } - - # Load the SQLite Database and get info about the database. + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - 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. + # The database does not exist, so return an error. - 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"); + kiriwrite_error("databasemissingfile"); - # Define some values for later. + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - 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; + # The database has invalid permissions set, so return + # an error. - # Get the date and time information. + kiriwrite_error("databaseinvalidpermissions"); - 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; + # Get information about the database. + my %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - # Check if the template filename is !skip and - # set the alter template value to off if it - # is. + # Check if any errors had occured while getting the database + # information. - if ($newtemplate eq "!skip"){ + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - $altertemplate = "off"; + # A database error has occured so return an error and + # also the extended error information. - } + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - # Check if all values are not selected and return - # an error if they are. + }; - if ($altersection ne "on" && $altertemplate ne "on" && $altersettings ne "on"){ + my $database_name = $database_info{"DatabaseName"}; - # All values are not selected so return - # an error. + # Define some values for later. - kiriwrite_error("noeditvaluesselected"); + my %page_info; + my %copy_list; + my %db_list; + my @page_info; + my $page; + my $data_file; + my $dbname; + my $filename; + my $pageseek = 0; + my $dbseek = 0; + my $pagefound = 0; - } + tie(%copy_list, 'Tie::IxHash'); + tie(%db_list, 'Tie::IxHash'); - # Check if each value is meant to be changed on - # the selected files. Start with the section - # name. + # Process each filename given. - if ($altersection eq "on"){ + foreach $filename (@filelist){ - # Convert the value so that it will work - # when SQL query is made. + # Get the page information. - $newsection_sql = kiriwrite_convert($newsection, "kiriwrite"); + %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filename }); - # 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. + # Check if any errors occured. - if ($sqlquery_seek eq 0){ + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # This is the first part of the SQL query. + # A database error has occured so return an error and + # also the extended error information. - $sqlquery_list[$sqlquery_seek] = "pagesection = \'" . $newsection_sql . "\'"; - $sqlquery_seek++; + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - } else { + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ - # This isn't the first part of the SQL query. + # The page does not exist, so process the next page. - $sqlquery_list[$sqlquery_seek] = ", pagesection = \'" . $newsection_sql . "\'"; - $sqlquery_seek++; + next; } - } - - # Check if the template name should be changed. - - if ($altertemplate eq "on"){ + # Add the page name and file name to the list of + # pages to move. - # Convert the value so that it will work - # when SQL query is made. + $copy_list{$pageseek}{Filename} = $page_info{"PageFilename"}; + $copy_list{$pageseek}{Name} = $page_info{"PageName"}; - $newtemplate_sql = kiriwrite_convert($newtemplate, "kiriwrite"); + # Increment the page seek counter. - # 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. + $pageseek++; - if ($sqlquery_seek eq 0){ + } - # This is the first part of the SQL query. + # Check if any pages exust and return an error if + # there wasn't. - $sqlquery_list[$sqlquery_seek] = "pagetemplate = \'" . $newtemplate_sql . "\'"; - $sqlquery_seek++; + if ($pageseek eq 0){ - } else { + # None of the selected pages exist, so return + # an error. - # This isn't the first part of the SQL query. + kiriwrite_error("nopagesselected"); - $sqlquery_list[$sqlquery_seek] = ", pagetemplate = \'" . $newtemplate_sql . "\'"; - $sqlquery_seek++; + } - } + # Get the database filenames and names. - } + my @database_list = $kiriwrite_dbmodule->getdblist(); - # Check if the page settings should be changed. + # Check if any errors occured while trying to get the list of databases. - if ($altersettings eq "on"){ + if ($kiriwrite_dbmodule->geterror eq "DataDirMissing"){ - # Convert the value so that it will work - # when SQL query is made. + # The database directory is missing so return an error. - $newsettings_sql = kiriwrite_convert($newsettings, "kiriwrite"); + kiriwrite_error("datadirectorymissing"); - # 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. + } elsif ($kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){ - if ($sqlquery_seek eq 0){ + # The database directory has invalid permissions set so return + # an error. - # This is the first part of the SQL query. + kiriwrite_error("datadirectoryinvalidpermissions"); - $sqlquery_list[$sqlquery_seek] = "pagesettings = \'" . $newsettings_sql . "\'"; - $sqlquery_seek++; + } - } else { + # Process each database to get the database name. - # This isn't the first part of the SQL query. + foreach $data_file (@database_list){ - $sqlquery_list[$sqlquery_seek] = ", pagesettings = \'" . $newsettings_sql . "\'"; - $sqlquery_seek++; + $kiriwrite_dbmodule->selectdb({ DatabaseName => $data_file }); - } + # Check if any errors occured while selecting the database. - } + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - # Add a new modification date. + # The database does not exist, so process the next + # database. - $sqlquery_list[$sqlquery_seek] = ", lastmodified = \'" . $pagelastmodified . "\'"; + next; - # Create the line for the needed SQL query. + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - foreach $sqlquery_option (@sqlquery_list){ + # The database has invalid permissions set, so process + # the next database. - # Add the line to the needed SQL query. + next; - $sqlquery_options = $sqlquery_options . $sqlquery_option; + } - } + # Get the database information. - # Edit each filename. + %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - foreach $filename (@filelist){ + # Check if any errors had occured while getting the database + # information. - # Check if the page filename exists in the - # database. + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - $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(); + # A database error has occured so process the next + # database. - # Check if the filename given exists and if it - # doesn't then skip this filename and go onto - # the next filename. + next; - while (@database_page = $string_handle->fetchrow_array()){ + }; - $pagefound = 1; + # Check if the database name is undefined and if it is + # then set it blank. + if (!$database_name){ + $database_name = ""; } - - 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; + # Append the database filename and name to the list of databases + # to move the pages to. - } + $db_list{$dbseek}{Filename} = $data_file; + $db_list{$dbseek}{Name} = $database_info{"DatabaseName"}; - # Get the page name. + $dbseek++; - $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. + # Disconnect from the database server. - $string_handle = $database_handle->prepare('UPDATE kiriwrite_database_pages SET ' . $sqlquery_options . ' WHERE filename = \'' . $filename_sql . '\''); - $string_handle->execute(); + $kiriwrite_dbmodule->disconnect(); - # Add the page to the list of edited pages. Check if - # the page name is blank. + # Write out the form. - if (!$page_name_out){ + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{copypages}, { Style => "pageheader" }); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "page"); + $kiriwrite_presmodule->addhiddendata("action", "multicopy"); + $kiriwrite_presmodule->addhiddendata("database", $database); + $kiriwrite_presmodule->addhiddendata("count", $pageseek); + $kiriwrite_presmodule->addhiddendata("confirm", 1); - # The page name is blank so write no name. + $pageseek = 1; - $edited_list = $edited_list . "The page (" . $filename_out . ") was edited." . "
"; + foreach $page (keys %copy_list){ + $kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on"); + $kiriwrite_presmodule->addhiddendata("id[" . $pageseek . "]", $copy_list{$page}{Filename}); + $pageseek++; + } - } else { + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{copypagesmessage}, $database_name)); - # Add the page to the list of edited pages. + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); - $edited_list = $edited_list . "The page called '" . $page_name_out . "' (" . $filename_out . ") was edited." . "
"; + $kiriwrite_presmodule->startbox("datalist"); + foreach $page (keys %copy_list){ + if (!$copy_list{$page}{Name}){ + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname}); + $kiriwrite_presmodule->addtext(" (" . $copy_list{$page}{Filename} . ")"); + } else { + $kiriwrite_presmodule->addtext($copy_list{$page}{Name} . " (" . $copy_list{$page}{Filename} . ")"); } + $kiriwrite_presmodule->addlinebreak(); + } - # Increment the counter of edited pages. + $kiriwrite_presmodule->endbox(); - $pageedited++; + $kiriwrite_presmodule->addlinebreak(); - } + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{copypagesto}); + $kiriwrite_presmodule->addselectbox("newdatabase"); - $pagedata = $pagedata . "

Edit selected pages

"; + foreach $dbname (keys %db_list){ + $kiriwrite_presmodule->addoption($db_list{$dbname}{Name} . " (" . $db_list{$dbname}{Filename} . ")", { Value => $db_list{$dbname}{Filename}}); + } - # 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. + $kiriwrite_presmodule->endselectbox(); - if ($pageedited eq 0){ + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{copypagesbutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name) }); + $kiriwrite_presmodule->endform(); - $pagedata = $pagedata . "No pages were edited in the '" . $database_name_out . "' database.

"; + return $kiriwrite_presmodule->grab(); - } else { + } else { - # Write out the message saying that the selected pages - # were edited. + # The confirm value is other than 0 or 1, so return + # an error. - $pagedata = $pagedata . "The selected pages in the '" . $database_name_out . "' database have been edited:

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

"; + kiriwrite_error("invalidvariable"); - } + } - # Check if any warnings have occured and write a message - # if any warnings did occur. +} - if ($warninglist){ +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. # +################################################################################# - # One or several warnings have occured so - # write a message. + # Get the values that were passed to the subroutine. - $pagedata = $pagedata . "The following errors/warnings occured while editing the selected pages:

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

"; + my ($database, $newsection, $altersection, $newtemplate, $altertemplate, $newsettings, $altersettings, $confirm, @filelist) = @_; - } + # Check if the file list is blank and return an error + # if it is. - # Write a link going back to the page list for - # the selected database. + if (!@filelist){ - $pagedata = $pagedata . "Return to the page list for the '" . $database_name_out . "' database."; + # The file list really is blank so return + # an error. - return $pagedata; + kiriwrite_error("nopagesselected"); - } elsif ($confirm eq 0){ + } - # The action to edit the template has not been confirmed - # so write a form out instead. + # Check if certain values are undefined and define them if + # they are. - # Load the SQLite Database and get info about the database. + if (!$altersection){ - 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(); + # The alter section value is blank, so set it to + # off. - # Get the database name. + $altersection = "off"; - 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. + if (!$altertemplate){ - 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; + # The alter template value is blank, so set it to + # off. - # Get the information about each page that is going - # to be edited. + $altertemplate = "off"; - foreach $filelist_filename (@filelist){ + } - $filelist_filename_sql = kiriwrite_convert($filelist_filename, "kiriwrite"); - $filelist_filename_out = kiriwrite_convert($filelist_filename, "normal_display"); + if (!$altersettings){ - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $filelist_filename . '\' LIMIT 1') or kiriwrite_error("databasefileinvalid"); + # The alter settings value is blank, so set it to + # off. - $string_handle->execute(); + $altersettings = "off"; - # 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()){ + # Check if the database filename is valid and return an error if + # it isn't. - $pagefound = 1; + my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1); - } - - if ($pagefound eq 0){ + if ($pagedatabase_filename_check eq 1){ - next; + # The database filename is blank, so return an error. - } + kiriwrite_error("blankdatabasepageadd"); - # Get the data again. + } elsif ($pagedatabase_filename_check eq 2){ - $string_handle->execute(); - @page_info = $string_handle->fetchrow_array(); + # The database filename is invalid, so return an error. - # Add the page name and file name to their seperate - # arrays. + kiriwrite_error("databasefilenameinvalid"); - $pagenames[$pageseek] = $page_info[1]; - $filenames[$pageseek] = $page_info[0]; + } - # Add the form data for the page filename. + # Check if the confirm value is blank and if it is then + # set the confirm value to 0. - # BLEARGH + if (!$confirm){ - $pagelistformdata = $pagelistformdata . ""; - $pagelistformdata = $pagelistformdata . ""; + $confirm = 0; - # Increment the page seek counter and reset the - # page found value. + } - $pageseek++; - $pagefound = 0; + if ($confirm eq 1){ - } + # The action to edit the template has been confirmed so + # edit the selected pages. - # Check if any pages were found in the database and return - # an error if not. + # Check the values recieved at UTF8 compliant before + # converting. - if ($pageseek eq 0){ + kiriwrite_variablecheck($newsection, "utf8", 0, 0); + kiriwrite_variablecheck($newtemplate, "utf8", 0, 0); + kiriwrite_variablecheck($newsettings, "utf8", 0, 0); - # No pages were found so return an error. + # Convert the values into proper UTF8 values. - kiriwrite_error("nopagesselected"); + $newsection = kiriwrite_utf8convert($newsection); + $newtemplate = kiriwrite_utf8convert($newtemplate); + $newsettings = kiriwrite_utf8convert($newsettings); - } + # Check the length of the variables. - # Get the template list and select the template that is being used by - # the page, check the permissions and if the template database exists. + 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); - my $template_file_exists = kiriwrite_fileexists("templates.db"); - my $template_file_permissions = kiriwrite_filepermissions("templates.db", 1, 0, 0); + # Check the values and return an error if needed. - if ($template_file_exists eq 1){ + if ($newsection_maxlength_check eq 1 && $altersection eq "on"){ - # The template database does not exist, so write a warning messsage. + # The new section name is too long, so return an + # error. - $template_warning = "The template database does not exist. Existing template settings for selected pages kept."; + kiriwrite_error("pagesectiontoolong"); } - if ($template_file_permissions eq 1 && $template_file_exists ne 1){ + if ($newtemplate_maxlength_check eq 1 && $altertemplate eq "on"){ - # The template database has invalid permissions set, so write a warning message. + # The new template name is too long, so return an + # error. - $template_warning = "The template database has invalid permissions set. Existing template settings for selected pages kept."; + kiriwrite_error("templatefilenametoolong"); } - # Get the list of templates. + # Check if the template filename is set to !skip or !none + # and skip this check if it is. - if (!$template_warning){ + if ($newtemplate eq "!skip" || $newtemplate eq "!none"){ - # Load the templates database and get the templates. + # Skip this check as the template filename is + # !skip or !none. - $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){ + } else { + if ($newtemplate_filename_check eq 1 && $altertemplate eq "on" || $newtemplate_filename_check eq 2 && $altertemplate eq "on"){ - $string_handle->execute(); + # The new template filename is invalid, so return + # an error. - $template_data = ""; + # Define some values for later. - } + my %database_info; + my %edited_list; + my %warning_list; + my %page_info; + my $page; + my $warning; + my $filename; + my $page_name; + my $pagefound = 0; + my $pageedited = 0; + my $warning_count = 0; - } + tie(%edited_list, 'Tie::IxHash'); + tie(%warning_list, 'Tie::IxHash'); + + # Check if the template filename is !skip and + # set the alter template value to off if it + # is. - # Process the list of selected pages. + if ($newtemplate eq "!skip"){ - $pageseek = 1; - foreach $filename (@filenames){ + $altertemplate = "off"; - # Process each filename. + } - $page_name = $pagenames[$pageseek - 1]; - $page_filename = $filenames[$pageseek - 1]; + # Check if all values are not selected and return + # an error if they are. - # Check if the page name is blank. + if ($altersection ne "on" && $altertemplate ne "on" && $altersettings ne "on"){ - if (!$page_name){ + # All values are not selected so return + # an error. - # Write a message saying there's no page name. + kiriwrite_error("noeditvaluesselected"); - $pagelist = $pagelist . "No Name" . " (" . $page_filename . ")" . "
" + } - } else { + # Connect to the database server. - # Append the page to the list of pages to edit. + $kiriwrite_dbmodule->connect(); - $pagelist = $pagelist . $page_name . " (" . $page_filename . ")" . "
"; + # Check if any errors occured while connecting to the database server. - } + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - $pageseek++; + # A database connection error has occured so return + # an error. + + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); } - # Write a form for editing the selected pages. + # Select the database. - $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. + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database }); - if ($template_warning){ + # Check if any errors occured while selecting the database. - # There is a message in the template warning variable + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - $pagedata = $pagedata . ""; + # The database does not exist, so return an error. - } else { - - $pagedata = $pagedata . ""; + kiriwrite_error("databasemissingfile"); + + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ + + # The database has invalid permissions set, so return + # an error. + + kiriwrite_error("databaseinvalidpermissions"); } - $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 . "
"; + # Check if the database has read and write permissions. - return $pagedata; + my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1); - } else { + if ($database_permissions eq 1){ - # The confirm value is something else other than - # 1 or 0, so return an error. + # The database permissions are invalid so return an error. - kiriwrite_error("invalidvariable"); + kiriwrite_error("databaseinvalidpermissions"); - } + } -} + # Get information about the database. -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. # -################################################################################# + %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - # Get the database file name from what was passed to the subroutine. + # Check if any errors had occured while getting the database + # information. - 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. + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - $data_file_length = length($data_file); - $data_file_friendly = substr($data_file, 0, $data_file_length - 3); + # A database error has occured so return an error and + # also the extended error information. - # Check if the permissions for the database are valid. + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - $file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' .$data_file, 1, 0); - - if ($file_permissions ne 0){ + }; + + my $database_name = $database_info{"DatabaseName"}; + + # Edit the selected pages. + + foreach $filename (@filelist){ - # The permissions for the database are invalid - # so process the next database. + # Get the page information. + %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filename }); + + # Check if any errors occured. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ + + # A database error has occured so write a warning message. + + $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasepageerror}, $filename, $kiriwrite_dbmodule->geterror(1)); + + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ + + # The page does not exist, so write a warning message. + + $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasepagedoesnotexist}, $filename); + $warning_count++; next; } - # Load the SQLite database. + # Check if the page section should be altered. - $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(); + if ($altersection eq "on"){ - # Get the database name from the results. + # Change the section name. - $database_name = $database_info[0]; - $database_name = kiriwrite_convert($database_name, "normal_display"); + $page_info{"PageSection"} = $newsection; - # 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 = ""; + # Check if the page template should be altered. - my $page_filename = ""; - my $page_name = ""; - my $page_description = ""; - my $page_modified = ""; + if ($altertemplate eq "on"){ - 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. + # Change the page template filename. - my $database_db_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_file . '.db', 1, 0, 0); + $page_info{"PageTemplate"} = $newtemplate; - if ($database_db_permissions eq 1){ + } - kiriwrite_error("databaseinvalidpermissions"); + # Check if the page settings should be altered. + + if ($altersettings eq "on"){ + + # Change the page settings value. + + $page_info{"PageSettings"} = $newsettings; } - # Load the SQLite database. + # Edit the selected page. - $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database_file . '.db'); - - # Get the database name. + $kiriwrite_dbmodule->editpage({ PageFilename => $page_info{"PageFilename"}, PageNewFilename => $page_info{"PageFilename"}, PageNewName => $page_info{"PageName"}, PageNewDescription => $page_info{"PageDescription"}, PageNewSection => $page_info{"PageSection"}, PageNewTemplate => $page_info{"PageTemplate"}, PageNewContent => $page_info{"PageContent"}, PageNewSettings => $page_info{"PageSettings"} }); - $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_info LIMIT 1") or kiriwrite_error("databasenameinvalid"); - $string_handle->execute(); + # Check if any errors occured while editing the page. - @database_info = $string_handle->fetchrow_array(); + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - $db_friendlyname = $database_info[0]; + # A database error has occured so write a warning message + # with the extended error information. - $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_pages") or kiriwrite_error("databasenameinvalid"); - $string_handle->execute(); + $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasepageerror}, $filename, $kiriwrite_dbmodule->geterror(1)); + $warning_count++; + next; - # Write the table header into the tabledata string. + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ - $tabledata = "\r\n\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n"; + # The pages does not exist in the database. - # Write the results out as a list and append it to the - # tabledata string. + $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasepagedoesnotexist}, $filename); + $warning_count++; + next; - 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"); + # The page has been edited so write a message saying that the page + # has been edited. - if ($database_pages[0]){ - $page_count++; - } else { - next; - } + $edited_list{$pageedited}{Filename} = $page_info{"PageFilename"}; + $edited_list{$pageedited}{Name} = $page_info{"PageName"}; + + # Increment the counter of edited pages. + + $pageedited++; - if ($tablestyletype eq 0){ + } - $tablestyle = "tablecell1"; - $tablestyletype = 1; + # Disconnect from the database server. - } else { + $kiriwrite_dbmodule->disconnect(); - $tablestyle = "tablecell2"; - $tablestyletype = 0; + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{multiedit}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); - } + # 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. - # Check if the page name and description names - # are blank and if they are write a message saying that - # field contains no data. + if ($pageedited eq 0){ - if ($page_name eq ""){ + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{nopagesedited}, $database_name)); - $page_name = "No Name"; + } else { - } + # Write out the message saying that the selected pages + # were edited. - if ($page_description eq ""){ + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{pagesedited}, $database_name)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); - $page_description = "No Description"; + foreach $page (keys %edited_list){ - } + # Check if the page name is not blank. - if ($page_modified eq ""){ + if (!$edited_list{$page}{Name}){ - $page_modified = "No Date"; + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{pages}->{noname}); + $kiriwrite_presmodule->addtext(" (" . $edited_list{$page}{Filename} . ")"); - } + } else { - $tabledata = $tabledata . ""; - + $kiriwrite_presmodule->addtext($edited_list{$page}{Name}); + $kiriwrite_presmodule->addtext(" (" . $edited_list{$page}{Filename} . ")"); + } + $kiriwrite_presmodule->addlinebreak(); } - # Check if the page count is more than - - if ($page_count > 0){ - $db_file_notblank = 1; - } + $kiriwrite_presmodule->endbox(); - # Append the closing table part into the tabledata string. + } + + # Check if any warnings have occured and write a message + # if any warnings did occur. + + if (%warning_list){ + + # One or several warnings have occured so + # write a message. + + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{editedpageswarnings}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); + foreach $warning (keys %warning_list) { + $kiriwrite_presmodule->addtext($warning_list{$warning}{Message}); + $kiriwrite_presmodule->addlinebreak(); + } + $kiriwrite_presmodule->endbox(); - $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"); + # Write a link going back to the page list for + # the selected database. - if ($db_file_notblank eq 0){ + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name) }); - $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.
"; + return $kiriwrite_presmodule->grab(); - } else { + } elsif ($confirm eq 0){ - $pagemultioptions = " | | | | "; + # The action to edit the template has not been confirmed + # so write a form out instead. - $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 . "

"; + # Connect to the database server. - } - - return $pagedata; - - } + $kiriwrite_dbmodule->connect(); -} + # Check if any errors occured while connecting to the database server. -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(); # -################################################################################# + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - # Load the required perl modules for this subroutine. + # A database connection error has occured so return + # an error. - 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 . ']'); + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - # 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; + # Select the database. -} + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database }); -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 any errors occured while selecting the database. - # Check if the confirm value is blank and if it is then set confirm to 0. + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - if (!$confirm){ + # The database does not exist, so return an error. - # The confirm value is blank, so set the value of confirm to 0. + kiriwrite_error("databasemissingfile"); - $confirm = 0; + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - } + # The database has invalid permissions set, so return + # an error. - 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); + kiriwrite_error("databaseinvalidpermissions"); - # Convert the values into proper UTF8 strings that can be used. + } - $templatename = kiriwrite_utf8convert($templatename); - $templatedescription = kiriwrite_utf8convert($templatedescription); - $templatelayout = kiriwrite_utf8convert($templatelayout); + # Check if the database has read and write permissions. - # Check the length of the converted UTF8 strings. + my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1); - 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 ($database_permissions eq 1){ - if ($templatefilename_length_check eq 1){ - - # The template filename length is too long, so return an error. + # The database permissions are invalid so return an error. - kiriwrite_error("templatefilenametoolong"); + kiriwrite_error("databaseinvalidpermissions"); } - if ($templatename_length_check eq 1){ - - # The template name length is too long, so return an error. + # Get information about the database. - kiriwrite_error("templatenametoolong"); + my %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - } + # Check if any errors had occured while getting the database + # information. + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - if ($templatedescription_length_check eq 1){ + # A database error has occured so return an error and + # also the extended error information. - # The template description length is too long, so return an error. + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - kiriwrite_error("templatedescriptiontoolong"); + }; - } + my $database_name = $database_info{"DatabaseName"}; - # Check if the filename specified is a valid filename. + # Define some variables for later. - kiriwrite_variablecheck($templatefilename, "filename", "", 0); + my %edit_list; + my %template_list; + my %template_info; + my %page_info; + my @templates_list; + my @filenames; + my $filelist_filename; + my $filename; + my $page; + my $pageseek = 0; + my $page_name; + my $page_filename; + my $template; + my $template_filename; + my $template_warning; + my $templateseek = 0; - # Check if the template database file permissions are valid and - # return an error if they aren't. + tie(%edit_list, 'Tie::IxHash'); + tie(%template_list, 'Tie::IxHash'); - my $template_database_permissions = kiriwrite_filepermissions("templates.db", 1, 1, 1); + # Get the information about each page that is going + # to be edited. - if ($template_database_permissions eq 1){ + foreach $filelist_filename (@filelist){ - # Template database has invalid permissions set, so return - # an error. + %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filelist_filename }); - kiriwrite_error("templatedatabasefileinvalidpermissions"); - } + # Check if any errors occured. - # Check if the template database exists and if it doesn't then - # create the database and populate it. + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - my $template_database_exists = kiriwrite_fileexists("templates.db"); - my $database_handle; - my $string_handle; + # A database error has occured so return an error and + # also the extended error information. - if ($template_database_exists eq 1){ + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - # The template database does not exist, so try to create a database. + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ - # Check if the directory has valid permissions to create files (and - # thus be able create a template database). + # The page does not exist, so process the next page. - my $directory_permissions = kiriwrite_filepermissions(".", 1, 1, 0); + next; - if ($directory_permissions eq 1){ + } - # The template database cannot be created because of invalid directory - # permissions so return an error. + # Add the page name and file name to the list of + # pages to edit. - kiriwrite_error("templatedatabasefilenotcreated"); - } + $edit_list{$pageseek}{Filename} = $page_info{"PageFilename"}; + $edit_list{$pageseek}{Name} = $page_info{"PageName"}; - # Create the SQLite database for the templates and populate it. + # Increment the page seek counter and reset the + # page found value. - $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(); + $pageseek++; } - # 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(); + # Check if any pages were found in the database and return + # an error if not. - my @database_template_check = $string_handle->fetchrow_array(); - my $template_checkname = $database_template_check[0]; + if ($pageseek eq 0){ - if ($template_checkname){ + # No pages were found so return an error. - # A template already exists with the filename given, so return an error. + kiriwrite_error("nopagesselected"); - kiriwrite_error("templatefilenameexists"); } - # Get the current date. + # Connect to the template database. - my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; + $kiriwrite_dbmodule->connecttemplate(); - my $templatedate = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second; + # Check if any errors had occured. - # Convert the values that are going to be added for storing in the database. + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){ - $templatename = kiriwrite_convert($templatename, "kiriwrite"); - $templatedescription = kiriwrite_convert($templatedescription, "kiriwrite"); - $templatelayout = kiriwrite_convert($templatelayout, "kiriwrite"); + # The template database does not exist so write a warning + # message. - # Add the template to the template database. + $template_warning = $kiriwrite_lang->{pages}->{templatedatabasenotexistmultieditkeep}; - $string_handle = $database_handle->prepare('INSERT INTO kiriwrite_templates values( - \'' . $templatefilename . '\', - \'' . $templatename . '\', - \'' . $templatedescription . '\', - \'' . $templatelayout . '\', - \'' . $templatedate . '\' - )'); - $string_handle->execute(); - - # Print out the confirmation message. + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){ - 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; - - } - - -} + # The template database has invalid permissions set so + # return an error. -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. # -################################################################################# + $template_warning = $kiriwrite_lang->{pages}->{templatedatabasepermissionsinvalidmultieditkeep}; - # Get all the variables that have been passed to the subroutine. + } - my ($templatefilename, $templatenewfilename, $templatenewname, $templatenewdescription, $templatelayout, $confirm) = @_; + if (!$template_warning){ - # 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; - - } + # Get the list of templates available. - # Check if the template filename is blank and if it is, then return - # an error. + @templates_list = $kiriwrite_dbmodule->gettemplatelist(); - if (!$templatefilename){ + # Check if any errors had occured. - kiriwrite_error("templatefilenameblank"); + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ - } - - if ($confirm eq 1){ + # A database error occured while getting the list + # of templates so write a warning message with the + # extended error information. - # 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); + $template_warning = kiriwrite_language($kiriwrite_lang->{pages}->{templatedatabaseerrormultieditkeep}, $kiriwrite_dbmodule->geterror(1)); - # Convert the values into proper UTF8 strings. + } - $templatenewname = kiriwrite_utf8convert($templatenewname); - $templatenewdescription = kiriwrite_utf8convert($templatenewdescription); - $templatelayout = kiriwrite_utf8convert($templatelayout); + if (!$template_warning){ - # Check if the filenames recieved are valid filenames. + foreach $template_filename (@templates_list){ - 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); + # Get the template data. - kiriwrite_variablecheck($templatefilename, "filename", "", 0); - kiriwrite_variablecheck($templatenewfilename, "filename", "", 0); + %template_info = $kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_filename }); - # Check that the template database file exists and the permissions - # of the template database are valid. + # Check if any error occured while getting the template information. - my $template_database_exists = kiriwrite_fileexists("templates.db"); - my $template_database_permissions = kiriwrite_filepermissions("templates.db", 1, 1, 0); + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ - if ($template_database_exists eq 1){ + # A database error has occured, so write a warning message with + # the extended error information. - # the template database does not exist so return an error. + $template_warning = kiriwrite_language($kiriwrite_lang->{pages}->{templatedatabaseerrormultieditkeep}, $kiriwrite_dbmodule->geterror(1)); - kiriwrite_error("templatedatabasemissing"); + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){ - } + # The template does not exist, so process the next page. - if ($template_database_permissions eq 1){ - - # The template database permissions are set incorrectly so - # return an error. + next; - kiriwrite_error("templatedatabaseinvalidpermissions"); + } - } + # Add the template to the list of templates. - # Get the date. + $template_list{$templateseek}{Filename} = $template_info{"TemplateFilename"}; + $template_list{$templateseek}{Name} = $template_info{"TemplateName"}; - my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; + $templateseek++; - 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. + # Disconnect from the template 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(); + $kiriwrite_dbmodule->disconnecttemplate(); - # Convert the following values so that display + # Disconnect from the database server. - $templatenewname = kiriwrite_convert($templatenewname, "normal_display"); + $kiriwrite_dbmodule->disconnect(); - # 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. + # Write a form for editing the selected pages. - my $templatefilename_sql = kiriwrite_convert($templatefilename, "kiriwrite"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{multiedit}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "page"); + $kiriwrite_presmodule->addhiddendata("action", "multiedit"); + $kiriwrite_presmodule->addhiddendata("database", $database); + $kiriwrite_presmodule->addhiddendata("count", $pageseek); + $kiriwrite_presmodule->addhiddendata("confirm", 1); - 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(); + $pageseek = 1; - # Check if there is a result from the SQL query made (meaning - # that the template exists). + foreach $page (keys %edit_list){ + $kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on"); + $kiriwrite_presmodule->addhiddendata("id[" . $pageseek . "]", $edit_list{$page}{Filename}); + $pageseek++; + } - my $template_found = 0; - my @database_template; + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{multieditmessage}, $database_name)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); - while (@database_template = $string_handle->fetchrow_array()){ + foreach $page (keys %edit_list){ + if (!$edit_list{$page}{Name}){ + $kiriwrite_presmodule->additalictext("No Name"); + $kiriwrite_presmodule->addtext(" (" . $edit_list{$page}{Filename} . ")"); + } else { + $kiriwrite_presmodule->addtext($edit_list{$page}{Name} . " (" . $edit_list{$page}{Filename} . ")"); + } - # The template has been found, so set the template - # found value to 1 so it doesn't return an error. + $kiriwrite_presmodule->addlinebreak(); + } + + $kiriwrite_presmodule->endbox(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{multieditmessagevalues}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 }); + + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{alter}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{setting}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{value}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->endheader(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addcheckbox("altersection"); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagesection}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addinputbox("newsection", { Size => 64, MaxLength => 256 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addcheckbox("altertemplate"); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagetemplate}); + $kiriwrite_presmodule->endcell(); + + $kiriwrite_presmodule->addcell("tablecell2"); - $template_found = 1; + if ($template_warning){ - } + $kiriwrite_presmodule->addhiddendata("newtemplate", "!skip"); + $kiriwrite_presmodule->addtext($template_warning); - if ($template_found eq 0){ + } else { - # The template was not found (doesn't exist) so - # return an error. + $kiriwrite_presmodule->addselectbox("newtemplate"); - kiriwrite_error("templatedoesnotexist"); + foreach $template (keys %template_list){ - } + $kiriwrite_presmodule->addoption($template_list{$template}{Name} . " (" . $template_list{$template}{Filename} . ")", { Value => $template_list{$template}{Filename}}); - # Execute the query and get the information again. + } - $string_handle->execute(); - @database_template = $string_handle->fetchrow_array(); + $kiriwrite_presmodule->addoption($kiriwrite_lang->{pages}->{usenotemplate}, { Value => "!none", Selected => 1 }); + $kiriwrite_presmodule->endselectbox(); + } + + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addcheckbox("altersettings"); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagesettings}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addradiobox("newsettings", { Description => $kiriwrite_lang->{pages}->{usepageandsection}, Value => 1 , Selected => 1}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addradiobox("newsettings", { Description => $kiriwrite_lang->{pages}->{usepagename}, Value => 2 }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addradiobox("newsettings", { Description => $kiriwrite_lang->{pages}->{usesectionname}, Value => 3 }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addradiobox("newsettings", { Description => $kiriwrite_lang->{pages}->{nopagesection}, Value => 0 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->endtable(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{editpagesbutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addreset($kiriwrite_lang->{common}->{clearvalues}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name) }); + $kiriwrite_presmodule->endform(); + + return $kiriwrite_presmodule->grab(); - # Get the values from the query results. + } else { - 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]; + # The confirm value is something else other than + # 1 or 0, so return an error. - # Convert the values that are going to be displayed. + kiriwrite_error("invalidvariable"); - $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{ +sub kiriwrite_page_list{ ################################################################################# -# kiriwrite_template_delete: Delete a template from the template folder. # +# kiriwrite_page_list: Lists pages from an database. # # # # Usage: # # # -# kiriwrite_template_delete(filename, confirm); # +# kiriwrite_page_list([database]); # # # -# filename Specifies the filename of the database to delete. # -# confirm Confirms the action to delete a template. # +# database Specifies the database to retrieve the pages from. # ################################################################################# - # Get the parameters that were passed to the subroutine. - - my ($template_filename, $template_confirm) = @_; - - if (!$template_confirm){ - $template_confirm = 0; - } + # Get the database file name from what was passed to the subroutine. - # 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){ + my ($database_file) = @_; - # The action to delete the template from the template database has - # been confirmed so delete the template. + # 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. - # Check if the template database exists and the file permissions - # are valid and return an error if they aren't. + if (!$database_file) { - my $template_database_exists = kiriwrite_fileexists("templates.db"); - my $template_database_permissions = kiriwrite_filepermissions("templates.db", 1, 1, 0); + # Define the variables required for this section. - if ($template_database_exists eq 1){ + my %database_info; + my @database_list; + my @databasefilenames; + my @databasenames; + my $dbseek = 0; + my $dbfilename = ""; + my $dbname = ""; + my $data_file = ""; + my $data_file_length = 0; + my $data_file_friendly = ""; + my $database_name = ""; + my $file_permissions = ""; - # the template database does not exist so return an error. + # Connect to the database server. - kiriwrite_error("templatedatabasemissing"); + $kiriwrite_dbmodule->connect(); + + # Check if any errors occured while connecting to the database server. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ + + # A database connection error has occured so return + # an error. + + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); } - if ($template_database_permissions eq 1){ - - # The template database permissions are set incorrectly so - # return an error. + # Open the data directory and get all of the databases. - kiriwrite_error("templatedatabaseinvalidpermissions"); + @database_list = $kiriwrite_dbmodule->getdblist(); + + # Check if any errors occured while trying to get the list of databases. + + if ($kiriwrite_dbmodule->geterror eq "DataDirMissing"){ + + # The database directory is missing so return an error. + + kiriwrite_error("datadirectorymissing"); + + } elsif ($kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){ + + # The database directory has invalid permissions set so return + # an error. + + kiriwrite_error("datadirectoryinvalidpermissions"); } - # Load thw SQLite database. + # Get the information about each database (the short name and friendly name). - my $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db"); + foreach $data_file (@database_list){ - # Get the template name. + $kiriwrite_dbmodule->selectdb({ DatabaseName => $data_file }); - my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates WHERE filename = \'' . $template_filename . '\' LIMIT 1') or die(kiriwrite_error("templatedatabaseinvalidformat")); - $string_handle->execute(); + # Check if any errors occured while selecting the database. - my @database_template_page = $string_handle->fetchrow_array(); - my $database_template_name = $database_template_page[1]; + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - $database_template_name = kiriwrite_convert($database_template_name, "normal_display"); + # The database does not exist, so process the next + # database. - # Delete the selected template. + next; - $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"; + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - 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. + # The database has invalid permissions set, so process + # the next database. + + next; - 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){ + # Get the database information. - # The template database does not exist so return an error. + %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - kiriwrite_error("templatedatabasemissing"); + # Check if any errors had occured while getting the database + # information. - } - - if ($template_database_permissions eq 1){ + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # The template database has invalid permissions set so return - # an error. + # A database error has occured, so process the next + # database. - kiriwrite_error("templatedatabaseinvalidpermissions"); + next; - } + }; - # Load the SQLite database. + # Set the database name. - 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(); + $database_name = $database_info{"DatabaseName"}; - # Check if a result had returned and return an error if no result - # was returned. + # Check if the database name is undefined and if it is + # then set it blank. - my @template_data; - my $template_found = 0; + if (!$database_name){ + $database_name = ""; + } - while(@template_data = $string_handle->fetchrow_array()){ - - # A template has been found so increment the counter. + # Append the database to the list of databases available. + + push(@databasefilenames, $data_file); + push(@databasenames, $database_name); - $template_found++; } - if ($template_found eq 0){ + # Disconnect from the database server. - # The template does not exist, so return an error. - kiriwrite_error("templatedoesnotexist"); + $kiriwrite_dbmodule->disconnect(); - } + # Write the page data. - # Get the template file information. + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{viewpages}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{nodatabaseselected}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}); + $kiriwrite_presmodule->addhiddendata("mode", "page"); + $kiriwrite_presmodule->addhiddendata("action", "view"); + $kiriwrite_presmodule->addselectbox("database"); + foreach $dbfilename (@databasefilenames){ + $dbname = $databasenames[$dbseek]; + $dbseek++; + $kiriwrite_presmodule->addoption($dbname . " (" . $dbfilename . ")", { Value => $dbfilename }); + } + $kiriwrite_presmodule->endselectbox(); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{viewbutton}); + $kiriwrite_presmodule->endform(); + + return $kiriwrite_presmodule->grab(); - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates WHERE filename = \'' . $template_filename . '\' LIMIT 1'); - $string_handle->execute(); - @template_data = $string_handle->fetchrow_array(); + } else { - my $template_data_filename = $template_data[0]; - my $template_data_name = $template_data[1]; + my %database_info; + my %template_info; + my @database_pages; + my $pagemultioptions = ""; + my $db_name = ""; + my $tablestyle = ""; - # Check if the template name is blank and if it is + my $page_filename = ""; + my $page_name = ""; + my $page_description = ""; + my $page_modified = ""; - # Convert the strings so that display properly. + my $tablestyletype = 0; + my $page_count = 0; + my $db_file_notblank = 0; - $template_data_name = kiriwrite_convert($template_data_name, "normal_display"); - $template_data_name = kiriwrite_convert($template_data_name, "normal_display"); + tie(%database_info, 'Tie::IxHash'); + tie(%template_info, 'Tie::IxHash'); - # 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 { + # The database_file variable is not blank, so print out a list of pages from + # the selected database. - kiriwrite_error("invalidvariable"); + # 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", 32, 0); -} + # Connect to the database server. -sub kiriwrite_template_list{ -################################################################################# -# kiriwrite_template_list: List the templates in the template folder. # -# # -# Usage: # -# # -# kiriwrite_template_list(); # -################################################################################# + $kiriwrite_dbmodule->connect(); - # Load the module required for processing the XML configuration files. - - use DBI; + # Check if any errors occured while connecting to the database server. - # Define certain values for later. + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - my @database_template; - - my $database_handle; - my $string_handle; - - my $template_filename = ""; - my $template_name = ""; - my $template_description = ""; - my $template_data = ""; + # A database connection error has occured so return + # an error. - my $template_count = 0; + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - 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. + # Select the database. - my $template_database_permissions = kiriwrite_filepermissions("templates.db", 1, 0, 1); - my $template_database_exists = kiriwrite_fileexists("templates.db"); + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database_file }); - if ($template_database_permissions eq 1){ + # Check if any errors had occured while selecting the database. - # The templates directory has invalid permissions so an - # error will be returned. + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - kiriwrite_error("templatedatabaseinvalidpermissions"); + # The database does not exist, so return an error. - } + kiriwrite_error("databasemissingfile"); - if ($template_database_exists eq 1){ + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - $pagedata = "

View Templates

"; - $pagedata = $pagedata . "
The template database doesn't exist and will be created when a template is added.
"; + # The database has invalid permissions set, so return + # an error. - return $pagedata; + kiriwrite_error("databaseinvalidpermissions"); - } - - # Place the table cell headings into the templatedata string. + } - $templatedata = ""; + # Get information about the database. - # Check if the database exists first before loading it. + %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - if ($template_database_exists eq 1){ + $db_name = $database_info{"DatabaseName"}; - } else { + # Check if any errors had occured while getting the database + # information. - # Load the SQLite database. + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - $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(); + # A database error has occured so return an error and + # also the extended error information. - # Process each template. + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - while (@database_template = $string_handle->fetchrow_array()){ + } - # Get certain values from the array. + # Get the list of pages. - $template_filename = $database_template[0]; - $template_name = $database_template[1]; - $template_description = $database_template[2]; - $template_data = $database_template[3]; + @database_pages = $kiriwrite_dbmodule->getpagelist(); - # Convert the data into information that can be displayed. + # Check if any errors had occured while getting the list of pages. - $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"); + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # Check what style the row of table cells should be. + # A database error has occured so return an error and + # also the extended error information. - if ($template_style eq 0){ + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - $template_stylename = "tablecell1"; - $template_style = 1; + } - } else { + # Check if there are any page names in the database array. - $template_stylename = "tablecell2"; - $template_style = 0; + if (@database_pages){ - } + # Write the start of the page. - # 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. + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{pagelist}, $db_name), { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "page"); + $kiriwrite_presmodule->addhiddendata("database", $database_file); + $kiriwrite_presmodule->addhiddendata("type", "multiple"); - if (!$template_name){ - $template_name = "No Name"; - } + # Write the list of multiple selection options. - if (!$template_description){ - $template_description = "No Description"; - } + $kiriwrite_presmodule->addreset($kiriwrite_lang->{common}->{selectnone}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addbutton("action", { Value => "multidelete", Description => $kiriwrite_lang->{pages}->{deleteselectedbutton} }); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addbutton("action", { Value => "multimove", Description => $kiriwrite_lang->{pages}->{moveselectedbutton} }); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addbutton("action", { Value => "multicopy", Description => $kiriwrite_lang->{pages}->{copyselectedbutton} }); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addbutton("action", { Value => "multiedit", Description => $kiriwrite_lang->{pages}->{editselectedbutton} }); - # Check if there is no template data and if there isn't write - # a blank template message. + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); - if (!$template_data){ - $template_filename = $template_filename . " [Blank Template]"; - } + # Write the table header. - # Append the table row to the templatedata string. + $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 }); + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader("", { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{pages}->{pagefilename}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{pages}->{pagename}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{pages}->{pagedescription}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{pages}->{lastmodified}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{options}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->endheader(); - $templatedata = $templatedata . ""; + # Process each page filename and get the page information. - # Increment the template counter. + foreach $page_filename (@database_pages){ - $template_count++; + %template_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $page_filename }); - } + # Check if any errors have occured. - } - - $templatedata = $templatedata . "
Template FilenameTemplate NameTemplate DescriptionOptions
" . $template_filename . "" . $template_name . "" . $template_description . "Edit Delete
"; + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # 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. + # A database error has occured so return an error and + # also the extended error information. - if ($template_count eq 0){ - $templatedata = "
There are no templates in the template database. To add a template click on the Add Template link.
"; - } + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - # Process the templatedata into pagedata. + } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){ - $pagedata = "

View Templates

"; - $pagedata = $pagedata . $templatedata; - - return $pagedata; - -} + # The page does not exist, so process the next page. -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. # -################################################################################# + next; - # 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. + $page_count++; - use DBI; + $page_filename = $template_info{"PageFilename"}; + $page_name = $template_info{"PageName"}; + $page_description = $template_info{"PageDescription"}; + $page_modified = $template_info{"PageLastModified"}; - # Check if the confirm value is blank and if it is then - # set the confirm value to 0. + # Set the table cell style. - if (!$database_confirm){ + if ($tablestyletype eq 0){ - # The confirm value was blank so set the value to 0. + $tablestyle = "tablecell1"; + $tablestyletype = 1; - $database_confirm = 0; + } else { - } - - - if ($database_confirm eq 1){ + $tablestyle = "tablecell2"; + $tablestyletype = 0; - # 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); + # Write out the row of data. - # Convert the UTF8 strings before checking the length of the strings. + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell($tablestyle); + $kiriwrite_presmodule->addhiddendata("id[" . $page_count . "]", $page_filename); + $kiriwrite_presmodule->addcheckbox("name[" . $page_count . "]"); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($tablestyle); + $kiriwrite_presmodule->addtext($page_filename); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($tablestyle); - $database_name = kiriwrite_utf8convert($database_name); - $database_description = kiriwrite_utf8convert($database_description); - $database_notes = kiriwrite_utf8convert($database_notes); - $database_categories = kiriwrite_utf8convert($database_categories); + if (!$page_name){ - 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); + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname}); - # Check if values returned contains any values that would - # result in a specific error message being returned. + } else { - if ($database_name_check_length eq 1){ + $kiriwrite_presmodule->addtext($page_name); - # The length of the database name is too long, so return an error. - kiriwrite_error("databasenametoolong"); + } - } + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($tablestyle); - if ($database_description_check_length eq 1){ + if (!$page_description){ - # The database description length is too long, so return an error. - kiriwrite_error("databasedescriptiontoolong"); + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{nodescription}); - } + } else { - if ($database_name_check_blank eq 1){ + $kiriwrite_presmodule->addtext($page_description); - # The database name is blank, so return an error. - kiriwrite_error("databasenameblank"); + } - } + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($tablestyle); - if ($database_filename_check_length eq 1){ + if (!$page_modified){ - # The database filename is to long, so return an error. - kiriwrite_error("databasefilenametoolong"); + $kiriwrite_presmodule->additalictext("No Date"); - } + } else { - if ($database_categories_check_length eq 1){ + $kiriwrite_presmodule->addtext($page_modified); - # The database categories is too long, so return an error. - kiriwrite_error("databasecategoriestoolong"); + } - } + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($tablestyle); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=edit&database=" . $database_file . "&page=" . $page_filename, { Text => $kiriwrite_lang->{options}->{edit} }); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=delete&database=" . $database_file . "&page=" . $page_filename, { Text => $kiriwrite_lang->{options}->{delete} }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + # Increment the counter. - # 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. + # Disconnect from the database server. + + $kiriwrite_dbmodule->disconnect(); + + $kiriwrite_presmodule->addhiddendata("count", $page_count); + $kiriwrite_presmodule->endtable(); + $kiriwrite_presmodule->endform(); + + if (!@database_pages || !$page_count){ + + # There were no values in the database pages array and + # the page count had not been incremented so write a + # message saying that there were no pages in the + # database. + + $kiriwrite_presmodule->clear(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{pagelist}, $db_name), { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("errorbox"); + $kiriwrite_presmodule->enterdata($kiriwrite_lang->{pages}->{nopagesindatabase}); + $kiriwrite_presmodule->endbox(); + + } + + return $kiriwrite_presmodule->grab(); - 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{ +sub kiriwrite_page_multipleselect{ ################################################################################# -# kiriwrite_database_edit: Edits an database. # -# # +# 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_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. # +# kiriwrite_page_multipleselect(); # ################################################################################# - # First, get all the variables passed to the subroutine. + # Load the required perl modules for this subroutine. - my ($database_shortname, $database_name, $database_description, $database_newfilename, $database_newname, $database_newdescription, $database_notes, $database_categories, $database_confirm) = @_; + my $query = new CGI; - # 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. + # Setup some variables that will be used later on. - if (!$database_confirm){ + my $page_select_seek = 1; + my $page_current_value = ""; + my $selectionlist = ""; - $database_confirm = 0; + # Get the required variables from the HTTP query. - } + my $page_count = $query->param('count'); - # 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). + do { - if ($database_confirm eq 1){ + # Get the current value of the selected page's checkbox. - # Check if the database exists before trying to edit it. + $page_current_value = $query->param('name[' . $page_select_seek . ']'); - my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db'); + # If page_current_value is undefinied or blank, set page_current_value + # to off. - if ($database_exists eq 1){ + if (!$page_current_value){ - # The database does not exist so return an error. - - kiriwrite_error("databasemissingfile"); + $page_current_value = "off"; } - - # 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); + # Check if the page_current_value is set to 'on' if it is append the + # current page seek value to the selection list. - # Convert the UTF8 strings to make sure their length is accurate. + if ($page_current_value eq "on"){ - $database_newname = kiriwrite_utf8convert($database_newname); - $database_newdescription = kiriwrite_utf8convert($database_newdescription); - $database_notes = kiriwrite_utf8convert($database_notes); - $database_categories = kiriwrite_utf8convert($database_categories); + # Append the current seek value to the selection list. - # Check if the database filename given is valid and return an error - # if it isn't. + $selectionlist = $selectionlist . $page_select_seek . "|"; - 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); + # Increment the page selection seeking counter. - # Check if the data is valid and return a specific error if it doesn't. + $page_select_seek++; - if ($database_name_check_length eq 1){ + } until ($page_select_seek eq $page_count); - # The length of the database name is too long, so return an error. - kiriwrite_error("databasenametoolong"); + return $selectionlist; - } +} - if ($database_description_check_length eq 1){ +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. # +################################################################################# - # The database description length is too long, so return an error. - kiriwrite_error("databasedescriptiontoolong"); + # Get the variables that were passed to the subroutine. - } + my ($templatefilename, $templatename, $templatedescription, $templatelayout, $confirm) = @_; - if ($database_name_check_blank eq 1){ + # Check if the confirm value is blank and if it is then set confirm to 0. - # The database name is blank, so return an error. - kiriwrite_error("databasenameblank"); + if (!$confirm){ - } + # The confirm value is blank, so set the value of confirm to 0. - if ($database_filename_check_length eq 1){ + $confirm = 0; - # The database filename is too long, so return an error. - kiriwrite_error("databasefilenametoolong"); + } - } + if ($confirm eq 1){ - if ($database_categories_check_length eq 1){ + # Check (validate) each of the values. - # The database categories is too long, so return an error. - kiriwrite_error("databasecategoriestoolong"); + 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 permissions of the database file to see if it is valid - # and return an error if it isn't. + # Check the length of the converted UTF8 strings. - my $database_file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db', 1, 1, 1); + 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 ($database_file_permissions eq 1){ + if ($templatefilename_length_check eq 1){ - # The database file itself has invalid permissions. + # The template filename length is too long, so return an error. - kiriwrite_error("databaseinvalidpermissions"); + kiriwrite_error("templatefilenametoolong"); } - # 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){ + if ($templatename_length_check eq 1){ - # 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"); - } + # The template name length is too long, so return an error. + + kiriwrite_error("templatenametoolong"); + + } - # 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. + if ($templatedescription_length_check eq 1){ + + # The template description length is too long, so return an error. - $database_shortname = $database_newfilename; + kiriwrite_error("templatedescriptiontoolong"); } - - # Load the SQLite database. - my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . ".db"); + # Check if the filename specified is a valid filename. - # Convert the UTF8 strings so that they can be properly updated. + kiriwrite_variablecheck($templatefilename, "filename", "", 0); - $database_name = kiriwrite_utf8convert($database_name); - $database_description = kiriwrite_utf8convert($database_description); + # Connect to the template server. - # Convert the strings that are going to put into the database so that - # the database query doesn't break. + $kiriwrite_dbmodule->connect(); - $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(); + # Connect to the template database. - # Convert a string so that it can be displayed properly. + $kiriwrite_dbmodule->connecttemplate(1); - $database_newname = kiriwrite_convert($database_newname, "normal_display"); + # Check if any errors had occured. - # Write out a message saying that the database has been updated. + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){ - $pagedata = $pagedata . "Database '" . $database_newname . "' updated.
"; - $pagedata = $pagedata . "
\r\nReturn to database list."; - - return $pagedata; - - } else { + # The template database has invalid permissions set so + # return an error. - # Check if the database filename given is valid and return an error - # if it isn't. + kiriwrite_error("templatedatabaseinvalidpermissions"); - kiriwrite_variablecheck($database_shortname, "filenameindir", "", 0); + } - # Check if the database exists before trying to edit it. + $kiriwrite_dbmodule->addtemplate({ TemplateFilename => $templatefilename, TemplateName => $templatename, TemplateDescription => $templatedescription, TemplateLayout => $templatelayout }); - my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db'); + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ - if ($database_exists eq 1){ + # A database error has occured so return an error along + # with the extended error information. - # The database does not exist so return an error. - - kiriwrite_error("databasemissingfile"); + kiriwrite_error("templatedatabaseerror", $kiriwrite_dbmodule->geterror(1)); - } + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){ + + # The template database has invalid permissions set so return + # an error. + kiriwrite_error("templatedatabaseinvalidpermissions"); - # Check the permissions of the database file to see if it is valid - # and return an error if it isn't. + } elsif ($kiriwrite_dbmodule->geterror eq "TemplatePageExists"){ - my $database_file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db', 1, 0, 1); + # The template page already exists so return an error. - if ($database_file_permissions eq 1){ + kiriwrite_error("templatefilenameexists"); - # The database file itself has invalid permissions. + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseUncreateable"){ - kiriwrite_error("databaseinvalidpermissions"); + # The template databases is uncreatable so return an error. + + kiriwrite_error("templatedatabasenotcreated"); } - # Load the SQLite database. + $kiriwrite_dbmodule->disconnecttemplate(); - 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(); + # Disconnect from the template server. - # Get the values needed from the kiriwrite_database_info table. + $kiriwrite_dbmodule->disconnect(); - my $database_oldname = $database_info[0]; - my $database_olddescription = $database_info[1]; - my $database_notes = $database_info[2]; - my $database_categories = $database_info[3]; + # Print out the confirmation message. - # Convert the values in the kieiwrite format into the format that can be understood - # with a web browser. + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{addedtemplate}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{template}->{addedtemplatemessage}, $templatename)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=template", { Text => $kiriwrite_lang->{template}->{returntemplatelist} }); + return $kiriwrite_presmodule->grab(); - $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"); + } else { + # No confirmation was made, so print out a form for adding a template. + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{addtemplate}, { Style => "pageheader" }); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "template"); + $kiriwrite_presmodule->addhiddendata("action", "add"); + $kiriwrite_presmodule->addhiddendata("confirm", 1); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->starttable("", { CellSpacing => 0, CellPadding => 5 }); + + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{setting}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{value}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->endheader(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{templatename}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("templatename", { Size => 64, MaxLength => 512 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{templatedescription}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("templatedescription", { Size => 64, MaxLength => 512 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{templatefilename}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("templatefilename", { Size => 32, MaxLength => 64 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{templatelayout}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtextbox("templatelayout", { Columns => 50, Rows => 10 }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); + $kiriwrite_presmodule->addboldtext($kiriwrite_lang->{common}->{tags}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagecontent}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagetitle}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagename}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagedescription}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagesection}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pageautosection}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pageautotitle}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->endbox(); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + $kiriwrite_presmodule->endtable(); + + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{template}->{addtemplatebutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addreset($kiriwrite_lang->{common}->{clearvalues}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=template" , { Text => $kiriwrite_lang->{template}->{returntemplatelist} }); + + $kiriwrite_presmodule->endform(); + + return $kiriwrite_presmodule->grab(); - # 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{ +sub kiriwrite_template_edit{ ################################################################################# -# kiriwrite_database_delete: Deletes an database. # +# kiriwrite_template_edit: Edit a template from the template folder. # # # # Usage: # # # -# kiriwrite_database_delete(filename, [confirm]); # +# kiriwrite_template_edit(filename, [newfilename], [newname], [newdescription], # +# [templatelayout], [confirm]); # # # -# filename Specifies the filename for the database to be deleted. # -# confirm Confirms the action to delete a database. # +# 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. # ################################################################################# - 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; + # Get all the variables that have been passed to the subroutine. - } + my ($templatefilename, $templatenewfilename, $templatenewname, $templatenewdescription, $templatelayout, $confirm) = @_; - # Check if the database exists before trying to edit it. + # Check if the confirm variable is blank, if it is then + # set confirm to '0' - my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db'); + if (!$confirm){ - if ($database_exists eq 1){ + # confirm is uninitalised/blank, so set the value of confirm + # to '0' - # The database does not exist so return an error. - - kiriwrite_error("databasemissingfile"); + $confirm = 0; } - # Check if the database filename given is valid and return an error - # if it isn't. + # Check if the template filename is blank and if it is, then return + # an error. - kiriwrite_variablecheck($database_filename, "filename", "", 0); + if (!$templatefilename){ - # 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 = ""; + kiriwrite_error("templatefilenameblank"); - $deleted_database_file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db', 1, 1, 1); + } - if ($deleted_database_file_permissions eq 1){ + # Connect to the database server. - # The database file itself has invalid permissions. + $kiriwrite_dbmodule->connect(); - kiriwrite_error("databaseinvalidpermissions"); + # Check if any errors occured while connecting to the database server. - } - - # Load the SQLite database to get the database name. + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - 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(); + # A database connection error has occured so return + # an error. - my $database_name = $database_info[0]; - $database_name = kiriwrite_convert($database_name, "normal_display"); + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - # Untaint the database filename given. + } - ($database_filename) = $database_filename =~ /^([a-zA-Z0-9.]+)$/; + if ($confirm eq 1){ - # Delete the database file. + # Check certain strings to see if they UTF8 compiliant. - 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"; + kiriwrite_variablecheck($templatenewname, "utf8", 0, 0); + kiriwrite_variablecheck($templatenewdescription, "utf8", 0, 0); + kiriwrite_variablecheck($templatelayout, "utf8", 0, 0); - $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. + # Convert the values into proper UTF8 strings. - my $delete_database_file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db', 1, 1, 1); + $templatenewname = kiriwrite_utf8convert($templatenewname); + $templatenewdescription = kiriwrite_utf8convert($templatenewdescription); + $templatelayout = kiriwrite_utf8convert($templatelayout); - if ($delete_database_file_permissions eq 1){ + # Check if the filenames recieved are valid filenames. - # The database file itself has invalid permissions. + 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_error("databaseinvalidpermissions"); + kiriwrite_variablecheck($templatefilename, "filename", "", 0); + kiriwrite_variablecheck($templatenewfilename, "filename", "", 0); - } + # Connect to the template database. - # 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(); + $kiriwrite_dbmodule->connecttemplate(); - # Convert the database name so that it can be displayed properly. + # Check if any errors had occured. - 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; + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){ -} + # The template database has invalid permissions set so + # return an error. -sub kiriwrite_database_list{ -################################################################################# -# kiriwrite_database_list: Lists the databases available. # -# # -# Usage: # -# # -# kiriwrite_database_list(); # -################################################################################# + kiriwrite_error("templatedatabaseinvalidpermissions"); - # 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. + # Edit the template. - my $data_directory_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"}, 1, 0); + $kiriwrite_dbmodule->edittemplate({ TemplateFilename => $templatefilename, NewTemplateFilename => $templatenewfilename, NewTemplateName => $templatenewname, NewTemplateDescription => $templatenewdescription, NewTemplateLayout => $templatelayout }); - if ($data_directory_permissions eq 1){ + # Check if any error occured while editing the template. - # The data directory has invalid permissions set, so return an error. + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ - kiriwrite_error("datadirectoryinvalidpermissions"); + # A database error has occured, so return an error. - } + kiriwrite_error("templatedatabaseerror", $kiriwrite_dbmodule->geterror(1)); - # Open the directory and get the list of all files ending with .xml and - # put them into the data_directory array. + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){ - 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. + # The template database has invalid permissions set so return + # an error. - $database_filename = $kiriwrite_config{"directory_data_db"} . '/' . $data_file; - $database_permissions = kiriwrite_filepermissions($database_filename, 1, 0, 0); + kiriwrite_error("templatedatabaseinvalidpermissions"); + + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){ + + # The template does not exist, so process the next template. + + kiriwrite_error("templatedoesnotexist"); - 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); + # Disconnect from the database server. - # Query the SQLite database or return an error (meaning that the database is in - # a invalid format). + $kiriwrite_dbmodule->disconnect(); - $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 - ); + # Disconnect from the template database. - $string_handle->execute(); - @database_info = $string_handle->fetchrow_array(); - - # Check the style to be used with. + $kiriwrite_dbmodule->disconnecttemplate(); - if ($table_style eq 0){ + # Append a link so that the user can return to the templates list. - # Use the first style and set the style value - # to use the next style, the next time the - # if statement is checked. + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{editedtemplate}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{template}->{editedtemplatemessage}, $templatenewname)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=template", { Text => $kiriwrite_lang->{template}->{returntemplatelist} }); - $table_style_name = "tablecell1"; - $table_style = 1; - } else { + } else { - # Use the second style and set the style - # value to use the first style, the next - # time if statement is checked. + # Connect to the template database. + + $kiriwrite_dbmodule->connecttemplate(); + + # Check if any errors had occured. + + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){ + + # The template database has invalid permissions set so + # return an error. + + kiriwrite_error("templatedatabaseinvalidpermissions"); - $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"); + # Get the template information. - # Create a friendly name for the database. + my %template_info = $kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $templatefilename }); - $database_filename_length = length($data_file); - $database_filename_friendly = substr($data_file, 0, $database_filename_length - 3); + # Check if any error occured while getting the template information. - # Append the database information to the table. + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ - $pagedata = $pagedata . "\r\n"; + # A database error has occured, so return an error. - $database_count++; - - } - - $pagedata = $pagedata . "
Database NameDatabase DescriptionOptions
" . $database_info[0] . "" . $database_info[1] . "Edit Delete Compile
\r\n
"; + kiriwrite_error("templatedatabaseerror", $kiriwrite_dbmodule->geterror(1)); - # 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. + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){ - if ($database_count eq 0){ + # The template does not exist, so return an error. + + kiriwrite_error("templatedoesnotexist"); - # + } - $pagedata = "

Database List

"; - $pagedata = $pagedata . "

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

"; + # Disconnect from the template database. - } + $kiriwrite_dbmodule->disconnecttemplate(); - # Check if any databases with problems have appeared and if they - # have, print out a message saying which databases have problems. + # Get the values from the query results. - if ($permissions_warning eq 1){ + my $template_filename = $template_info{"TemplateFilename"}; + my $template_name = $template_info{"TemplateName"}; + my $template_description = $template_info{"TemplateDescription"}; + my $template_layout = $template_info{"TemplateLayout"}; + my $template_modified = $template_info{"TemplateLastModified"}; - $pagedata = $pagedata . "

Databases with invalid permissions

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

"; - $pagedata = $pagedata . $permissions_list; + # Check if the values are undefined and set them blank + # if they are. - } - - if ($invalid_warning eq 1){ + if (!$template_name){ + $template_name = ""; + } + + if (!$template_description){ + $template_description = ""; + } + + if (!$template_layout){ + $template_layout = ""; + } - $pagedata = $pagedata . "

Databases with invalid formats

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

"; - $pagedata = $pagedata . $invalid_list; + # Write out the form for editing an template with the current template + # settings put into the correct place. + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{edittemplate}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "template"); + $kiriwrite_presmodule->addhiddendata("action", "edit"); + $kiriwrite_presmodule->addhiddendata("confirm", 1); + $kiriwrite_presmodule->addhiddendata("template", $template_filename); + $kiriwrite_presmodule->starttable("", { CellSpacing => 0, CellPadding => 5}); + + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{setting}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{value}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->endheader(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{templatename}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("newname", { Size => 64, MaxLength => 512, Value => $template_name }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{templatedescription}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("newdescription", { Size => 64, MaxLength => 512, Value => $template_description }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{templatefilename}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("newfilename", { Size => 32, MaxLength => 64, Value => $template_filename }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{templatelayout}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtextbox("newlayout", { Rows => 10, Columns => 50, Value => $template_layout}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); + $kiriwrite_presmodule->addboldtext($kiriwrite_lang->{common}->{tags}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagecontent}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagetitle}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagename}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagedescription}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagesection}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pageautosection}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pageautotitle}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->endbox(); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->endtable(); + + $kiriwrite_presmodule->addlinebreak(); + + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{template}->{edittemplatebutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addreset($kiriwrite_lang->{common}->{restorecurrent}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=template", { Text => $kiriwrite_lang->{template}->{returntemplatelist} }); + + $kiriwrite_presmodule->endform(); } - return $pagedata; # Return to the main part of the script with the processed information. + # Disconnect from the database server. -} + $kiriwrite_dbmodule->disconnect(); + return $kiriwrite_presmodule->grab(); -sub kiriwrite_filter_list{ +} + +sub kiriwrite_template_delete{ ################################################################################# -# kiriwrite_filter_list: Lists the filters that will be used when compiling a # -# webpage. # +# kiriwrite_template_delete: Delete a template from the template folder. # # # # Usage: # # # -# kiriwrite_filter_list(); # +# kiriwrite_template_delete(filename, confirm); # +# # +# filename Specifies the filename of the database to delete. # +# confirm Confirms the action to delete a template. # ################################################################################# - - # Load the needed Perl modules. - use DBI; + # Get the parameters that were passed to the subroutine. - # Check if the filters database exists and the - # permissions for the filters database are - # valid. + my ($template_filename, $template_confirm) = @_; - my $database_exists = kiriwrite_fileexists("filters.db"); - my $database_permissions = kiriwrite_filepermissions("filters.db", 1, 0, 0); - my $filtersdb_notexist = 0; + if (!$template_confirm){ + $template_confirm = 0; + } - if ($database_exists eq 1){ + # Check the length of the variables. + kiriwrite_variablecheck($template_filename, "maxlength", 64, 0); + kiriwrite_variablecheck($template_confirm, "maxlength", 1, 0); - # The filters database does not exist so - # set the value for the filters database - # not existing to 1. + # 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. - $filtersdb_notexist = 1; + if (!$template_filename){ - } + # The template_filename string really is blank, + # so return an error saying that an empty + # filename was passed (to the subroutine). - if ($database_permissions eq 1 && $database_exists ne 1){ + kiriwrite_error("templatefilenameblank"); - # The filters database has invalid - # permissions set, so return an error. + } - kiriwrite_error("filtersdbpermissions"); + # 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){ - # Define some variables required for processing the filters list. + # The action to delete the template from the template database has + # been confirmed so delete the template. - 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 = ""; + # Connect to the database server. - $pagedata = $pagedata . "

View Filters

"; + $kiriwrite_dbmodule->connect(); - # 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. + # Check if any errors occured while connecting to the database server. - if ($filtersdb_notexist eq 0){ + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - # Get the SQLite database and get the filters ordered - # by priority. + # A database connection error has occured so return + # an error. - $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(); + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - $filterdata = $filterdata . ""; - $filterdata = $filterdata . ""; + } - while (@database_filters = $string_handle->fetchrow_array()){ + # Check if the template database exists and the file permissions + # are valid and return an error if they aren't. - # Get the values from the from the array. + $kiriwrite_dbmodule->connecttemplate(); - $filter_id = $database_filters[0]; - $filter_priority = $database_filters[1]; - $filter_find = $database_filters[2]; - $filter_replace = $database_filters[3]; + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){ - # Convert the values into values that can be displayed. + # The template database does not exist so write a warning + # message. - $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"); + kiriwrite_error("templatedatabasemissing"); - # Check which style should be used. + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){ - if ($filter_style eq 0){ + # The template database has invalid permissions set so + # return an error. - $filter_style_name = "tablecell1"; - $filter_style = 1; + kiriwrite_error("templatedatabaseinvalidpermissions"); - } else { + } - $filter_style_name = "tablecell2"; - $filter_style = 0; + my %template_info = $kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_filename }); - } + # Check if any error occured while getting the template information. - # Check if the replace filter is blank and if it is - # then say no replace setting is given. + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ - if (!$filter_replace){ + # A database error has occured, so return an error. - # No replace filter is specified, so write a message - # saying that there is no replace filter. + kiriwrite_error("templatedatabaseerror", $kiriwrite_dbmodule->geterror(1)); - $filter_replace_out = "Replace filter is blank."; + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){ - } + # The template does not exist, so return an error. - # Check if the find filter is blank. + kiriwrite_error("templatedoesnotexist"); - 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. + # Delete the selected template. - $filterdata = "Warning: One (or more) of your filters has a blank find filter and needs to be fixed.

" . $filterdata; + $kiriwrite_dbmodule->deletetemplate({ TemplateFilename => $template_filename }); - } + # Check if any error occured while deleting the template. - # Add the filter to the list of filters in the database. + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ - $filterdata = $filterdata . ""; + # A database error has occured, so return an error. - $filter_count++; + kiriwrite_error("templatedatabaseerror", $kiriwrite_dbmodule->geterror(1)); + + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){ + + # The template does not exist, so process the next template. + + kiriwrite_error("templatedoesnotexist"); } - $filterdata = $filterdata . "
PriorityFind SettingReplace SettingOptions
" . $filter_priority_out . "" . $filter_find_out . "" . $filter_replace_out . "Edit Delete
"; + $kiriwrite_dbmodule->disconnecttemplate(); - # Check if there are filters in the filters database and - # write a message if there isn't. + # Get the deleted database name. - if ($filter_count eq 0){ + my $database_template_name = $template_info{"TemplateName"}; - # There are no filters in the filters database. + # Disconnect from the database server. - $filterswarning = "There are no filters available in the filters database. To add a filter, click on the Add Filter link."; + $kiriwrite_dbmodule->disconnect(); - } + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{deletedtemplate}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{template}->{deletedtemplatemessage}, $database_template_name) ); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=template", { Text => $kiriwrite_lang->{template}->{returntemplatelist} }); - } + return $kiriwrite_presmodule->grab(); - # 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. + } elsif ($template_confirm eq 0) { - if ($filtersdb_notexist eq 1){ + # 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. - # The filters database doesn't exist so write - # a message. + # Connect to the database server. - $filterswarning = "The filters database does not exist and will be created when a filter is added."; + $kiriwrite_dbmodule->connect(); + # Check if any errors occured while connecting to the database server. - } + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - # Check if there is a warning message and if - # there is then write that warning message - # else write the list of filters. + # A database connection error has occured so return + # an error. - if ($filterswarning){ + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - $pagedata = $pagedata . "
"; - $pagedata = $pagedata . $filterswarning; - $pagedata = $pagedata . "
"; + } - } else { + # Connect to the template database. - # The filters database exists so write out the - # list of filters. + $kiriwrite_dbmodule->connecttemplate(); - $pagedata = $pagedata . $filterdata; + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){ - } + # The template database does not exist so write a warning + # message. - return $pagedata; + kiriwrite_error("templatedatabasemissing"); -} + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){ -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. # -################################################################################# + # The template database has invalid permissions set so + # return an error. - # Get the values that have been passed to the subroutine. - - my ($filter_new_find, $filter_new_replace, $filter_new_priority, $filter_new_notes, $confirm) = @_; + kiriwrite_error("templatedatabaseinvalidpermissions"); - # Load the needed Perl modules. + } - use DBI; + my %template_info = $kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_filename }); - # 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. + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ - 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); + # A database error has occured, so return an error. - # Convert the UTF8 values so that the length can - # checked properly. + kiriwrite_error("templatedatabaseerror", $kiriwrite_dbmodule->geterror(1)); - $filter_new_find = kiriwrite_utf8convert($filter_new_find); - $filter_new_replace = kiriwrite_utf8convert($filter_new_replace); - $filter_new_priority = kiriwrite_utf8convert($filter_new_priority); + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){ - # Check if the find filter is blank and return an error - # if it is. + # The template does not exist, so return an error. - if (!$filter_new_find){ + kiriwrite_error("templatedoesnotexist"); - # The find filter given is blank so return an - # error. + } - kiriwrite_error("blankfindfilter"); + my $template_data_filename = $template_info{"TemplateFilename"}; + my $template_data_name = $template_info{"TemplateName"}; - } + $kiriwrite_dbmodule->disconnecttemplate(); - if (!$filter_new_priority){ + # Disconnect from the database server. - # The filter priority is blank so set it - # to 1. + $kiriwrite_dbmodule->disconnect(); - $filter_new_priority = 1; + # Write out the confirmation form. - } + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{deletetemplate}, { Style => "pageheader" }); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "template"); + $kiriwrite_presmodule->addhiddendata("template", $template_filename); + $kiriwrite_presmodule->addhiddendata("action", "delete"); + $kiriwrite_presmodule->addhiddendata("confirm", 1); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{template}->{deletetemplatemessage}, $template_data_name, $template_data_filename)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{template}->{deletetemplatebutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=template", { Text => $kiriwrite_lang->{template}->{deletetemplatereturntolist} }); + $kiriwrite_presmodule->endform(); + + return $kiriwrite_presmodule->grab(); - # 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); + } else { - # Check if the result of the tests to see if they - # are valid. + kiriwrite_error("invalidvariable"); - if ($filterfind_maxlength_check eq 1){ + } - # The find filter is too long, so return - # an error. +} - kiriwrite_error("findfiltertoolong"); +sub kiriwrite_template_list{ +################################################################################# +# kiriwrite_template_list: List the templates in the template folder. # +# # +# Usage: # +# # +# kiriwrite_template_list(); # +################################################################################# - } + # Define certain values for later. - if ($filterreplace_maxlength_check eq 1){ + my %template_info; - # The replace filter is too long, so - # return an error. + my @templates_list; - kiriwrite_error("replacefiltertoolong"); + my $template; + my $template_filename = ""; + my $template_filename_list = ""; + my $template_name = ""; + my $template_description = ""; + my $template_data = ""; - } + my $template_count = 0; - if ($filterpriority_maxlength_check eq 1){ + my $template_style = 0; + my $template_stylename = ""; - # The length of the filter priority - # given is too long, so return an - # error. + my $templatewarning = ""; - kiriwrite_error("filterprioritytoolong"); + # Connect to the database server. - } + $kiriwrite_dbmodule->connect(); - if ($filterpriority_numbers_check eq 1){ + # Check if any errors occured while connecting to the database server. - # The priority of the filter given - # contains characters other than - # numbers. + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - kiriwrite_error("filterpriorityinvalidchars"); + # A database connection error has occured so return + # an error. - } + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - # 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){ + # Connect to the template database. - # The filter priority is less than 1 and - # more than 10000, so return an error. + $kiriwrite_dbmodule->connecttemplate(); - kiriwrite_error("filterpriorityinvalid"); + # Check if any errors had occured. - } - - # Define some variables for later on. + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){ - my @database_filters; - my @database_check; + # The template database does not exist so write a warning + # message. - my $database_handle; - my $string_handle; - my $chk_database_handle; - my $chk_string_handle; + $templatewarning = $kiriwrite_lang->{template}->{templatedatabasedoesnotexist}; - 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; + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){ - my $first_filter = 0; + # The template database has invalid permissions set so + # return an error. - my $new_id; + kiriwrite_error("templatedatabaseinvalidpermissions"); - # Check if the filters database exists, has valid - # permission settings and if it doesn't create - # the database first. + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ - $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. + # A database error occured while getting the list of + # templates so return an error with the extended + # error information. - $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 1, 1); - - if ($filters_permissions eq 1){ + kiriwrite_error("templatedatabaseerror", $kiriwrite_dbmodule->geterror(1)); - # The filters database has invalid permissions so - # return an error. + } - kiriwrite_error("filtersdbpermissions"); + # Get the list of template databases. - } + if (!$templatewarning){ - # Load the SQLite database. + @templates_list = $kiriwrite_dbmodule->gettemplatelist(); - $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); + # Check if any errors had occured. - if ($directory_permissions eq 1){ + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ - # The filters database cannot be created because of invalid directory - # permissions so return an error. + # A database error occured while getting the list + # of templates so return an error with the + # extended error information. - kiriwrite_error("filtersdatabasefilenotcreated"); - } + kiriwrite_error("templatedatabaseerror", $kiriwrite_dbmodule->geterror(1)); - # 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"); + # 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. - # Find the lowest identification number available. + if (!@templates_list && !$templatewarning){ + $templatewarning = $kiriwrite_lang->{template}->{notemplatesavailable}; + } - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters ORDER BY id ASC') or kiriwrite_error("filtersdbinvalidformat");; - $string_handle->execute(); + # Process the templates into a template list. - # Process each filter to find a blank identification - # number. + $kiriwrite_presmodule->addtext($kiriwrite_lang->{template}->{viewtemplates}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); - while(@database_filters = $string_handle->fetchrow_array()){ + if ($templatewarning){ - # Check the next filter identification number to see - # if it exists and use that identification number if - # it doesn't exist. + $kiriwrite_presmodule->startbox("errorbox"); + $kiriwrite_presmodule->addtext($templatewarning); + $kiriwrite_presmodule->endbox(); - $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(); + } else { - while(@database_check = $chk_string_handle->fetchrow_array()){ + $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 }); + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{template}->{templatefilename}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{template}->{templatename}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{template}->{templatedescription}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{options}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->endheader(); - $filter_exists = 1; + foreach $template (@templates_list){ + # Get the template data. - } + %template_info = $kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template }); - if ($filter_exists eq 0 && $blankid_found eq 0){ + # Check if any errors occured while trying to get the template + # data. - $new_id = $next_id; - $blankid_found = 1; + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ - } + # A database error has occured, so return an error. - # 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. + kiriwrite_error("templatedatabaseerror", $kiriwrite_dbmodule->geterror(1)); - if ($first_filter eq 0 && $current_id > 1 && $blankid_found eq 0){ + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){ - # The first filter has an identification - # number more than 1, so set the new - # identification number to 1. + # The template does not exist, so process the next template. - $new_id = 1; - $blankid_found = 1; - $first_filter = 1; + next; + } + $template_filename = $template_info{"TemplateFileName"}; + $template_name = $template_info{"TemplateName"}; + $template_description = $template_info{"TemplateDescription"}; + + # 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; + + } + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell($template_stylename); + $kiriwrite_presmodule->addtext($template_info{"TemplateFilename"}); + + # Check if the blank template value was set. + + if (!$template_info{"TemplateLayout"}){ + $kiriwrite_presmodule->additalictext(" " . "[Blank Template]"); } - # Set the next identification number as the - # current identification number add one and - # increment the filters count. + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($template_stylename); - $first_filter = 1; - $filters_count++; - $filter_exists = 0; + # Check if the template name is blank and if it is + # write a message to say there's no name for the + # template. - } + if (!$template_info{"TemplateName"}){ + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname}); + } else { + $kiriwrite_presmodule->addtext($template_info{"TemplateName"}); + } - # Check if there are any filters in the database - # and if not set the identification number to 1. + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($template_stylename); - if ($filters_count eq 0){ + # Check if the template description is blank and if + # it is then write a message to say there's no + # description for the template. - # No filters were really in the filters - # database. + if (!$template_info{"TemplateDescription"}){ + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{nodescription}); + } else { + $kiriwrite_presmodule->addtext($template_info{"TemplateDescription"}); + } - $new_id = 1; + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($template_stylename); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=template&action=edit&template=" . $template_info{"TemplateFilename"}, { Text => $kiriwrite_lang->{options}->{edit} }); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=template&action=delete&template=" . $template_info{"TemplateFilename"}, { Text => $kiriwrite_lang->{options}->{delete} }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); } - # Convert the values so that they can be processed - # properly. + $kiriwrite_presmodule->endtable(); + $kiriwrite_presmodule->endform(); - 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. + # Disconnect from the database server. - $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(); + $kiriwrite_dbmodule->disconnect(); + + $kiriwrite_dbmodule->disconnecttemplate(); + return $kiriwrite_presmodule->grab(); - # 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{ +sub kiriwrite_database_add{ ################################################################################# -# kiriwrite_filter_edit: Edits a filter from the filter list. # -# # +# kiriwrite_database_add: Creates a new database. # +# # # Usage: # # # -# kiriwrite_filter_edit(filternumber, newfilterfind, newfilterreplace, # -# newfilterpriority, newfilternotes, confirm); # +# kiriwrite_database_add(filename, name, description, [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. # +# 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 values that have been passed to the subroutine. - - my ($filter_id, $filter_new_find, $filter_new_replace, $filter_new_priority, $filter_new_notes, $confirm) = @_; + # Get the variables passed from the subroutine. - # Load the needed Perl modules. + my ($database_filename, $database_name, $database_description, $database_notes, $database_categories, $database_confirm) = @_; - use DBI; + # Check if the confirm value is blank and if it is then + # set the confirm value to 0. - # Check the confirm value to make sure it is no more than - # one character long. + if (!$database_confirm){ - kiriwrite_variablecheck($confirm, "maxlength", 1, 0); + # The confirm value was blank so set the value to 0. - # Define the page data value for later. + $database_confirm = 0; - my $pagedata = ""; + } - # Check if the confirm value is blank and if it is - # srt the confirm value to 0. + if ($database_confirm eq 1){ - if (!$confirm){ + # The action to create a new database is confirmed. - # The confirm value does not have any value - # set so set it to 0. + # Validate the database name and database descriptions. - $confirm = 0; + 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. - # Check if the filter identification number is blank, - # contains characters other than numbers and is more - # than seven characters long. + $database_name = kiriwrite_utf8convert($database_name); + $database_description = kiriwrite_utf8convert($database_description); + $database_notes = kiriwrite_utf8convert($database_notes); + $database_categories = kiriwrite_utf8convert($database_categories); - if (!$filter_id){ + 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", 32, 1); + my $database_categories_check_length = kiriwrite_variablecheck($database_categories, "maxlength", 512, 1); - # The filter identification number is blank, - # so return an error. + # Check if values returned contains any values that would + # result in a specific error message being returned. - kiriwrite_error("filteridblank"); + if ($database_name_check_length eq 1){ - } + # The length of the database name is too long, so return an error. + kiriwrite_error("databasenametoolong"); - my $filter_id_numbers_check = kiriwrite_variablecheck($filter_id, "numbers", 0, 1); + } - if ($filter_id_numbers_check eq 1){ + if ($database_description_check_length eq 1){ - # The filter identification number contains - # characters other than numbers, so return - # an error. + # The database description length is too long, so return an error. + kiriwrite_error("databasedescriptiontoolong"); - kiriwrite_error("filteridinvalid"); + } - } + if ($database_name_check_blank eq 1){ - my $filter_id_maxlength_check = kiriwrite_variablecheck($filter_id, "maxlength", 7, 1); + # The database name is blank, so return an error. + kiriwrite_error("databasenameblank"); - if ($filter_id_maxlength_check eq 1){ + } - # The filter identification number given - # is more than seven characters long, so - # return an error. + if ($database_filename_check_length eq 1){ - kiriwrite_error("filteridtoolong"); + # The database filename is to long, so return an error. + kiriwrite_error("databasefilenametoolong"); - } + } - # Check if the filters database exists and the - # permissions for it are valid. + if ($database_categories_check_length eq 1){ - my $filters_exists = kiriwrite_fileexists("filters.db"); + # The database categories is too long, so return an error. + kiriwrite_error("databasecategoriestoolong"); - if ($filters_exists eq 1){ + } - # The filters database does not exist, so - # return an error. + # Check if the database filename is blank and if it is then + # generate a filename. - kiriwrite_error("filtersdbmissing"); + if ($database_filename eq ""){ - } + # Filename is blank so generate a file name from + # the database name. - my $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 0); + $database_filename = kiriwrite_processfilename($database_name); - if ($filters_permissions eq 1){ + } else { - # The filters database has invalid permissions - # set, so return an error. + # Filename is not blank so don't generate a filename. - kiriwrite_error("filtersdbpermissions"); + } - } + kiriwrite_variablecheck($database_filename, "filename", "", 0); + kiriwrite_variablecheck($database_filename, "maxlength", 32, 0); - # Define some variables for later. + # Connect to the database server. - 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; + $kiriwrite_dbmodule->connect(); - # Check if the action to edit a filter has been - # confirmed. + # Check if any errors occured while connecting to the database server. - # Load the SQLite database. + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - $database_handle = DBI->connect("dbi:SQLite:dbname=filters.db"); + # A database connection error has occured so return + # an error. - if ($confirm eq 1){ + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(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. + my $database_name_final = $database_name; - $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 1); + # Create the database. - if ($filters_permissions eq 1){ + $kiriwrite_dbmodule->adddatabase({ DatabaseFilename => $database_filename, DatabaseName => $database_name, DatabaseDescription => $database_description, DatabaseNotes => $database_notes, DatabaseCategories => $database_categories, VersionMajor => $kiriwrite_version{"major"}, VersionMinor => $kiriwrite_version{"minor"}, VersionRevision => $kiriwrite_version{"revision"} }); - # The filters database has invalid permissions - # set, so return an error. + # Check if any errors have occured. - kiriwrite_error("filtersdbpermissions"); + if ($kiriwrite_dbmodule->geterror eq "DatabaseExists"){ - } + # A database with the filename given already exists, so + # return an error. - # Define some variables for later. + kiriwrite_error("fileexists"); - my @database_filter; - my $filter_exists = 0; + } elsif ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # Check if the filter exists. + # A database error has occured so return an error with + # the extended error information. - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters WHERE id = \'' . $filter_id_sql . '\' LIMIT 1') or kiriwrite_error("filtersdbinvalidformat"); - $string_handle->execute(); + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - while (@database_filter = $string_handle->fetchrow_array()){ + } - # The filter exists. + # Disconnect from the database server. - $filter_exists = 1; + $kiriwrite_dbmodule->disconnect(); - } + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{adddatabase}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{database}->{databaseadded} , $database_name_final)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=db", { Text => $kiriwrite_lang->{database}->{databaselistreturnlink} }); - # Check if the filter really doesn't exist. + return $kiriwrite_presmodule->grab(); - if ($filter_exists eq 0){ + } - # The filter really does not exist so - # return an error. + # There is confirm value is not 1, so write a form for creating a database to + # store pages in. - kiriwrite_error("filterdoesnotexist"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{adddatabase}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "db"); + $kiriwrite_presmodule->addhiddendata("action", "new"); + $kiriwrite_presmodule->addhiddendata("confirm", "1"); + $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 }); + + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{setting}, { Style => "tablecellheader"}); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{value}, { Style => "tablecellheader"}); + $kiriwrite_presmodule->endheader(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databasename}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("databasename", { Size => 64, MaxLength => 256 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databasedescription}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("databasedescription", { Size => 64, MaxLength => 512 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databasecategories}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("databasecategories", { Size => 64, MaxLength => 512 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databasenotes}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtextbox("databasenotes", { Columns => 50, Rows => 10, WordWrap => 0 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databasefilename}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("databasefilename", { Size => 32, MaxLength => 32 }); + $kiriwrite_presmodule->startlist(); + $kiriwrite_presmodule->additem($kiriwrite_lang->{database}->{adddatabaseautogenerate}); + $kiriwrite_presmodule->additem($kiriwrite_lang->{database}->{adddatabasenoextensions}); + $kiriwrite_presmodule->additem($kiriwrite_lang->{database}->{adddatabasecharacterlength}); + $kiriwrite_presmodule->additem($kiriwrite_lang->{database}->{adddatabasecharacters}); + $kiriwrite_presmodule->endlist(); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->endtable(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{database}->{adddatabasebutton}); + $kiriwrite_presmodule->addtext("|"); + $kiriwrite_presmodule->addreset($kiriwrite_lang->{database}->{clearvaluesbutton}); + $kiriwrite_presmodule->addtext("| "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=db", { Text => $kiriwrite_lang->{database}->{databaselistreturnlink} }); + $kiriwrite_presmodule->endform(); - } + # Exit the subroutine taking the data in the pagadata variable with it. - # First, check the variables recieved are UTF8 - # copliant. + return $kiriwrite_presmodule->grab(); - 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. +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. # +################################################################################# - $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); + # First, get all the variables passed to the subroutine. - # Check if the find filter is blank and return an error - # if it is. + my ($database_shortname, $database_name, $database_description, $database_newfilename, $database_newname, $database_newdescription, $database_notes, $database_categories, $database_confirm) = @_; - if (!$filter_new_find){ + # Check if the database confirm value is blank and if it is + # set the confirm value to 0. - # The find filter given is blank so return an - # error. + if (!$database_confirm){ - kiriwrite_error("blankfindfilter"); + $database_confirm = 0; - } + } - if (!$filter_new_priority){ + # 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). - # The filter priority is blank so set it - # to 1. + if ($database_confirm eq 1){ - $filter_new_priority = 1; + # 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); - # 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); + # Convert the UTF8 strings to make sure their length is accurate. - # Check if the result of the tests to see if they - # are valid. + $database_newname = kiriwrite_utf8convert($database_newname); + $database_newdescription = kiriwrite_utf8convert($database_newdescription); + $database_notes = kiriwrite_utf8convert($database_notes); + $database_categories = kiriwrite_utf8convert($database_categories); - if ($filterfind_maxlength_check eq 1){ + # Check if the database filename given is valid and return an error + # if it isn't. - # The find filter is too long, so return - # an error. + kiriwrite_variablecheck($database_shortname, "filename", "", 0); - kiriwrite_error("findfiltertoolong"); + # Preform the following tests. - } + my $database_filename_check_length = kiriwrite_variablecheck($database_newfilename, "maxlength", 32, 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); - if ($filterreplace_maxlength_check eq 1){ + # Check if the data is valid and return a specific error if it doesn't. - # The replace filter is too long, so - # return an error. + if ($database_name_check_length eq 1){ - kiriwrite_error("replacefiltertoolong"); + # The length of the database name is too long, so return an error. + kiriwrite_error("databasenametoolong"); } - if ($filterpriority_maxlength_check eq 1){ - - # The length of the filter priority - # given is too long, so return an - # error. + if ($database_description_check_length eq 1){ - kiriwrite_error("filterprioritytoolong"); + # The database description length is too long, so return an error. + kiriwrite_error("databasedescriptiontoolong"); } - if ($filterpriority_numbers_check eq 1){ - - # The priority of the filter given - # contains characters other than - # numbers. + if ($database_name_check_blank eq 1){ - kiriwrite_error("filterpriorityinvalidchars"); + # The database name is blank, so return an error. + kiriwrite_error("databasenameblank"); } - # Check if the filter priority is less than 1 - # and more than 10000 and return an error - # if it is. + if ($database_filename_check_length eq 1){ - if ($filter_new_priority < 1 || $filter_new_priority > 50000){ + # The database filename is too long, so return an error. + kiriwrite_error("databasefilenametoolong"); - # The filter priority is less than 1 and - # more than 10000, so return an error. + } - kiriwrite_error("filterpriorityinvalid"); + if ($database_categories_check_length eq 1){ + + # The database categories is too long, so return an error. + kiriwrite_error("databasecategoriestoolong"); } - # Convert the new information about the filter given - # so that it can be added to the SQL query properly. + # Connect to the database server. - $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"); + $kiriwrite_dbmodule->connect(); - # Edit the filter using the information provided. + # Check if any errors occured while connecting to the database server. - $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(); + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - # Write a message saying that the filter was edited. + # A database connection error has occured so return + # an error. - $pagedata = $pagedata . "

Filter edited

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

"; - $pagedata = $pagedata . "Return to the list of filters."; + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - return $pagedata; + } - } elsif ($confirm eq 0){ + # Get the database. - # The action to edit a filter has not been confirmed - # so write a form for editing the filter with. + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database_shortname }); - # Define some variables for later. + # Check if any errors had occured while selecting the database. - my @database_filter; - my $filter_exists = 0; + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - # Check if the filter exists. + # The database does not exist, so return an error. - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters WHERE id = \'' . $filter_id_sql . '\' LIMIT 1') or kiriwrite_error("filtersdbinvalidformat"); - $string_handle->execute(); + kiriwrite_error("databasemissingfile"); - while (@database_filter = $string_handle->fetchrow_array()){ + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - # The filter exists. + # The database has invalid permissions set, so return + # an error. - $filter_exists = 1; + kiriwrite_error("databaseinvalidpermissions"); } - # Check if the filter really doesn't exist. + # FIX THIS!! >O - if ($filter_exists eq 0){ + $kiriwrite_dbmodule->editdatabase({ DatabaseNewFilename => $database_newfilename, DatabaseName => $database_newname , DatabaseDescription => $database_newdescription , DatabaseNotes => $database_notes, DatabaseCategories => $database_categories }); - # The filter really does not exist so - # return an error. + # Check if any errors had occured while using the database. - kiriwrite_error("filterdoesnotexist"); + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - } + # The database does not exist, so return an error. - # Get the filter information. + kiriwrite_error("databasemissingfile"); - $string_handle->execute(); + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - @database_filter = $string_handle->fetchrow_array(); - - # Get the required information. + # The database has invalid permissions set, so return + # an error. - $filter_priority = $database_filter[1]; - $filter_find = $database_filter[2]; - $filter_replace = $database_filter[3]; - $filter_notes = $database_filter[4]; + kiriwrite_error("databaseinvalidpermissions"); - $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. + } elsif ($kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){ - $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; + # The database directory has invalid permissions set, so + # return an error. - } else { + kiriwrite_error("datadirectoryinvalidpermissions"); - # A confirm value other than 0 or 1 has been - # specified, so return an error. + } elsif ($kiriwrite_dbmodule->geterror eq "DatabaseExists"){ - kiriwrite_error("invalidvalue"); + # A database already exists with the new filename, so + # return an error. - } + kiriwrite_error("databasealreadyexists"); -} + } elsif ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ -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. # -################################################################################# + # A database error has occured so return an error with + # the extended error information. - # Get the values that were passed to this subroutine. - - my ($filter_id, $confirm) = @_; - - # Load the needed Perl modules. + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - use DBI; + } - # Check the confirm value to make sure it is no more than - # one character long. + # Disconnect from the server. - kiriwrite_variablecheck($confirm, "maxlength", 1, 0); + $kiriwrite_dbmodule->disconnect(); - # Define the page data value for later. + # Write out a message saying that the database has been updated. - my $pagedata = ""; + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{editeddatabase}, { Style => "pageheader" } ); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{database}->{databaseupdated}, $database_newname)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=db", { Text => $kiriwrite_lang->{database}->{databaselistreturnlink} }); - # Check if the confirm value is blank and if it is - # srt the confirm value to 0. + return $kiriwrite_presmodule->grab(); - if (!$confirm){ + } else { - # The confirm value does not have any value - # set so set it to 0. + my (%database_info); - $confirm = 0; + # Check if the database filename given is valid and return an error + # if it isn't. - } + # Connect to the database server. - # Check if the filter identification number is blank, - # contains characters other than numbers and is more - # than seven characters long. + $kiriwrite_dbmodule->connect(); - if (!$filter_id){ + # Check if any errors occured while connecting to the database server. - # The filter identification number is blank, - # so return an error. + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - kiriwrite_error("filteridblank"); + # A database connection error has occured so return + # an error. - } + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - my $filter_id_numbers_check = kiriwrite_variablecheck($filter_id, "numbers", 0, 1); + } - if ($filter_id_numbers_check eq 1){ + # Select the database. - # The filter identification number contains - # characters other than numbers, so return - # an error. + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database_shortname }); - kiriwrite_error("filteridinvalid"); + # Check if any errors had occured while setting the database. - } + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - my $filter_id_maxlength_check = kiriwrite_variablecheck($filter_id, "maxlength", 7, 1); + # The database does not exist, so return an error. - if ($filter_id_maxlength_check eq 1){ + kiriwrite_error("databasemissingfile"); - # The filter identification number given - # is more than seven characters long, so - # return an error. + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ - kiriwrite_error("filteridtoolong"); + # The database has invalid permissions set, so return + # an error. - } + kiriwrite_error("databaseinvalidpermissions"); - # Check if the filters database exists and the - # permissions for it are valid. + } - my $filters_exists = kiriwrite_fileexists("filters.db"); + # Get the database information. - if ($filters_exists eq 1){ + %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - # The filters database does not exist, so - # return an error. + # Check if any errors had occured while getting the database + # information. - kiriwrite_error("filtersdbmissing"); + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - } + # A database error has occured so return an error and + # also the extended error information. - my $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 0); + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - 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; + # Get the values needed from the kiriwrite_database_info table. - # Load the SQLite database. + my $database_oldname = $database_info{"DatabaseName"}; + my $database_olddescription = $database_info{"Description"}; + my $database_notes = $database_info{"Notes"}; + my $database_categories = $database_info{"Categories"}; - $database_handle = DBI->connect("dbi:SQLite:dbname=filters.db"); + # Disconnect from the database server. - # Check if the confirm integer has a value of '1'. - - if ($confirm eq 1){ - - # The action to delete a filter has been confirmed. + $kiriwrite_dbmodule->disconnect(); - # Check the permissions of the filters database is - # valid (for writing). + # Print out the form for editing a database's settings. - $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 1); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{database}->{editdatabase}, $database_oldname), { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "db"); + $kiriwrite_presmodule->addhiddendata("action", "edit"); + $kiriwrite_presmodule->addhiddendata("database", $database_shortname); + $kiriwrite_presmodule->addhiddendata("confirm", "1"); + $kiriwrite_presmodule->addhiddendata("olddatabasename", $database_oldname); + $kiriwrite_presmodule->addhiddendata("olddatabasedescription", $database_olddescription); + + $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 }); + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader("Setting", { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader("Value", { Style => "tablecellheader" }); + $kiriwrite_presmodule->endheader(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databasename}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("databasename", { Size => 64, MaxLength => 256, Value => $database_oldname } ); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databasedescription}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("databasedescription", { Size => 64, MaxLength => 512, Value => $database_olddescription } ); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databasecategories}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("databasecategories", { Size => 64, MaxLength => 512, Value => $database_categories } ); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databasenotes}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtextbox("databasenotes", { Columns => 50, Rows => 10, Value => $database_notes } ); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databasefilename}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("databasefilename", { Size => 32, MaxLength => 32, Value => $database_shortname } ); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->endtable(); + + $kiriwrite_presmodule->addlinebreak(); + + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{database}->{editdatabasebutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addreset($kiriwrite_lang->{common}->{restorecurrent}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=db", { Text => $kiriwrite_lang->{database}->{databaselistreturnlink} }); + + $kiriwrite_presmodule->endform(); + + return $kiriwrite_presmodule->grab(); - if ($filters_permissions eq 1){ + } - # The filters database has invalid permissions - # set, so return an error. + # The interpreter should not be here. So return an error saying invalid variable. - kiriwrite_error("filtersdbpermissions"); + kiriwrite_error("invalidvariable"); - } +} - # Check if the filter exists. +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. # +################################################################################# - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters WHERE id = \'' . $filterid_sql . '\' LIMIT 1') or kiriwrite_error("filtersdbinvalidformat"); - $string_handle->execute(); + my ($database_filename, $database_confirm) = @_; - while (@database_filter = $string_handle->fetchrow_array()){ + # Check if the confirm value is blank and if it is then set the + # confirm value to 0. - # The filter exists. + if (!$database_confirm){ - $filter_exists = 1; + $database_confirm = 0; - } + } - # Check if the filter really doesn't exist. + # Connect to the database server. - if ($filter_exists eq 0){ + $kiriwrite_dbmodule->connect(); - # The filter really does not exist so - # return an error. + # Check if any errors occured while connecting to the database server. - kiriwrite_error("filterdoesnotexist"); + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - } + # A database connection error has occured so return + # an error. - # Delete the filter from the filters database. + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - $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. + # Check if the database filename given is valid and return an error + # if it isn't. - $pagedata = $pagedata . "

Delete Filter

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

"; - $pagedata = $pagedata . "Return to the filters database."; + kiriwrite_variablecheck($database_filename, "filename", "", 0); - } 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 request to delete a database has been confirmed. If it has, + # then delete the database itself. - # Check if the filter exists. + if ($database_confirm eq 1){ + # There is a value in the confirm variable of the HTTP query. - $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters WHERE id = \'' . $filterid_sql . '\' LIMIT 1') or kiriwrite_error("filtersdbinvalidformat"); - $string_handle->execute(); + # Select the database to delete and get the database name. - while (@database_filter = $string_handle->fetchrow_array()){ + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database_filename }); - # The filter exists. + # Check if any error occured while selecting the database. - $filter_exists = 1; + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - } + # The database does not exist so return an error. - # Check if the filter really doesn't exist. + kiriwrite_error("databasemissingfile"); - if ($filter_exists eq 0){ + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet") { - # The filter really does not exist so - # return an error. + # The database has invalid permissions set so return + # an error. - kiriwrite_error("filterdoesnotexist"); + kiriwrite_error("databaseinvalidpermissions"); } - # 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"); - - } + my %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - return $pagedata; + # Check if any errors have occured while getting the database + # name. -} + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ -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. # -################################################################################# + # A database error has occured so return an error with + # the extended error information. - # Get the values that have been passed to the subroutine. - - my ($type, $confirm, @selectedlist) = @_; + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - # Check if the confirm value is more than one - # character long. + } - kiriwrite_variablecheck($confirm, "maxlength", 1, 0); + my $database_name = $database_info{"DatabaseName"}; - # Check if the confirm value is blank and if it - # is then set the confirm value to 0. + # Delete the selected database. - if (!$confirm){ + $kiriwrite_dbmodule->deletedatabase({ DatabaseName => $database_filename }); - # The confirm value is blank, so set the - # confirm value to 0. + # Check if any error occured while deleting the database. - $confirm = 0; + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - } + # The database does not exist so return an error. - # Check if there are any databases selected - # and return an error if there isn't. + kiriwrite_error("databasemissingfile"); - if (!@selectedlist){ + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet") { - # There are no databases in the array - # so return an error. + # The database has invalid permissions set so return + # an error. - kiriwrite_error("nodatabaseselected"); + kiriwrite_error("databaseinvalidpermissions"); - } + } - # Check if the type given is no more than - # 7 characters long. + # Disconnect from the database server. - my $type_maxlength_check = kiriwrite_variablecheck($type, "maxlength", 8, 1); + $kiriwrite_dbmodule->disconnect(); - if ($type_maxlength_check eq 1){ + # Write a message saying that the database has been deleted. - # The type length given is too long so - # return an error. + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{deleteddatabase}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{database}->{deleteddatabasemessage}, $database_name)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=db", { Text => $kiriwrite_lang->{database}->{databaselistreturnlink} }); - kiriwrite_error("variabletoolong"); + return $kiriwrite_presmodule->grab(); } - # 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 has not been confirmed, so write out a form asking the + # user to confirm. - # The action to compile the datavases has - # been confirmed. + # Get the database name. - # Define some variables for later. + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database_filename }); - 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 any error occured while selecting the database. - # Check if the output directory exists and has - # valid permissions set. + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - $output_exists = kiriwrite_fileexists($kiriwrite_config{'directory_data_output'}); + # The database does not exist so return an error. - if ($output_exists ne 0){ + kiriwrite_error("databasemissingfile"); - # The output directory does not exist so - # return an error. + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet") { - kiriwrite_error("outputdirectorymissing"); + # The database has invalid permissions set so return + # an error. - } + kiriwrite_error("databaseinvalidpermissions"); - $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. + # Check if any errors have occured. - kiriwrite_error("outputdirectoryinvalidpermissions"); + my %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - } + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # Check if the filters database exists and has valid - # permissions set. + # A database error has occured so return an error with + # the extended error information. - $filters_exists = kiriwrite_fileexists("filters.db"); + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); - if ($filters_exists ne 0){ + } - # The filters database does not exist - # so write a warning. + my $database_name = $database_info{"DatabaseName"}; - $messages = $messages . $warning_prefix . "The filters database does not exist. No filters will be used." . "
"; - $filters_skip = 1; - $warning_count++; + # Disconnect from the database server. - } + $kiriwrite_dbmodule->disconnect(); - $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 0); - - if ($filters_permissions ne 0 && $filters_exists eq 0){ + # Write out the form to ask the user to confirm the deletion of the + # selected database. - # The filters database has invalid - # permissions set so write a warning. + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{deletedatabase}, { Style => "pageheader" }); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "db"); + $kiriwrite_presmodule->addhiddendata("action", "delete"); + $kiriwrite_presmodule->addhiddendata("database", $database_filename); + $kiriwrite_presmodule->addhiddendata("confirm", "1"); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{database}->{deletedatabasemessage}, $database_name)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{database}->{deletedatabasebutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=db", { Text => $kiriwrite_lang->{database}->{deletedatabasereturn} }); + $kiriwrite_presmodule->endform(); + + return $kiriwrite_presmodule->grab(); - $messages = $messages . $warning_prefix . "The filters database has invalid permissions set. No filters will be used." . "
"; - $filters_skip = 1; - $warning_count++; +} - } +sub kiriwrite_database_list{ +################################################################################# +# kiriwrite_database_list: Lists the databases available. # +# # +# Usage: # +# # +# kiriwrite_database_list(); # +################################################################################# - # Load the filters database (if the filters skip - # value isn't set to 1). + # Connect to the database server. - if ($filters_skip eq 0){ + $kiriwrite_dbmodule->connect(); - # Load the filters database. + # Check if any errors occured while connecting to the database server. - $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; + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - # Check if the filters skip value is set to 0 - # before executing the query. + # A database connection error has occured so return + # an error. - if ($filters_skip eq 0){ + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - # Get the filters. + } - $string_handle->execute(); - while (@filterslist = $string_handle->fetchrow_array()){ + # Get the list of available databases and process any errors that + # might have occured. - # Check if the find filter is blank and - # if it is then write a warning message. + my @database_list = $kiriwrite_dbmodule->getdblist(); - if (!$filterslist[2]){ + if ($kiriwrite_dbmodule->geterror eq "DataDirMissing"){ - if ($filters_find_blank_warning ne 1){ + # The database directory is missing so return an error. - $messages = $messages . $warning_prefix . "One (or more) of the find filters from the filters database is blank." . "
"; - $filters_find_blank_warning = 1; - } - next; + kiriwrite_error("datadirectorymissing"); - } else { + } elsif ($kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){ - # Add each find and replace filter. + # The database directory has invalid permissions set so return + # an error. - $findfilter[$filters_count] = $filterslist[2]; - $replacefilter[$filters_count] = $filterslist[3]; + kiriwrite_error("datadirectoryinvalidpermissions"); - } + } - $filters_count++; + # Declare the following variables that are going to be used before using + # the foreach function. - } - $messages = $messages . $information_prefix . "The filters database has been loaded." . "
"; + my ($database_info, %database_info); + my @error_list; + my @permissions_list; + my $database_count = 0; + my $database_filename = ""; + my $database_filename_friendly = ""; + my $database_filename_length = 0; + my $database_name = ""; + my $database_description = ""; + my $database_permissions = ""; + my $nodescription = 0; + my $noname = 0; + my $data_file = ""; + my $table_style = 0; + my $table_style_name = ""; - } + # Begin creating the table for the list of databases. - } + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databaselist}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->starttable("", { CellPadding => "5", CellSpacing => "0" }); + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{database}->{databasename}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{database}->{databasedescription}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{database}->{databaseoptions}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->endheader(); - # Check if the templates database exists and has - # valid permissions set. + foreach $data_file (@database_list){ - $templates_exists = kiriwrite_fileexists("templates.db"); + # Select the database. - if ($templates_exists ne 0){ + $kiriwrite_dbmodule->selectdb({ DatabaseName => $data_file }); - # The template database does not exist - # so write a warning. + # Check if any error occured while selecting the database. - $messages = $messages . $warning_prefix . "The templates database does not exist. Pages will be compiled without templates being used." . "
"; - $templates_skip = 1; - $warning_count++; + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ - } + # The database does not exist, so process the next + # database. - $templates_permissions = kiriwrite_filepermissions("templates.db", 1, 0); + next; - if ($templates_permissions ne 0 && $templates_exists eq 0){ + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet") { - # The template database has invalid - # permissions set so write a warning. + # The database has invalid permissions settings, so + # add the database to the list of databases with + # invalid permissions set and process the next + # database. - $messages = $messages . $warning_prefix . "The templates database has invalid permissions set. Pages will be compiled without templates being used." . "
"; - $templates_skip = 1; - $warning_count++; + push(@permissions_list, $data_file); + next; } - # Load the templates database (if the template - # skip value isn't set to 1). + # Get information about the database. - if ($templates_skip eq 0){ + %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - # Load the templates database. + # Check if any error occured while getting information from the + # 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; + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # Check if the templates skip value is set to - # 0 before executing the query. + # A database error has occured, add the database and specific + # error message to the list of databases with errors and + # process the next database. - if ($templates_skip eq 0){ + push(@error_list, $data_file . ": " . $kiriwrite_dbmodule->geterror(1)); + next; - # Get the templates and place them into the - # template files hash. + } - $string_handle->execute(); - while(@templateslist = $string_handle->fetchrow_array()){ + $database_name = $database_info{"DatabaseName"}; + $database_description = $database_info{"Description"}; - # Place each template file into the hash. + # Check the style to be used with. - $templatefiles{$templateslist[0]}{template} = $templateslist[3]; - $templatefiles{$templateslist[0]}{valid} = 1; + if ($table_style eq 0){ - } - $messages = $messages . $information_prefix . "The templates database has been loaded." . "
"; + # 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; } - # Process each database. + # Create a friendly name for the database. - foreach $database (@selectedlist){ + $database_filename_friendly = $data_file; - # Check if the database filename and length - # are valid. + # Append the database information to the table. - $messages = $messages . "
"; + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell($table_style_name); - $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_name){ + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname}); + } else { + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database_filename_friendly, { Text => $database_name }); + } - if ($database_filename_check ne 0){ + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($table_style_name); - # The database filename is invalid, so process - # the next database. + if (!$database_description){ + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{nodescription}); + } else { + $kiriwrite_presmodule->addtext($database_description); + } - $messages = $messages . $error_prefix . "The database filename '" . $database_out . ".db' is invalid. Skipping this database..." . "
"; - $error_count++; - next; + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($table_style_name); + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=db&action=edit&database=" . $database_filename_friendly, { Text => $kiriwrite_lang->{options}->{edit} }); + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=compile&action=compile&type=single&database=" . $database_filename_friendly, { Text => $kiriwrite_lang->{options}->{compile} }); + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=db&action=delete&database=" . $database_filename_friendly, { Text => $kiriwrite_lang->{options}->{delete} }); + $kiriwrite_presmodule->endrow(); - } + $database_count++; + $nodescription = 0; + $noname = 0; - if ($database_maxlength_check ne 0){ + } - # The database file is too long, so process the - # next database. + $kiriwrite_presmodule->endtable(); - $messages = $messages . $error_prefix . "The database with the filename '" . $database_out . ".db' is too long. Skipping this database..." . "
"; - $error_count++; - next; + # Disconnect from the database server. - } + $kiriwrite_dbmodule->disconnect(); - # Check if the database exists and has valid - # permissions set. + # 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. - $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); - - if ($database_exists ne 0){ + if ($database_count eq 0){ - # The database does not exist so process - # the next database. + $kiriwrite_presmodule->clear(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databaselist}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("errorbox"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{nodatabasesavailable}); + $kiriwrite_presmodule->endbox(); - $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); + # Check if any databases with problems have appeared and if they + # have, print out a message saying which databases have problems. - if ($database_permissions ne 0){ + if (@permissions_list){ - # The permissions for the database are invalid - # so process the next database. + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databaseinvalidpermissions}, { Style => "smallpageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databaseinvalidpermissionstext}); + $kiriwrite_presmodule->addlinebreak(); - $messages = $messages . $error_prefix . "The database with the filename '" . $database_out . ".db' has invalid permissions set. Skipping this database..." . "
"; - $error_count++; - next; + foreach $data_file (@permissions_list){ + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($data_file); + } - } + $kiriwrite_presmodule->addlinebreak(); - # Load the SQLite database. + } - $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db'); + if (@error_list){ - # Get the database name. + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databaseerrors}, { Style => "smallpageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databaseerrorstext}); + $kiriwrite_presmodule->addlinebreak(); - $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..." . "
"; + foreach $data_file (@error_list){ + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($data_file); + } - # Get the pages in the database. + $kiriwrite_presmodule->addlinebreak(); - $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()){ + return $kiriwrite_presmodule->grab(); # Return to the main part of the script with the processed information. - # 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"); +sub kiriwrite_filter_list{ +################################################################################# +# kiriwrite_filter_list: Lists the filters that will be used when compiling a # +# webpage. # +# # +# Usage: # +# # +# kiriwrite_filter_list(); # +################################################################################# - # Check if the filename is valid. + my $filtersdb_notexist = 0; - $page_filename_check = kiriwrite_variablecheck($page_filename, "page_filename"); + # Connect to the database server. - if ($page_filename_check ne 0){ + $kiriwrite_dbmodule->connect(); - # The file name is not valid so write a - # error and process the next page. + # Check if any errors occured while connecting to the database server. - $messages = $messages . $error_prefix . "The page '" . $page_name_out . "' has an invalid filename. Page skipped." . "
"; - next; + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - } + # A database connection error has occured so return + # an error. - # 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){ + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - $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; + # Connect to the filter database. - } elsif ($page_template eq "!none"){ + $kiriwrite_dbmodule->connectfilter(); - $page_final = $page_content; + # Check if any error has occured while connecting to the filter + # database. - } else { + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){ - $page_final = $templatefiles{$page_template}{template}; - $page_final =~ s//$page_content/g; + # The filter database does not exist. - } + $filtersdb_notexist = 1; - # Create the combined page title (if needed). + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){ - if ($page_settings eq 0){ + # The filter database has invalid permissions set so return + # an error. - # Don't use page name or section name. + kiriwrite_error("filtersdbpermissions"); - $page_final =~ s///g; + } - } elsif ($page_settings eq 1){ + # Define some variables required for processing the filters list. - # Use the page name and section name. + my %filter_list; + my %filter_info; + my @database_filters; + my $blankfindfilter = 0; + my $filterswarning = ""; + my $filter; + my $filter_count = 0; + my $filter_style = 0; + my $filter_style_name = ""; - $page_autotitle = "(" . $page_section . " - " . $page_name . ")"; - $page_title = $page_section . " - " . $page_name; - $page_final =~ s//$page_title/g; + tie(%filter_list, 'Tie::IxHash'); - } elsif ($page_settings eq 2){ + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{viewfilters}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); - # Use the page name only. + # 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. - $page_autotitle = "(" . $page_name . ")"; - $page_final =~ s//$page_name/g; + if ($filtersdb_notexist eq 0){ - } elsif ($page_settings eq 3){ + # Get the list of available filters. - # Use the section name only. + @database_filters = $kiriwrite_dbmodule->getfilterlist(); - if ($page_section){ - $page_autotitle = "(" . $page_section . ")"; - } - $page_final =~ s//$page_section/g; + # Check if any errors occured while getting the list of filters. - } + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){ - # Check if the section name is not blank and - # place brackets inbetween if it is. + # A database error has occured with the filters database. - if ($page_section){ + kiriwrite_error("filtersdbdatabaseerror", $kiriwrite_dbmodule->geterror(1)); - $page_autosection = "(" . $page_section . ")"; + } - } + # Process each filter getting the priority, find setting and + # replace setting. - # Replace each value with the apporiate page - # values. + foreach $filter (@database_filters){ - $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; + # Get the information about the filter. - # Process the filters on the page data. + %filter_info = $kiriwrite_dbmodule->getfilterinfo({ FilterID => $filter }); - if ($filters_skip eq 0){ + # Check if any errors occured while getting the filter information. - $filters_count = 0; + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){ - foreach $filter_find (@findfilter){ + # A database error occured while using the filter database. - # Get the replace filter and process each - # filter on the page. + kiriwrite_error("filtersdbdatabaseerror", $kiriwrite_dbmodule->geterror(1)); - $filter_replace = $replacefilter[$filters_count]; - $page_final =~ s/$filter_find/$filter_replace/g; - $filters_count++; + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDoesNotExist"){ - } + # The filter does not exist so process the next filter. - } + next; - # Process the page filename and check what directories - # need to be created. + } - $page_filename_length = int(length($page_filename)); + # Check if the find filter is blank. - do { + if (!$filter_info{"FilterFind"}){ - $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. + # The find filter is blank, so set the value to write a warning + # message saying that a find filter given is blank. - if ($page_filename_char eq '/'){ + $blankfindfilter = 1; - # 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++; + $filter_list{$filter_count}{ID} = $filter_info{"FilterID"}; + $filter_list{$filter_count}{Priority} = $filter_info{"FilterPriority"}; + $filter_list{$filter_count}{Find} = $filter_info{"FilterFind"}; + $filter_list{$filter_count}{Replace} = $filter_info{"FilterReplace"}; + $filter_list{$filter_count}{Notes} = $filter_info{"FilterNotes"}; - } else { + $filter_count++; - # Append the character to the directory/filename. + } - $page_filename_directory = $page_filename_directory . $page_filename_char; + # Check if there are filters in the filters database and + # write a message if there isn't. - } + if ($filter_count eq 0){ - $page_filename_seek++; + # There are no filters in the filters database. - } until ($page_filename_length eq $page_filename_seek); + $filterswarning = $kiriwrite_lang->{filter}->{nofiltersavailable}; - 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); + # 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){ - # Write the file to the output directory. + # The filters database doesn't exist so write + # a message. - open(PAGE, "> " . $kiriwrite_config{"directory_data_output"} . '/' . $page_filename); - print PAGE $page_final; - close(PAGE); + $filterswarning = $kiriwrite_lang->{filter}->{filterdatabasedoesnotexist}; - # 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. + # Check if there is a warning message and if + # there is then write that warning message + # else write the list of filters. - $page_autotitle = ""; - $page_autosection = ""; - $page_filename_seek = 0; - $page_filename_dircount = 0; - - $page_filename_directory = ""; - $page_directory_path = ""; - $page_directory_name = ""; - @pagedirectories = (); + if ($filterswarning){ - } + $kiriwrite_presmodule->startbox("errorbox"); + $kiriwrite_presmodule->addtext($filterswarning); + $kiriwrite_presmodule->endbox(); - # Write a message saying that the database has - # been processed. + } else { + + # The filters database exists so write out the + # list of filters. - $messages = $messages . $information_prefix . "Finished compiling pages in the '" . $database_name_out . "' database..." . "
"; + if ($blankfindfilter eq 1){ + + $kiriwrite_presmodule->addboldtext($kiriwrite_lang->{filter}->{warningtitle}); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{blankfindfilters}); + $kiriwrite_presmodule->addtext(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); } - $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 . "
"; + $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 }); - return $pagedata; + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{filter}->{priority}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{filter}->{findsetting}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{filter}->{replacesetting}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{options}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->endheader(); - } elsif ($confirm eq 0){ + foreach $filter (keys %filter_list){ - # The action to compile the databases has - # not been confirmed so check what type - # is being used. + # Check which style should be used. - if ($type eq "single"){ + if ($filter_style eq 0){ - # The type is a single database selected so - # process that database. + $filter_style_name = "tablecell1"; + $filter_style = 1; - # Define some variables for later. + } else { - 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; + $filter_style_name = "tablecell2"; + $filter_style = 0; - # 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); + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell($filter_style_name); + $kiriwrite_presmodule->addtext($filter_list{$filter}{Priority}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($filter_style_name); - if ($database_filename_check ne 0){ + # Check if the find filter is blank. - # The database filename is invalid, so - # return an error. + if (!$filter_list{$filter}{Find}){ - kiriwrite_error("databasefilenameinvalid"); + # The find filter is blank. - } + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{filter}->{blankfindsetting}); - if ($database_maxlength_check ne 0){ + } else { - # The database filename is too long, so - # return an error. + # The find filter is not blank. - kiriwrite_error("databasefilenametoolong"); + $kiriwrite_presmodule->addtext($filter_list{$filter}{Find}); } - # 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); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($filter_style_name); - if ($database_exists ne 0){ + # Check if the replace filter is blank. - # The database filename does not exist, so - # return an error. + if (!$filter_list{$filter}{Replace}){ - kiriwrite_error("databasemissingfile"); + # The replace filter is blank. - } + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{filter}->{blankreplacesetting}); - if ($database_permissions ne 0){ + } else { - # The database permissions are invalid, so - # return an error. + # The replace filter is not blank. - kiriwrite_error("databaseinvalidpermissions"); + $kiriwrite_presmodule->addtext($filter_list{$filter}{Replace}); } - # Load the SQLite database. + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($filter_style_name); + $kiriwrite_presmodule->addlink("?mode=filter&action=edit&filter=" . $filter_list{$filter}{ID}, { Text => $kiriwrite_lang->{options}->{edit} }); + $kiriwrite_presmodule->addlink("?mode=filter&action=delete&filter=" . $filter_list{$filter}{ID}, { Text => $kiriwrite_lang->{options}->{delete} }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); - $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"); + $kiriwrite_presmodule->endtable(); - # 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; + # Disconnect from the filter database. - } elsif ($type eq "multiple"){ + $kiriwrite_dbmodule->disconnectfilter(); - # The type is multiple databases selected - # so process each database. + # Disconnect from the database server. - # Define some variables for later. + $kiriwrite_dbmodule->disconnect(); - 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 = ""; + return $kiriwrite_presmodule->grab(); - foreach $databasename (@selectedlist){ +} - # Check if the database is in the database - # directory and skip it if it isn't. +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. # +################################################################################# - $database_filename_check = kiriwrite_variablecheck($databasename, "filename", "", 1); - $database_maxlength_check = kiriwrite_variablecheck($databasename, "maxlength", 64, 1); + # Get the values that have been passed to the subroutine. - if ($database_filename_check ne 0 || $database_maxlength_check ne 0){ + my ($filter_new_find, $filter_new_replace, $filter_new_priority, $filter_new_notes, $confirm) = @_; - # The database filename given is invalid or - # the database filename given is too long - # so process the next database. + # Check the confirm value to make sure it is no more than + # one character long. - next; + kiriwrite_variablecheck($confirm, "maxlength", 1, 0); - } + if (!$confirm){ - # Check if the database exists and has valid permissions - # set and skip them if they don't. + # The confirm value is undefined, so set the + # value of the confirm integer to '0'. - $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $databasename . '.db'); - $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $databasename . '.db', 1, 0); + $confirm = 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. + if ($confirm eq 1){ - next; + # The confirm integer is '1', so add the word + # to the filter list. - } + # First, check the variables recieved are UTF8 + # copliant. - # Get the database name. + 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); - $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(); + # Convert the UTF8 values so that the length can + # checked properly. - # Increment the amount of databases to compile. + $filter_new_find = kiriwrite_utf8convert($filter_new_find); + $filter_new_replace = kiriwrite_utf8convert($filter_new_replace); + $filter_new_priority = kiriwrite_utf8convert($filter_new_priority); + $filter_new_notes = kiriwrite_utf8convert($filter_new_notes); - $database_count++; + # Check if the find filter is blank and return an error + # if it is. - # Get the database name, convert it so that it can - # be displayed properly and add it to the list of - # databases to be compiled. + if (!$filter_new_find){ - @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"); + # The find filter given is blank so return an + # error. - $databaselist = $databaselist . "" . $database_info_name_out . "
"; + kiriwrite_error("blankfindfilter"); - } + } - # Check if any databases are available to be compiled. + if (!$filter_new_priority){ - if ($database_count eq 0){ + # The filter priority is blank so set it + # to 1. - # No databases are available to be compiled. + $filter_new_priority = 1; - kiriwrite_error("nodatabaseselected"); + } - } + # Check the length and contents of the values given + # to make sure they are valid. - # Write out the form for compiling the database. + 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); - $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; + # Check if the result of the tests to see if they + # are valid. - } else { + if ($filterfind_maxlength_check eq 1){ - # The type is something else other than - # single or multiple, so return an error. + # The find filter is too long, so return + # an error. - kiriwrite_error("invalidvariable"); + kiriwrite_error("findfiltertoolong"); } - } else { - - # The confirm value is neither 0 or 1, so - # return an error. - - kiriwrite_error("invalidvariable"); - - } - -} + if ($filterreplace_maxlength_check eq 1){ -sub kiriwrite_compile_all{ -################################################################################# -# kiriwrite_compile_all: Compile all of the databases in the database # -# directory. # -# # -# Usage: # -# # -# kiriwrite_compile_all(); # -################################################################################# + # The replace filter is too long, so + # return an error. - # Get the list of databases to compile. + kiriwrite_error("replacefiltertoolong"); - opendir(DATABASE, $kiriwrite_config{"directory_data_db"}); - my @database_list = grep /m*\.db/, readdir(DATABASE); - closedir(DATABASE); + } - # Define some variables for later. + if ($filterpriority_maxlength_check eq 1){ - 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){ + # The length of the filter priority + # given is too long, so return an + # error. - # Check if the database filename is valid before - # using the database. + kiriwrite_error("filterprioritytoolong"); - $database_name_filename_check = kiriwrite_variablecheck($database_name, "filename", 0, 1); + } - if ($database_name_filename_check ne 0){ + if ($filterpriority_numbers_check eq 1){ - # The database filename is invalid so process - # the next database. + # The priority of the filter given + # contains characters other than + # numbers. - next; + kiriwrite_error("filterpriorityinvalidchars"); } - # 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 . ""; + # Check if the filter priority is less than 1 + # and more than 10000 and return an error + # if it is. - $database_count++; + if ($filter_new_priority < 1 || $filter_new_priority > 50000){ - } + # The filter priority is less than 1 and + # more than 10000, so return an error. - # Check the list of databases to compile to see if it is blank, - # if it is then return an error. + kiriwrite_error("filterpriorityinvalid"); - if ($database_count eq 0){ + } - # The list of database is blank so return an error. + # Connect to the database server. - kiriwrite_error("nodatabasesavailable"); + $kiriwrite_dbmodule->connect(); - } + # Check if any errors occured while connecting to the database server. - # Write out a form for confirming the action to compile all of the databases. + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - 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 . "
"; + # A database connection error has occured so return + # an error. - return $pagedata; + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); -} + } -sub kiriwrite_selectedlist{ -################################################################################# -# kiriwrite_page_selectedlist: Get the list of selected pages to use. # -# # -# Usage: # -# # -# kiriwrite_page_selectedlist(); # -################################################################################# + # Connect to the filters database. - # 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. + $kiriwrite_dbmodule->connectfilter(1); - if (!$count){ + # Check if any error has occured while connecting to the filter + # database. - $count = 0; + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){ - } + # The filter database does not exist. - # Define some values for later. + kiriwrite_error("filtersdbmissing"); - my @filename_list; - my @selected_list; - my @final_list; + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){ - my $filename; - my $selected; - - my $final_count = 0; - my $seek = 0; + # The filter database has invalid permissions set so return + # an error. - # Get the list of filenames. + kiriwrite_error("filtersdbpermissions"); - do { + } - # Get the values from id[] + # Add the filter to the filter database. - $seek++; + $kiriwrite_dbmodule->addfilter({ FindFilter => $filter_new_find, ReplaceFilter => $filter_new_replace, Priority => $filter_new_priority, Notes => $filter_new_notes}); - $filename = $query->param('id[' . $seek . ']'); - $filename_list[$seek] = $filename; + # Check if any errors have occured while adding the filter. - } until ($seek eq $count || $count eq 0); + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){ - # Get the list of selected filenames. + # The filter database has invalid permissions set so return + # an error. - $seek = 0; + kiriwrite_error("filtersdbpermissions"); - do { + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDatabaseUncreatable"){ - # Get the values from name[] + # The filter database is uncreatable so return an error. - $seek++; + kiriwrite_error("filterdatabase"); - $selected = $query->param('name[' . $seek . ']'); + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){ - if (!$selected){ + # A database error with the filter database has occured so return + # an error with the extended error information. - $selected = 'off'; + kiriwrite_error("filtersdbdatabaseerror", $kiriwrite_dbmodule->geterror(1)); } - $selected_list[$seek] = $selected; + # Disconnect from the filter database. - } until ($seek eq $count || $count eq 0); + $kiriwrite_dbmodule->disconnectfilter(); - # Create a final list of filenames to be used for - # processing. + # Disconnect from the database server. - $seek = 0; + $kiriwrite_dbmodule->disconnect(); - do { + # Write out a message saying that the filter was added to the + # filters database. - # Check if the selected value is on and include - # the filename in the final list. + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{filteradded}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{filteraddedmessage}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=filter", { Text => $kiriwrite_lang->{filter}->{returnfilterlist} }); - $seek++; + return $kiriwrite_presmodule->grab(); - $selected = $selected_list[$seek]; + } elsif ($confirm ne 0) { - if ($selected eq "on"){ + # The confirm integer is another value (which + # it shouldn't be) so return an error. - $filename = $filename_list[$seek]; - $final_list[$final_count] = $filename; - $final_count++; + kiriwrite_error("invalidvalue"); - } + } - } until ($seek eq $count || $count eq 0); + # The confirm integer was blank so print out a form + # for adding a new filter. - return @final_list; + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{addfilter}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "filter"); + $kiriwrite_presmodule->addhiddendata("action", "add"); + $kiriwrite_presmodule->addhiddendata("confirm", 1); + $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 }); + + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{setting}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{value}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->endheader(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{findfilter}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("findword", { Size => 64, MaxLength => 1024 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{replacefilter}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("replaceword", { Size => 64, MaxLength => 1024 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{priority}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("priority", { Size => 5, MaxLength => 5 }); + $kiriwrite_presmodule->startlist(); + $kiriwrite_presmodule->additem($kiriwrite_lang->{filter}->{noprioritygiven}); + $kiriwrite_presmodule->endlist(); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{notes}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtextbox("notes", { Columns => 50, Rows => 10 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->endtable(); + + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{filter}->{addfilterbutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addreset($kiriwrite_lang->{common}->{clearvalues}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=filter", { Text => $kiriwrite_lang->{filter}->{returnfilterlist} }); + + $kiriwrite_presmodule->endform(); + + return $kiriwrite_presmodule->grab(); } -sub kiriwrite_compile_list{ +sub kiriwrite_filter_edit{ ################################################################################# -# kiriwrite_compile_list: Shows a list of databases that can be compiled. # +# kiriwrite_filter_edit: Edits a filter from the filter list. # # # # Usage: # # # -# kiriwrite_compile_list(); # +# 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. # ################################################################################# - # Load the required Perl modules. - - use DBI; + # Get the values that have been passed to the subroutine. - # Check the directory to make sure the permissions are settings are valid - # and return an error if the permission settings are invalid. + my ($filter_id, $filter_new_find, $filter_new_replace, $filter_new_priority, $filter_new_notes, $confirm) = @_; - my $data_directory_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"}, 1, 0); + # Check the confirm value to make sure it is no more than + # one character long. + + kiriwrite_variablecheck($confirm, "maxlength", 1, 0); + + # 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"); + + } + + my $filter_priority; + my $filter_find; + my $filter_replace; + my $filter_notes; + + # Check if the action to edit a filter has been + # confirmed. + + if ($confirm eq 1){ + + # The action to edit a filter has been confirmed so + # edit the selected filter. + + # 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"); + + } + + # Connect to the database server. + + $kiriwrite_dbmodule->connect(); + + # Check if any errors occured while connecting to the database server. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ + + # A database connection error has occured so return + # an error. + + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); + + } + + # Connect to the filters database. + + $kiriwrite_dbmodule->connectfilter(); + + # Check if any error has occured while connecting to the filter + # database. + + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){ + + # The filter database does not exist. + + kiriwrite_error("filtersdbmissing"); + + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){ + + # The filter database has invalid permissions set so return + # an error. + + kiriwrite_error("filtersdbpermissions"); + + } + + # Edit the selected filter in the filter database. + + $kiriwrite_dbmodule->editfilter({ FilterID => $filter_id, NewFindFilter => $filter_new_find, NewReplaceFilter => $filter_new_replace, NewFilterPriority => $filter_new_priority, NewFilterNotes => $filter_new_notes }); + + # Check if any errors occured while editing the filter. + + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){ + + # The filter database has invalid permissions set so return + # an error. + + kiriwrite_error("filtersdbpermissions"); + + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){ + + # A database error has occured while using the filters database + # so return an error. + + kiriwrite_error("filtersdbdatabaseerror", $kiriwrite_dbmodule->geterror(1)); + + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDoesNotExist"){ + + # The specified filter does not exist so return an error. + + kiriwrite_error("filterdoesnotexist"); + + } + + # Disconnect from the filter database. + + $kiriwrite_dbmodule->disconnectfilter(); + + # Disconnect from the database server. + + $kiriwrite_dbmodule->disconnect(); + + # Write a message saying that the filter was edited. + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{editedfilter}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{editedfiltermessage}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=filter", { Text => $kiriwrite_lang->{filter}->{returnfilterlist}}); + + return $kiriwrite_presmodule->grab(); + + } elsif ($confirm eq 0){ + + # The action to edit a filter has not been confirmed + # so write a form for editing the filter with. + + # Connect to the database server. + + $kiriwrite_dbmodule->connect(); + + # Check if any errors occured while connecting to the database server. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ + + # A database connection error has occured so return + # an error. + + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); + + } + + # Connect to the database server. + + $kiriwrite_dbmodule->connect(); + + # Check if any errors occured while connecting to the database server. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ + + # A database connection error has occured so return + # an error. + + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); + + } + + # Connect to the filters database. + + $kiriwrite_dbmodule->connectfilter(); + + # Check if any error has occured while connecting to the filter + # database. + + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){ + + # The filter database does not exist. + + kiriwrite_error("filtersdbmissing"); + + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){ + + # The filter database has invalid permissions set so return + # an error. + + kiriwrite_error("filtersdbpermissions"); + + } + + # Get information about the filter. + + my %filter_info = $kiriwrite_dbmodule->getfilterinfo({ FilterID => $filter_id }); + + # Check if any errors occured while getting information about the filter. + + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){ + + # A database error occured while using the filter database so + # return an error. + + kiriwrite_error("filtersdbdatabaseerror", $kiriwrite_dbmodule->geterror(1)); + + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDoesNotExist"){ + + # The filter does not exist so return an error. + + kiriwrite_error("filterdoesnotexist"); + + } + + # Get the required information. + + $filter_priority = $filter_info{"FilterPriority"}; + $filter_find = $filter_info{"FilterFind"}; + $filter_replace = $filter_info{"FilterReplace"}; + $filter_notes = $filter_info{"FilterNotes"}; + + # Disconnect from the filter database. + + $kiriwrite_dbmodule->disconnectfilter(); + + # Disconnect from the database server. + + $kiriwrite_dbmodule->disconnect(); + + # Write out the form. + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{editfilter}, { Style => "pageheader" }); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "filter"); + $kiriwrite_presmodule->addhiddendata("action", "edit"); + $kiriwrite_presmodule->addhiddendata("filter", $filter_id); + $kiriwrite_presmodule->addhiddendata("confirm", 1); + + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 }); + + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{setting}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{value}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->endheader(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{findfilter}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("filterfind", { Size => 64, MaxLength => 1024, Value => $filter_find }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{replacefilter}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("filterreplace", { Size => 64, MaxLength => 1024, Value => $filter_replace }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{priority}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("priority", { Size => 5, MaxLength => 5, Value => $filter_priority }); + $kiriwrite_presmodule->startlist(); + $kiriwrite_presmodule->additem($kiriwrite_lang->{filter}->{noprioritygiven}); + $kiriwrite_presmodule->endlist(); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{notes}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtextbox("notes", { Columns => 50, Rows => 10}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->endtable(); + + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{filter}->{editfilterbutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addreset($kiriwrite_lang->{common}->{restorecurrent}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=filter", { Text => $kiriwrite_lang->{filter}->{returnfilterlist} }); + + return $kiriwrite_presmodule->grab(); + + } 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) = @_; + + # Check the confirm value to make sure it is no more than + # one character long. + + kiriwrite_variablecheck($confirm, "maxlength", 1, 0); + + # 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"); + + } + + # Define some values for later. + + my @database_filter; + my $filter_exists = 0; + + # Check if the confirm integer has a value of '1'. + + if ($confirm eq 1){ + + # The action to delete a filter has been confirmed. + + # Connect to the database server. + + $kiriwrite_dbmodule->connect(); + + # Check if any errors occured while connecting to the database server. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ + + # A database connection error has occured so return + # an error. + + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); + + } + + # Connect to the filter database. + + $kiriwrite_dbmodule->connectfilter(); + + # Check if any error has occured while connecting to the filter + # database. + + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){ + + # The filter database does not exist. + + kiriwrite_error("filtersdbmissing"); + + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){ + + # The filter database has invalid permissions set so return + # an error. + + kiriwrite_error("filtersdbpermissions"); + + } + + # Delete the filter from the filter database. + + $kiriwrite_dbmodule->deletefilter({ FilterID => $filter_id }); + + # Check if any errors occured while deleting the filter. + + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){ + + # A database error has occured while trying to delete a filter so + # return an error. + + kiriwrite_error("filtersdbdatabaseerror", $kiriwrite_dbmodule->geterror(1)); + + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDoesNotExist"){ + + # The filter does not exist so return an error. + + kiriwrite_error("filterdoesnotexist"); + + } + + # Disconnect from the filter database. + + $kiriwrite_dbmodule->disconnectfilter(); + + # Disconnect from the database server. + + $kiriwrite_dbmodule->disconnect(); + + # Write a message saying that the filter was deleted + # from the filters database. + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{deletedfilter}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{deletedfiltermessage}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=filter", { Text => $kiriwrite_lang->{filter}->{returnfilterlist} }); + + } elsif ($confirm eq 0) { + + # Connect to the database server. + + $kiriwrite_dbmodule->connect(); + + # Check if any errors occured while connecting to the database server. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ + + # A database connection error has occured so return + # an error. + + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); + + } + + # Connect to the filter database. + + $kiriwrite_dbmodule->connectfilter(); + + # Check if any error has occured while connecting to the filter + # database. + + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){ + + # The filter database does not exist. + + kiriwrite_error("filtersdbmissing"); + + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){ + + # The filter database has invalid permissions set so return + # an error. + + kiriwrite_error("filtersdbpermissions"); + + } + + # Get information about the filter (to check if it exists). + + my %filter_info = $kiriwrite_dbmodule->getfilterinfo({ FilterID => $filter_id }); + + # Check if any errors occured while getting information about the filter. + + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){ + + # A database error occured while using the filter database so + # return an error. + + kiriwrite_error("filtersdbdatabaseerror", $kiriwrite_dbmodule->geterror(1)); + + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDoesNotExist"){ + + # The filter does not exist so return an error. + + kiriwrite_error("filterdoesnotexist"); + + } + + # Disconnect from the filter database. + + $kiriwrite_dbmodule->disconnectfilter(); + + # Disconnect from the database + + # The confirm integer is '0', so continue write out + # a form asking the user to confirm the deletion + # pf the filter. + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{deletefilter}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{filter}->{deletefiltermessage}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "filter"); + $kiriwrite_presmodule->addhiddendata("action", "delete"); + $kiriwrite_presmodule->addhiddendata("filter", $filter_id); + $kiriwrite_presmodule->addhiddendata("confirm", 1); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{filter}->{deletefilterbutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=filter", { Text => $kiriwrite_lang->{filter}->{deletefilterreturn} }); + $kiriwrite_presmodule->endform(); + + } else { + + kiriwrite_error("invalidvalue"); + + } + + return $kiriwrite_presmodule->grab(); + +} + +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"); + + } + + # 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 %database_info; + my %filter_info; + my %template_info; + my %page_info; + my %templatefiles; + my @page_filenames; + my @databaseinfo; + my @databasepages; + my @filterslist; + my @findfilter; + my @replacefilter; + my @templateslist; + my @pagedirectories; + my @database_filters; + my $warning_count = 0; + my $error_count = 0; + my $pages_count = 0; + my $filter; + my $filters_count = 0; + my $filters_find_blank_warning = 0; + my $filter_find; + my $filter_replace; + my $database; + my $database_name; + my $page_filename; + 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_filename_exists = 0; + my $page_filename_permissions = 0; + my $page_directory_name; + my $page_directory_path; + my $page_name; + my $page_description; + my $page_section; + my $page_template; + my $page_content; + my $page_settings; + my $page_lastmodified; + my $page_title; + my $page_final; + my $page_autosection; + my $page_autotitle; + my $page; + 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 $template; + my $templates_skip = 0; + my $information_prefix = $kiriwrite_lang->{compile}->{informationprefix}; + my $error_prefix = $kiriwrite_lang->{compile}->{errorprefix}; + my $warning_prefix = $kiriwrite_lang->{compile}->{warningprefix}; + my $filehandle_page; + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{compile}->{compiledatabases}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); + + # 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"); + + } + + # Connect to the database server. + + $kiriwrite_dbmodule->connect(); + + # Check if any errors occured while connecting to the database server. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ + + # A database connection error has occured so return + # an error. + + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); + + } + + # Connect to the filter database. + + $kiriwrite_dbmodule->connectfilter(); + + # Check if any error has occured while connecting to the filter + # database. + + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){ + + # The filter database does not exist so write a warning message. + + $kiriwrite_presmodule->addtext($warning_prefix . $kiriwrite_lang->{compile}->{filterdatabasemissing}); + $kiriwrite_presmodule->addlinebreak(); + $filters_skip = 1; + $warning_count++; + + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){ + + # The filter database has invalid permissions set so write a + # an error message. + + $kiriwrite_presmodule->addtext($error_prefix . $kiriwrite_lang->{compile}->{filterdatabasepermissions}); + $kiriwrite_presmodule->addlinebreak(); + $filters_skip = 1; + $error_count++; + + } + + # Load the filters database (if the filters skip + # value isn't set to 1). + + if ($filters_skip eq 0){ + + # Get the list of available filters. + + @database_filters = $kiriwrite_dbmodule->getfilterlist(); + + # Check if any errors occured while getting the list of filters. + + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){ + + # A database error has occured with the filters database. + + $kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{filterdatabaseerror}, $kiriwrite_dbmodule->geterror(1))); + $kiriwrite_presmodule->addlinebreak(); + $error_count++; + + } + + # Check if the filters skip value is set to 0 + # before executing the query. + + if ($filters_skip eq 0){ + + foreach $filter (@database_filters){ + + # Get the filter information. + + %filter_info = $kiriwrite_dbmodule->getfilterinfo({ FilterID => $filter }); + + # Check if any errors occured while getting the filter information. + + if ($kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){ + + # A database error occured while using the filter database. + + $kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{filterdatabaseerror}, $kiriwrite_dbmodule->geterror(1))); + $kiriwrite_presmodule->addlinebreak(); + $error_count++; + next; + + } elsif ($kiriwrite_dbmodule->geterror eq "FilterDoesNotExist"){ + + # The filter does not exist so process the next filter. + + next; + + } + + # Check if the find filter is blank and + # if it is then write a warning message. + + if (!$filter_info{"FilterFind"}){ + + if ($filters_find_blank_warning ne 1){ + + $kiriwrite_presmodule->addtext($warning_prefix . $kiriwrite_lang->{compile}->{findfilterblank}); + $kiriwrite_presmodule->addlinebreak(); + $filters_find_blank_warning = 1; + } + next; + + } else { + + # Add each find and replace filter. + + $findfilter[$filters_count] = $filter_info{"FilterFind"}; + $replacefilter[$filters_count] = $filter_info{"FilterReplace"}; + + } + + $filters_count++; + + } + + $kiriwrite_presmodule->addtext($information_prefix . $kiriwrite_lang->{compile}->{finishfilterdatabase}); + $kiriwrite_presmodule->addlinebreak(); + + } + + } + + # Disconnect from the filter database. + + $kiriwrite_dbmodule->disconnectfilter(); + + # Connect to the template database. + + $kiriwrite_dbmodule->connecttemplate(); + + # Check if any errors occured while connecting to the template database. + + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){ + + # The template database does not exist so set the template + # warning message. + + $kiriwrite_presmodule->addtext($warning_prefix . $kiriwrite_lang->{compile}->{templatedatabasemissing}); + $kiriwrite_presmodule->addlinebreak(); + $templates_skip = 1; + $warning_count++; + + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){ + + # The template database has invalid permissions set so write + # the template warning message. + + $kiriwrite_presmodule->addtext($error_prefix . $kiriwrite_lang->{compile}->{templatedatabasepermissions}); + $kiriwrite_presmodule->addlinebreak(); + $templates_skip = 1; + $error_count++; + + } + + # Check if the template skip value isn't set and if it isn't + # then get the list of templates. + + if (!$templates_skip){ + + @templateslist = $kiriwrite_dbmodule->gettemplatelist(); + + # Check if any errors had occured. + + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ + + # A database error occured while getting the list + # of templates so return a warning message with the + # extended error information. + + $kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{templatedatabaseerror}, $kiriwrite_dbmodule->geterror(1))); + $templates_skip = 1; + $error_count++; + + } + + # Check if the template skip value isn't set and if it isn't + # then process each template. + + if (!$templates_skip){ + + # Process each template. + + foreach $template (@templateslist){ + + # Get information about the template. + + %template_info = $kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template }); + + # Check if any error occured while getting the template information. + + if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){ + + # A database error has occured, so return an error. + + $kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{templatedatabaseerror}, $kiriwrite_dbmodule->geterror(1))); + $error_count++; + + } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){ + + # The template does not exist, so process the next template. + + next; + + } + + # Place each template file into the hash. + + $templatefiles{$template_info{"TemplateFilename"}}{template} = $template_info{"TemplateFilename"}; + $templatefiles{$template_info{"TemplateFilename"}}{valid} = 1; + + } + + $kiriwrite_presmodule->addtext($information_prefix . $kiriwrite_lang->{compile}->{finishtemplatedatabase}); + $kiriwrite_presmodule->addlinebreak(); + + } + + } + + # Disconnect from the template database. + + $kiriwrite_dbmodule->disconnecttemplate(); + + # Process each database. + + foreach $database (@selectedlist){ + + # Check if the database filename and length + # are valid. + + $kiriwrite_presmodule->addhorizontalline(); + + $database_filename_check = kiriwrite_variablecheck($database, "page_filename", "", 1); + $database_maxlength_check = kiriwrite_variablecheck($database, "maxlength", 32, 1); + + if ($database_filename_check ne 0){ + + # The database filename is invalid, so process + # the next database. + + $kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{databasefilenameinvalidcharacters}, $database)); + $kiriwrite_presmodule->addlinebreak(); + $error_count++; + next; + + } + + if ($database_maxlength_check ne 0){ + + # The database file is too long, so process the + # next database. + + $kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{databasefilenametoolong}, $database)); + $kiriwrite_presmodule->addlinebreak(); + $error_count++; + next; + + } + + # Select the database. + + $kiriwrite_dbmodule->selectdb({ DatabaseName => $database }); + + # Check if any errors had occured while selecting the database. + + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ + + # The database does not exist, so write a warning message. + + $kiriwrite_presmodule->addtext($warning_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{databasemissing}, $database)); + $kiriwrite_presmodule->addlinebreak(); + $warning_count++; + next; + + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ + + # The database has invalid permissions set, so write + # an error message. + + $kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{databaseinvalidpermissions}, $database)); + $kiriwrite_presmodule->addlinebreak(); + $error_count++; + next; + + } + + # Get information about the database. + + my %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); + + # Check if any error occured while getting the database information. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ + + # A database error has occured so write an error. + + $kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{databaseerror}, $database, $kiriwrite_dbmodule->geterror(1))); + $kiriwrite_presmodule->addlinebreak(); + $error_count++; + next; + + }; + + # Get the database name. + + $database_name = $database_info{"DatabaseName"}; + + $kiriwrite_presmodule->addtext($information_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{compilingpages}, $database_name)); + $kiriwrite_presmodule->addlinebreak(); + + # Get the list of pages in the database. + + @databasepages = $kiriwrite_dbmodule->getpagelist(); + + # Check if any errors occured while getting the list of pages. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ + + # A database error has occured so return an error and + # also the extended error information. + + $kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{databasepageerror}, $database, $kiriwrite_dbmodule->geterror(1))); + $kiriwrite_presmodule->addlinebreak(); + $error_count++; + next; + + } + + foreach $page (@databasepages) { + + # Get information about the page. + + %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $page }); + + $page_filename = $page_info{"PageFilename"}; + $page_name = $page_info{"PageName"}; + $page_description = $page_info{"PageDescription"}; + $page_section = $page_info{"PageSection"}; + $page_template = $page_info{"PageTemplate"}; + $page_content = $page_info{"PageContent"}; + $page_settings = $page_info{"PageSettings"}; + $page_lastmodified = $page_info{"PageLastModified"}; + + # Check if the filename is valid. + + $page_filename_check = kiriwrite_variablecheck($page_filename, "page_filename", 0, 1); + + if ($page_filename_check ne 0){ + + # The file name is not valid so write a + # error and process the next page. + + $kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{invalidpagefilename}, $page_name)); + $kiriwrite_presmodule->addlinebreak(); + $error_count++; + 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){ + + $kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{templatefilemissing}, $page_template, $page_name, $page_filename)); + $kiriwrite_presmodule->addlinebreak(); + $error_count++; + next; + + $page_final = $page_content; + + } elsif ($page_template eq "!none"){ + + $page_final = $page_content; + + } else { + + if ($page_content){ + + $page_final = $templatefiles{$page_template}{template}; + $page_final =~ s//$page_content/g; + + } + + } + + # Create the combined page title (if needed). + + if ($page_settings eq 0 || $page_settings > 3){ + + # 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 name is undefined and if it + # is then set it blank. + + if (!$page_directory_name){ + $page_directory_name = ""; + } + + if (!$page_directory_path){ + $page_directory_path = ""; + } + + # 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); + + } + + # Check if the file already exists and if it does then check + # the permissions of the file and return an error if the + # permissions set are invalid. + + $page_filename_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_output"} . '/' . $page_filename); + + if ($page_filename_exists eq 0){ + + # The page filename exists, so check if the permissions given are + # valid. + + $page_filename_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_output"} . '/' . $page_filename, 1, 1); + + if ($page_filename_permissions eq 1){ + + # The file has invalid permissions set. + + $kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{pageinvalidpermissions}, $page_filename)); + $kiriwrite_presmodule->addlinebreak(); + $error_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 = (); + + next; + + } + + } + + # 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 the file to the output directory. + + ($page_filename) = $page_filename =~ m/^(.*)$/g; + ($kiriwrite_config{"directory_data_output"}) = $kiriwrite_config{"directory_data_output"} =~ m/^(.*)$/g; + open($filehandle_page, ">:utf8 ", $kiriwrite_config{"directory_data_output"} . '/' . $page_filename) or ($kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{pagenotwritten}, $page_filename, $!)), $kiriwrite_presmodule->addlinebreak(), $error_count++, next); + binmode $filehandle_page, ':utf8'; + print $filehandle_page $page_final; + close($filehandle_page); + + # Write a message saying the page has been compiled. Check + # to see if the page name is blank and write a message + # saying there's no page name. + + if (!$page_name){ + $kiriwrite_presmodule->addtext($information_prefix . ' '); + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname}); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{compile}->{compiledpageblankname}, $page_filename)); + } else { + $kiriwrite_presmodule->addtext($information_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{compiledpage}, $page_name, $page_filename)); + } + + + $kiriwrite_presmodule->addlinebreak(); + $pages_count++; + + } + + # Write a message saying that the database has + # been processed. + + $kiriwrite_presmodule->addtext($information_prefix . kiriwrite_language($kiriwrite_lang->{compile}->{databasefinish}, $database_name)); + $kiriwrite_presmodule->addlinebreak(); + + } + + # Disconnect from the database server. + + $kiriwrite_dbmodule->disconnect(); + + $kiriwrite_presmodule->addhorizontalline(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{compile}->{compileresults}, $pages_count, $error_count, $warning_count)); + $kiriwrite_presmodule->endbox(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $kiriwrite_lang->{compile}->{returncompilelist} }); + + return $kiriwrite_presmodule->grab(); + + } 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_info; + my $database_filename_check; + my $database_maxlength_check; + my $databasefilename; + my $database_name; + + # Check that the database name and length are + # valid and return an error if they aren't. + + $databasefilename = $selectedlist[0]; + + # Connect to the database server. + + $kiriwrite_dbmodule->connect(); + + # Check if any errors occured while connecting to the database server. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ + + # A database connection error has occured so return + # an error. + + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); + + } + + # Select the database. + + $kiriwrite_dbmodule->selectdb({ DatabaseName => $databasefilename }); + + # Check if any errors had occured while selecting the database. + + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ + + # The database does not exist, so return an error. + + kiriwrite_error("databasemissingfile"); + + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ + + # The database has invalid permissions set, so return + # an error. + + kiriwrite_error("databaseinvalidpermissions"); + + } + + # Get information about the database. + + %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); + + # Check if any error occured while getting the database information. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ + + # A database error has occured so return an error and + # also the extended error information. + + kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1)); + + }; + + $database_name = $database_info{"DatabaseName"}; + + # Disconnect from the database server. + + $kiriwrite_dbmodule->disconnect(); + + # Write out a form asking the user to confirm if the + # user wants to compile the selected database. + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{compile}->{compiledatabase}, { Style => "pageheader" }); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "compile"); + $kiriwrite_presmodule->addhiddendata("action", "compile"); + $kiriwrite_presmodule->addhiddendata("type", "multiple"); + $kiriwrite_presmodule->addhiddendata("id[1]", $databasefilename); + $kiriwrite_presmodule->addhiddendata("name[1]", "on"); + $kiriwrite_presmodule->addhiddendata("confirm", 1); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{compile}->{compiledatabasemessage}, $database_name)); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{compile}->{compiledatabasebutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $kiriwrite_lang->{compile}->{returncompilelist} }); + + return $kiriwrite_presmodule->grab(); + + } elsif ($type eq "multiple"){ + + # The type is multiple databases selected + # so process each database. + + # Define some variables for later. + + my %database_list; + my $databasename; + my $database; + my $database_filename_check; + my $database_maxlength_check; + my $database_count = 0; + my $database_info_name; + + # Connect to the database server. + + $kiriwrite_dbmodule->connect(); + + # Check if any errors occured while connecting to the database server. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ + + # A database connection error has occured so return + # an error. + + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); + + } + + 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", 32, 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; + + } + + # Select the database to add the page to. + + $kiriwrite_dbmodule->selectdb({ DatabaseName => $databasename }); + + # Check if any errors had occured while selecting the database. + + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ + + # The database does not exist, so process the next database. + + next; + + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){ + + # The database has invalid permissions set, so process + # the next database. + + next; + + } + + # Get information about the database. + + my %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); + + # Check if any error occured while getting the database information. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ + + # A database error has occured so process the next + # database. + + next; + + }; + + $database_list{$database_count}{Name} = $database_info{"DatabaseName"}; + $database_list{$database_count}{Filename} = $databasename; + + $database_count++; + + } + + # 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. + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{compile}->{compileselecteddatabases}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "compile"); + $kiriwrite_presmodule->addhiddendata("action", "compile"); + $kiriwrite_presmodule->addhiddendata("type", "multiple"); + $kiriwrite_presmodule->addhiddendata("count", $database_count); + $kiriwrite_presmodule->addhiddendata("confirm", 1); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{compile}->{compileselecteddatabasesmessage}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); + + $database_count = 0; + + # write out the list of databases to compile. + + foreach $database (keys %database_list){ + + $database_count++; + + $kiriwrite_presmodule->addhiddendata("id[" . $database_count . "]", $database_list{$database}{Filename}); + $kiriwrite_presmodule->addhiddendata("name[" . $database_count . "]", "on"); + + # Check if the database name is undefined and if it is + # then write a message saying the database name is blank. + + if (!$database_list{$database}{Name}){ + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{compile}->{blankdatabasename}); + } else { + $kiriwrite_presmodule->addtext($database_list{$database}{Name}); + } + + $kiriwrite_presmodule->addlinebreak(); + + } + + $kiriwrite_presmodule->endbox(); + + # Disconnect from the database server. + + $kiriwrite_dbmodule->disconnect(); + + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{compile}->{compileselecteddatabasesbutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $kiriwrite_lang->{compile}->{returncompilelist} }); + $kiriwrite_presmodule->endform(); + + return $kiriwrite_presmodule->grab(); + + } 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(); # +################################################################################# + + # Connect to the database server. + + $kiriwrite_dbmodule->connect(); + + # Check if any errors occured while connecting to the database server. + + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ + + # A database connection error has occured so return + # an error. + + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); + + } + + # Get the list of available databases. + + my @database_list = $kiriwrite_dbmodule->getdblist(); + + # Check if any errors occured while getting the databases. + + if ($kiriwrite_dbmodule->geterror eq "DataDirMissing"){ + + # The database directory is missing so return an error. + + kiriwrite_error("datadirectorymissing"); + + } elsif ($kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){ + + # The database directory has invalid permissions set so return + # an error. + + kiriwrite_error("datadirectoryinvalidpermissions"); + + } + + # Define some variables for later. + + my $database; + my $database_name_filename_check; + my $database_count = 0; + + # Check the list of databases to compile to see if it is blank, + # if it is then return an error. + + if (!@database_list){ + + # 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. + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{compile}->{compilealldatabases}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "compile"); + $kiriwrite_presmodule->addhiddendata("action", "compile"); + $kiriwrite_presmodule->addhiddendata("type", "multiple"); + + foreach $database (@database_list){ + + # Check if the database filename is blank. + + if ($database eq ""){ + + # The database filename is blank so process + # the next database. + + next; + + } + + # Check if the database filename is valid before + # using the database. + + $database_name_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1); + + if ($database_name_filename_check ne 0){ + + # The database filename is invalid so process + # the next database. + + next; + + } + + $database_count++; + $kiriwrite_presmodule->addhiddendata("id[" . $database_count . "]", $database); + $kiriwrite_presmodule->addhiddendata("name[" . $database_count . "]", "on"); + + } - if ($data_directory_permissions eq 1){ + $kiriwrite_presmodule->addhiddendata("count", $database_count); - # The data directory has invalid permissions set, so return an error. + # Disconnect from the database server. - kiriwrite_error("datadirectoryinvalidpermissions"); + $kiriwrite_dbmodule->disconnect(); + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{compile}->{compilealldatabasesmessage}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + + $kiriwrite_presmodule->addhiddendata("confirm", 1); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{compile}->{compilealldatabasesbutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $kiriwrite_lang->{compile}->{returncompilelist} }); + + return $kiriwrite_presmodule->grab(); + +} + +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; } - # Open the directory and get the list of all files ending with .xml and - # put them into the data_directory array. + # Define some values for later. + + my @filename_list; + my @selected_list; + my @final_list; - opendir(DATADIR, $kiriwrite_config{"directory_data_db"}); - my @data_directory = grep /m*\.db/, readdir(DATADIR); - closedir(DATADIR); + my $filename; + my $selected; - # Declare the following variables that are going to be used before using + 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(); # +################################################################################# + + # Define the following variables that are going to be used before using # the foreach function. - - my $pagedata = ""; + + my %database_info; + my %database_list; 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 $database_name = ""; + my $database_description = ""; my $data_file = ""; - my $string_handle = ""; - my @database_info; + my @permissions_list; + my @error_list; 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 . ""; + my $database; - $select_menu = " | "; + tie(%database_list, 'Tie::IxHash'); - foreach $data_file (@data_directory){ - # Check the database file permissions before opening it. + # Connect to the database server. - $database_filename = $kiriwrite_config{"directory_data_db"} . '/' . $data_file; - $database_permissions = kiriwrite_filepermissions($database_filename, 1, 0, 0); + $kiriwrite_dbmodule->connect(); - if ($database_permissions eq 1){ - $permissions_warning = 1; - $permissions_list = $permissions_list . $data_file . "
\r\n"; - next; - } + # Check if any errors occured while connecting to the database server. - # Load the SQLite database. - - $database_handle = DBI->connect("dbi:SQLite:dbname=" . $database_filename); + if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){ - # Query the SQLite database or return an error (meaning that the database is in - # a invalid format). + # A database connection error has occured so return + # an error. - $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 - ); + kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1)); - $string_handle->execute(); - @database_info = $string_handle->fetchrow_array(); - - # Check the style to be used with. + } - if ($table_style eq 0){ + # Get the list of available databases and process any errors that + # might have occured. - # Use the first style and set the style value - # to use the next style, the next time the - # if statement is checked. + my @database_list = $kiriwrite_dbmodule->getdblist(); - $table_style_name = "tablecell1"; - $table_style = 1; - } else { + if ($kiriwrite_dbmodule->geterror eq "DataDirMissing"){ - # Use the second style and set the style - # value to use the first style, the next - # time if statement is checked. + # The database directory is missing so return an error. + + kiriwrite_error("datadirectorymissing"); + + } elsif ($kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){ + + # The database directory has invalid permissions set so return + # an error. + + kiriwrite_error("datadirectoryinvalidpermissions"); + + } + + # Begin creating the table for the list of databases. + + foreach $data_file (@database_list){ + + # Select the database. + + $kiriwrite_dbmodule->selectdb({ DatabaseName => $data_file }); + + # Check if any error occured while selecting the database. + + if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){ + + # The database does not exist, so process the next + # database. + + next; + + } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet") { + + # The database has invalid permissions settings, so + # add the database to the list of databases with + # invalid permissions set and process the next + # database. + + push(@permissions_list, $data_file); + next; - $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"); + # Get information about the database. - # Create a friendly name for the database. + %database_info = $kiriwrite_dbmodule->getdatabaseinfo(); - $database_filename_length = length($data_file); - $database_filename_friendly = substr($data_file, 0, $database_filename_length - 3); + # Check if any error occured while getting information from the + # database. - $database_count++; + if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){ - # Append the database information to the table. + # A database error has occured, add the database and specific + # error message to the list of databases with errors and + # process the next database. - $tabledata = $tabledata . "" . $database_name_out . "" . $database_description_out . "Compile\r\n"; - - } + push(@error_list, $data_file . ": " . $kiriwrite_dbmodule->geterror(1)); + next; + + } - $pagedata = $pagedata . ""; + $database_name = $database_info{"DatabaseName"}; + $database_description = $database_info{"Description"}; - $pagedata = $pagedata . $select_menu . "

"; + # Create a friendly name for the database. - $pagedata = $pagedata . "\r\n"; + $database_filename_friendly = $data_file; - $pagedata = $pagedata . $tabledata; - - $pagedata = $pagedata . "
Database NameDatabase DescriptionOptions
\r\n
"; + # Append the database information to the table. + + $database_list{$database_count}{Filename} = $database_filename_friendly; + $database_list{$database_count}{Name} = $database_name; + $database_list{$database_count}{Description} = $database_description; - $pagedata = $pagedata . $select_menu; - $pagedata = $pagedata . "
"; + $database_count++; + + } # 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. + $kiriwrite_presmodule->addtext($kiriwrite_lang->{compile}->{compilepages}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + if ($database_count eq 0){ - # + # There are no databases available for compiling so + # write a message instead. + + $kiriwrite_presmodule->startbox("errorbox"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{compile}->{nodatabasesavailable}); + $kiriwrite_presmodule->endbox(); + + } else { + + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "compile"); + $kiriwrite_presmodule->addhiddendata("action", "compile"); + $kiriwrite_presmodule->addhiddendata("type", "multiple"); + + $kiriwrite_presmodule->addreset($kiriwrite_lang->{common}->{selectnone}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{compile}->{compileselectedbutton}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addhiddendata("count", $database_count); + $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 }); + + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader("", { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{database}->{databasename}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{database}->{databasedescription}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{options}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->endheader(); + + $database_count = 1; + + foreach $database (keys %database_list){ + + # 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; - $pagedata = "

Database List

"; - $pagedata = $pagedata . "

There are no databases that can be used for compiling.

"; + } 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; + } + + # Add the template to the list of available + # templates to compile. + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell($table_style_name); + $kiriwrite_presmodule->addhiddendata("id[" . $database_count . "]", $database_list{$database}{Filename}); + $kiriwrite_presmodule->addcheckbox("name[" . $database_count . "]"); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($table_style_name); + + if (!$database_list{$database}{Name}){ + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=compile&action=compile&type=single&database=" . $database_list{$database}{Filename}, { Text => $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname}) }); + } else { + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database_list{$database}{Filename}, { Text => $database_list{$database}{Name} }); + } + + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($table_style_name); + + if (!$database_list{$database}{Description}){ + $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{nodescription}); + } else { + $kiriwrite_presmodule->addtext($database_list{$database}{Description}); + } + + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell($table_style_name); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=compile&action=compile&type=single&database=" . $database_list{$database}{Filename}, { Text => $kiriwrite_lang->{options}->{compile} }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $database_count++; + + } + + $kiriwrite_presmodule->endtable(); + $kiriwrite_presmodule->endform(); } + # Disconnect from the database server. + + $kiriwrite_dbmodule->disconnect(); + # 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 (@permissions_list){ + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databaseinvalidpermissions}, { Style => "smallpageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databaseinvalidpermissionstext}); + $kiriwrite_presmodule->addlinebreak(); + + foreach $database (@permissions_list){ + + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($database); + + } + + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); } - - 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; + if (@error_list){ + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databaseerrors}, { Style => "smallpageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{database}->{databaseerrorstext}); + $kiriwrite_presmodule->addlinebreak(); + + foreach $database (@error_list){ + + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($database); + + } } - return $pagedata; + return $kiriwrite_presmodule->grab(); } @@ -8115,7 +9831,7 @@ sub kiriwrite_compile_clean{ ################################################################################# # Get the values passed to the subroutine. - + my ($confirm) = @_; # Define some variables for later. @@ -8124,11 +9840,10 @@ sub kiriwrite_compile_clean{ 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"}); + $output_directory_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_output"}); if ($output_directory_exists eq 1){ @@ -8152,14 +9867,14 @@ sub kiriwrite_compile_clean{ 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. @@ -8172,45 +9887,59 @@ sub kiriwrite_compile_clean{ } - $pagedata = "

Clean Output Directory

"; + $kiriwrite_presmodule->addtext($kiriwrite_lang->{compile}->{cleanoutputdirectory}, { Style => "pageheader" }); 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.

"; + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{compile}->{somecontentnotremoved}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); } else { - $pagedata = $pagedata . "The contents of the output directory have been removed.

"; + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{compile}->{contentremoved}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); } - $pagedata = $pagedata . "Return to the compile databases list."; - - return $pagedata; - + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $kiriwrite_lang->{compile}->{returncompilelist} }); + + return $kiriwrite_presmodule->grab(); + } 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; + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{compile}->{cleanoutputdirectory}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "compile"); + $kiriwrite_presmodule->addhiddendata("action", "clean"); + $kiriwrite_presmodule->addhiddendata("confirm", 1); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{compile}->{cleanoutputdirectorymessage}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{compile}->{cleanoutputdirectorybutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $kiriwrite_lang->{compile}->{returncompilelist}}); + $kiriwrite_presmodule->endform(); + + return $kiriwrite_presmodule->grab(); } @@ -8231,11 +9960,11 @@ sub kiriwrite_compile_clean_helper{ ################################################################################# # Get the values passed to the subroutine. - - my ($directory, $directory_keep, $permissions) = @_; - + + 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; @@ -8250,26 +9979,26 @@ sub kiriwrite_compile_clean_helper{ $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 @@ -8287,52 +10016,63 @@ sub kiriwrite_compile_clean_helper{ } # 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; + ($directory) = $directory =~ m/^(.*)$/g; + ($directory_file) = $directory_file =~ m/^(.*)$/g; + + # Check if the directory is undefined and if it is then + # set it to blank. + + if (!$directory){ + $directory = ""; + } + + if (!$directory_file){ + $directory_file = ""; + } 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; + + ($directory) = $directory =~ m/^(.*)$/g; rmdir($directory); - + } else { - + # A value other than 0 or 1 was specified so return # an error, kiriwrite_error('invalidvalue'); - + } return $permissions; @@ -8350,101 +10090,259 @@ sub 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; + 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_presentation = $kiriwrite_config{"system_presmodule"}; + my $settings_system_database = $kiriwrite_config{"system_dbmodule"}; + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{viewsettings}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{currentsettings}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 }); + + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{setting}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{value}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->endheader(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{directories}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{databasedirectory}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtext($settings_directory_db); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{outputdirectory}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtext($settings_directory_output); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{imagesuripath}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtext($settings_noncgi_images); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{date}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{dateformat}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtext($settings_system_datetime); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{language}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{systemlanguage}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtext($settings_system_language); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{modules}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{presentationmodule}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtext($settings_system_presentation); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{databasemodule}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addtext($settings_system_database); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->endtable(); + + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{altersettings}); + + return $kiriwrite_presmodule->grab(); } sub kiriwrite_settings_edit{ ################################################################################# -# kiriwrite_options_edit: Edits the options. # +# kiriwrite_settings_edit: Edits the options. # # # # Usage: # # # -# kiriwrite_options_edit(dbdirectory, outputdirectory, imagesuri, # -# languagesystem, outputsystem, confirm); # +# kiriwrite_settings_edit(options); # +# # +# options Specifies the following options in any order. # +# # +# DatabaseDirectory Specifies the new database directory to use. # +# OutputDirectory Specifies the new output directory to use. # +# ImagesURIPath Specifies the new URI path for images. # +# DateTimeFormat Specifies the new date and time format. # +# SystemLanguage Specifies the new language to use for Kiriwrite. # +# PrsentationModule Specifies the new presentation module to use for # +# Kiriwrite. # +# DatabaseModule Specifies the new database module to use for Kiriwrite. # +# # +# Options for server-based database modules. # # # -# 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. # +# DatabaseServer Specifies the database server to use. # +# DaravasePort Specifies the port the database server is running on. # +# DatabaseProtocol Specifies the protocol the database server is using. # +# DatabaseSQLDatabase Specifies the SQL database name to use. # +# DatabaseUsername Specifies the database server username. # +# DatabasePasswordKeep Keeps the current password in the configuration file. # +# DatabasePassword Specifies the password for the database server username.# +# DatabaseTablePrefix Specifies the prefix used for tables. # ################################################################################# # Get the values that have been passed to the subroutine. - - my ($settings_dbdirectory, $settings_outputdirectory, $settings_imagesuri, $settings_datetimeformat, $settings_languagesystem, $settings_outputsystem, $confirm) = @_; - + + my ($passedoptions) = @_; + + # Get the values from the hash. + + my $settings_dbdirectory = $passedoptions->{"DatabaseDirectory"}; + my $settings_outputdirectory = $passedoptions->{"OutputDirectory"}; + my $settings_imagesuri = $passedoptions->{"ImagesURIPath"}; + my $settings_datetimeformat = $passedoptions->{"DateTimeFormat"}; + my $settings_languagesystem = $passedoptions->{"SystemLanguage"}; + my $settings_presmodule = $passedoptions->{"PresentationModule"}; + my $settings_dbmodule = $passedoptions->{"DatabaseModule"}; + + my $settings_database_server = $passedoptions->{"DatabaseServer"}; + my $settings_database_port = $passedoptions->{"DatabasePort"}; + my $settings_database_protocol = $passedoptions->{"DatabaseProtocol"}; + my $settings_database_sqldatabase = $passedoptions->{"DatabaseSQLDatabase"}; + my $settings_database_username = $passedoptions->{"DatabaseUsername"}; + my $settings_database_passwordkeep = $passedoptions->{"DatabasePasswordKeep"}; + my $settings_database_password = $passedoptions->{"DatabasePassword"}; + my $settings_database_tableprefix = $passedoptions->{"DatabaseTablePrefix"}; + + my $confirm = $passedoptions->{"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 the module names to see if they're valid. + + my $kiriwrite_presmodule_modulename_check = kiriwrite_variablecheck($settings_presmodule, "module", 0, 1); + my $kiriwrite_dbmodule_modulename_check = kiriwrite_variablecheck($settings_dbmodule, "module", 0, 1); + + if ($kiriwrite_presmodule_modulename_check eq 1){ + + # The presentation module name is blank, so return + # an error. + + kiriwrite_error("presmoduleblank"); + + } + + if ($kiriwrite_presmodule_modulename_check eq 2){ + + # The presentation module name is invalid, so return + # an error. + + kiriwrite_error("presmoduleinvalid"); + + } + + if ($kiriwrite_dbmodule_modulename_check eq 1){ + + # The database module name is blank, so return + # an error. + + kiriwrite_error("dbmoduleblank"); + + } + + if ($kiriwrite_dbmodule_modulename_check eq 2){ + + # The database module name is invalid, so return + # an error. + + kiriwrite_error("dbmoduleinvalid"); + + } # Check if the directory names only contain letters and numbers and # return a specific error if they don't. @@ -8452,7 +10350,7 @@ sub kiriwrite_settings_edit{ 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 @@ -8485,314 +10383,868 @@ sub kiriwrite_settings_edit{ } - # Place the settings into the array. + # Check if the presentation module with the filename given exists. + + my $presmodule_exists = kiriwrite_fileexists("Modules/Presentation/" . $settings_presmodule . ".pm"); + + if ($presmodule_exists eq 1){ + + # The presentation module does not exist so return an error. + + kiriwrite_error("presmodulemissing"); + + } + + # Check if the database module with the filename given exists. + + my $dbmodule_exists = kiriwrite_fileexists("Modules/Database/" . $settings_dbmodule . ".pm"); + + if ($dbmodule_exists eq 1){ + + # The database module does not exist so return an error. + + kiriwrite_error("dbmodulemissing"); + + } + + # Check if the language filename given exists. - $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; + my $languagefile_exists = kiriwrite_fileexists("lang/" . $settings_languagesystem . ".xml"); + + if ($languagefile_exists eq 1){ + + # The language filename given does not exist so return an error. + + kiriwrite_error("languagefilenamemissing"); + + } + + # Check the database server options to see if they are valid. + + my $kiriwrite_databaseserver_length_check = kiriwrite_variablecheck($settings_database_server, "maxlength", 128, 1); + my $kiriwrite_databaseserver_lettersnumbers_check = kiriwrite_variablecheck($settings_database_server, "lettersnumbers", 0, 1); + my $kiriwrite_databaseport_length_check = kiriwrite_variablecheck($settings_database_port, "maxlength", 5, 1); + my $kiriwrite_databaseport_numbers_check = kiriwrite_variablecheck($settings_database_port, "numbers", 0, 1); + my $kiriwrite_databaseport_port_check = kiriwrite_variablecheck($settings_database_port, "port", 0, 1); + my $kiriwrite_databaseprotocol_length_check = kiriwrite_variablecheck($settings_database_protocol, "maxlength", 5, 1); + my $kiriwrite_databaseprotocol_protocol_check = kiriwrite_variablecheck($settings_database_protocol, "serverprotocol", 0, 1); + my $kiriwrite_databasename_length_check = kiriwrite_variablecheck($settings_database_sqldatabase, "maxlength", 32, 1); + my $kiriwrite_databasename_lettersnumbers_check = kiriwrite_variablecheck($settings_database_sqldatabase, "lettersnumbers", 0, 1); + my $kiriwrite_databaseusername_length_check = kiriwrite_variablecheck($settings_database_username, "maxlength", 16, 1); + my $kiriwrite_databaseusername_lettersnumbers_check = kiriwrite_variablecheck($settings_database_username, "lettersnumbers", 0, 1); + my $kiriwrite_databasepassword_length_check = kiriwrite_variablecheck($settings_database_password, "maxlength", 64, 1); + my $kiriwrite_databasetableprefix_length_check = kiriwrite_variablecheck($settings_database_tableprefix, "maxlength", 16, 1); + my $kiriwrite_databasetableprefix_lettersnumbers_check = kiriwrite_variablecheck($settings_database_tableprefix, "lettersnumbers", 0, 1); + + if ($kiriwrite_databaseserver_length_check eq 1){ + + # The length of the database server name is too long so + # return an error. + + kiriwrite_error("servernametoolong"); + + } + + if ($kiriwrite_databaseserver_lettersnumbers_check eq 1){ + + # The database server name contains characters other + # than letters and numbers, so return an error. + + kiriwrite_error("servernameinvalid"); + + } + + if ($kiriwrite_databaseport_length_check eq 1){ + + # The database port number length is too long so return + # an error. + + kiriwrite_error("serverportnumbertoolong"); + + } + + if ($kiriwrite_databaseport_numbers_check eq 1){ + + # The database port number contains characters other + # than numbers so return an error. + + kiriwrite_error("serverportnumberinvalidcharacters"); + + } + + if ($kiriwrite_databaseport_port_check eq 1){ + + # The database port number given is invalid so return + # an error. + + kiriwrite_error("serverportnumberinvalid"); + + } + + if ($kiriwrite_databaseprotocol_length_check eq 1){ + + # The database protocol name given is too long so + # return an error. + + kiriwrite_error("serverprotocolnametoolong"); + + } + + if ($kiriwrite_databaseprotocol_protocol_check eq 1){ + + # The server protcol given is invalid so return + # an error. + + kiriwrite_error("serverprotocolinvalid"); + + } + + if ($kiriwrite_databasename_length_check eq 1){ + + # The SQL database name is too long so return + # an error. + + kiriwrite_error("serverdatabasenametoolong"); + + } + + if ($kiriwrite_databasename_lettersnumbers_check eq 1){ + + # The database name contains invalid characters + # so return an error. + + kiriwrite_error("serverdatabasenameinvalid"); + + } + + if ($kiriwrite_databaseusername_length_check eq 1){ + + # The database username given is too long so + # return an error. + + kiriwrite_error("serverdatabaseusernametoolong"); + + } + + if ($kiriwrite_databaseusername_lettersnumbers_check eq 1){ + + # The database username contains invalid characters + # so return an error. + + kiriwrite_error("serverdatabaseusernameinvalid"); + + } + + if ($kiriwrite_databasepassword_length_check eq 1){ + + # The database password given is too long so return + # an error. + + kiriwrite_error("serverdatabasepasswordtoolong"); + + } + + if ($kiriwrite_databasetableprefix_length_check eq 1){ + + # The database table prefix given is too long so + # return an error. + + kiriwrite_error("serverdatabasetableprefixtoolong"); + + } + + if ($kiriwrite_databasetableprefix_lettersnumbers_check eq 1){ + + # The database table prefix given contains invalid + # characters so return an error. + + kiriwrite_error("serverdatabasetableprefixinvalid"); + + } + + # Check if the current password should be kept. + + if ($settings_database_passwordkeep eq "on"){ + + # The current password in the configuration file should be used. + + $settings_database_password = $kiriwrite_config{"database_password"}; + + } # Write the new settings to the XML file. - - kiriwrite_output_xml("kiriwrite.xml", "config", @kiriwrite_new_settings); - + + kiriwrite_output_xml("kiriwrite.xml", "config", { DatabaseDirectory => $settings_dbdirectory, OutputDirectory => $settings_outputdirectory, ImagesURIPath => $settings_imagesuri, DateTimeFormat => $settings_datetimeformat, SystemLanguage => $settings_languagesystem, PresentationModule => $settings_presmodule, DatabaseModule => $settings_dbmodule, DatabaseServer => $settings_database_server, DatabasePort => $settings_database_port, DatabaseProtocol => $settings_database_protocol, DatabaseSQLDatabase => $settings_database_sqldatabase, DatabaseUsername => $settings_database_username, DatabasePassword => $settings_database_password, DatabaseTablePrefix => $settings_database_tableprefix }); + # 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; - + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{settingsedited}, { Style => "pageheadeR" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{settingseditedmessage}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=settings", { Text => $kiriwrite_lang->{setting}->{returnsettingslist} }); + + return $kiriwrite_presmodule->grab(); + } - + # Get the list of languages available. - + + my %language_list; my @language_directory = ""; + my $language; 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_count = 0; my $language_file_char = ""; my $language_file_friendly = ""; - my $language_selectlist = ""; - + my $language_config = $kiriwrite_config{"system_language"}; + + tie(%language_list, 'Tie::IxHash'); + opendir(LANGUAGEDIR, "lang"); - @language_directory = grep /m*\.xml/, readdir(LANGUAGEDIR); + @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 + + } + + # Get the list of presentation modules available. + + my %presmodule_list; + my @presmodule_directory; + my $presmodule; + my $presmodule_file = ""; + my $presmodule_char = ""; + my $presmodule_dot = 0; + my $presmodule_firstdot = 0; + my $presmodule_firstdotfound = ""; + my $presmodule_seek = 0; + my $presmodule_length = 0; + my $presmodule_count = 0; + my $presmodule_friendly = ""; + my $presmodule_selectlist = ""; + my $presmodule_config = $kiriwrite_config{"system_presmodule"}; + + # Open and get the list of presentation modules (perl modules) by filtering # out the - - opendir(OUTPUTSYSTEMDIR, "Modules/Output"); - @outputsys_directory = grep /m*\.pm/, readdir(OUTPUTSYSTEMDIR); + + opendir(OUTPUTSYSTEMDIR, "Modules/Presentation"); + @presmodule_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"); - + + 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 $database_server = $kiriwrite_config{"database_server"}; + my $database_port = $kiriwrite_config{"database_port"}; + my $database_protocol = $kiriwrite_config{"database_protocol"}; + my $database_sqldatabase = $kiriwrite_config{"database_sqldatabase"}; + my $database_username = $kiriwrite_config{"database_username"}; + my $database_passwordhash = $kiriwrite_config{"database_passwordhash"}; + my $database_password = $kiriwrite_config{"database_password"}; + my $database_prefix = $kiriwrite_config{"database_tableprefix"}; + # 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; + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{editsettings}, { Style => "pageheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addboldtext($kiriwrite_lang->{setting}->{warning}); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{warningmessage}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + + $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST"); + $kiriwrite_presmodule->addhiddendata("mode", "settings"); + $kiriwrite_presmodule->addhiddendata("action", "edit"); + $kiriwrite_presmodule->addhiddendata("confirm", 1); + + $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 }); + + $kiriwrite_presmodule->startheader(); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{setting}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{value}, { Style => "tablecellheader" }); + $kiriwrite_presmodule->endheader(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{directories}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{databasedirectory}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("databasedir", { Size => 32, MaxLength => 64, Value => $directory_settings_database }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{outputdirectory}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("outputdir", { Size => 32, MaxLength => 64, Value => $directory_settings_output }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{imagesuripath}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("imagesuripath", { Size => 32, MaxLength => 64, Value => $directory_settings_imagesuri }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{date}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{dateformat}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("datetime", { Size => 32, MaxLength => 64, Value => $datetime_setting }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); + + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{singleday}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{doubleday}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{singlemonth}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{doublemonth}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{singleyear}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{doubleyear}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{singlehour}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{doublehour}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{singleminute}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{doubleminute}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{singlesecond}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{doublesecond}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{othercharacters}); + $kiriwrite_presmodule->endbox(); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{language}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{systemlanguage}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + + $kiriwrite_presmodule->addselectbox("language"); + + # Process the list of available languages. + + foreach $language (keys %language_list){ + + # Check if the language filename matches the filename in the configuration + # file. + + if ($language_list{$language}{Filename} eq $language_config){ + + $kiriwrite_presmodule->addoption($language_list{$language}{Name}, { Value => $language_list{$language}{Filename} , Selected => 1 }); + + } else { + + $kiriwrite_presmodule->addoption($language_list{$language}{Name}, { Value => $language_list{$language}{Filename} }); + + } + + } + + $kiriwrite_presmodule->endselectbox(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{modules}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecellheader"); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{presentationmodule}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + + $kiriwrite_presmodule->addselectbox("presmodule"); + + # Process the list of available presentation modules. + + foreach $presmodule (keys %presmodule_list){ + + # Check if the presentation module fileanme matches the filename in the + # configuration file. + + if ($presmodule_list{$presmodule}{Filename} eq $presmodule_config){ + + $kiriwrite_presmodule->addoption($presmodule_list{$presmodule}{Filename}, { Value => $presmodule_list{$presmodule}{Filename} , Selected => 1 }); + + } else { + + $kiriwrite_presmodule->addoption($presmodule_list{$presmodule}{Filename}, { Value => $presmodule_list{$presmodule}{Filename} }); + + } + + } + + $kiriwrite_presmodule->endselectbox(); + + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{databasemodule}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + + # Process the list of available database modules. + + $kiriwrite_presmodule->addselectbox("dbmodule"); + + foreach $dbmodule (keys %dbmodule_list){ + + # Check if the database module fileanme matches the filename in the + # configuration file. + + if ($dbmodule_list{$dbmodule}{Filename} eq $dbmodule_config){ + + $kiriwrite_presmodule->addoption($dbmodule_list{$dbmodule}{Filename}, { Value => $dbmodule_list{$dbmodule}{Filename} , Selected => 1 }); + + } else { + + $kiriwrite_presmodule->addoption($dbmodule_list{$dbmodule}{Filename}, { Value => $dbmodule_list{$dbmodule}{Filename} }); + + } + + + } + + $kiriwrite_presmodule->endselectbox(); + + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{databaseserver}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("database_server", { Size => 32, MaxLength => 128, Value => $database_server }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{databaseport}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("database_port", { Size => 5, MaxLength => 5, Value => $database_port }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{databaseprotocol}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + + # Check if TCP is being used. + + $kiriwrite_presmodule->addselectbox("database_protocol"); + + if ($database_protocol eq "tcp"){ + + # The TCP protocol is selected so have the TCP option selected. + + $kiriwrite_presmodule->addoption("TCP", { Value => "tcp", Selected => 1}); + + } else { + + # The TCP protocol is not selected. + + $kiriwrite_presmodule->addoption("TCP", { Value => "tcp"}); + + } + + # Check if UDP is being used. + + if ($database_protocol eq "udp"){ + + # The UDP protocol is selected so have the UDP option selected. + + $kiriwrite_presmodule->addoption("UDP", { Value => "udp", Selected => 1}); + + } else { + + # The UDP protocol is not selected. + + $kiriwrite_presmodule->addoption("UDP", { Value => "udp"}); + + } + + $kiriwrite_presmodule->endselectbox(); + + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{databasename}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("database_sqldatabase", { Size => 32, MaxLength => 32, Value => $database_sqldatabase }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{databaseusername}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("database_username", { Size => 16, MaxLength => 16, Value => $database_username }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{databasepassword}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("database_password", { Size => 16, MaxLength => 64, Password => 1 }); + $kiriwrite_presmodule->addtext(" "); + $kiriwrite_presmodule->addcheckbox("database_password_keep", { OptionDescription => "Keep the current password", Checked => 1 }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->startrow(); + $kiriwrite_presmodule->addcell("tablecell1"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{setting}->{tableprefix}); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->addcell("tablecell2"); + $kiriwrite_presmodule->addinputbox("database_tableprefix", { Size => 16, MaxLength => 16, Value => $database_prefix }); + $kiriwrite_presmodule->endcell(); + $kiriwrite_presmodule->endrow(); + + $kiriwrite_presmodule->endtable(); + + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{setting}->{changesettingsbutton}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addreset($kiriwrite_lang->{common}->{restorecurrent}); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=settings", { Text => $kiriwrite_lang->{setting}->{returnsettingslist} }); + + $kiriwrite_presmodule->endform(); + + return $kiriwrite_presmodule->grab(); } @@ -8809,13 +11261,13 @@ sub kiriwrite_settings_load{ # Load the required Perl modules. use XML::Simple; - my $xsl = XML::Simple->new(); + 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. + # return an 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. @@ -8825,7 +11277,7 @@ sub kiriwrite_settings_load{ } # Check if the Kiriwrite configuration file has valid permission settings - # before using it and return a critical error if it doesn't have the + # before using it and return an critical error if it doesn't have the # valid permission settings. my $kiriwrite_conf_permissions = kiriwrite_filepermissions("kiriwrite.xml", 1, 0); @@ -8840,62 +11292,208 @@ sub kiriwrite_settings_load{ } # 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); + 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} - - ); - + + "system_language" => $kiriwrite_conf_data->{settings}->{language}->{lang}, + "system_presmodule" => $kiriwrite_conf_data->{settings}->{system}->{presentation}, + "system_dbmodule" => $kiriwrite_conf_data->{settings}->{system}->{database}, + "system_datetime" => $kiriwrite_conf_data->{settings}->{system}->{datetime}, + + "database_server" => $kiriwrite_conf_data->{settings}->{database}->{server}, + "database_port" => $kiriwrite_conf_data->{settings}->{database}->{port}, + "database_protocol" => $kiriwrite_conf_data->{settings}->{database}->{protocol}, + "database_sqldatabase" => $kiriwrite_conf_data->{settings}->{database}->{database}, + "database_username" => $kiriwrite_conf_data->{settings}->{database}->{username}, + "database_password" => $kiriwrite_conf_data->{settings}->{database}->{password}, + "database_tableprefix" => $kiriwrite_conf_data->{settings}->{database}->{prefix} + + ); + # 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_language_filename = kiriwrite_variablecheck($kiriwrite_config{"system_language"}, "language_filename", "", 1); + my $kiriwrite_config_presmodule_filename = kiriwrite_variablecheck($kiriwrite_config{"system_presmodule"}, "module", 0, 1); + my $kiriwrite_config_dbmodule_filename = kiriwrite_variablecheck($kiriwrite_config{"system_dbmodule"}, "module", 0, 1); - my $kiriwrite_config_systemoutput_fileexists = kiriwrite_fileexists("Modules/Output/" . $kiriwrite_config{"system_output"} . ".pm"); + # Check if the language filename is valid and return an critical error if + # they aren't. - if ($kiriwrite_config_systemoutput_fileexists eq 1){ + if ($kiriwrite_config_language_filename eq 1){ - # Output system module does not exist so return an critical error. - - kiriwrite_critical("outputsystemmissing"); + # The language filename is blank so return an critical error. + + kiriwrite_critical("languagefilenameblank"); + + } elsif ($kiriwrite_config_language_filename eq 2){ + + # The language filename is invalid so return an critical error. + + kiriwrite_critical("languagefilenameinvalid"); + + } + + # Check if the presentation and database module names are valid and return a critical + # error if they aren't. + + if ($kiriwrite_config_presmodule_filename eq 1){ + + # The presentation module filename given is blank so return an + # critical error. + + kiriwrite_critical("presmoduleblank"); + + } + + if ($kiriwrite_config_presmodule_filename eq 2){ + + # The presentation module filename is invalid so return an + # critical error. + + kiriwrite_critical("presmoduleinvalid"); + + } + + if ($kiriwrite_config_dbmodule_filename eq 1){ + + # The database module filename given is blank so return an + # critical error. + + kiriwrite_critical("dbmoduleblank"); + + } + + if ($kiriwrite_config_dbmodule_filename eq 2){ + + # The database module filename given is invalid so return + # an critical error. + + kiriwrite_critical("dbmoduleinvalid"); + + } + + # Check if the language file does exist before loading it and return an critical error + # if it does not exist. + + my $kiriwrite_config_language_fileexists = kiriwrite_fileexists("lang/" . $kiriwrite_config{"system_language"} . ".xml"); + + if ($kiriwrite_config_language_fileexists eq 1){ + + # Language file does not exist so return an critical error. + + kiriwrite_critical("languagefilemissing"); + + } + + # Check if the language file has valid permission settings and return an critical error if + # the language file has invalid permissions settings. + + my $kiriwrite_config_language_filepermissions = kiriwrite_filepermissions("lang/" . $kiriwrite_config{"system_language"} . ".xml", 1, 0); + + if ($kiriwrite_config_language_filepermissions eq 1){ + + # Language file contains invalid permissions so return an critical error. + + kiriwrite_critical("languagefilepermissions"); + + } + + # Load the language file. + + $kiriwrite_lang = $xsl->XMLin("lang/" . $kiriwrite_config{"system_language"} . ".xml", SuppressEmpty => 1); + + # Check if the presentation module does exist before loading it and return an critical error + # if the presentation module does not exist. + + my $kiriwrite_config_presmodule_fileexists = kiriwrite_fileexists("Modules/Presentation/" . $kiriwrite_config{"system_presmodule"} . ".pm"); + + if ($kiriwrite_config_presmodule_fileexists eq 1){ + + # Presentation module does not exist so return an critical error. + + kiriwrite_critical("presmodulemissing"); + + } + + # Check if the presentation module does have the valid permission settings and return a + # critical error if the presentation module contains invalid permission settings. + + my $kiriwrite_config_presmodule_permissions = kiriwrite_filepermissions("Modules/Presentation/" . $kiriwrite_config{"system_presmodule"} . ".pm", 1, 0); + + if ($kiriwrite_config_presmodule_permissions eq 1){ + + # Presentation module contains invalid permissions so return an critical error. + + kiriwrite_critical("presmoduleinvalidpermissions"); + + } + + # Check if the database module does exist before loading it and return an critical error + # if the database module does not exist. + + my $kiriwrite_config_dbmodule_fileexists = kiriwrite_fileexists("Modules/Database/" . $kiriwrite_config{"system_dbmodule"} . ".pm"); + + if ($kiriwrite_config_dbmodule_fileexists eq 1){ + + # Database module does not exist so return an critical error. + + kiriwrite_critical("dbmodulemissing"); } - # 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. + # Check if the database module does have the valid permission settings and return an + # critical error if the database module contains invalid permission settings. - my $kiriwrite_config_systemoutput_permissions = kiriwrite_filepermissions("Modules/Output/" . $kiriwrite_config{"system_output"} . ".pm", 1, 0); + my $kiriwrite_config_dbmodule_permissions = kiriwrite_filepermissions("Modules/Database/" . $kiriwrite_config{"system_dbmodule"} . ".pm", 1, 0); - if ($kiriwrite_config_systemoutput_permissions eq 1){ + if ($kiriwrite_config_dbmodule_permissions eq 1){ - # Output system contains invalid permissions so return an critical error. + # Presentation module contains invalid permissions so return an critical error. - kiriwrite_critical("outputsysteminvalidpermissions"); + kiriwrite_critical("dbmoduleinvalidpermissions"); } + # Include the Modules directory. + + use lib "Modules/"; + + # Load the presentation module. + + my $presmodulename = "Presentation::" . $kiriwrite_config{"system_presmodule"}; + ($presmodulename) = $presmodulename =~ m/^(.*)$/g; + eval "use " . $presmodulename; + $presmodulename = "Kiriwrite::Presentation::" . $kiriwrite_config{"system_presmodule"}; + $kiriwrite_presmodule = $presmodulename->new(); + + # Load the database module. + + my $dbmodulename = "Database::" . $kiriwrite_config{"system_dbmodule"}; + ($dbmodulename) = $dbmodulename =~ m/^(.*)$/g; + eval "use " . $dbmodulename; + $dbmodulename = "Kiriwrite::Database::" . $kiriwrite_config{"system_dbmodule"}; + $kiriwrite_dbmodule = $dbmodulename->new(); + + # Load the following settings to the database module. + + $kiriwrite_dbmodule->loadsettings({ Directory => $kiriwrite_config{"directory_data_db"}, DateTime => $kiriwrite_config{"system_datetime"}, Server => $kiriwrite_config{"database_server"}, Port => $kiriwrite_config{"database_port"}, Protocol => $kiriwrite_config{"database_protocol"}, Database => $kiriwrite_config{"database_sqldatabase"}, Username => $kiriwrite_config{"database_username"}, Password => $kiriwrite_config{"database_password"}, TablePrefix => $kiriwrite_config{"database_tableprefix"} }); + return; - + } sub kiriwrite_variablecheck{ @@ -8903,7 +11501,7 @@ 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. # @@ -8918,11 +11516,11 @@ sub kiriwrite_variablecheck{ # 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. @@ -8932,35 +11530,35 @@ sub kiriwrite_variablecheck{ } 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; - + + return 0; + } elsif ($variable_type eq "lettersnumbers"){ # Check for letters and numbers and return an error if there is anything else other @@ -8977,27 +11575,27 @@ sub kiriwrite_variablecheck{ # 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"); - + } } @@ -9006,22 +11604,22 @@ sub kiriwrite_variablecheck{ } 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; - + + 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); - + $variable_data_length = length($variable_data); + } @@ -9030,40 +11628,40 @@ sub kiriwrite_variablecheck{ # 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; - + + 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. @@ -9103,136 +11701,136 @@ sub kiriwrite_variablecheck{ } 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_database_list = ""; + my $variable_database_listcurrent = ""; my $variable_data_firstlevel = 1; # Get the length of the variable recieved. @@ -9242,77 +11840,77 @@ sub kiriwrite_variablecheck{ # 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 "."){ - + + if ($variable_database_listcurrent eq "" && $variable_data_firstlevel eq 1 || $variable_database_listcurrent eq ".." || $variable_database_listcurrent 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_database_list = $variable_database_list . $variable_data_char; + $variable_database_listcurrent = ""; $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; - + + $variable_database_list = $variable_database_list . $variable_data_char; + $variable_database_listcurrent = $variable_database_listcurrent . $variable_data_char; + } - + # Increment the seek counter. - + $variable_data_seek++; - + } until ($variable_data_seek eq $variable_data_length); - return 0; + return 0; } elsif ($variable_type eq "datetime"){ # Check if the date and time setting format is valid. @@ -9320,27 +11918,27 @@ sub kiriwrite_variablecheck{ 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"); - + } } @@ -9358,29 +11956,29 @@ sub kiriwrite_variablecheck{ # 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"); - + } } @@ -9397,27 +11995,27 @@ sub kiriwrite_variablecheck{ 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"); - + } } @@ -9432,29 +12030,29 @@ sub kiriwrite_variablecheck{ # 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"); - + } } @@ -9462,105 +12060,105 @@ sub kiriwrite_variablecheck{ 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"); - + + kiriwrite_critical("languagefilenameblank"); + } 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"); - + + kiriwrite_critical("languagefilenameinvalid"); + } 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 @@ -9569,7 +12167,7 @@ sub kiriwrite_variablecheck{ 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. + # to the end of this section. } else { @@ -9577,28 +12175,28 @@ sub kiriwrite_variablecheck{ # 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"); - + } } @@ -9610,57 +12208,59 @@ sub kiriwrite_variablecheck{ # 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_slash = 0; my $variable_data_char = ""; my $variable_data_validated = ""; my $variable_data_seek = 0; - my $variable_data_directory = ""; - my $variable_data_directorycurrent = ""; + my $variable_database_list = ""; + my $variable_database_listcurrent = ""; 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; + $variable_data_validated =~ tr|a-zA-Z0-9\.\/\-_||d; if ($variable_data_validated ne ""){ @@ -9668,98 +12268,182 @@ sub kiriwrite_variablecheck{ # variable contains invalid characters, so return # an error. - kiriwrite_error("invalidfilename"); + 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"); + + } } # 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 "."){ - + + $variable_data_slash = 1; + + if ($variable_database_listcurrent eq "" && $variable_data_firstlevel eq 1 || $variable_database_listcurrent eq ".." || $variable_database_listcurrent 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_database_list = $variable_database_list . $variable_data_char; + $variable_database_listcurrent = ""; $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; - + + $variable_data_slash = 0; + + $variable_database_list = $variable_database_list . $variable_data_char; + $variable_database_listcurrent = $variable_database_listcurrent . $variable_data_char; + } - + # Increment the seek counter. - + $variable_data_seek++; - + } until ($variable_data_seek eq $variable_data_length); - + + # Check if the last character is a slash and return an + # error if it is. + + if ($variable_data_slash eq 1){ + + if ($variable_noerror eq 1){ + + # Last character is a slash 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 a slash for the last + # character 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"); + + } + + } + return 0; - - } elsif ($variable_type eq "outputmodule"){ - - # The variable type is a output module filename. + + } elsif ($variable_type eq "module"){ + + # The variable type is a presentation 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 + # The presentation module is blank so check if an error # value should be returned or a number should be # returned. + if ($variable_noerror eq 1){ + + # Module name is blank and the no error value + # is set to 1 so return a value of 2 (meaning + # that the page filename is blank). + + return 1; + + } elsif ($variable_noerror eq 0) { + + # Module name contains is blank and the no error + # value is set to 0 so return an error. + + kiriwrite_critical("moduleblank"); + + } else { + + # The no error value is something else other + # than 0 or 1 so return an error. + + kiriwrite_critical("invalidvalue"); + + } + } else { } @@ -9771,7 +12455,31 @@ sub kiriwrite_variablecheck{ } else { - kiriwrite_error("outputmoduleinvalid"); + if ($variable_noerror eq 1){ + + # Module name 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) { + + # Module name contains invalid characters and + # the no error value is set to 0 so return an + # error. + + kiriwrite_critical("moduleinvalid"); + + } else { + + # The no error value is something else other + # than 0 or 1 so return an error. + + kiriwrite_error("invalidvalue"); + + } } @@ -9781,6 +12489,12 @@ sub kiriwrite_variablecheck{ # The variable type is a UTF8 string. + if (!$variable_data){ + + $variable_data = ""; + + } + # Check if the string is a valid UTF8 string. if ($variable_data =~ m/^( @@ -9815,7 +12529,7 @@ sub kiriwrite_variablecheck{ # an error. kiriwrite_error("invalidutf8"); - + } else { # The no error value is something else other than 0 @@ -9829,303 +12543,86 @@ sub kiriwrite_variablecheck{ 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; + } elsif ($variable_type eq "serverprotocol"){ - } - - $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++; + # Check if the server protocol is TCP or UDP and return + # an error if it isn't. - } until ($seek eq $length); + if ($variable_data ne "tcp" && $variable_data ne "udp"){ - # 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 { + # The protocol given is not valid, check if the no + # error value is set to 1 and return an error if it isn't. - $hour_full = $hour; + if ($variable_noerror eq 1){ - } + # The no error value has been set to 1, so return a + # value of 1 (meaning that the server protocol is + # invalid). - } elsif ($count eq 1){ + return 1; - # Get the minute and second from the time. + } elsif ($variable_noerror eq 0){ - $minute = substr($time, $startchar + 1, $timelength - 1); - $count = 2; - - # If the minute is less than ten then add a - # zero. + # The no error value has been set to 0, so return + # an error. - if ($minute < 10){ + kiriwrite_error("serverprotocolinvalid"); - $minute_full = '0' . $minute; + } else { - } else { + # The no error value is something else other than 0 + # or 1, so return an error. - $minute_full = $minute; + kiriwrite_error("invalidoption"); - } + } - $startchar = $seek; + } - $secondlength = $length - $seek + 1; - $second = substr($time, $startchar + 1, $secondlength); - - # If the second is less than ten then add a - # zero. + return 0; - if ($second < 10){ + } elsif ($variable_type eq "port"){ - $second_full = '0' . $second; + # Check if the port number given is less than 0 or more than 65535 + # and return an error if it is. - } else { + if ($variable_data < 0 || $variable_data > 65535){ - $second_full = $second; + # The port number is less than 0 and more than 65535 so + # 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 port number is invalid). - } + return 1; - $seek++; + } elsif ($variable_noerror eq 0){ - } until ($seek eq $length); + # The no error value has been set to 0, so return + # an error. - # Get the setting for displaying the date and time. + kiriwrite_error("serverportnumberinvalid"); - $data = $kiriwrite_config{"system_datetime"}; + } else { - # Process the setting for displaying the date and time - # using regular expressions + # The no error value is something else other than 0 + # or 1, so return an error. - $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; + kiriwrite_error("invalidoption"); - $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 0; + } - return $data; + # Another type than the valid ones above has been specified so return an error specifying an invalid option. + kiriwrite_error("invalidoption"); } @@ -10146,7 +12643,7 @@ sub kiriwrite_output_header{ #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'); + print header(-Expires=>'Sunday, 01-Jan-06 00:00:00 GMT', -charset=>'utf-8'); return; } @@ -10164,277 +12661,283 @@ sub kiriwrite_processfilename{ ################################################################################# # 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. - + # then limit the filename down to 32 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 + # filename and do so until the seek counter is 32 # 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); - + + } until ($processed_seek eq 32 || $processed_seek eq $processed_length); + return $processed_filename; } -sub kiriwrite_error{ +sub kiriwrite_language{ ################################################################################# -# kiriwrite_error: Prints out an error message. # -# # +# kiriwrite_language: Process language strings that need certain text inserted. # +# # # Usage: # # # -# kiriwrite_error(errortype); # +# kiriwrite_language(string, [text, text, ...]); # # # -# errortype Specifies the type of error that occured. # +# string Specifies the string to process. # +# text Specifies the text to pass to the string (can be repeated many # +# times). # ################################################################################# - # 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.", + my $string = shift; + my $item; - # 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.", - ); + foreach $item (@_){ - # Check if the specified error is blank and if it is - # use the generic error messsage. + $string =~ s/%s/$item/; - 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; + return $string; } -sub kiriwrite_get_templates{ +sub kiriwrite_error{ ################################################################################# -# kiriwrite_get_templates: Get the list of templates available (and valid) from # -# the template directory. # -# # +# kiriwrite_error: Prints out an error message. # +# # # Usage: # # # -# kiriwrite_get_templates(); # +# kiriwrite_error(errortype, errorext); # +# # +# errortype Specifies the type of error that occured. # +# errorext Specifies the extended error information. # ################################################################################# - # 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. + # Get the error type from the subroutine. - 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; + my ($error_type, $error_extended) = @_; - foreach $templatedir_filename (@templatedir){ + # Disconnect from the database server. - # Get the length of the original filename. + if ($kiriwrite_dbmodule){ + $kiriwrite_dbmodule->disconnect(); + } - $templatedir_filename_length = length($templatedir_filename); - $templatedir_filename_finallength = $templatedir_filename_length - 4; + # Load the list of error messages. - # Get the filename minus the last four characters and put the processed - # filename into the array of processed filenames. + my ($kiriwrite_error, %kiriwrite_error); - $templatedir_filename_processed = substr($templatedir_filename, 0, $templatedir_filename_finallength); + %kiriwrite_error = ( - $templatelist_processed[$templatedir_filename_seek] = $templatedir_filename_processed; + # Catch all error message. + "generic" => $kiriwrite_lang->{error}->{generic}, - # Increment the counter. + # Standard error messages. + "blankfilename" => $kiriwrite_lang->{error}->{blankfilename}, + "blankvariable" => $kiriwrite_lang->{error}->{blankvariable}, + "fileexists" => $kiriwrite_lang->{error}->{fileexists}, + "internalerror" => $kiriwrite_lang->{error}->{internalerror}, + "invalidoption" => $kiriwrite_lang->{error}->{invalidoption}, + "invalidaction" => $kiriwrite_lang->{error}->{invalidaction}, + "invalidfilename" => $kiriwrite_lang->{error}->{invalidfilename}, + "invalidmode" => $kiriwrite_lang->{error}->{invalidmode}, + "invalidutf8" => $kiriwrite_lang->{error}->{invalidutf8}, + "invalidvariable" => $kiriwrite_lang->{error}->{invalidvariable}, + "variabletoolong" => $kiriwrite_lang->{error}->{variabletoolong}, - $templatedir_filename_seek++; + # Specific error messages. + "blankcompiletype" => $kiriwrite_lang->{error}->{blankcompiletype}, + "blankdatabasepageadd" => $kiriwrite_lang->{error}->{blankdatabasepageadd}, + "blankdirectory" => $kiriwrite_lang->{error}->{blankdirectory}, + "blankfindfilter" => $kiriwrite_lang->{error}->{blankfindfilter}, + "blankdatetimeformat" => $kiriwrite_lang->{error}->{blankdatetimeformat}, + "databaseconnectionerror" => $kiriwrite_lang->{error}->{databaseconnectionerror}, + "databasecategoriestoolong" => $kiriwrite_lang->{error}->{databasecategoriestoolong}, + "databasecopysame" => $kiriwrite_lang->{error}->{databasecopysame}, + "databasealreadyexists" => $kiriwrite_lang->{error}->{databasealreadyexists}, + "datadirectorymissing" => $kiriwrite_lang->{error}->{datadirectorymissing}, + "datadirectoryinvalidpermissions" => $kiriwrite_lang->{error}->{datadirectoryinvalidpermissions}, + "databasedescriptiontoolong" => $kiriwrite_lang->{error}->{databasedescriptiontoolong}, + "databasefilenameinvalid" => $kiriwrite_lang->{error}->{databasefilenameinvalid}, + "databasefilenametoolong" => $kiriwrite_lang->{error}->{databasefilenametoolong}, + "databaseerror" => $kiriwrite_lang->{error}->{databaseerror}, + "databaseinvalidpermissions" => $kiriwrite_lang->{error}->{databaseinvalidpermissions}, + "databasenameinvalid" => $kiriwrite_lang->{error}->{databasenameinvalid}, + "databasenametoolong" => $kiriwrite_lang->{error}->{databasenametoolong}, + "databasenameblank" => $kiriwrite_lang->{error}->{databasenameblank}, + "databasemissingfile" => $kiriwrite_lang->{error}->{databasemissingfile}, + "databasemovemissingfile" => $kiriwrite_lang->{error}->{databasemovemissingfile}, + "databasenorename" => $kiriwrite_lang->{error}->{databasenorename}, + "databasemovesame" => $kiriwrite_lang->{error}->{databasemovesame}, + "dbmoduleblank" => $kiriwrite_lang->{error}->{dbmoduleblank}, + "dbmoduleinvalid" => $kiriwrite_lang->{error}->{dbmoduleinvalid}, + "dbdirectoryblank" => $kiriwrite_lang->{error}->{dbdirectoryblank}, + "dbdirectoryinvalid" => $kiriwrite_lang->{error}->{dbdirectoryinvalid}, + "dbmodulemissing" => $kiriwrite_lang->{error}->{dbmodulemissing}, + "filtersdatabasenotcreated" => $kiriwrite_lang->{error}->{filtersdatabasenotcreated}, + "filtersdbdatabaseerror" => $kiriwrite_lang->{error}->{filtersdbdatabaseerror}, + "filtersdbpermissions" => $kiriwrite_lang->{error}->{filtersdbpermissions}, + "filtersdbmissing" => $kiriwrite_lang->{error}->{filtersdbmissing}, + "filteridblank" => $kiriwrite_lang->{error}->{filteridblank}, + "filterdoesnotexist" => $kiriwrite_lang->{error}->{filterdoesnotexist}, + "filteridinvalid" => $kiriwrite_lang->{error}->{filteridinvalid}, + "filteridtoolong" => $kiriwrite_lang->{error}->{filteridtoolong}, + "findfiltertoolong" => $kiriwrite_lang->{error}->{findfiltertoolong}, + "filterpriorityinvalid" => $kiriwrite_lang->{error}->{filterpriorityinvalid}, + "filterpriorityinvalidchars" => $kiriwrite_lang->{error}->{filterpriorityinvalidchars}, + "filterprioritytoolong" => $kiriwrite_lang->{error}->{filterprioritytoolong}, + "invalidcompiletype" => $kiriwrite_lang->{error}->{invalidcompiletype}, + "invalidpagenumber" => $kiriwrite_lang->{error}->{invalidpagenumber}, + "nopagesselected" => $kiriwrite_lang->{error}->{nopagesselected}, + "invaliddirectory" => $kiriwrite_lang->{error}->{invaliddirectory}, + "invaliddatetimeformat" => $kiriwrite_lang->{error}->{invaliddatetimeformat}, + "invalidlanguagefilename" => $kiriwrite_lang->{error}->{invalidlanguagefilename}, + "languagefilenamemissing" => $kiriwrite_lang->{error}->{languagefilenamemissing}, + "moduleblank" => $kiriwrite_lang->{error}->{moduleblank}, + "moduleinvalid" => $kiriwrite_lang->{error}->{moduleinvalid}, + "newcopydatabasedatabaseerror" => $kiriwrite_lang->{error}->{newcopydatabasedatabaseerror}, + "newcopydatabasedoesnotexist" => $kiriwrite_lang->{error}->{newcopydatabasedoesnotexist}, + "newcopydatabasefileinvalidpermissions" => $kiriwrite_lang->{error}->{newcopydatabasefileinvalidpermissions}, + "newmovedatabasedatabaseerror" => $kiriwrite_lang->{error}->{newmovedatabasedatabaseerror}, + "newmovedatabasedoesnotexist" => $kiriwrite_lang->{error}->{newmovedatabasedoesnotexist}, + "newmovedatabasefileinvalidpermissions" => $kiriwrite_lang->{error}->{newmovedatabasefileinvalidpermissions}, + "nodatabasesavailable" => $kiriwrite_lang->{error}->{nodatabasesavailable}, + "nodatabaseselected" => $kiriwrite_lang->{error}->{nodatabaseselected}, + "noeditvaluesselected" => $kiriwrite_lang->{error}->{noeditvaluesselected}, + "oldcopydatabasedatabaseerror" => $kiriwrite_lang->{error}->{oldcopydatabasedatabaseerror}, + "oldcopydatabasedoesnotexist" => $kiriwrite_lang->{error}->{oldcopydatabasedoesnotexist}, + "oldcopydatabasefileinvalidpermissions" => $kiriwrite_lang->{error}->{oldcopydatabasefileinvalidpermissions}, + "oldmovedatabasedatabaseerror" => $kiriwrite_lang->{error}->{oldmovedatabasedatabaseerror}, + "oldmovedatabasedoesnotexist" => $kiriwrite_lang->{error}->{oldmovedatabasedoesnotexist}, + "oldmovedatabasefileinvalidpermissions" => $kiriwrite_lang->{error}->{oldmovedatabasefileinvalidpermissions}, + "outputdirectoryblank" => $kiriwrite_lang->{error}->{outputdirectoryblank}, + "outputdirectoryinvalid" => $kiriwrite_lang->{error}->{outputdirectoryinvalid}, + "outputdirectorymissing" => $kiriwrite_lang->{error}->{outputdirectorymissing}, + "outputdirectoryinvalidpermissions" => $kiriwrite_lang->{error}->{outputdirectoryinvalidpermissions}, + "presmoduleblank" => $kiriwrite_lang->{error}->{presmoduleblank}, + "presmoduleinvalid" => $kiriwrite_lang->{error}->{presmoduleinvalid}, + "presmodulemissing" => $kiriwrite_lang->{error}->{presmodulemissing}, + "pagefilenamedoesnotexist" => $kiriwrite_lang->{error}->{pagefilenamedoesnotexist}, + "pagefilenameexists" => $kiriwrite_lang->{error}->{pagefilenameexists}, + "pagefilenameinvalid" => $kiriwrite_lang->{error}->{pagefilenameinvalid}, + "pagefilenametoolong" => $kiriwrite_lang->{error}->{pagefilenametoolong}, + "pagefilenameblank" => $kiriwrite_lang->{error}->{pagefilenameblank}, + "pagetitletoolong" => $kiriwrite_lang->{error}->{pagetitletoolong}, + "pagedescriptiontoolong" => $kiriwrite_lang->{error}->{pagedescriptiontoolong}, + "pagesectiontoolong" => $kiriwrite_lang->{error}->{pagesectiontoolong}, + "pagedatabasefilenametoolong" => $kiriwrite_lang->{error}->{pagedatabasefilenametoolong}, + "pagesettingstoolong" => $kiriwrite_lang->{error}->{pagesettingstoolong}, + "pagesettingsinvalid" => $kiriwrite_lang->{error}->{pagesettingsinvalid}, + "pagetemplatefilenametoolong" => $kiriwrite_lang->{error}->{pagetemplatefilenametoolong}, + "replacefiltertoolong" => $kiriwrite_lang->{error}->{replacefiltertoolong}, + "servernameinvalid" => $kiriwrite_lang->{error}->{servernameinvalid}, + "servernametoolong" => $kiriwrite_lang->{error}->{servernametoolong}, + "serverdatabasenameinvalid" => $kiriwrite_lang->{error}->{serverdatabasenameinvalid}, + "serverdatabasenametoolong" => $kiriwrite_lang->{error}->{serverdatabasenametoolong}, + "serverdatabaseusernameinvalid" => $kiriwrite_lang->{error}->{serverdatabaseusernameinvalid}, + "serverdatabaseusernametoolong" => $kiriwrite_lang->{error}->{serverdatabaseusernametoolong}, + "serverdatabasepasswordtoolong" => $kiriwrite_lang->{error}->{serverdatabasepasswordtoolong}, + "serverdatabasetableprefixinvalid" => $kiriwrite_lang->{error}->{serverdatabasetableprefixinvalid}, + "serverdatabasetableprefixtoolong" => $kiriwrite_lang->{error}->{serverdatabasetableprefixtoolong}, + "serverportnumberinvalid" => $kiriwrite_lang->{error}->{serverportnumberinvalid}, + "serverportnumberinvalidcharacters" => $kiriwrite_lang->{error}->{serverportnumberinvalidcharacters}, + "serverportnumbertoolong" => $kiriwrite_lang->{error}->{serverportnumbertoolong}, + "serverprotocolnametoolong" => $kiriwrite_lang->{error}->{serverprotocolnametoolong}, + "serverprotocolinvalid" => $kiriwrite_lang->{error}->{serverprotocolinvalid}, + "templatenameblank" => $kiriwrite_lang->{error}->{templatenameblank}, + "templatefilenameexists" => $kiriwrite_lang->{error}->{templatefilenameexists}, + "templatefilenameinvalid" => $kiriwrite_lang->{error}->{templatefilenameinvalid}, + "templatedatabaseerror" => $kiriwrite_lang->{error}->{templatedatabaseerror}, + "templatedatabaseinvalidpermissions" => $kiriwrite_lang->{error}->{templatedatabaseinvalidpermissions}, + "templatedatabaseinvalidformat" => $kiriwrite_lang->{error}->{templatedatabaseinvalidformat}, + "templatedirectoryblank" => $kiriwrite_lang->{error}->{templatedirectoryblank}, + "templatedirectoryinvalid" => $kiriwrite_lang->{error}->{templatedirectoryinvalid}, + "templatedatabasenotcreated" => $kiriwrite_lang->{error}->{templatedatabasenotcreated}, + "templatefilenametoolong" => $kiriwrite_lang->{error}->{templatefilenametoolong}, + "templatenametoolong" => $kiriwrite_lang->{error}->{templatenametoolong}, + "templatedescriptiontoolong" => $kiriwrite_lang->{error}->{templatedescriptiontoolong}, + "templatedatabasemissing" => $kiriwrite_lang->{error}->{templatedatabasemissing}, + "templatedoesnotexist" => $kiriwrite_lang->{error}->{templatedoesnotexist}, + "templatefilenameblank" => $kiriwrite_lang->{error}->{templatefilenameblank}, - # Clear certain variables before using them again. + ); - $templatedir_filename_processed = ""; - $templatedir_filename_length = 0; - $templatedir_filename_finallength = 0; + # Check if the specified error is blank and if it is + # use the generic error messsage. + if (!$kiriwrite_error{$error_type}){ + $error_type = "generic"; } - # Check that each template really does exist and put each valid - # template into the final list. + $kiriwrite_presmodule->clear(); - foreach $templatedir_processed_filename (@templatelist_processed){ + $kiriwrite_presmodule->startbox("errorbox"); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{error}->{error}, { Style => "errorheader" }); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_error{$error_type}, { Style => "errortext" }); - if (-e $kiriwrite_config{"directory_data_template"} . '/' . $templatedir_processed_filename){ + # Check to see if extended error information was passed. - # The template does exist, so add the template to the list of valid templates. + if ($error_extended){ - $templatelist_final[$templatelist_final_count] = $templatedir_processed_filename; - $templatelist_final_count++; + # Write the extended error information. - } + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addtext($kiriwrite_lang->{error}->{extendederror}); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->addlinebreak(); + $kiriwrite_presmodule->startbox("datalist"); + $kiriwrite_presmodule->addtext($error_extended); + $kiriwrite_presmodule->endbox(); } - # Return the list of valid templates. + $kiriwrite_presmodule->endbox(); - return @templatelist_final; + kiriwrite_output_header; + kiriwrite_output_page($kiriwrite_lang->{error}->{error}, $kiriwrite_presmodule->grab(), "none"); + + exit; } @@ -10449,27 +12952,27 @@ sub kiriwrite_fileexists{ # # # 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. + # Check if the filename exists, if it does, return a value of 0, else + # return a value of 1, meaning that the file was not found. if (-e $filename){ - # Specified file does exist so return a value of 1. + # Specified file does exist so return a value of 0. return 0; } else { - # Specified file does not exist so return a value of 0. + # Specified file does not exist so return a value of 1. return 1; - } + } } @@ -10522,7 +13025,7 @@ sub kiriwrite_filepermissions{ $ignorechecks_result = 1; } - + } else { $ignorechecks_result = 0; @@ -10605,7 +13108,7 @@ sub kiriwrite_utf8convert{ sub kiriwrite_critical{ ################################################################################# -# kiriwrite_critical: Displays a critical error message that cannot be # +# kiriwrite_critical: Displays an critical error message that cannot be # # normally by the kiriwrite_error subroutine. # # # # Usage: # @@ -10617,55 +13120,43 @@ sub kiriwrite_critical{ 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") { + my %error_list; - # The error is that the output system module is missing. Print the - # header, error message and then end the script. + # Get the error type from the errortype string. - print header(); - print "Critical Error: The output system module is missing! Running the setup script for Kiriwrite is recommended."; - exit; + %error_list = ( - } elsif ($error_type eq "outputsysteminvalidpermissions"){ + # Generic critical error message. - # The error is that the output system module has invalid permissions - # set. Print the header, error message and then end the script. + "generic" => "A critical error has occured but the error is not known to Kiriwrite.", - print header(); - print "Critical Error: The output system module contains invalid permission settings! Please set the valid permission settings for the output module."; - exit; + # Specific critical error messages. - }else { + "configfilemissing" => "The Kiriwrite configuration file is missing! Running the installer script for Kiriwrite is recommended.", + "configfileinvalidpermissions" => "The Kiriwrite configuration file has invalid permission settings set! Please set the valid permission settings for the configuration file.", + "dbmodulemissing" => "The database module is missing! Running the installer script for Kiriwrite is recommended.", + "dbmoduleinvalidpermissions" => "The database module cannot be used as it has invalid permission settings set! Please set the valid permission settings for the configuration file.", + "dbmoduleinvalid" => "The database module name given is invalid. Running the installer script for Kiriwrite is recommended.", + "invalidvalue" => "An invalid value was passed.", + "languagefilenameblank" => "The language filename given is blank! Running the installer script for Kiriwrite is recommended.", + "languagefilenameinvalid" => "The language filename given is invalid! Running the installer script for Kiriwrite is recommended.", + "languagefilemissing" => "The language filename given does not exist. Running the installer script for Kiriwrite is recommended.", + "languagefilenameinvalidpermissions" => "The language file with the filename given has invalid permissions set. Please set the valid permission settings for the language file.", + "presmodulemissing" => "The presentation module is missing! Running the installer script for Kiriwrite is recommended.", + "presmoduleinvalidpermissions" => "The presentation module cannot be used as it has invalid permission settings set! Please set the valid permission settings for the presentation module.", + "presmoduleinvalid" => "The presentation module name given is invalid. Running the installer script for Kiriwrite is recommended.", + ); - # The error type is unspecified, so return a generic error message. + if (!$error_list{$error_type}){ - print header(); - print "Critical Error: An unspecified critical error has occured."; - exit; + $error_type = "generic"; } + print header(); + print "Critical Error: " . $error_list{$error_type}; + exit; + } sub kiriwrite_output_page{ @@ -10686,98 +13177,134 @@ sub kiriwrite_output_page{ # Open the script page template and load it into the scriptpage variable, # while declaring the variable. - open (SCRIPTPAGE, 'page.html'); - my @scriptpage = ; - close (SCRIPTPAGE); - + open (my $filehandle_scriptpage, "<:utf8", 'page.html'); + my @scriptpage = <$filehandle_scriptpage>; + binmode $filehandle_scriptpage, ':utf8'; + close ($filehandle_scriptpage); + # Define the variables required. - + my $scriptpageline = ""; my $pageoutput = ""; my $menuoutput = ""; - + + $kiriwrite_presmodule->clear(); + # Print out the main menu for Kiriwrite. - - $menuoutput = "View Databases | View Pages | View Filters | View Templates | Compile Pages | View Settings\r\n
"; - + + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=db", { Text => $kiriwrite_lang->{menu}->{viewdatabases} }); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=page", { Text => $kiriwrite_lang->{menu}->{viewpages} }); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=filter", { Text => $kiriwrite_lang->{menu}->{viewfilters} }); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=template", { Text => $kiriwrite_lang->{menu}->{viewtemplates} }); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=compile", { Text => $kiriwrite_lang->{menu}->{compilepages} }); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=settings", { Text => $kiriwrite_lang->{menu}->{viewsettings} }); + $kiriwrite_presmodule->addlinebreak(); + # 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"; - + + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=db", { Text => $kiriwrite_lang->{database}->{submenu}->{viewdatabases} }); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=db&action=new", { Text => $kiriwrite_lang->{database}->{submenu}->{adddatabase} }); + } 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"; - + + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=page&action=add&database=" . $db_filename, { Text => $kiriwrite_lang->{pages}->{submenu}->{addpage} }); + } - + } elsif ($menutype eq "filter"){ - + # If the menu type is filters then print out the filter sub-menu. - $menuoutput = $menuoutput . "Show Filters | Add Filter"; - + + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=filter", { Text => $kiriwrite_lang->{filter}->{submenu}->{showfilters} }); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=filter&action=add", { Text => $kiriwrite_lang->{filter}->{submenu}->{addfilter} }); + } elsif ($menutype eq "settings"){ - + # If the menu type is options then print out the options sub-menu. - $menuoutput = $menuoutput . "Show Settings | Edit Settings"; - + + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=settings", { Text => $kiriwrite_lang->{setting}->{submenu}->{viewsettings} }); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=settings&action=edit", { Text => $kiriwrite_lang->{setting}->{submenu}->{editsettings} }); + } elsif ($menutype eq "template"){ - + # If the menu type is template then print out the template sub-menu. - $menuoutput = $menuoutput . "Show Templates | Add Template"; - + + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=template", { Text => $kiriwrite_lang->{template}->{submenu}->{showtemplates} }); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=template&action=add", { Text => $kiriwrite_lang->{template}->{submenu}->{addtemplate} }); + } elsif ($menutype eq "compile"){ - + # If the menu type is compile then print out the compile sub-menu. - $menuoutput = $menuoutput . "Compile All | Clean Output Directory"; - + + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=compile", { Text => $kiriwrite_lang->{compile}->{submenu}->{listdatabases} }); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=compile&action=all", { Text => $kiriwrite_lang->{compile}->{submenu}->{compileall} }); + $kiriwrite_presmodule->addtext(" | "); + $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=compile&action=clean", { Text => $kiriwrite_lang->{compile}->{submenu}->{cleanoutputdirectory} }); + } - + + $menuoutput = $kiriwrite_presmodule->grab(); + # Find tages and replace with the apporiate variables. - + foreach $scriptpageline (@scriptpage){ - + $scriptpageline =~ s//$menuoutput/g; + $scriptpageline =~ s//$kiriwrite_config{"directory_noncgi_images"}/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; - } + } + + # Append processed line to the pageoutput variable. - + $pageoutput = $pageoutput . $scriptpageline; - + } - - # Print out the page to the browser/console/stdout. - + + binmode STDOUT, ':utf8'; + print $pageoutput; - + return; } @@ -10788,81 +13315,137 @@ sub kiriwrite_output_xml{ # # # Usage: # # # -# kiriwrite_output_xml(filename, type, data); # +# kiriwrite_output_xml(filename, type, settings); # # # # 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. # +# settings Specifies the following settings in any order. # +# # +# Settings for Kiriwrite configuration files: # +# # +# DatabaseDirectory Specifies the new database directory to use. # +# OutputDirectory Specifies the new output directory to use. # +# ImagesURIPath Specifies the new URI path for images. # +# DateTimeFormat Specifies the new date and time format. # +# SystemLanguage Specifies the new language to use for Kiriwrite. # +# PrsentationModule Specifies the new presentation module to use for # +# Kiriwrite. # +# DatabaseModule Specifies the new database module to use for Kiriwrite. # +# DatabaseServer Specifies the database server to use. # +# DaravasePort Specifies the port the database server is running on. # +# DatabaseProtocol Specifies the protocol the database server is using. # +# DatabaseSQLDatabase Specifies the SQL database name to use. # +# DatabaseUsername Specifies the database server username. # +# DatabasePassword Specifies the password for the database server username.# +# DatabaseTablePrefix Specifies the table prefix to use. # ################################################################################# # Get the variables passed from the subroutine. - my ($xml_filename, $xml_type, @newsettings) = @_; - + my $xml_filename = shift; + my $xml_type = shift; + my ($passedsettings) = @_; + # 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; - + + # Get the data from the hash. + + my $settings_databasedir = $passedsettings->{"DatabaseDirectory"}; + my $settings_outputdir = $passedsettings->{"OutputDirectory"}; + my $settings_imagesuri = $passedsettings->{"ImagesURIPath"}; + my $settings_datetime = $passedsettings->{"DateTimeFormat"}; + my $settings_systemlanguage = $passedsettings->{"SystemLanguage"}; + my $settings_presmodule = $passedsettings->{"PresentationModule"}; + my $settings_dbmodule = $passedsettings->{"DatabaseModule"}; + + my $settings_database_server = $passedsettings->{"DatabaseServer"}; + my $settings_database_port = $passedsettings->{"DatabasePort"}; + my $settings_database_protocol = $passedsettings->{"DatabaseProtocol"}; + my $settings_database_sqldatabase = $passedsettings->{"DatabaseSQLDatabase"}; + my $settings_database_username = $passedsettings->{"DatabaseUsername"}; + my $settings_database_password = $passedsettings->{"DatabasePassword"}; + my $settings_database_tableprefix = $passedsettings->{"DatabaseTablePrefix"}; + + # Convert the password to make sure it can be read properly. + + $settings_database_password =~ s/\0//g; + $settings_database_password =~ s//>/g; + + # Convert the less than and greater than characters are there and + # convert them. + + $settings_imagesuri =~ s//>/g; + # 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\t" . $settings_databasedir . "\r\n"; + $xmldata = $xmldata . "\t\t\t" . $settings_outputdir . "\r\n"; + $xmldata = $xmldata . "\t\t\t" . $settings_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\t" . $settings_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\t" . $settings_presmodule . "\r\n"; + $xmldata = $xmldata . "\t\t\t" . $settings_dbmodule . "\r\n"; + $xmldata = $xmldata . "\t\t\t" . $settings_datetime . "\r\n"; $xmldata = $xmldata . "\t\t\r\n"; - + + $xmldata = $xmldata . "\t\t\r\n"; + $xmldata = $xmldata . "\t\t\t" . $settings_database_server . "\r\n"; + $xmldata = $xmldata . "\t\t\t" . $settings_database_port . "\r\n"; + $xmldata = $xmldata . "\t\t\t" . $settings_database_protocol . "\r\n"; + $xmldata = $xmldata . "\t\t\t" . $settings_database_sqldatabase . "\r\n"; + $xmldata = $xmldata . "\t\t\t" . $settings_database_username . "\r\n"; + $xmldata = $xmldata . "\t\t\t" . $settings_database_password . "\r\n"; + $xmldata = $xmldata . "\t\t\t" . $settings_database_tableprefix . "\r\n"; + $xmldata = $xmldata . "\t\t\r\n"; + $xmldata = $xmldata . "\t\r\n"; - + $xmldata = $xmldata . ""; # Open the Kiriwrite XML configuration file and write the new settings to the # configuration file. - - open(XMLCONFIG, "> kiriwrite.xml"); - print XMLCONFIG $xmldata; - close(XMLCONFIG); - + + open(my $filehandle_xmlconfig, "> ", "kiriwrite.xml"); + print $filehandle_xmlconfig $xmldata; + close($filehandle_xmlconfig); + } else { - + # The type of XML data is something else that is not supported by # Kiriwrite, so return an error. - + kiriwrite_error("invalidoption"); - + } - + return; } @@ -10886,49 +13469,49 @@ my $query = new CGI; # Easily fetch variables from the HTTP string. 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. - + 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 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'); - + # 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')){ # 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"){ + + 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 $databasename = $query->param('olddatabasename'); my $databasedescription = $query->param('olddatabasedescription'); my $databaseshortname = $query->param('database'); my $databasenotes = $query->param('databasenotes'); @@ -10936,164 +13519,164 @@ if ($query->param('mode')){ # Check the permissions of the database configuration file and return # an error if the database permissions are invalid. - + # Pass the variables to the database editing subroutine. - + my $pagedata = kiriwrite_database_edit($databaseshortname, $databasename, $databasedescription, $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')){ - + # 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 $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 $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'); - + # 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 $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; - + kiriwrite_output_header; - kiriwrite_output_page("Add Database", $pagedata, "database"); + kiriwrite_output_page($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. - + 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. - + 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'); - + # 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 $database_name = $query->param('database'); my $pagedata = kiriwrite_page_list($database_name); - + 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"); # 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'); - + 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'); @@ -11102,38 +13685,38 @@ if ($query->param('mode')){ my $http_query_template = $query->param('pagetemplate'); my $http_query_settings = $query->param('pagesettings'); my $http_query_content = $query->param('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 $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'); - + 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'); @@ -11142,63 +13725,63 @@ if ($query->param('mode')){ 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_content = $query->param('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'); - + # 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"){ - + # 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 $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 @@ -11219,7 +13802,7 @@ if ($query->param('mode')){ $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. } @@ -11231,7 +13814,7 @@ if ($query->param('mode')){ $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"){ @@ -11255,7 +13838,7 @@ if ($query->param('mode')){ $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. + kiriwrite_output_page($kiriwrite_lang->{pages}->{movepages}, $pagedata, "pages"); # Output the page to browser/console/stdout. exit; # End the script. } @@ -11267,7 +13850,7 @@ if ($query->param('mode')){ $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. + 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 "multicopy"){ @@ -11291,7 +13874,7 @@ if ($query->param('mode')){ $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. + kiriwrite_output_page($kiriwrite_lang->{pages}->{copypages}, $pagedata, "pages"); # Output the page to browser/console/stdout. exit; # End the script. } @@ -11303,7 +13886,7 @@ if ($query->param('mode')){ $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. + kiriwrite_output_page($kiriwrite_lang->{pages}->{copypages}, $pagedata, "pages"); # Output the page to browser/console/stdout. exit; # End the script. } elsif ($http_query_action eq "multiedit"){ @@ -11329,8 +13912,8 @@ if ($query->param('mode')){ $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; + kiriwrite_output_page($kiriwrite_lang->{pages}->{multiedit}, $pagedata, "pages"); # Output the page to browser/console/stdout. + exit; } @@ -11341,279 +13924,279 @@ if ($query->param('mode')){ $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. + 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; - + kiriwrite_output_header; # Output the header to browser/console/stdout. - kiriwrite_output_page("Database Selection", $pagedata, "pages"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang->{pages}->{databaseselecttitle}, $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')){ - + # 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"){ - + # 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); - + 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->{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("Add Filters", $pagedata, "filter"); # Output the page 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 filters database. - + my $http_query_number = $query->param('filter'); 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 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); - + 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->{filter}->{editfilter}, $pagedata, "filter"); # Output the page to browser/console/stdout. exit; # End the script. - + } - + my $pagedata = kiriwrite_filter_edit($http_query_number); 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->{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 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. + 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("Delete Filter", $pagedata, "filter"); # Output the page to browser/console/stdout. + kiriwrite_output_page($kiriwrite_lang->{filter}->{deletefilter}, $pagedata, "filter"); # Output the page to browser/console/stdout. exit; # End the script. - + } else { - + # 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 { - + 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->{filter}->{viewfilters}, $pagedata, "filter"); # 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')){ - + # An action has been specified in the HTTP query. - + my $http_query_action = $query->param('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'); - + # 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'); - + # 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. - + + # Get the required parameters from the HTTP query. + my $http_query_templatefile = $query->param('template'); my $http_query_confirm = $query->param('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 $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"); - + } - + } else { # Another action was specified and was not one of the ones above, so @@ -11622,48 +14205,48 @@ if ($query->param('mode')){ 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("View Templates", $pagedata, "template"); # Output the page 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 "compile"){ - + # 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'); - + 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'); - + # 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. @@ -11676,33 +14259,33 @@ if ($query->param('mode')){ } - 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); - + 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); - + 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"){ @@ -11713,7 +14296,7 @@ if ($query->param('mode')){ my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, @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 { @@ -11721,7 +14304,7 @@ if ($query->param('mode')){ kiriwrite_error("invalidcompiletype"); } - + } elsif ($http_query_action eq "all"){ # The selected action is to compile all of the databases @@ -11748,48 +14331,48 @@ if ($query->param('mode')){ my $pagedata = kiriwrite_compile_all(); 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'); - + 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 @@ -11799,28 +14382,28 @@ if ($query->param('mode')){ } } - + 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. - + 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'); if (!$http_query_confirm){ @@ -11830,35 +14413,45 @@ if ($query->param('mode')){ $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_presmodule = $query->param('presmodule'); + my $http_query_dbmodule = $query->param('dbmodule'); + + my $http_query_database_server = $query->param('database_server'); + my $http_query_database_port = $query->param('database_port'); + my $http_query_database_protocol = $query->param('database_protocol'); + my $http_query_database_sqldatabase = $query->param('database_sqldatabase'); + my $http_query_database_username = $query->param('database_username'); + my $http_query_database_passwordkeep = $query->param('database_password_keep'); + my $http_query_database_password = $query->param('database_password'); + my $http_query_database_tableprefix = $query->param('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, 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; - + 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 @@ -11867,35 +14460,35 @@ if ($query->param('mode')){ kiriwrite_error("invalidaction"); } - + } - + # No action has been specified, so print out the list of settings currently being used. - + 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. - + 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__ diff --git a/cgi-files/page.html b/cgi-files/page.html index 07e30e2..5c6a8c1 100644 --- a/cgi-files/page.html +++ b/cgi-files/page.html @@ -48,6 +48,7 @@ border-style: 1px; border-color: #102020; padding: 2px; + white-space: nowrap; } .page { @@ -83,6 +84,7 @@ font-size: 12px; background-color: #204040; font-weight: bold; + text-align: left; } .tablecell1 { @@ -145,6 +147,15 @@ .warningoption { background-color: #902020; } + + .pageheader { + font-size: 18px; + font-weight: bold; + } + + .smallpageheader{ + font-weight: bold; + } @@ -155,10 +166,10 @@
- +
- ©2005-2006 Steve Brokenshire
+ ©2005-2007 Steve Brokenshire
diff --git a/misc/dbspecs/kiriwrite_database.sqlite b/misc/dbspecs/kiriwrite_database.sqlite index 3d9ac7f..b72fd91 100644 --- a/misc/dbspecs/kiriwrite_database.sqlite +++ b/misc/dbspecs/kiriwrite_database.sqlite @@ -3,6 +3,10 @@ Kiriwrite Page Database Format Specifications Version 1.0 */ +/* +Specification for SQLite. +*/ + create table kiriwrite_database_info( name varchar(256) primary key, description varchar(512), @@ -15,11 +19,13 @@ create table kiriwrite_database_info( create table kiriwrite_database_pages( filename varchar(256) primary key, - pagename varchar(256), + pagename varchar(512), pagedescription varchar(512), - pagesection varchar(128), + pagesection varchar(256), pagetemplate varchar(64), pagedata text, pagesettings int(1), lastmodified datetime ); + +