- if ($warninglist){
-
- $pagedata = $pagedata . "The following errors/warnings have occured while copying the pages:<br><br>";
- $pagedata = $pagedata . "<div class=\"datalist\">";
- $pagedata = $pagedata . $warninglist;
- $pagedata = $pagedata . "</div><br><br>";
-
- }
-
- $pagedata = $pagedata . "<a href=\"kiriwrite.cgi?mode=page&action=view&database=" . $olddatabase_out . "\">Return to the page list for the '" . $olddatabase_name_out . "' database.</a> | <a href=\"kiriwrite.cgi?mode=page&action=view&database=" . $newdatabase_out . "\">View the page list for the '" . $newdatabase_name_out . "' database.</a>";
-
- return $pagedata;
-
- } elsif ($confirm eq 0) {
-
- # The action to copy several pages from one database
- # to another has not been confirmed so write a form.
-
- # Load the SQLite database and get the needed
- # information about the database.
-
- my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db');
- my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("databasefileinvalid");
- $string_handle->execute();
-
- my @database_info = $string_handle->fetchrow_array();
- my $database_name = $database_info[0];
-
- # Define some values for later.
-
- my $database_info;
- my @page_info;
- my @pagenames;
- my @filenames;
- my $data_file;
- my $data_file_length;
- my $database_list;
- my $database_filename;
- my $filename;
- my $filename_out;
- my $filelist_filename_sql;
- my $filelist_filename;
- my $pagelist_formdata;
- my $newdatabase_filename;
- my $newdatabase_filename_out;
- my $newdatabase_name;
- my $newdatabase_name_out;
- my $pagelist;
- my $pagename;
- my $pageseek = 0;
- my $dbseek = 0;
- my $pagefound = 0;
-
- # Process each filename given.
-
- foreach $filelist_filename (@filelist){
-
- $filelist_filename_sql = kiriwrite_convert($filelist_filename, "kiriwrite");
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $filelist_filename . '\' LIMIT 1') or kiriwrite_error("databasefileinvalid");
-
- $string_handle->execute();
-
- # Check if the filename given exists and if it
- # doesn't then skip this filename and go onto
- # the next filename.
-
- while (@page_info = $string_handle->fetchrow_array()){
-
- $pagefound = 1;
-
- }
-
- if ($pagefound eq 0){
-
- next;
-
- }
-
- # Get the data again.
-
- $string_handle->execute();
- @page_info = $string_handle->fetchrow_array();
-
- # Add the page name and file name to their seperate
- # arrays.
-
- $pagenames[$pageseek] = $page_info[1];
- $filenames[$pageseek] = $page_info[0];
-
- # Increment the page seek counter and reset the
- # page found value.
-
- $pageseek++;
- $pagefound = 0;
-
- }
-
- # Check if any pages exust and return an error if
- # there wasn't.
-
- if ($pageseek eq 0){
-
- # None of the selected pages exist, so return
- # an error.
-
- kiriwrite_error("nopagesselected");
-
- }
-
- # Create the page list of files to move.
-
- $pageseek = 1;
- $pagelist = "";
- $pagelist_formdata = "";
-
- foreach $filename (@filenames){
-
- $pagename = $pagenames[$pageseek - 1];
-
- # Check if the
-
- if (!$pagename){
-
- # Write a message saying that there is no page name.
-
- $pagelist = $pagelist . "<i>No Name</i>" . " (" . $filename . ")<br>";
-
- } else {
-
- # Append the page name and filename to the page list.
-
- $pagelist = $pagelist . $pagename . " (" . $filename . ")<br>";
-
- }
-
-
-
- # Append the form data to the page list form data.
-
- $filename_out = kiriwrite_convert($filename, "normal_display");
-
- $pagelist_formdata = $pagelist_formdata . "<input type=\"hidden\" name=\"name[" . $pageseek . "]\" value=\"on\">";
- $pagelist_formdata = $pagelist_formdata . "<input type=\"hidden\" name=\"id[" . $pageseek . "]\" value=\"" . $filename . "\">";
-
- $pageseek++;
-
- }
-
- # Get the database filenames and names.
-
- # Check the directory to make sure the permissions are settings are valid
- # and return an error if the permission settings are invalid.
-
- my $data_directory_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"}, 1, 0);
-
- if ($data_directory_permissions eq 1){
-
- # The data directory has invalid permissions set, so return an error.
-
- kiriwrite_error("datadirectoryinvalidpermissions");
-
- }
-
- # Open the directory and get the list of all files ending with .xml and
- # put them into the data_directory array.
-
- opendir(DATADIR, $kiriwrite_config{"directory_data_db"});
- my @data_directory = grep /m*\.db/, readdir(DATADIR);
- closedir(DATADIR);
-
- # Process each database to get the database name.
-
- $database_list = "<select name=\"newdatabase\">";
-
- foreach $data_file (@data_directory){
-
- # Get the length of the filename.
-
- $data_file_length = length($data_file);
-
- # Remove the last three characters from the filename.
-
- $data_file = substr($data_file, 0, $data_file_length - 3);
-
- # Check if the permissions are valid before trying
- # to load the database.
-
- $database_filename = $kiriwrite_config{"directory_data_db"} . '/' . $data_file . '.db';
- $database_permissions = kiriwrite_filepermissions($database_filename, 1, 0, 0);
-
- if ($database_permissions eq 1){
-
- # If the database has invalid permissions set then
- # process the next database.
-
- next;
-
- }
-
- # Load the SQLite database.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=" . $database_filename);
-
- # Query the SQLite database or return an error (meaning that the database is in
- # a invalid format), if it can't then process the next database.
-
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or next;
-
- $string_handle->execute();
- @database_info = $string_handle->fetchrow_array();
-
- # Get the values from the query.
-
- $newdatabase_name = $database_info[0];
-
- # Convert the values so that they can be displayed
- # properly.
-
- $newdatabase_filename_out = kiriwrite_convert($data_file, "normal_display");
- $newdatabase_name_out = kiriwrite_convert($newdatabase_name, "normal_display");
-
- # Append the database filename and name to the list of databases
- # to move the pages to.
-
- $database_list = $database_list . "<option value=\"" . $newdatabase_filename_out . "\">" . $newdatabase_name_out . "</option>";
-
- }
-
- $database_list = $database_list . "</select>";
-
- # Convert some values so that they display properly.
-
- my $database_name_out = kiriwrite_convert($database_name, "normal_display");
- my $database_out = kiriwrite_convert($database, "normal_display");
-
- # Write out the form.
-
- $pagedata = "<h2>Copy selected pages</h2>";
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"page\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"multicopy\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"database\" value=\"" . $database_out . "\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"count\" value=\"" . ($pageseek - 1) . "\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"confirm\" value=\"1\">";
- $pagedata = $pagedata . $pagelist_formdata;
- $pagedata = $pagedata . "Which database do you want to copy the following pages from the '" . $database_name_out . "' database to?<br><br>";
- $pagedata = $pagedata . "<div class=\"datalist\">";
- $pagedata = $pagedata . $pagelist;
- $pagedata = $pagedata . "</div><br>";
- $pagedata = $pagedata . "Copy pages to: " . $database_list . "<br><br>";
- $pagedata = $pagedata . "<input type=\"submit\" value=\"Copy pages to the selected database.\"> | <a href=\"kiriwrite.cgi?mode=page&action=view&database=" . $database_out . "\">Return to the page list for the '" . $database_name_out . "' database.</a>";
- $pagedata = $pagedata . "</form>";
-
- return $pagedata;
-
- } else {
-
- # The confirm value is other than 0 or 1, so return
- # an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
-}
-
-sub kiriwrite_page_multiedit{
-#################################################################################
-# kiriwrite_page_multiedit: Edit several pages from a database. #
-# #
-# Usage: #
-# #
-# kiriwrite_page_multiedit(database, newsection, altersection, newtemplate, #
-# altertemplate, newsettings, altersettings #
-# confirm, filelist); #
-# #
-# database Specifies the database to edit the pages from. #
-# newsection Specifies the new section name to use on the selected pages. #
-# altersection Specifies if the section name should be altered. #
-# newtemplate Specifies the new template filename to use on the selected #
-# pages. #
-# altertemplate Specifies if the template filename should be altered. #
-# newsettings Specifies the new settings to use on the selected pages. #
-# altersettings Specifies if the settings should be altered. #
-# confirm Confirms the action to edit the selected pages. #
-# filelist The list of file names to edit. #
-#################################################################################
-
- # Get the values that were passed to the subroutine.
-
- my ($database, $newsection, $altersection, $newtemplate, $altertemplate, $newsettings, $altersettings, $confirm, @filelist) = @_;
-
- # Load the required Perl modules.
-
- use DBI;
-
- # Define a variable for later.
-
- my $pagedata = "";
-
- # Check if the file list is blank and return an error
- # if it is.
-
- if (!@filelist){
-
- # The file list really is blank so return
- # an error.
-
- kiriwrite_error("nopagesselected");
-
- }
-
- # Check if the file permissions on the original database
- # are valid and return an error if they aren't.
-
- my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db');
- my $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db', 1, 1, 0);
-
- if ($database_exists eq 1){
-
- # The database does not exist, so return an error.
-
- kiriwrite_error("databasemissingfile");
-
- }
-
- if ($database_permissions eq 1){
-
- # The database permissions are invalid, so return
- # an error.
-
- kiriwrite_error("databaseinvalidpermissions");
-
- }
-
- # Check if certain values are undefined and define them if
- # they are.
-
- if (!$altersection){
-
- # The alter section value is blank, so set it to
- # off.
-
- $altersection = "off";
-
- }
-
- if (!$altertemplate){
-
- # The alter template value is blank, so set it to
- # off.
-
- $altertemplate = "off";
-
- }
-
- if (!$altersettings){
-
- # The alter settings value is blank, so set it to
- # off.
-
- $altersettings = "off";
-
- }
-
- # Check if the database filename is valid and return an error if
- # it isn't.
-
- my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1);
-
- if ($pagedatabase_filename_check eq 1){
-
- # The database filename is blank, so return an error.
-
- kiriwrite_error("blankdatabasepageadd");
-
- } elsif ($pagedatabase_filename_check eq 2){
-
- # The database filename is invalid, so return an error.
-
- kiriwrite_error("databasefilenameinvalid");
-
- }
-
- # Check if the confirm value is blank and if it is then
- # set the confirm value to 0.
-
- if (!$confirm){
-
- $confirm = 0;
-
- }
-
- if ($confirm eq 1){
-
- # The action to edit the template has been confirmed so
- # edit the selected pages.
-
- # Check the values recieved at UTF8 compliant before
- # converting.
-
- kiriwrite_variablecheck($newsection, "utf8", 0, 0);
- kiriwrite_variablecheck($newtemplate, "utf8", 0, 0);
- kiriwrite_variablecheck($newsettings, "utf8", 0, 0);
-
- # Convert the values into proper UTF8 values.
-
- $newsection = kiriwrite_utf8convert($newsection);
- $newtemplate = kiriwrite_utf8convert($newtemplate);
- $newsettings = kiriwrite_utf8convert($newsettings);
-
- # Check the length of the variables.
-
- kiriwrite_variablecheck($altersection, "maxlength", 3, 0);
- kiriwrite_variablecheck($altertemplate, "maxlength", 3, 0);
- kiriwrite_variablecheck($altersettings, "maxlength", 3, 0);
- my $newsection_maxlength_check = kiriwrite_variablecheck($newsection, "maxlength", 256, 1);
- my $newtemplate_maxlength_check = kiriwrite_variablecheck($newtemplate, "maxlength", 256, 1);
- my $newtemplate_filename_check = kiriwrite_variablecheck($newtemplate, "filename", 0, 1);
- my $newsettings_maxlength_check = kiriwrite_variablecheck($newsettings, "maxlength", 1, 1);
- my $newsettings_settings_check = kiriwrite_variablecheck($newsettings, "pagesetting", 0, 1);
-
- # Check the values and return an error if needed.
-
- if ($newsection_maxlength_check eq 1 && $altersection eq "on"){
-
- # The new section name is too long, so return an
- # error.
-
- kiriwrite_error("pagesectiontoolong");
-
- }
-
- if ($newtemplate_maxlength_check eq 1 && $altertemplate eq "on"){
-
- # The new template name is too long, so return an
- # error.
-
- kiriwrite_error("templatefilenametoolong");
-
- }
-
- # Check if the template filename is set to !skip or !none
- # and skip this check if it is.
-
- if ($newtemplate eq "!skip" || $newtemplate eq "!none"){
-
- # Skip this check as the template filename is
- # !skip or !none.
-
- } else {
- if ($newtemplate_filename_check eq 1 && $altertemplate eq "on" || $newtemplate_filename_check eq 2 && $altertemplate eq "on"){
-
- # The new template filename is invalid, so return
- # an error.
-
- kiriwrite_error("templatefilenameinvalid");
-
- }
- }
-
- if ($newsettings_maxlength_check eq 1 && $altertemplate eq "on"){
-
- # The new settings value is too long, so return
- # an error.
-
- kiriwrite_error("pagesettingstoolong");
-
- }
-
- if ($newsettings_settings_check eq 1 && $altertemplate eq "on"){
-
- # The new settings value is invalid, so return
- # an error.
-
- kiriwrite_error("pagesettingsinvalid");
-
- }
-
- # Load the SQLite Database and get info about the database.
-
- my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db');
- my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("databasefileinvalid");
- $string_handle->execute();
-
- # Get the database name.
-
- my @database_info = $string_handle->fetchrow_array();
- my $database_name = $database_info[0];
- my $database_name_out = kiriwrite_convert($database_name, "normal_display");
- my $database_out = kiriwrite_convert($database, "normal_display");
-
- # Define some values for later.
-
- my @database_page;
- my $edited_list = "";
- my $filename;
- my $filename_sql;
- my $filename_out;
- my $sqlquery_options = "";
- my @sqlquery_list;
- my $sqlquery_option;
- my $page_name;
- my $page_name_out;
- my $newsection_sql;
- my $newtemplate_sql;
- my $newsettings_sql;
- my $pagefound = 0;
- my $pageedited = 0;
- my $sqlquery_seek = 0;
- my $warninglist;
-
- # Get the date and time information.
-
- my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime;
-
- my $pagelastmodified = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second;
-
-
- # Check if the template filename is !skip and
- # set the alter template value to off if it
- # is.
-
- if ($newtemplate eq "!skip"){
-
- $altertemplate = "off";
-
- }
-
- # Check if all values are not selected and return
- # an error if they are.
-
- if ($altersection ne "on" && $altertemplate ne "on" && $altersettings ne "on"){
-
- # All values are not selected so return
- # an error.
-
- kiriwrite_error("noeditvaluesselected");
-
- }
-
- # Check if each value is meant to be changed on
- # the selected files. Start with the section
- # name.
-
- if ($altersection eq "on"){
-
- # Convert the value so that it will work
- # when SQL query is made.
-
- $newsection_sql = kiriwrite_convert($newsection, "kiriwrite");
-
- # The section name should be altered so
- # prepare the a part of the SQL query.
- # Check if this is the first part of
- # the SQL query.
-
- if ($sqlquery_seek eq 0){
-
- # This is the first part of the SQL query.
-
- $sqlquery_list[$sqlquery_seek] = "pagesection = \'" . $newsection_sql . "\'";
- $sqlquery_seek++;
-
- } else {
-
- # This isn't the first part of the SQL query.
-
- $sqlquery_list[$sqlquery_seek] = ", pagesection = \'" . $newsection_sql . "\'";
- $sqlquery_seek++;
-
- }
-
- }
-
- # Check if the template name should be changed.
-
- if ($altertemplate eq "on"){
-
- # Convert the value so that it will work
- # when SQL query is made.
-
- $newtemplate_sql = kiriwrite_convert($newtemplate, "kiriwrite");
-
- # The section name should be altered so
- # prepare the a part of the SQL query.
- # Check if this is the first part of
- # the SQL query.
-
- if ($sqlquery_seek eq 0){
-
- # This is the first part of the SQL query.
-
- $sqlquery_list[$sqlquery_seek] = "pagetemplate = \'" . $newtemplate_sql . "\'";
- $sqlquery_seek++;
-
- } else {
-
- # This isn't the first part of the SQL query.
-
- $sqlquery_list[$sqlquery_seek] = ", pagetemplate = \'" . $newtemplate_sql . "\'";
- $sqlquery_seek++;
-
- }
-
- }
-
- # Check if the page settings should be changed.
-
- if ($altersettings eq "on"){
-
- # Convert the value so that it will work
- # when SQL query is made.
-
- $newsettings_sql = kiriwrite_convert($newsettings, "kiriwrite");
-
- # The section name should be altered so
- # prepare the a part of the SQL query.
- # Check if this is the first part of
- # the SQL query.
-
- if ($sqlquery_seek eq 0){
-
- # This is the first part of the SQL query.
-
- $sqlquery_list[$sqlquery_seek] = "pagesettings = \'" . $newsettings_sql . "\'";
- $sqlquery_seek++;
-
- } else {
-
- # This isn't the first part of the SQL query.
-
- $sqlquery_list[$sqlquery_seek] = ", pagesettings = \'" . $newsettings_sql . "\'";
- $sqlquery_seek++;
-
- }
-
- }
-
- # Add a new modification date.
-
- $sqlquery_list[$sqlquery_seek] = ", lastmodified = \'" . $pagelastmodified . "\'";
-
- # Create the line for the needed SQL query.
-
- foreach $sqlquery_option (@sqlquery_list){
-
- # Add the line to the needed SQL query.
-
- $sqlquery_options = $sqlquery_options . $sqlquery_option;
-
- }
-
- # Edit each filename.
-
- foreach $filename (@filelist){
-
- # Check if the page filename exists in the
- # database.
-
- $filename_sql = kiriwrite_convert($filename, "kiriwrite");
- $filename_out = kiriwrite_convert($filename, "normal_display");
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $filename_sql . '\'') or kiriwrite_error("databasefileinvalid");
- $string_handle->execute();
-
- # Check if the filename given exists and if it
- # doesn't then skip this filename and go onto
- # the next filename.
-
- while (@database_page = $string_handle->fetchrow_array()){
-
- $pagefound = 1;
-
- }
-
- if ($pagefound eq 0){
-
- # The page was not find in the database so
- # add a warning saying it could not be
- # found in the database and process the
- # next file.
-
-
- $warninglist = $warninglist . "The page \'" . $filename_out . "\'could not be found." . "<br>";
- next;
-
- }
-
- # Get the page name.
-
- $string_handle->execute();
- @database_page = $string_handle->fetchrow_array();
- $page_name = $database_page[1];
- $page_name_out = kiriwrite_convert($page_name, "normal_display");
-
- # Alter the values of the page using the values recieved.
-
- $string_handle = $database_handle->prepare('UPDATE kiriwrite_database_pages SET ' . $sqlquery_options . ' WHERE filename = \'' . $filename_sql . '\'');
- $string_handle->execute();
-
- # Add the page to the list of edited pages. Check if
- # the page name is blank.
-
- if (!$page_name_out){
-
- # The page name is blank so write no name.
-
- $edited_list = $edited_list . "The page (" . $filename_out . ") was edited." . "<br>";
-
- } else {
-
- # Add the page to the list of edited pages.
-
- $edited_list = $edited_list . "The page called '" . $page_name_out . "' (" . $filename_out . ") was edited." . "<br>";
-
- }
-
- # Increment the counter of edited pages.
-
- $pageedited++;
-
- }
-
- $pagedata = $pagedata . "<h2>Edit selected pages</h2>";
-
- # Check if the counter of edited pages is 0 and if it is
- # then write a message saying that no pages were edited
- # else write a message listing all of the pages edited.
-
- if ($pageedited eq 0){
-
- $pagedata = $pagedata . "No pages were edited in the '" . $database_name_out . "' database. <br><br>";
-
- } else {
-
- # Write out the message saying that the selected pages
- # were edited.
-
- $pagedata = $pagedata . "The selected pages in the '" . $database_name_out . "' database have been edited:<br><br>";
- $pagedata = $pagedata . "<div class=\"datalist\">";
- $pagedata = $pagedata . $edited_list;
- $pagedata = $pagedata . "</div><br>";
-
- }
-
- # Check if any warnings have occured and write a message
- # if any warnings did occur.
-
- if ($warninglist){
-
- # One or several warnings have occured so
- # write a message.
-
- $pagedata = $pagedata . "The following errors/warnings occured while editing the selected pages:<br><br>";
- $pagedata = $pagedata . "<div class=\"datalist\">";
- $pagedata = $pagedata . $warninglist;
- $pagedata = $pagedata . "</div><br>";
-
- }
-
- # Write a link going back to the page list for
- # the selected database.
-
- $pagedata = $pagedata . "<a href=\"kiriwrite.cgi?mode=page&action=view&database=" . $database_out . "\">Return to the page list for the '" . $database_name_out . "' database.</a>";
-
- return $pagedata;
-
- } elsif ($confirm eq 0){
-
- # The action to edit the template has not been confirmed
- # so write a form out instead.
-
- # Load the SQLite Database and get info about the database.
-
- my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db');
- my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or kiriwrite_error("databasefileinvalid");
- $string_handle->execute();
-
- # Get the database name.
-
- my @database_info = $string_handle->fetchrow_array();
- my $database_name = $database_info[0];
- my $database_name_out = kiriwrite_convert($database_name, "normal_display");
- my $database_out = kiriwrite_convert($database, "normal_display");
-
- # Define some variables for later.
-
- my @database_page;
- my @database_templates;
- my @filenames;
- my @page_info;
- my @pagenames;
- my $filelist_filename;
- my $filelist_filename_sql;
- my $filelist_filename_out;
- my $filename;
- my $pagefound;
- my $pagelist = "";
- my $pagelistformdata = "";
- my $pageseek = 0;
- my $page_name;
- my $page_filename;
- my $template_data;
- my $template_filename;
- my $template_name;
- my $template_warning;
-
- # Get the information about each page that is going
- # to be edited.
-
- foreach $filelist_filename (@filelist){
-
- $filelist_filename_sql = kiriwrite_convert($filelist_filename, "kiriwrite");
- $filelist_filename_out = kiriwrite_convert($filelist_filename, "normal_display");
-
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages WHERE filename = \'' . $filelist_filename . '\' LIMIT 1') or kiriwrite_error("databasefileinvalid");
-
- $string_handle->execute();
-
- # Check if the filename given exists and if it
- # doesn't then skip this filename and go onto
- # the next filename.
-
- while (@page_info = $string_handle->fetchrow_array()){
-
- $pagefound = 1;
-
- }
-
- if ($pagefound eq 0){
-
- next;
-
- }
-
- # Get the data again.
-
- $string_handle->execute();
- @page_info = $string_handle->fetchrow_array();
-
- # Add the page name and file name to their seperate
- # arrays.
-
- $pagenames[$pageseek] = $page_info[1];
- $filenames[$pageseek] = $page_info[0];
-
- # Add the form data for the page filename.
-
- # BLEARGH
-
- $pagelistformdata = $pagelistformdata . "<input type=\"hidden\" name=\"name[" . ($pageseek + 1) . "]\" value=\"on\">";
- $pagelistformdata = $pagelistformdata . "<input type=\"hidden\" name=\"id[" . ($pageseek + 1) . "]\" value=\"" . $filelist_filename_out . "\">";
-
- # Increment the page seek counter and reset the
- # page found value.
-
- $pageseek++;
- $pagefound = 0;
-
- }
-
- # Check if any pages were found in the database and return
- # an error if not.
-
- if ($pageseek eq 0){
-
- # No pages were found so return an error.
-
- kiriwrite_error("nopagesselected");
-
- }
-
- # Get the template list and select the template that is being used by
- # the page, check the permissions and if the template database exists.
-
- my $template_file_exists = kiriwrite_fileexists("templates.db");
- my $template_file_permissions = kiriwrite_filepermissions("templates.db", 1, 0, 0);
-
- if ($template_file_exists eq 1){
-
- # The template database does not exist, so write a warning messsage.
-
- $template_warning = "The template database does not exist. Existing template settings for selected pages kept.";
-
- }
-
- if ($template_file_permissions eq 1 && $template_file_exists ne 1){
-
- # The template database has invalid permissions set, so write a warning message.
-
- $template_warning = "The template database has invalid permissions set. Existing template settings for selected pages kept.";
-
- }
-
- # Get the list of templates.
-
- if (!$template_warning){
-
- # Load the templates database and get the templates.
-
- $database_handle = DBI->connect("dbi:SQLite:templates.db");
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates') or $template_warning = "The template database is in an invalid format. Existing template settings for selected pages kept.";
-
- if (!$template_warning){
-
- $string_handle->execute();
-
- $template_data = "<select name=\"newtemplate\">";
-
- while (@database_templates = $string_handle->fetchrow_array()){
-
- # Get the filename and name of the database.
-
- $template_filename = $database_templates[0];
- $template_name = $database_templates[1];
-
- # Convert the values so that they can be displayed in the list.
-
- $template_filename = kiriwrite_convert($template_filename, "normal_display");
- $template_name = kiriwrite_convert($template_name, "normal_display");
-
- # Add the template to the list of templates.
-
- $template_data = $template_data . "<option value=\"" . $template_filename . "\">" . $template_name . " (" . $template_filename .")</option>";
-
- }
-
- # Add the option to not use a template at all.
-
- $template_data = $template_data . "<option value=\"!none\" selected>Don't use a template</option>";
- $template_data = $template_data . "</select>";
-
- }
-
- }
-
- # Process the list of selected pages.
-
- $pageseek = 1;
- foreach $filename (@filenames){
-
- # Process each filename.
-
- $page_name = $pagenames[$pageseek - 1];
- $page_filename = $filenames[$pageseek - 1];
-
- # Check if the page name is blank.
-
- if (!$page_name){
-
- # Write a message saying there's no page name.
-
- $pagelist = $pagelist . "<i>No Name</i>" . " (" . $page_filename . ")" . "<br>"
-
- } else {
-
- # Append the page to the list of pages to edit.
-
- $pagelist = $pagelist . $page_name . " (" . $page_filename . ")" . "<br>";
-
- }
-
- $pageseek++;
-
- }
-
- # Write a form for editing the selected pages.
-
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"page\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"multiedit\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"database\" value=\"" . $database_out . "\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"count\" value=\"" . ($pageseek - 1) . "\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"confirm\" value=\"1\">";
- $pagedata = $pagedata . "<h2>Edit selected pages</h2>";
- $pagedata = $pagedata . "The following pages from the '" . $database_name_out . "' database will be altered:<br><br>";
- $pagedata = $pagedata . "<div class=\"datalist\">";
- $pagedata = $pagedata . $pagelist;
- $pagedata = $pagedata . "</div><br>";
- $pagedata = $pagedata . $pagelistformdata;
- $pagedata = $pagedata . "Using the values below (click on the checkbox for each value to be edited on the selected pages):<br><br>";
- $pagedata = $pagedata . "<table cellpadding=\"5\" cellspacing=\"0\">";
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Alter</td><td class=\"tablecellheader\">Setting</td><td class=\"tablecellheader\">Value</td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\"><input type=\"checkbox\" name=\"altersection\"></td><td class=\"tablecell1\">Page Section</td><td class=\"tablecell1\"><input type=\"text\" name=\"newsection\" size=\"64\" maxlength=\"256\"></td></tr>";
-
- # Check if a warning for template database has been written
- # and return the warning message if it has else write the
- # list of templates.
-
- if ($template_warning){
-
- # There is a message in the template warning variable
-
- $pagedata = $pagedata . "<tr><td class=\"tablecell2\"><input type=\"checkbox\" name=\"altertemplate\"></td><td class=\"tablecell2\">Page Template</td><td class=\"tablecell2\"><input type=\"hidden\" name=\"newtemplate\" value=\"!skip\">" . $template_warning . "</td></tr>";
-
- } else {
-
- $pagedata = $pagedata . "<tr><td class=\"tablecell2\"><input type=\"checkbox\" name=\"altertemplate\"></td><td class=\"tablecell2\">Page Template</td><td class=\"tablecell2\">" . $template_data . "</td></tr>";
-
- }
-
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\"><input type=\"checkbox\" name=\"altersettings\"></td><td class=\"tablecell1\">Page Settings</td><td class=\"tablecell1\"><input type=\"radio\" name=\"newsettings\" value=\"1\"> Use page name and section name.<br><input type=\"radio\" name=\"newsettings\" value=\"2\"> Use the page name only.<br><input type=\"radio\" name=\"newsettings\" value=\"3\"> Use the section name only.<br><input type=\"radio\" name=\"newsettings\" value=\"0\" checked> Don't use page name or section name.<br></td></tr>";
- $pagedata = $pagedata . "</table><br>";
- $pagedata = $pagedata . "<input type=\"submit\" value=\"Edit selected pages\"> | <a href=\"kiriwrite.cgi?mode=page&action=view&database=" . $database_out . "\">Return to the page list for the '" . $database_name_out . "' database.</a>";
- $pagedata = $pagedata . "</form>";
-
- return $pagedata;
-
- } else {
-
- # The confirm value is something else other than
- # 1 or 0, so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
-}
-
-sub kiriwrite_page_list{
-#################################################################################
-# kiriwrite_page_list: Lists pages from an database. #
-# #
-# Usage: #
-# #
-# kiriwrite_page_list([database]); #
-# #
-# database Specifies the database to retrieve the pages from. #
-#################################################################################
-
- # Get the database file name from what was passed to the subroutine.
-
- my ($database_file) = @_;
-
- # Load the required Perl modules.
-
- my $xsl = XML::Simple->new();
- use DBI;
-
- # Check if the database_file variable is empty, if it is then print out a
- # select box asking the user to select a database from the list.
-
- if (!$database_file) {
-
- # Define the variables required for this section.
-
- my $pagedata = "";
- my $dblistdata = "";
- my $data_file = "";
- my $data_file_length = 0;
- my $data_file_friendly = "";
- my $database_handle = "";
- my $string_handle = "";
- my $database_name = "";
- my $file_permissions = "";
- my @database_info;
- my @data_directory;
-
- # Open the data directory and get all of the databases.
-
- opendir(DATADIR, $kiriwrite_config{"directory_data_db"});
- @data_directory = grep /m*\.db/, readdir(DATADIR);
- closedir(DATADIR);
-
- # Get the information about each database (the short name and friendly name).
-
- foreach $data_file (@data_directory){
-
- # Give the filename a friendly name.
-
- $data_file_length = length($data_file);
- $data_file_friendly = substr($data_file, 0, $data_file_length - 3);
-
- # Check if the permissions for the database are valid.
-
- $file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' .$data_file, 1, 0);
-
- if ($file_permissions ne 0){
-
- # The permissions for the database are invalid
- # so process the next database.
-
- next;
-
- }
-
- # Load the SQLite database.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $data_file);
- $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_info LIMIT 1") or next;
- $string_handle->execute();
- @database_info = $string_handle->fetchrow_array();
-
- # Get the database name from the results.
-
- $database_name = $database_info[0];
- $database_name = kiriwrite_convert($database_name, "normal_display");
-
- # Append the database to the list of databases available.
-
- $dblistdata = $dblistdata . "<option value=\"" . $data_file_friendly . "\">" . $database_name . "</option>";
-
- }
-
- # Write the page data.
-
- $pagedata = "<h2>View Pages</h2>\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.<br><br>";
-
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">\r\n";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"page\">\r\n";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"view\">\r\n";
- $pagedata = $pagedata . "<select name=\"database\">";
- $pagedata = $pagedata . $dblistdata;
- $pagedata = $pagedata . "</select> | ";
- $pagedata = $pagedata . "<input type=\"submit\" value=\"View\">";
- $pagedata = $pagedata . "</form> <br>";
-
- return $pagedata;
-
- } else {
-
- my @database_pages;
- my @database_info;
- my $tabledata = "";
- my $pagedata = "";
- my $pagemultioptions = "";
- my $database_handle = "";
- my $string_handle = "";
- my $db_friendlyname = "";
- my $tablestyle = "";
-
- my $page_filename = "";
- my $page_name = "";
- my $page_description = "";
- my $page_modified = "";
-
- my $tablestyletype = 0;
- my $page_count = 0;
- my $db_file_notblank = 0;
-
- # The database_file variable is not blank, so print out a list of pages from
- # the selected database.
-
- # Preform a variable check on the database filename to make sure that it is
- # valid before using it.
-
- kiriwrite_variablecheck($database_file, "filename", "", 0);
- kiriwrite_variablecheck($database_file, "maxlength", 64, 0);
-
- # Check if the specified database file exists,
- # if it does exist then continue otherwise return an error saying the database
- # could not be found.
-
- if (-e $kiriwrite_config{"directory_data_db"} . '/' . $database_file . '.db'){
-
- # Check that the permissions for the database file are valid.
-
- my $database_db_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_file . '.db', 1, 0, 0);
-
- if ($database_db_permissions eq 1){
-
- kiriwrite_error("databaseinvalidpermissions");
-
- }
-
- # Load the SQLite database.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database_file . '.db');
-
- # Get the database name.
-
- $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_info LIMIT 1") or kiriwrite_error("databasenameinvalid");
- $string_handle->execute();
-
- @database_info = $string_handle->fetchrow_array();
-
- $db_friendlyname = $database_info[0];
-
- $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_pages") or kiriwrite_error("databasenameinvalid");
- $string_handle->execute();
-
- # Write the table header into the tabledata string.
-
- $tabledata = "<table cellpadding=\"5\" cellspacing=\"0\">\r\n<tr>\r\n\t<td class=\"tablecellheader\"></td>\r\n\t<td class=\"tablecellheader\">Page Location</td>\r\n\t<td class=\"tablecellheader\">Page Name</td>\r\n\t<td class=\"tablecellheader\">Page Description</td>\r\n\t<td class=\"tablecellheader\">Last Modified</td>\r\n\t<td class=\"tablecellheader\">Options</td>\r\n</tr>";
-
- # Write the results out as a list and append it to the
- # tabledata string.
-
- while (@database_pages = $string_handle->fetchrow()){
-
- $page_filename = kiriwrite_convert($database_pages[0], "normal_display");
- $page_name = kiriwrite_convert($database_pages[1], "normal_display");
- $page_description = kiriwrite_convert($database_pages[2], "normal_display");
- $page_modified = kiriwrite_convert($database_pages[7], "date");
- $page_modified = kiriwrite_convert($page_modified, "normal_display");
-
- if ($database_pages[0]){
- $page_count++;
- } else {
- next;
- }
-
- if ($tablestyletype eq 0){
-
- $tablestyle = "tablecell1";
- $tablestyletype = 1;
-
- } else {
-
- $tablestyle = "tablecell2";
- $tablestyletype = 0;
-
- }
-
- # Check if the page name and description names
- # are blank and if they are write a message saying that
- # field contains no data.
-
- if ($page_name eq ""){
-
- $page_name = "<i>No Name</i>";
-
- }
-
- if ($page_description eq ""){
-
- $page_description = "<i>No Description</i>";
-
- }
-
- if ($page_modified eq ""){
-
- $page_modified = "<i>No Date</i>";
-
- }
-
- $tabledata = $tabledata . "<tr><td class=\"" . $tablestyle . "\"><input type=\"hidden\" name=\"id[" . $page_count . "]\" value=\"" . $database_pages[0] . "\"><input type=\"checkbox\" name=\"name[" . $page_count . "]\"></td><td class=\"" . $tablestyle . "\">" . $page_filename ."</td><td class=\"" . $tablestyle . "\">" . $page_name . "</td><td class=\"" . $tablestyle . "\">" . $page_description . "</td><td class=\"" . $tablestyle . "\">" . $page_modified . "</td><td class=\"" . $tablestyle . "\"><a href=\"kiriwrite.cgi?mode=page&action=edit&database=" . $database_file . "&page=" . $page_filename ."\">Edit</a> <a href=\"kiriwrite.cgi?mode=page&action=delete&database=" . $database_file . "&page=" . $page_filename . "\">Delete</td></tr>";
-
-
-
- }
-
- # Check if the page count is more than
-
- if ($page_count > 0){
- $db_file_notblank = 1;
- }
-
- # Append the closing table part into the tabledata string.
-
- $tabledata = $tabledata . "</table>";
-
- } else {
- # Either the database file, the database configuration file or both are missing
- # so return an error saying that certain files are missing.
-
- kiriwrite_error("databasemissingfile");
- }
-
- # Check if the database really was not blank and if it was, write a message saying that
- # no pages existed in the database else write the list of pages in the database.
-
- $db_friendlyname = kiriwrite_convert($db_friendlyname, "normal_display");
-
- if ($db_file_notblank eq 0){
-
- $pagedata = "<h2>Page list for '" . $db_friendlyname . "'</h2>";
- $pagedata = $pagedata . "<div class=\"errorbox\">No pages exist in this database. To create a page for this database, click on Add Page link at the top of the page.</div>";
-
- } else {
-
- $pagemultioptions = "<input type=\"reset\" value=\"Select None\"> | <button name=\"action\" value=\"multidelete\">Delete Selected</button> | <button name=\"action\" value=\"multimove\">Move Selected</button> | <button name=\"action\" name=\"action\" value=\"multicopy\">Copy Selected</button> | <button name=\"action\" value=\"multiedit\">Edit Selected</button>";
-
- $pagedata = "<h2>Page list for '" . $db_friendlyname . "'</h2>";
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">\r\n";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"page\">\r\n";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"count\" value=\"" . $page_count . "\">\r\n";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"type\" value=\"multiple\">\r\n";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"database\" value=\"" . $database_file . "\">\r\n";
- $pagedata = $pagedata . $pagemultioptions . "<p>\r\n";
- $pagedata = $pagedata . $tabledata;
- $pagedata = $pagedata . "<br>" . $pagemultioptions . "<p>\r\n";
- $pagedata = $pagedata . "</form>";
-
- }
-
- return $pagedata;
-
- }
-
-}
-
-sub kiriwrite_page_multipleselect{
-#################################################################################
-# kiriwrite_page_multipleselect: Gets the multiple page selections from a #
-# database and processes them into a single which can be used in the #
-# kiriwrite_page_delete. #
-# #
-# Usage: #
-# #
-# kiriwrite_page_multipleselect(); #
-#################################################################################
-
- # Load the required perl modules for this subroutine.
-
- my $query = new CGI;
-
- # Setup some variables that will be used later on.
-
- my $page_select_seek = 1;
- my $page_current_value = "";
- my $selectionlist = "";
-
- # Get the required variables from the HTTP query.
-
- my $page_count = $query->param('count');
-
- do {
-
- # Get the current value of the selected page's checkbox.
-
- $page_current_value = $query->param('name[' . $page_select_seek . ']');
-
- # If page_current_value is undefinied or blank, set page_current_value
- # to off.
-
- if (!$page_current_value){
-
- $page_current_value = "off";
-
- }
-
- # Check if the page_current_value is set to 'on' if it is append the
- # current page seek value to the selection list.
-
- if ($page_current_value eq "on"){
-
- # Append the current seek value to the selection list.
-
- $selectionlist = $selectionlist . $page_select_seek . "|";
-
- }
-
- # Increment the page selection seeking counter.
-
- $page_select_seek++;
-
- } until ($page_select_seek eq $page_count);
-
- return $selectionlist;
-
-}
-
-sub kiriwrite_template_add{
-#################################################################################
-# kiriwrite_template_add: Add a template to the template folder #
-# #
-# Usage: #
-# #
-# kiriwrite_template_add(filename, name, description, layout, confirm); #
-# #
-# filename The filename of the new template. #
-# name The name of the template. #
-# description The description of the template. #
-# layout The layout of the new template. #
-# confirm Confirm the action of creating a new template. #
-#################################################################################
-
- # Get the variables that were passed to the subroutine.
-
- my ($templatefilename, $templatename, $templatedescription, $templatelayout, $confirm) = @_;
-
- # Load the needed Perl Modules
-
- use DBI;
-
- # Check if the confirm value is blank and if it is then set confirm to 0.
-
- if (!$confirm){
-
- # The confirm value is blank, so set the value of confirm to 0.
-
- $confirm = 0;
-
- }
-
- if ($confirm eq 1){
-
- # Check (validate) each of the values.
-
- kiriwrite_variablecheck($templatename, "utf8", 0, 0);
- kiriwrite_variablecheck($templatedescription, "utf8", 0, 0);
- kiriwrite_variablecheck($templatelayout, "utf8", 0, 0);
-
- # Convert the values into proper UTF8 strings that can be used.
-
- $templatename = kiriwrite_utf8convert($templatename);
- $templatedescription = kiriwrite_utf8convert($templatedescription);
- $templatelayout = kiriwrite_utf8convert($templatelayout);
-
- # Check the length of the converted UTF8 strings.
-
- my $templatefilename_length_check = kiriwrite_variablecheck($templatefilename, "maxlength", 64, 1);
- my $templatename_length_check = kiriwrite_variablecheck($templatename, "maxlength", 512, 1);
- my $templatedescription_length_check = kiriwrite_variablecheck($templatedescription, "maxlength", 512, 1);
- kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
-
- if ($templatefilename_length_check eq 1){
-
- # The template filename length is too long, so return an error.
-
- kiriwrite_error("templatefilenametoolong");
-
- }
-
- if ($templatename_length_check eq 1){
-
- # The template name length is too long, so return an error.
-
- kiriwrite_error("templatenametoolong");
-
- }
-
-
- if ($templatedescription_length_check eq 1){
-
- # The template description length is too long, so return an error.
-
- kiriwrite_error("templatedescriptiontoolong");
-
- }
-
- # Check if the filename specified is a valid filename.
-
- kiriwrite_variablecheck($templatefilename, "filename", "", 0);
-
- # Check if the template database file permissions are valid and
- # return an error if they aren't.
-
- my $template_database_permissions = kiriwrite_filepermissions("templates.db", 1, 1, 1);
-
- if ($template_database_permissions eq 1){
-
- # Template database has invalid permissions set, so return
- # an error.
-
- kiriwrite_error("templatedatabasefileinvalidpermissions");
- }
-
- # Check if the template database exists and if it doesn't then
- # create the database and populate it.
-
- my $template_database_exists = kiriwrite_fileexists("templates.db");
- my $database_handle;
- my $string_handle;
-
- if ($template_database_exists eq 1){
-
- # The template database does not exist, so try to create a database.
-
- # Check if the directory has valid permissions to create files (and
- # thus be able create a template database).
-
- my $directory_permissions = kiriwrite_filepermissions(".", 1, 1, 0);
-
- if ($directory_permissions eq 1){
-
- # The template database cannot be created because of invalid directory
- # permissions so return an error.
-
- kiriwrite_error("templatedatabasefilenotcreated");
- }
-
- # Create the SQLite database for the templates and populate it.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db");
- $string_handle = $database_handle->prepare('CREATE TABLE kiriwrite_templates(
- filename varchar(64) primary key,
- templatename varchar(512),
- templatedescription varchar(512),
- templatelayout text,
- datemodified datetime
- )') or die(kiriwrite_error("templatedatabaseinvalidformat"));
- $string_handle->execute();
-
- }
-
- # Check if the template filename is already used and if it is then
- # return an error.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db");
- $string_handle = $database_handle->prepare('select * from kiriwrite_templates where filename = \'' . $templatefilename . '\' limit 1') or die(kiriwrite_error("templatedatabaseinvalidformat"));
- $string_handle->execute();
-
- my @database_template_check = $string_handle->fetchrow_array();
- my $template_checkname = $database_template_check[0];
-
- if ($template_checkname){
-
- # A template already exists with the filename given, so return an error.
-
- kiriwrite_error("templatefilenameexists");
- }
-
- # Get the current date.
-
- my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime;
-
- my $templatedate = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second;
-
- # Convert the values that are going to be added for storing in the database.
-
- $templatename = kiriwrite_convert($templatename, "kiriwrite");
- $templatedescription = kiriwrite_convert($templatedescription, "kiriwrite");
- $templatelayout = kiriwrite_convert($templatelayout, "kiriwrite");
-
- # Add the template to the template database.
-
- $string_handle = $database_handle->prepare('INSERT INTO kiriwrite_templates values(
- \'' . $templatefilename . '\',
- \'' . $templatename . '\',
- \'' . $templatedescription . '\',
- \'' . $templatelayout . '\',
- \'' . $templatedate . '\'
- )');
- $string_handle->execute();
-
- # Print out the confirmation message.
-
- my $pagedata = "<h2>Template Added</h2>";
- $pagedata = $pagedata . "The template called '" . $templatename ."' was sucessfully created.<br><br>";
- $pagedata = $pagedata . "<a href=\"kiriwrite.cgi?mode=template\">Return to the templates list</a>";
- return $pagedata;
-
- } else {
- # No confirmation was made, so print out a form for adding a template.
-
- my $pagedata = "<h2>Add Template</h2>";
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"post\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"template\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"add\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"confirm\" value=\"1\">";
- $pagedata = $pagedata . "<table cellpadding=\"5\" cellspacing=\"0\">";
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Setting</td><td class=\"tablecellheader\">Value</td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Name:</td><td class=\"tablecell2\"><input type=\"text\" name=\"templatename\" maxlength=\"512\" size=\"64\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Description:</td><td class=\"tablecell2\"><input type=\"text\" name=\"templatedescription\" maxlength=\"512\" size=\"64\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Filename:</td><td class=\"tablecell2\"><input type=\"text\" name=\"templatefilename\" maxlength=\"64\" size=\"32\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Template Layout:</td><td class=\"tablecell2\"><textarea name=\"templatelayout\" rows=\"15\" cols=\"50\" wrap=off></textarea></td></tr>";
- $pagedata = $pagedata . "</table><br>";
- $pagedata = $pagedata . "<input type=\"submit\" value=\"Create New Template\"> | <input type=\"reset\" value=\"Clear Settings\">";
- $pagedata = $pagedata . "</form>";
-
- return $pagedata;
-
- }
-
-
-}
-
-sub kiriwrite_template_edit{
-#################################################################################
-# kiriwrite_template_edit: Edit a template from the template folder. #
-# #
-# Usage: #
-# #
-# kiriwrite_template_edit(filename, [newfilename], [newname], [newdescription], #
-# [templatelayout], [confirm]); #
-# #
-# filename The current filename of the template to edit. #
-# newfilename The new filename of the template to edit. #
-# newname The new name of the template being edited. #
-# newdescription The new description of the template being edited. #
-# templatelayout The modified/altered template layout. #
-# confirm Confirms the action to edit a template and its #
-# settings. #
-#################################################################################
-
- # Get all the variables that have been passed to the subroutine.
-
- my ($templatefilename, $templatenewfilename, $templatenewname, $templatenewdescription, $templatelayout, $confirm) = @_;
-
- # Load the Perl modules required for this subroutine.
-
- use DBI;
-
- # Define the pagedata variable for later on.
-
- my $pagedata = "";
-
- # Check if the confirm variable is blank, if it is then
- # set confirm to '0'
-
- if (!$confirm){
-
- # confirm is uninitalised/blank, so set the value of confirm
- # to '0'
-
- $confirm = 0;
-
- }
-
- # Check if the template filename is blank and if it is, then return
- # an error.
-
- if (!$templatefilename){
-
- kiriwrite_error("templatefilenameblank");
-
- }
-
- if ($confirm eq 1){
-
- # Check certain strings to see if they UTF8 compiliant.
-
- kiriwrite_variablecheck($templatenewname, "utf8", 0, 0);
- kiriwrite_variablecheck($templatenewdescription, "utf8", 0, 0);
- kiriwrite_variablecheck($templatelayout, "utf8", 0, 0);
-
- # Convert the values into proper UTF8 strings.
-
- $templatenewname = kiriwrite_utf8convert($templatenewname);
- $templatenewdescription = kiriwrite_utf8convert($templatenewdescription);
- $templatelayout = kiriwrite_utf8convert($templatelayout);
-
- # Check if the filenames recieved are valid filenames.
-
- kiriwrite_variablecheck($templatenewfilename, "maxlength", 64, 0);
- kiriwrite_variablecheck($templatenewdescription, "maxlength", 512, 0);
- kiriwrite_variablecheck($templatenewname, "maxlength", 512, 0);
- kiriwrite_variablecheck($templatefilename, "maxlength", 64, 0);
- kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
-
- kiriwrite_variablecheck($templatefilename, "filename", "", 0);
- kiriwrite_variablecheck($templatenewfilename, "filename", "", 0);
-
- # Check that the template database file exists and the permissions
- # of the template database are valid.
-
- my $template_database_exists = kiriwrite_fileexists("templates.db");
- my $template_database_permissions = kiriwrite_filepermissions("templates.db", 1, 1, 0);
-
- if ($template_database_exists eq 1){
-
- # the template database does not exist so return an error.
-
- kiriwrite_error("templatedatabasemissing");
-
- }
-
- if ($template_database_permissions eq 1){
-
- # The template database permissions are set incorrectly so
- # return an error.
-
- kiriwrite_error("templatedatabaseinvalidpermissions");
-
- }
-
- # Get the date.
-
- my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime;
-
- my $templatenewdate = $created_year . '-' . $created_month . '-' . $created_day . ' ' . $created_hour . ':' . $created_minute . ':' . $created_second;
-
- # Convert the values so that they don't break when entering them into the SQL query.
-
- $templatenewname = kiriwrite_convert($templatenewname, "kiriwrite");
- $templatenewdescription = kiriwrite_convert($templatenewdescription, "kiriwrite");
- $templatelayout = kiriwrite_convert($templatelayout, "kiriwrite");
-
- # Load the SQLite database.
-
- my $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db");
- my $string_handle = $database_handle->prepare('UPDATE kiriwrite_templates SET
- filename = \'' . $templatenewfilename . '\',
- templatename = \'' . $templatenewname . '\',
- templatedescription = \'' . $templatenewdescription . '\',
- templatelayout = \'' . $templatelayout . '\',
- datemodified = \'' . $templatenewdate . '\'
- WHERE filename = \'' . $templatefilename . '\'
- ') or die(kiriwrite_error("templatedatabaseinvalidformat"));
- $string_handle->execute();
-
- # Convert the following values so that display
-
- $templatenewname = kiriwrite_convert($templatenewname, "normal_display");
-
- # Append a link so that the user can return to the templates list.
-
- $pagedata = $pagedata . "<h2>Edit Template</h2>";
- $pagedata = $pagedata . "The selected template called '" . $templatenewname . "' was edited.<p>";
- $pagedata = $pagedata . "<a href=\"kiriwrite.cgi?mode=template\">Return to the templates list.</a>";
-
- } else {
-
- # Load the SQLite database.
-
- my $templatefilename_sql = kiriwrite_convert($templatefilename, "kiriwrite");
-
- my $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db");
- my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates where filename = \'' . $templatefilename_sql . '\' limit 1') or die(kiriwrite_error("templatedatabaseinvalidformat"));
- $string_handle->execute();
-
- # Check if there is a result from the SQL query made (meaning
- # that the template exists).
-
- my $template_found = 0;
- my @database_template;
-
- while (@database_template = $string_handle->fetchrow_array()){
-
- # The template has been found, so set the template
- # found value to 1 so it doesn't return an error.
-
- $template_found = 1;
-
- }
-
- if ($template_found eq 0){
-
- # The template was not found (doesn't exist) so
- # return an error.
-
- kiriwrite_error("templatedoesnotexist");
-
- }
-
- # Execute the query and get the information again.
-
- $string_handle->execute();
- @database_template = $string_handle->fetchrow_array();
-
- # Get the values from the query results.
-
- my $template_filename = $database_template[0];
- my $template_name = $database_template[1];
- my $template_description = $database_template[2];
- my $template_layout = $database_template[3];
- my $template_modified = $database_template[4];
-
- # Convert the values that are going to be displayed.
-
- $template_filename = kiriwrite_convert($template_filename, "normal_display");
- $template_name = kiriwrite_convert($template_name, "normal_display");
- $template_description = kiriwrite_convert($template_description, "normal_display");
- $template_layout = kiriwrite_convert($template_layout, "normal_display");
-
- # Write out the form for editing an template with the current template
- # settings put into the correct place.
-
- $pagedata = $pagedata . "<h2>Edit Template</h2>";
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"template\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"edit\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"confirm\" value=\"1\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"template\" value=\"" . $template_filename . "\">";
- $pagedata = $pagedata . "<table cellspacing=\"0\" cellpadding=\"5\">";
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Setting</td><td class=\"tablecellheader\">Value</td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Name:</td><td class=\"tablecell2\"><input type=\"text\" name=\"newname\" value=\"" . $template_name . "\" maxlength=\"512\" size=\"64\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Description:</td><td class=\"tablecell2\"><input type=\"text\" name=\"newdescription\" value=\"" . $template_description . "\" maxlength=\"512\" size=\"64\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Filename:</td><td class=\"tablecell2\"><input type=\"text\" name=\"newfilename\" maxlength=\"64\" size=\"32\" value=\"" . $template_filename . "\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Template Layout:</td><td class=\"tablecell2\"><textarea rows=\"15\" cols=\"50\" name=\"newlayout\" wrap=off>" . $template_layout . "</textarea></td></tr>";
- $pagedata = $pagedata . "</table><br>";
- $pagedata = $pagedata . "<input type=\"submit\" value=\"Update template settings\"> | <input type=\"reset\" value=\"Restore current settings\"> | <a href=\"kiriwrite.cgi?mode=template\">Return to the templates list.</a>";
- $pagedata = $pagedata . "</form>";
-
- }
-
- return $pagedata;
-
-}
-
-sub kiriwrite_template_delete{
-#################################################################################
-# kiriwrite_template_delete: Delete a template from the template folder. #
-# #
-# Usage: #
-# #
-# kiriwrite_template_delete(filename, confirm); #
-# #
-# filename Specifies the filename of the database to delete. #
-# confirm Confirms the action to delete a template. #
-#################################################################################
-
- # Get the parameters that were passed to the subroutine.
-
- my ($template_filename, $template_confirm) = @_;
-
- if (!$template_confirm){
- $template_confirm = 0;
- }
-
- # Load the required Perl modules
- use DBI;
-
- # Check the length of the variables.
- kiriwrite_variablecheck($template_filename, "maxlength", 64, 0);
- kiriwrite_variablecheck($template_confirm, "maxlength", 1, 0);
-
- # Check if the template_name string is blank and if it is then
- # return an error (as the template_name string should not be
- # blank.
-
- if (!$template_filename){
-
- # The template_filename string really is blank,
- # so return an error saying that an empty
- # filename was passed (to the subroutine).
-
- kiriwrite_error("templatefilenameblank");
-
- }
-
- # Check if the template_confirm string is blank and if it is, write
- # out a form asking the user to confirm the deletion.
-
- if ($template_confirm eq 1){
-
- # The action to delete the template from the template database has
- # been confirmed so delete the template.
-
- # Check if the template database exists and the file permissions
- # are valid and return an error if they aren't.
-
- my $template_database_exists = kiriwrite_fileexists("templates.db");
- my $template_database_permissions = kiriwrite_filepermissions("templates.db", 1, 1, 0);
-
- if ($template_database_exists eq 1){
-
- # the template database does not exist so return an error.
-
- kiriwrite_error("templatedatabasemissing");
-
- }
-
- if ($template_database_permissions eq 1){
-
- # The template database permissions are set incorrectly so
- # return an error.
-
- kiriwrite_error("templatedatabaseinvalidpermissions");
-
- }
-
- # Load thw SQLite database.
-
- my $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db");
-
- # Get the template name.
-
- my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates WHERE filename = \'' . $template_filename . '\' LIMIT 1') or die(kiriwrite_error("templatedatabaseinvalidformat"));
- $string_handle->execute();
-
- my @database_template_page = $string_handle->fetchrow_array();
- my $database_template_name = $database_template_page[1];
-
- $database_template_name = kiriwrite_convert($database_template_name, "normal_display");
-
- # Delete the selected template.
-
- $string_handle = $database_handle->prepare('DELETE FROM kiriwrite_templates WHERE filename = \'' . $template_filename . '\'');
- $string_handle->execute();
-
- my $pagedata = "<h2>Template Deleted</h2>";
- $pagedata = $pagedata . "The selected template called '" . $database_template_name . "' was deleted.";
- $pagedata = $pagedata . "<br><br><a href=\"kiriwrite.cgi?mode=template\">Return to the templates list</a>";
-
- return $pagedata;
-
- } elsif ($template_confirm eq 0) {
-
- # The template confirm value is 0 (previously blank and then set to 0), so
- # write out a form asking the user to confirm the deletion of the template.
-
- # Check the templte database file exists and the permissions for the
- # template database are valid.
-
- my $template_database_exists = kiriwrite_fileexists("templates.db");
- my $template_database_permissions = kiriwrite_filepermissions("templates.db", 1, 1, 0);
-
- if ($template_database_exists eq 1){
-
- # The template database does not exist so return an error.
-
- kiriwrite_error("templatedatabasemissing");
-
- }
-
- if ($template_database_permissions eq 1){
-
- # The template database has invalid permissions set so return
- # an error.
-
- kiriwrite_error("templatedatabaseinvalidpermissions");
-
- }
-
- # Load the SQLite database.
-
- my $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db");
- my $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates WHERE filename = \'' . $template_filename . '\' LIMIT 1');
- $string_handle->execute();
-
- # Check if a result had returned and return an error if no result
- # was returned.
-
- my @template_data;
- my $template_found = 0;
-
- while(@template_data = $string_handle->fetchrow_array()){
-
- # A template has been found so increment the counter.
-
- $template_found++;
- }
-
- if ($template_found eq 0){
-
- # The template does not exist, so return an error.
- kiriwrite_error("templatedoesnotexist");
-
- }
-
- # Get the template file information.
-
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates WHERE filename = \'' . $template_filename . '\' LIMIT 1');
- $string_handle->execute();
- @template_data = $string_handle->fetchrow_array();
-
- my $template_data_filename = $template_data[0];
- my $template_data_name = $template_data[1];
-
- # Check if the template name is blank and if it is
-
- # Convert the strings so that display properly.
-
- $template_data_name = kiriwrite_convert($template_data_name, "normal_display");
- $template_data_name = kiriwrite_convert($template_data_name, "normal_display");
-
- # Write out the confirmation form.
-
- my $pagedata = "<h2>Template Deletion</h2>";
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"template\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"template\" value=\"" . $template_filename ."\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"delete\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"confirm\" value=\"1\">";
- $pagedata = $pagedata . "Are you sure you want to delete the template called '" . $template_data_name . "' (" . $template_data_filename . ")?<br><br>";
- $pagedata = $pagedata . "<input type=\"submit\" name=\"submit\" value=\"Yes, delete the template\"> | <a href=\"kiriwrite.cgi?mode=template\">No, return to the template list.</a>";
-
- $pagedata = $pagedata . "</form>";
-
- return $pagedata;
-
- } else {
-
- kiriwrite_error("invalidvariable");
-
- }
-
-}
-
-sub kiriwrite_template_list{
-#################################################################################
-# kiriwrite_template_list: List the templates in the template folder. #
-# #
-# Usage: #
-# #
-# kiriwrite_template_list(); #
-#################################################################################
-
- # Load the module required for processing the XML configuration files.
-
- use DBI;
-
- # Define certain values for later.
-
- my @database_template;
-
- my $database_handle;
- my $string_handle;
-
- my $template_filename = "";
- my $template_name = "";
- my $template_description = "";
- my $template_data = "";
-
- my $template_count = 0;
-
- my $template_style = 0;
- my $template_stylename = "";
-
- my $pagedata = "";
- my $templatedata = "";
-
- # Check if the template database exists and the permissions for it are
- # valid if the template database doesn't exist then write a message
- # saying it will be created when a template is added.
-
- my $template_database_permissions = kiriwrite_filepermissions("templates.db", 1, 0, 1);
- my $template_database_exists = kiriwrite_fileexists("templates.db");
-
- if ($template_database_permissions eq 1){
-
- # The templates directory has invalid permissions so an
- # error will be returned.
-
- kiriwrite_error("templatedatabaseinvalidpermissions");
-
- }
-
- if ($template_database_exists eq 1){
-
- $pagedata = "<h2>View Templates</h2>";
- $pagedata = $pagedata . "<div class=\"errorbox\">The template database doesn't exist and will be created when a template is added.</div>";
-
- return $pagedata;
-
- }
-
- # Place the table cell headings into the templatedata string.
-
- $templatedata = "<table cellspacing=\"0\" cellpadding=\"5\"><tr><td class=\"tablecellheader\">Template Filename</td><td class=\"tablecellheader\">Template Name</td><td class=\"tablecellheader\">Template Description</td><td class=\"tablecellheader\">Options</td></tr>";
-
- # Check if the database exists first before loading it.
-
- if ($template_database_exists eq 1){
-
- } else {
-
- # Load the SQLite database.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=templates.db");
- $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_templates ORDER BY filename ASC") or die(kiriwrite_error("templatedatabaseinvalidformat"));
- $string_handle->execute();
-
- # Process each template.
-
- while (@database_template = $string_handle->fetchrow_array()){
-
- # Get certain values from the array.
-
- $template_filename = $database_template[0];
- $template_name = $database_template[1];
- $template_description = $database_template[2];
- $template_data = $database_template[3];
-
- # Convert the data into information that can be displayed.
-
- $template_filename = kiriwrite_convert($template_filename, "normal_display");
- $template_name = kiriwrite_convert($template_name, "normal_display");
- $template_description = kiriwrite_convert($template_description, "normal_display");
- $template_data = kiriwrite_convert($template_data, "normal_display");
-
- # Check what style the row of table cells should be.
-
- if ($template_style eq 0){
-
- $template_stylename = "tablecell1";
- $template_style = 1;
-
- } else {
-
- $template_stylename = "tablecell2";
- $template_style = 0;
-
- }
-
- # Check if the template name and descriptions are blank and if
- # they are then insert a message saying that there's no name
- # or no description.
-
- if (!$template_name){
- $template_name = "<i>No Name</i>";
- }
-
- if (!$template_description){
- $template_description = "<i>No Description</i>";
- }
-
- # Check if there is no template data and if there isn't write
- # a blank template message.
-
- if (!$template_data){
- $template_filename = $template_filename . " <i>[Blank Template]</i>";
- }
-
- # Append the table row to the templatedata string.
-
- $templatedata = $templatedata . "<tr><td class=\"" . $template_stylename . "\">" . $template_filename . "</td><td class=\"" . $template_stylename . "\">" . $template_name . "</td><td class=\"" . $template_stylename . "\">" . $template_description . "</td><td class=\"" . $template_stylename . "\"><a href=\"kiriwrite.cgi?mode=template&action=edit&template=" . $template_filename . "\">Edit</a> <a href=\"kiriwrite.cgi?mode=template&action=delete&template=" . $template_filename . "\">Delete</a></td></tr>";
-
- # Increment the template counter.
-
- $template_count++;
-
- }
-
- }
-
- $templatedata = $templatedata . "</table>";
-
- # Check if any templates are in the database and if there isn't
- # then write a message saying that there are no templates in the
- # database.
-
- if ($template_count eq 0){
- $templatedata = "<div class=\"errorbox\">There are no templates in the template database. To add a template click on the Add Template link.</div>";
- }
-
- # Process the templatedata into pagedata.
-
- $pagedata = "<h2>View Templates</h2>";
- $pagedata = $pagedata . $templatedata;
-
- return $pagedata;
-
-}
-
-sub kiriwrite_database_add{
-#################################################################################
-# kiriwrite_database_add: Creates a new database. #
-# #
-# Usage: #
-# #
-# kiriwrite_database_add(filename, name, description, [confirm]); #
-# #
-# filename Specifies the filename for the database. #
-# name Specifies a (friendly) name for the database. #
-# description Specifies a description for the database. #
-# confirm Confirms the action to create a database. #
-#################################################################################
-
- # Get the variables passed from the subroutine.
-
- my ($database_filename, $database_name, $database_description, $database_notes, $database_categories, $database_confirm) = @_;
-
- # Load the perl modules for this subroutine.
-
- use DBI;
-
- # Check if the confirm value is blank and if it is then
- # set the confirm value to 0.
-
- if (!$database_confirm){
-
- # The confirm value was blank so set the value to 0.
-
- $database_confirm = 0;
-
- }
-
-
- if ($database_confirm eq 1){
-
- # The action to create a new database is confirmed.
-
- # Validate the database name and database descriptions.
-
- my $database_name_check_utf8 = kiriwrite_variablecheck($database_name, "utf8", 0, 0);
- my $database_description_check_utf8 = kiriwrite_variablecheck($database_description, "utf8", 0, 0);
- my $database_notes_check_utf8 = kiriwrite_variablecheck($database_notes, "utf8", 0, 0);
- my $database_categories_check_utf8 = kiriwrite_variablecheck($database_categories, "utf8", 0, 0);
-
- # Convert the UTF8 strings before checking the length of the strings.
-
- $database_name = kiriwrite_utf8convert($database_name);
- $database_description = kiriwrite_utf8convert($database_description);
- $database_notes = kiriwrite_utf8convert($database_notes);
- $database_categories = kiriwrite_utf8convert($database_categories);
-
- my $database_name_check_blank = kiriwrite_variablecheck($database_name, "blank", 0, 1);
- my $database_name_check_length = kiriwrite_variablecheck($database_name, "maxlength", 256, 1);
- my $database_description_check_length = kiriwrite_variablecheck($database_description, "maxlength", 512, 1);
- my $database_filename_check_length = kiriwrite_variablecheck($database_filename, "maxlength", 64, 1);
- my $database_categories_check_length = kiriwrite_variablecheck($database_categories, "maxlength", 512, 1);
-
- # Check if values returned contains any values that would
- # result in a specific error message being returned.
-
- if ($database_name_check_length eq 1){
-
- # The length of the database name is too long, so return an error.
- kiriwrite_error("databasenametoolong");
-
- }
-
- if ($database_description_check_length eq 1){
-
- # The database description length is too long, so return an error.
- kiriwrite_error("databasedescriptiontoolong");
-
- }
-
- if ($database_name_check_blank eq 1){
-
- # The database name is blank, so return an error.
- kiriwrite_error("databasenameblank");
-
- }
-
- if ($database_filename_check_length eq 1){
-
- # The database filename is to long, so return an error.
- kiriwrite_error("databasefilenametoolong");
-
- }
-
- if ($database_categories_check_length eq 1){
-
- # The database categories is too long, so return an error.
- kiriwrite_error("databasecategoriestoolong");
-
- }
-
- # Check if the database filename is blank and if it is then
- # generate a filename.
-
- if ($database_filename eq ""){
-
- # Filename is blank so generate a file name from
- # the database name.
-
- $database_filename = kiriwrite_processfilename($database_name);
-
- # Check to make sure that the database filename really
- # is valid.
-
- kiriwrite_variablecheck($database_filename, "filename", "", 0);
- kiriwrite_variablecheck($database_filename, "maxlength", 64, 0);
-
- # Check if the database and database configuration file does
- # not already exist.
-
- if (-e $kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db'){
-
- # A filename exists, so abort the script telling the user that those files exist.
- kiriwrite_error("fileexists");
-
- }
-
- } else {
-
- # Filename is not blank, so check if the filenames are already
- # being used and if the actual filename itself is valid.
-
- # Check the filename to make sure the database and the database configuration file does not already exist.
-
- if (-e $kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db' ){
-
- # A filename exists, so abort the script telling the user that those files exist.
-
- kiriwrite_error("fileexists");
-
-
- }
-
- # Check to make sure the database filename itself really is
- # valid.
-
- kiriwrite_variablecheck($database_filename, "filename", "", 0);
- kiriwrite_variablecheck($database_filename, "maxlength", 64, 0);
-
- }
-
- # Convert certain data so that the SQL query doesn't break.
-
- my $database_name_final = $database_name;
- $database_name = kiriwrite_convert($database_name, "kiriwrite");
- $database_description = kiriwrite_convert($database_description, "kiriwrite");
- $database_categories = kiriwrite_convert($database_categories, "kiriwrite");
-
- # Populate the database with the infomration and page tables.
-
- my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database_filename . ".db");
- my $string_handle = $database_handle->prepare('CREATE TABLE kiriwrite_database_info(
- name varchar(256) primary key,
- description varchar(512),
- notes text,
- categories varchar(512),
- kiriwrite_version_major int(4),
- kiriwrite_version_minor int(4),
- kiriwrite_version_revision int(4)
- )');
- $string_handle->execute();
-
- $string_handle = $database_handle->prepare('CREATE TABLE kiriwrite_database_pages(
- filename varchar(256) primary key,
- pagename varchar(512),
- pagedescription varchar(512),
- pagesection varchar(256),
- pagetemplate varchar(64),
- pagedata text,
- pagesettings int(1),
- lastmodified datetime
- )');
- $string_handle->execute();
-
- # Add an entry to the kiriwrite_database_info table.
-
- $string_handle = $database_handle->prepare('INSERT INTO kiriwrite_database_info values(
- \'' . $database_name . '\',
- \'' . $database_description . '\',
- \'' . $database_notes . '\',
- \'' . $database_categories . '\',
- \'' . $kiriwrite_version{"major"} . '\',
- \'' . $kiriwrite_version{"minor"} . '\',
- \'' . $kiriwrite_version{"revision"} . '\'
- )');
- $string_handle->execute();
-
- $database_name_final = kiriwrite_convert($database_name_final, "normal_display");
-
- my $pagedata = "<h2>Add Database</h2>";
- $pagedata = $pagedata . "Database '" . $database_name_final . "' has been created.<br><br>\r\n";
- $pagedata = $pagedata . "<a href=\"kiriwrite.cgi?mode=db\">Return to database list</a>";
-
- return $pagedata;
-
- }
-
- # There is confirm value is not 1, so write a form for creating a database to
- # store pages in.
-
- my $pagedata = "<h2>Add Database</h2>\r\n";
-
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">";
- $pagedata = $pagedata . "\t\t\t<table cellpadding=\"5\" cellspacing=\"0\">\r\n";
- $pagedata = $pagedata . "\t\t<input type=\"hidden\" name=\"mode\" value=\"db\">\r\n";
- $pagedata = $pagedata . "\t\t<input type=\"hidden\" name=\"action\" value=\"new\">\r\n";
- $pagedata = $pagedata . "\t\t<input type=\"hidden\" name=\"confirm\" value=\"1\">\r\n";
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Setting</td><td class=\"tablecellheader\">Value</td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Database name</td><td class=\"tablecell2\"><input type=\"text\" size=\"64\" maxlength=\"256\" name=\"databasename\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Database description</td><td class=\"tablecell2\"><input type=\"text\" size=\"64\" maxlength=\"512\" name=\"databasedescription\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Database notes</td><td class=\"tablecell2\"><textarea name=\"databasenotes\" wrap=\"off\" cols=\"50\" rows=\"10\"></textarea></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Database categories</td><td class=\"tablecell2\"><input type=\"text\" size=\"64\" maxlength=\"512\" name=\"databasecategories\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Database filename</td><td class=\"tablecell2\"><input type=\"text\" size=\"32\" maxlength=\"64\" name=\"databasefilename\"><br />
- <ul>
- <li>Leave the filename blank to automatically generate a filename.</li>
- <li>Don't include .db as it will be appended automatically.</li>
- <li>The filename cannot be any more than 64 characters long.</li>
- <li>The filename should only contain letters and numbers, no spaces.</li>
- </ul>
- </td></tr>";
- $pagedata = $pagedata . "\t\t\t</table>\r\n";
- $pagedata = $pagedata . "\t\t\t<br />\r\n";
- $pagedata = $pagedata . "\t\t\t<input type=\"submit\" value=\"Add Database\"> | <input type=\"reset\" value=\"Clear values\">";
- $pagedata = $pagedata . "\t\t</form>\r\n";
-
- # Exit the subroutine taking the data in the pagadata variable with it.
-
- return $pagedata;
-
-}
-
-sub kiriwrite_database_edit{
-#################################################################################
-# kiriwrite_database_edit: Edits an database. #
-# #
-# Usage: #
-# #
-# kiriwrite_database_edit(filename, name, description, newfilename, newname, #
-# newdescription, notes, categories, [confirm]); #
-# #
-# filename Specifies the filename of the database. #
-# name Specifies the name of the database. #
-# description Specifies the description of the database. #
-# newfilename Specifies the new filename of the database. #
-# newname Specifies the new name of the database. #
-# newdescription Specifies the new description of the database. #
-# notes Specifies the new notes of the database. #
-# categories Specifies the new categories of the database. #
-# confirm Confirms the action to edit a database. #
-#################################################################################
-
- # First, get all the variables passed to the subroutine.
-
- my ($database_shortname, $database_name, $database_description, $database_newfilename, $database_newname, $database_newdescription, $database_notes, $database_categories, $database_confirm) = @_;
-
- # Load the needed Perl modules.
-
- use DBI;
-
- # Check if the database confirm value is blank and if it is
- # set the confirm value to 0.
-
- if (!$database_confirm){
-
- $database_confirm = 0;
-
- }
-
- # Check if the confirm variable has a value in it, if it has, check again to make sure it really is the correct value (Perl moans
- # if $database_confirm was used directly).
-
- if ($database_confirm eq 1){
-
- # Check if the database exists before trying to edit it.
-
- my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db');
-
- if ($database_exists eq 1){
-
- # The database does not exist so return an error.
-
- kiriwrite_error("databasemissingfile");
-
- }
-
- # Check if the new data passes the validation tests below. First, check the length of the variables.
-
- my $database_name_check_utf8 = kiriwrite_variablecheck($database_newname, "utf8", 0, 0);
- my $database_description_check_utf8 = kiriwrite_variablecheck($database_newdescription, "utf8", 0, 0);
- my $database_notes_check_utf8 = kiriwrite_variablecheck($database_notes, "utf8", 0, 0);
- my $database_categories_check_utf8 = kiriwrite_variablecheck($database_categories, "utf8", 0, 0);
-
- # Convert the UTF8 strings to make sure their length is accurate.
-
- $database_newname = kiriwrite_utf8convert($database_newname);
- $database_newdescription = kiriwrite_utf8convert($database_newdescription);
- $database_notes = kiriwrite_utf8convert($database_notes);
- $database_categories = kiriwrite_utf8convert($database_categories);
-
- # Check if the database filename given is valid and return an error
- # if it isn't.
-
- kiriwrite_variablecheck($database_shortname, "filename", "", 0);
-
- # Preform the following tests.
-
- my $database_filename_check_length = kiriwrite_variablecheck($database_newfilename, "maxlength", 64, 1);
- my $database_filename_letnum = kiriwrite_variablecheck($database_newfilename, "filename", 0, 0);
- my $database_name_check_length = kiriwrite_variablecheck($database_newname, "maxlength", 256, 1);
- my $database_description_check_length = kiriwrite_variablecheck($database_newdescription, "maxlength", 512, 1);
- my $database_categories_check_length = kiriwrite_variablecheck($database_categories, "maxlength", 512, 1);
- my $database_name_check_blank = kiriwrite_variablecheck($database_newname, "blank", 0, 1);
-
- # Check if the data is valid and return a specific error if it doesn't.
-
- if ($database_name_check_length eq 1){
-
- # The length of the database name is too long, so return an error.
- kiriwrite_error("databasenametoolong");
-
- }
-
- if ($database_description_check_length eq 1){
-
- # The database description length is too long, so return an error.
- kiriwrite_error("databasedescriptiontoolong");
-
- }
-
- if ($database_name_check_blank eq 1){
-
- # The database name is blank, so return an error.
- kiriwrite_error("databasenameblank");
-
- }
-
- if ($database_filename_check_length eq 1){
-
- # The database filename is too long, so return an error.
- kiriwrite_error("databasefilenametoolong");
-
- }
-
- if ($database_categories_check_length eq 1){
-
- # The database categories is too long, so return an error.
- kiriwrite_error("databasecategoriestoolong");
-
- }
-
- # Check the permissions of the database file to see if it is valid
- # and return an error if it isn't.
-
- my $database_file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db', 1, 1, 1);
-
- if ($database_file_permissions eq 1){
-
- # The database file itself has invalid permissions.
-
- kiriwrite_error("databaseinvalidpermissions");
-
- }
-
- # Check if the old and new filenames have changed, if they have then rename the database file.
-
- my $pagedata;
-
- $pagedata = "<h2>Edit Database</h2>";
-
- if ($database_shortname ne $database_newfilename){
-
- # Old name does not match with the new filename, so rename the database file.
-
- # Check if a database with the same shortname already exists, if it does then return with an error.
-
- if (-e $kiriwrite_config{"directory_data_db"} . '/' . $database_newfilename . '.db'){
- kiriwrite_error("databasealreadyexists");
- }
-
- # Change the database filename.
-
- rename($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db', $kiriwrite_config{"directory_data_db"} . '/' . $database_newfilename . '.db');
- unlink($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db');
-
- # Set the filename to the new filename.
-
- $database_shortname = $database_newfilename;
-
- }
-
- # Load the SQLite database.
-
- my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . ".db");
-
- # Convert the UTF8 strings so that they can be properly updated.
-
- $database_name = kiriwrite_utf8convert($database_name);
- $database_description = kiriwrite_utf8convert($database_description);
-
- # Convert the strings that are going to put into the database so that
- # the database query doesn't break.
-
- $database_name = kiriwrite_convert($database_name, "kiriwrite");
- $database_newname = kiriwrite_convert($database_newname, "kiriwrite");
- $database_description = kiriwrite_convert($database_description, "kiriwrite");
- $database_newdescription = kiriwrite_convert($database_newdescription, "kiriwrite");
-
- my $string_handle = $database_handle->prepare('UPDATE kiriwrite_database_info SET name = \'' . $database_newname . '\', description = \'' . $database_newdescription . '\', notes = \'' . $database_notes . '\', categories = \'' . $database_categories . '\' WHERE name = \'' . $database_name . '\' AND description = \'' . $database_description . '\'') or kiriwrite_error("databasefileinvalid");
- $string_handle->execute();
-
- # Convert a string so that it can be displayed properly.
-
- $database_newname = kiriwrite_convert($database_newname, "normal_display");
-
- # Write out a message saying that the database has been updated.
-
- $pagedata = $pagedata . "Database '" . $database_newname . "' updated.<br>";
- $pagedata = $pagedata . "<br>\r\n<a href=\"kiriwrite.cgi?mode=db\">Return to database list.</a>";
-
- return $pagedata;
-
- } else {
-
- # Check if the database filename given is valid and return an error
- # if it isn't.
-
- kiriwrite_variablecheck($database_shortname, "filenameindir", "", 0);
-
- # Check if the database exists before trying to edit it.
-
- my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db');
-
- if ($database_exists eq 1){
-
- # The database does not exist so return an error.
-
- kiriwrite_error("databasemissingfile");
-
- }
-
-
- # Check the permissions of the database file to see if it is valid
- # and return an error if it isn't.
-
- my $database_file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . '.db', 1, 0, 1);
-
- if ($database_file_permissions eq 1){
-
- # The database file itself has invalid permissions.
-
- kiriwrite_error("databaseinvalidpermissions");
-
- }
-
- # Load the SQLite database.
-
- my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database_shortname . ".db");
- my $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_info LIMIT 1") or kiriwrite_error("databasefileinvalid");
- $string_handle->execute();
- my @database_info = $string_handle->fetchrow_array();
-
- # Get the values needed from the kiriwrite_database_info table.
-
- my $database_oldname = $database_info[0];
- my $database_olddescription = $database_info[1];
- my $database_notes = $database_info[2];
- my $database_categories = $database_info[3];
-
- # Convert the values in the kieiwrite format into the format that can be understood
- # with a web browser.
-
- $database_oldname = kiriwrite_convert($database_oldname, "normal_display");
- $database_olddescription = kiriwrite_convert($database_olddescription, "normal_display");
- $database_notes = kiriwrite_convert($database_notes, "normal_display");
- $database_categories = kiriwrite_convert($database_categories, "normal_display");
-
- # Print out the form for editing a database's settings.
-
- my $pagedata = "<h2>Edit Database '" . $database_oldname . "'</h2>";
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">\r\n";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"db\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"edit\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"database\" value=\"" . $database_shortname . "\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"confirm\" value=\"yes\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"olddatabasename\" value=\"" . $database_oldname . "\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"olddatabasedescription\" value=\"" . $database_olddescription . "\">";
- $pagedata = $pagedata . "<table cellspacing=\"0\" cellpadding=\"5\">\r\n";
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Setting</td><td class=\"tablecellheader\">Value</td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Database name</td><td class=\"tablecell2\"><input type=\"text\" name=\"databasename\" value=\"" . $database_oldname . "\" maxlength=\"256\" size=\"64\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Database description</td><td class=\"tablecell2\"><input name=\"databasedescription\" maxlength=\"512\" size=\"64\" value=\"" . $database_olddescription . "\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Database notes</td><td class=\"tablecell2\"><textarea name=\"databasenotes\" cols=\"50\" rows=\"10\" wrap=\"off\">" . $database_notes . "</textarea></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Database categories</td><td class=\"tablecell2\"><input name=\"databasecategories\" value=\"" . $database_categories . "\" size=\"64\" maxlength=\"512\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Database filename</td><td class=\"tablecell2\"><input name=\"databasefilename\" maxlength=\"64\" size=\"64\" value=\"" . $database_shortname . "\"></td></tr>";
- $pagedata = $pagedata . "</table><p />";
-
- $pagedata = $pagedata . "<input type=\"submit\" value=\"Edit settings\" /> | <input type=\"reset\" value=\"Reset settings\" />";
- $pagedata = $pagedata . "</form>";
- return $pagedata;
-
- }
-
- # The interpreter should not be here. So return an error saying invalid variable.
-
- kiriwrite_error("invalidvariable");
-
-}
-
-sub kiriwrite_database_delete{
-#################################################################################
-# kiriwrite_database_delete: Deletes an database. #
-# #
-# Usage: #
-# #
-# kiriwrite_database_delete(filename, [confirm]); #
-# #
-# filename Specifies the filename for the database to be deleted. #
-# confirm Confirms the action to delete a database. #
-#################################################################################
-
- my ($database_filename, $database_confirm) = @_;
-
- # Load the CGI module and the XML::Simple module for this subroutine.
-
- use DBI;
-
- # Check if the confirm value is blank and if it is then set the
- # confirm value to 0.
-
- if (!$database_confirm){
-
- $database_confirm = 0;
-
- }
-
- # Check if the database exists before trying to edit it.
-
- my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db');
-
- if ($database_exists eq 1){
-
- # The database does not exist so return an error.
-
- kiriwrite_error("databasemissingfile");
-
- }
-
- # Check if the database filename given is valid and return an error
- # if it isn't.
-
- kiriwrite_variablecheck($database_filename, "filename", "", 0);
-
- # Check if the request to delete a database has been confirmed. If it has,
- # then delete the database itself.
-
- if ($database_confirm eq 1){
- # There is a value in the confirm variable of the HTTP query.
-
- # Before deleting, check the permissions of the database file.
-
- my $deleted_database_file_permissions = 0;
-
- my $pagedata = "";
-
- $deleted_database_file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db', 1, 1, 1);
-
- if ($deleted_database_file_permissions eq 1){
-
- # The database file itself has invalid permissions.
-
- kiriwrite_error("databaseinvalidpermissions");
-
- }
-
- # Load the SQLite database to get the database name.
-
- my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db');
- my $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_info LIMIT 1");
- $string_handle->execute;
- my @database_info = $string_handle->fetchrow_array();
-
- my $database_name = $database_info[0];
- $database_name = kiriwrite_convert($database_name, "normal_display");
-
- # Untaint the database filename given.
-
- ($database_filename) = $database_filename =~ /^([a-zA-Z0-9.]+)$/;
-
- # Delete the database file.
-
- unlink($kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db');
-
- # Write a message saying that the database has been deleted.
-
- $pagedata = "<h2>Database Deleted</h2>";
- $pagedata = $pagedata . "Database '" . $database_name . "' was deleted.<br />\r\n";
-
- $pagedata = $pagedata . "<br><a href=\"kiriwrite.cgi?mode=db\">Return to database list.</a>";
-
- return $pagedata;
-
- }
-
- # The action has not been confirmed, so write out a form asking the
- # user to confirm.
-
- # Check the permissions of the database file to see if they are valid
- # and return an error if it isn't.
-
- my $delete_database_file_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db', 1, 1, 1);
-
- if ($delete_database_file_permissions eq 1){
-
- # The database file itself has invalid permissions.
-
- kiriwrite_error("databaseinvalidpermissions");
-
- }
-
- # Load the SQLite database to get the database name.
-
- my $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database_filename . '.db');
- my $string_handle = $database_handle->prepare("SELECT * FROM kiriwrite_database_info LIMIT 1");
- $string_handle->execute;
- my @database_info = $string_handle->fetchrow_array();
-
- # Convert the database name so that it can be displayed properly.
-
- my $database_name = $database_info[0];
- $database_filename = kiriwrite_convert($database_filename, "normal_display");
- $database_name = kiriwrite_convert($database_name, "normal_display");
-
- # Write out the form to ask the user to confirm the deletion of the
- # selected database.
-
- my $pagedata = "<h2>Database Deletion</h2>";
- $pagedata = $pagedata . "\t\tAre you sure you want to delete '". $database_name . "'\?<br><br>";
- $pagedata = $pagedata . "\t\t<form action=\"kiriwrite.cgi\" method=\"POST\">\r\n";
- $pagedata = $pagedata . "\t\t<input type=\"hidden\" name=\"mode\" value=\"db\">";
- $pagedata = $pagedata . "\t\t<input type=\"hidden\" name=\"action\" value=\"delete\">";
- $pagedata = $pagedata . "\t\t<input type=\"hidden\" name=\"database\" value=\"" . $database_filename . "\">";
- $pagedata = $pagedata . "\t\t<input type=\"hidden\" name=\"confirm\" value=\"1\">";
- $pagedata = $pagedata . "\t\t<input type=\"submit\" value=\"Delete Database\"> | <a href=\"kiriwrite.cgi?mode=db\">Return to database list.</a>";
- $pagedata = $pagedata . "\t\t</form>\r\n";
-
- return $pagedata;
-
-}
-
-sub kiriwrite_database_list{
-#################################################################################
-# kiriwrite_database_list: Lists the databases available. #
-# #
-# Usage: #
-# #
-# kiriwrite_database_list(); #
-#################################################################################
-
- # Load the following Perl modules.
- use DBI;
-
- # Check the directory to make sure the permissions are settings are valid
- # and return an error if the permission settings are invalid.
-
- my $data_directory_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"}, 1, 0);
-
- if ($data_directory_permissions eq 1){
-
- # The data directory has invalid permissions set, so return an error.
-
- kiriwrite_error("datadirectoryinvalidpermissions");
-
- }
-
- # Open the directory and get the list of all files ending with .xml and
- # put them into the data_directory array.
-
- opendir(DATADIR, $kiriwrite_config{"directory_data_db"});
- my @data_directory = grep /m*\.db/, readdir(DATADIR);
- closedir(DATADIR);
-
- # Declare the following variables that are going to be used before using
- # the foreach function.
-
- my $pagedata = "";
- my $database_count = 0;
- my $database_handle = "";
- my $database_filename = "";
- my $database_filename_friendly = "";
- my $database_filename_length = 0;
- my $database_permissions = "";
- my $data_file = "";
- my $string_handle = "";
- my @database_info;
- my $table_style = 0;
- my $table_style_name = "";
- my $permissions_warning = 0;
- my $permissions_list = "";
- my $invalid_warning = 0;
- my $invalid_list = "";
-
- # Begin creating the table for the list of databases.
-
- $pagedata = "<h2>Database List</h2>\r\n";
-
- $pagedata = $pagedata . "<table cellpadding=\"5\" cellspacing=\"0\"><tr><td class=\"tablecellheader\">Database Name</td><td class=\"tablecellheader\">Database Description</td><td class=\"tablecellheader\">Options</td></tr>\r\n";
-
- foreach $data_file (@data_directory){
- # Check the database file permissions before opening it.
-
- $database_filename = $kiriwrite_config{"directory_data_db"} . '/' . $data_file;
- $database_permissions = kiriwrite_filepermissions($database_filename, 1, 0, 0);
-
- if ($database_permissions eq 1){
- $permissions_warning = 1;
- $permissions_list = $permissions_list . $data_file . "<br>\r\n";
- next;
- }
-
- # Load the SQLite database.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=" . $database_filename);
-
- # Query the SQLite database or return an error (meaning that the database is in
- # a invalid format).
-
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or (
- $invalid_list = $invalid_list . $data_file . "<br>\r\n",
- $invalid_warning = 1,
- next
- );
-
- $string_handle->execute();
- @database_info = $string_handle->fetchrow_array();
-
- # Check the style to be used with.
-
- if ($table_style eq 0){
-
- # Use the first style and set the style value
- # to use the next style, the next time the
- # if statement is checked.
-
- $table_style_name = "tablecell1";
- $table_style = 1;
- } else {
-
- # Use the second style and set the style
- # value to use the first style, the next
- # time if statement is checked.
-
- $table_style_name = "tablecell2";
- $table_style = 0;
- }
-
- $database_info[0] = kiriwrite_convert($database_info[0], "normal_display");
- $database_info[1] = kiriwrite_convert($database_info[1], "normal_display");
-
- # Create a friendly name for the database.
-
- $database_filename_length = length($data_file);
- $database_filename_friendly = substr($data_file, 0, $database_filename_length - 3);
-
- # Append the database information to the table.
-
- $pagedata = $pagedata . "<tr><td class=\"" . $table_style_name . "\"><a href=\"kiriwrite.cgi?mode=page&action=view&database=" . $database_filename_friendly . "\">" . $database_info[0] . "</a></td><td class=\"" . $table_style_name . "\">" . $database_info[1] . "</td><td class=\"" . $table_style_name . "\"><a href=\"kiriwrite.cgi?mode=db&action=edit&&database=" . $database_filename_friendly . "\">Edit</a> <a href=\"kiriwrite.cgi?mode=db&action=delete&database=" . $database_filename_friendly . "\">Delete</a> <a href=\"kiriwrite.cgi?mode=compile&action=compile&type=single&database=" . $database_filename_friendly . "\">Compile</a></td></tr>\r\n";
-
- $database_count++;
-
- }
-
- $pagedata = $pagedata . "</table>\r\n<br />";
-
- # Check if there are no valid databases are if there is no
- # valid databases then write a message saying that no
- # valid databases are available.
-
- if ($database_count eq 0){
-
- #
-
- $pagedata = "<h2>Database List</h2><p>";
- $pagedata = $pagedata . "<div class=\"errorbox\">There are no databases that can be used. To create a database click on the Add Database link.</div><p>";
-
- }
-
- # 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 . "<h4>Databases with invalid permissions</h4>";
- $pagedata = $pagedata . "The following databases have invalid permissions set:<br><br>";
- $pagedata = $pagedata . $permissions_list;
-
- }
-
- if ($invalid_warning eq 1){
-
- $pagedata = $pagedata . "<h4>Databases with invalid formats</h4>";
- $pagedata = $pagedata . "The following databases are in a invalid format:<br><br>";
- $pagedata = $pagedata . $invalid_list;
-
- }
-
- return $pagedata; # Return to the main part of the script with the processed information.
-
-}
-
-
-sub kiriwrite_filter_list{
-#################################################################################
-# kiriwrite_filter_list: Lists the filters that will be used when compiling a #
-# webpage. #
-# #
-# Usage: #
-# #
-# kiriwrite_filter_list(); #
-#################################################################################
-
- # Load the needed Perl modules.
-
- use DBI;
-
- # Check if the filters database exists and the
- # permissions for the filters database are
- # valid.
-
- my $database_exists = kiriwrite_fileexists("filters.db");
- my $database_permissions = kiriwrite_filepermissions("filters.db", 1, 0, 0);
- my $filtersdb_notexist = 0;
-
- if ($database_exists eq 1){
-
- # The filters database does not exist so
- # set the value for the filters database
- # not existing to 1.
-
- $filtersdb_notexist = 1;
-
- }
-
- if ($database_permissions eq 1 && $database_exists ne 1){
-
- # The filters database has invalid
- # permissions set, so return an error.
-
- kiriwrite_error("filtersdbpermissions");
-
- }
-
- # Define some variables required for processing the filters list.
-
- my @database_filters;
- my $database_handle;
- my $string_handle;
- my $pagedata = "";
- my $filterdata = "";
- my $filterswarning = "";
- my $filter_id;
- my $filter_id_out;
- my $filter_find;
- my $filter_find_out;
- my $filter_replace;
- my $filter_replace_out;
- my $filter_count = 0;
- my $filter_priority;
- my $filter_priority_out;
- my $filter_style = 0;
- my $filter_find_blank = 0;
- my $filter_style_name = "";
-
- $pagedata = $pagedata . "<h2>View Filters</h2>";
-
- # If the filters database exists then get the list of filters,
- # otherwise write a message saying that the filters database
- # does not exist and will be created when a filter is added.
-
- if ($filtersdb_notexist eq 0){
-
- # Get the SQLite database and get the filters ordered
- # by priority.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=filters.db");
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters ORDER BY priority ASC') or kiriwrite_error("filtersdbinvalidformat");
- $string_handle->execute();
-
- $filterdata = $filterdata . "<table cellspacing=\"0\" cellpadding=\"5\">";
- $filterdata = $filterdata . "<tr><td class=\"tablecellheader\">Priority</td><td class=\"tablecellheader\">Find Setting</td><td class=\"tablecellheader\">Replace Setting</td><td class=\"tablecellheader\">Options</td></tr>";
-
- while (@database_filters = $string_handle->fetchrow_array()){
-
- # Get the values from the from the array.
-
- $filter_id = $database_filters[0];
- $filter_priority = $database_filters[1];
- $filter_find = $database_filters[2];
- $filter_replace = $database_filters[3];
-
- # Convert the values into values that can be displayed.
-
- $filter_id_out = kiriwrite_convert($filter_id, "normal_display");
- $filter_priority_out = kiriwrite_convert($filter_priority, "normal_display");
- $filter_find_out = kiriwrite_convert($filter_find, "normal_display");
- $filter_replace_out = kiriwrite_convert($filter_replace, "normal_display");
-
- # Check which style should be used.
-
- if ($filter_style eq 0){
-
- $filter_style_name = "tablecell1";
- $filter_style = 1;
-
- } else {
-
- $filter_style_name = "tablecell2";
- $filter_style = 0;
-
- }
-
- # Check if the replace filter is blank and if it is
- # then say no replace setting is given.
-
- if (!$filter_replace){
-
- # No replace filter is specified, so write a message
- # saying that there is no replace filter.
-
- $filter_replace_out = "<i>Replace filter is blank.</i>";
-
- }
-
- # Check if the find filter is blank.
-
- if (!$filter_find && $filter_find_blank eq 0){
-
- # No find filter is specified, So write a message saying
- # that one of your find filters is blank and needs to be
- # fixed.
-
- $filterdata = "<b>Warning</b>: One (or more) of your filters has a blank find filter and needs to be fixed.<br><br>" . $filterdata;
-
- }
-
- # Add the filter to the list of filters in the database.
-
- $filterdata = $filterdata . "<tr><td class=\"" . $filter_style_name . "\">" . $filter_priority_out . "</td><td class=\"" . $filter_style_name . "\">" . $filter_find_out . "</td><td class=\"" . $filter_style_name . "\">" . $filter_replace_out . "</td><td class=\"" . $filter_style_name . "\"><a href=\"\"><a href=\"kiriwrite.cgi?mode=filter&action=edit&filter=" . $filter_id_out . "\">Edit</a></a> <a href=\"kiriwrite.cgi?mode=filter&action=delete&filter=" . $filter_id_out . "\">Delete</a></td></tr>";
-
- $filter_count++;
-
- }
-
- $filterdata = $filterdata . "</table>";
-
- # Check if there are filters in the filters database and
- # write a message if there isn't.
-
- if ($filter_count eq 0){
-
- # There are no filters in the filters database.
-
- $filterswarning = "There are no filters available in the filters database. To add a filter, click on the Add Filter link.";
-
- }
-
- }
-
- # Check if the database wasn't found and if it
- # wasn't then write a message saying that the
- # database will be created when a filter is
- # added.
-
- if ($filtersdb_notexist eq 1){
-
- # The filters database doesn't exist so write
- # a message.
-
- $filterswarning = "The filters database does not exist and will be created when a filter is added.";
-
-
- }
-
- # Check if there is a warning message and if
- # there is then write that warning message
- # else write the list of filters.
-
- if ($filterswarning){
-
- $pagedata = $pagedata . "<div class=\"errorbox\">";
- $pagedata = $pagedata . $filterswarning;
- $pagedata = $pagedata . "</div>";
-
- } else {
-
- # The filters database exists so write out the
- # list of filters.
-
- $pagedata = $pagedata . $filterdata;
-
- }
-
- return $pagedata;
-
-}
-
-sub kiriwrite_filter_add{
-#################################################################################
-# kiriwrite_filter_add: Adds a filter to the filter list. #
-# #
-# Usage: #
-# #
-# kiriwrite_filter_add(filterfind, filterreplace, filterpriority, #
-# filternotes, [confirm]); #
-# #
-# filterfind Specifies the new word(s) to find. #
-# filterreplace Specifies the new word(s) to replace. #
-# filterpriority Specifies the new priority to use. #
-# filternotes Specifies the new notes to use. #
-# confirm Confirms the action to add a filter. #
-#################################################################################
-
- # Get the values that have been passed to the subroutine.
-
- my ($filter_new_find, $filter_new_replace, $filter_new_priority, $filter_new_notes, $confirm) = @_;
-
- # Load the needed Perl modules.
-
- use DBI;
-
- # Check the confirm value to make sure it is no more than
- # one character long.
-
- kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
-
- # Define the page data value for later.
-
- my $pagedata = "";
-
- if (!$confirm){
-
- # The confirm value is undefined, so set the
- # value of the confirm integer to '0'.
-
- $confirm = 0;
-
- }
-
- if ($confirm eq 1){
-
- # The confirm integer is '1', so add the word
- # to the filter list.
-
- # First, check the variables recieved are UTF8
- # copliant.
-
- kiriwrite_variablecheck($filter_new_find, "utf8", 0, 0);
- kiriwrite_variablecheck($filter_new_replace, "utf8", 0, 0);
- kiriwrite_variablecheck($filter_new_priority, "utf8", 0, 0);
-
- # Convert the UTF8 values so that the length can
- # checked properly.
-
- $filter_new_find = kiriwrite_utf8convert($filter_new_find);
- $filter_new_replace = kiriwrite_utf8convert($filter_new_replace);
- $filter_new_priority = kiriwrite_utf8convert($filter_new_priority);
-
- # Check if the find filter is blank and return an error
- # if it is.
-
- if (!$filter_new_find){
-
- # The find filter given is blank so return an
- # error.
-
- kiriwrite_error("blankfindfilter");
-
- }
-
- if (!$filter_new_priority){
-
- # The filter priority is blank so set it
- # to 1.
-
- $filter_new_priority = 1;
-
- }
-
- # Check the length and contents of the values given
- # to make sure they are valid.
-
- my $filterfind_maxlength_check = kiriwrite_variablecheck($filter_new_find, "maxlength", 1024, 1);
- my $filterreplace_maxlength_check = kiriwrite_variablecheck($filter_new_replace, "maxlength", 1024, 1);
- my $filterpriority_maxlength_check = kiriwrite_variablecheck($filter_new_priority, "maxlength", 5, 1);
- my $filterpriority_numbers_check = kiriwrite_variablecheck($filter_new_priority, "numbers", 0, 1);
-
- # Check if the result of the tests to see if they
- # are valid.
-
- if ($filterfind_maxlength_check eq 1){
-
- # The find filter is too long, so return
- # an error.
-
- kiriwrite_error("findfiltertoolong");
-
- }
-
- if ($filterreplace_maxlength_check eq 1){
-
- # The replace filter is too long, so
- # return an error.
-
- kiriwrite_error("replacefiltertoolong");
-
- }
-
- if ($filterpriority_maxlength_check eq 1){
-
- # The length of the filter priority
- # given is too long, so return an
- # error.
-
- kiriwrite_error("filterprioritytoolong");
-
- }
-
- if ($filterpriority_numbers_check eq 1){
-
- # The priority of the filter given
- # contains characters other than
- # numbers.
-
- kiriwrite_error("filterpriorityinvalidchars");
-
- }
-
- # Check if the filter priority is less than 1
- # and more than 10000 and return an error
- # if it is.
-
- if ($filter_new_priority < 1 || $filter_new_priority > 50000){
-
- # The filter priority is less than 1 and
- # more than 10000, so return an error.
-
- kiriwrite_error("filterpriorityinvalid");
-
- }
-
- # Define some variables for later on.
-
- my @database_filters;
- my @database_check;
-
- my $database_handle;
- my $string_handle;
- my $chk_database_handle;
- my $chk_string_handle;
-
- my $filters_exist;
- my $filters_permissions;
- my $filters_count = 0;
- my $blankid_found = 0;
- my $current_id = 0;
- my $next_id = 0;
- my $filter_exists = 0;
-
- my $first_filter = 0;
-
- my $new_id;
-
- # Check if the filters database exists, has valid
- # permission settings and if it doesn't create
- # the database first.
-
- $filters_exist = kiriwrite_fileexists("filters.db");
-
- if ($filters_exist eq 0){
-
- # The filters database does exist, so don't
- # bother trying to create another one.
-
- $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 1, 1);
-
- if ($filters_permissions eq 1){
-
- # The filters database has invalid permissions so
- # return an error.
-
- kiriwrite_error("filtersdbpermissions");
-
- }
-
- # Load the SQLite database.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=filters.db");
-
- } else {
-
- # The filters database does not exist, so create
- # the filters database.
-
- # Check if the filters database can really be
- # created.
-
- my $directory_permissions = kiriwrite_filepermissions(".", 1, 1, 0);
-
- if ($directory_permissions eq 1){
-
- # The filters database cannot be created because of invalid directory
- # permissions so return an error.
-
- kiriwrite_error("filtersdatabasefilenotcreated");
- }
-
- # Create the filters database.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=filters.db");
- $string_handle = $database_handle->prepare('create table kiriwrite_filters(
- id int(7) primary key,
- priority int(5),
- findsetting varchar(1024),
- replacesetting varchar(1024),
- notes text
- );
- ');
- $string_handle->execute();
-
- }
-
- $chk_database_handle = DBI->connect("dbi:SQLite:dbname=filters.db");
-
- # Find the lowest identification number available.
-
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters ORDER BY id ASC') or kiriwrite_error("filtersdbinvalidformat");;
- $string_handle->execute();
-
- # Process each filter to find a blank identification
- # number.
-
- while(@database_filters = $string_handle->fetchrow_array()){
-
- # Check the next filter identification number to see
- # if it exists and use that identification number if
- # it doesn't exist.
-
- $current_id = $database_filters[0];
- $next_id = $current_id + 1;
- $chk_string_handle = $chk_database_handle->prepare('SELECT * FROM kiriwrite_filters WHERE id = \'' . $next_id . '\' LIMIT 1');
- $chk_string_handle->execute();
-
- while(@database_check = $chk_string_handle->fetchrow_array()){
-
- $filter_exists = 1;
-
-
- }
-
- if ($filter_exists eq 0 && $blankid_found eq 0){
-
- $new_id = $next_id;
- $blankid_found = 1;
-
- }
-
- # Check if this is the first filter and the current
- # identification number is more than 1 and if it
- # is then set the new identification number to 1.
-
- if ($first_filter eq 0 && $current_id > 1 && $blankid_found eq 0){
-
- # The first filter has an identification
- # number more than 1, so set the new
- # identification number to 1.
-
- $new_id = 1;
- $blankid_found = 1;
- $first_filter = 1;
-
-
- }
-
- # Set the next identification number as the
- # current identification number add one and
- # increment the filters count.
-
- $first_filter = 1;
- $filters_count++;
- $filter_exists = 0;
-
- }
-
- # Check if there are any filters in the database
- # and if not set the identification number to 1.
-
- if ($filters_count eq 0){
-
- # No filters were really in the filters
- # database.
-
- $new_id = 1;
-
- }
-
- # Convert the values so that they can be processed
- # properly.
-
- my $filter_new_id_sql = kiriwrite_convert($new_id, "kiriwrite");
- my $filter_new_priority_sql = kiriwrite_convert($filter_new_priority, "kiriwrite");
- my $filter_new_find_sql = kiriwrite_convert($filter_new_find, "kiriwrite");
- my $filter_new_replace_sql = kiriwrite_convert($filter_new_replace, "kiriwrite");
- my $filter_new_notes_sql = kiriwrite_convert($filter_new_notes, "kiriwrite");
-
- # Add the new filter to the filters database.
-
- $string_handle = $database_handle->prepare('INSERT INTO kiriwrite_filters VALUES(
- \'' . $filter_new_id_sql . '\',
- \'' . $filter_new_priority_sql . '\',
- \'' . $filter_new_find_sql . '\',
- \'' . $filter_new_replace_sql . '\',
- \'' . $filter_new_notes_sql . '\'
- )');
- $string_handle->execute();
-
- # Write out a message saying that the filter was added to the
- # filters database.
-
- $pagedata = $pagedata . "<h2>Filter Added</h2>";
- $pagedata = $pagedata . "The filter was added sucessfully to the filters list.<br><br>";
- $pagedata = $pagedata . "<a href=\"kiriwrite.cgi?mode=filter\">Return to the filters list.</a>";
-
- 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 = "<h2>Add Filter</h2>";
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"filter\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"add\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"confirm\" value=\"1\">";
- $pagedata = $pagedata . "<table cellspacing=0 cellpadding=5>";
- $pagedata = $pagedata . "<Tr><td class=\"tablecellheader\">Setting</td><td class=\"tablecellheader\">Value</td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Find...</td><td class=\"tablecell2\"><input type=\"input\" name=\"findword\" size=\"64\" maxlength=\"1024\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Replace with...</td><td class=\"tablecell2\"><input type=\"input\" name=\"replaceword\" size=\"64\" maxlength=\"1024\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Filter Priority</td><td class=\"tablecell2\"><input type=\"input\" name=\"priority\" size=\"5\" maxlength=\"5\"><br><ul><li>If no filter priority is specified, the filter priority will be set to 1.</li></ul></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Filter Notes</td><td class=\"tablecell2\"><textarea name=\"notes\" cols=\"50\" rows=\"10\"></textarea></td></tr>";
- $pagedata = $pagedata . "</table>";
- $pagedata = $pagedata . "<br>";
- $pagedata = $pagedata . "<input type=\"submit\" value=\"Add Filter\"> | <input type=\"reset\" value=\"Clear values\">";
- $pagedata = $pagedata . "</form>";
-
- return $pagedata;
-
-}
-
-sub kiriwrite_filter_edit{
-#################################################################################
-# kiriwrite_filter_edit: Edits a filter from the filter list. #
-# #
-# Usage: #
-# #
-# kiriwrite_filter_edit(filternumber, newfilterfind, newfilterreplace, #
-# newfilterpriority, newfilternotes, confirm); #
-# #
-# filterid Specifies the filter number (line number) in the #
-# filters database. #
-# newfilterfind Specifies the new word to find. #
-# newfilterreplace Specifies the new word to replace. #
-# newfilterpriority Specifies the new filter priority. #
-# newfilternotes Specifies the new filter notes. #
-# confirm Confirms the action to edit a filter. #
-#################################################################################
-
- # Get the values that have been passed to the subroutine.
-
- my ($filter_id, $filter_new_find, $filter_new_replace, $filter_new_priority, $filter_new_notes, $confirm) = @_;
-
- # Load the needed Perl modules.
-
- use DBI;
-
- # Check the confirm value to make sure it is no more than
- # one character long.
-
- kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
-
- # Define the page data value for later.
-
- my $pagedata = "";
-
- # Check if the confirm value is blank and if it is
- # srt the confirm value to 0.
-
- if (!$confirm){
-
- # The confirm value does not have any value
- # set so set it to 0.
-
- $confirm = 0;
-
- }
-
- # Check if the filter identification number is blank,
- # contains characters other than numbers and is more
- # than seven characters long.
-
- if (!$filter_id){
-
- # The filter identification number is blank,
- # so return an error.
-
- kiriwrite_error("filteridblank");
-
- }
-
- my $filter_id_numbers_check = kiriwrite_variablecheck($filter_id, "numbers", 0, 1);
-
- if ($filter_id_numbers_check eq 1){
-
- # The filter identification number contains
- # characters other than numbers, so return
- # an error.
-
- kiriwrite_error("filteridinvalid");
-
- }
-
- my $filter_id_maxlength_check = kiriwrite_variablecheck($filter_id, "maxlength", 7, 1);
-
- if ($filter_id_maxlength_check eq 1){
-
- # The filter identification number given
- # is more than seven characters long, so
- # return an error.
-
- kiriwrite_error("filteridtoolong");
-
- }
-
- # Check if the filters database exists and the
- # permissions for it are valid.
-
- my $filters_exists = kiriwrite_fileexists("filters.db");
-
- if ($filters_exists eq 1){
-
- # The filters database does not exist, so
- # return an error.
-
- kiriwrite_error("filtersdbmissing");
-
- }
-
- my $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 0);
-
- if ($filters_permissions eq 1){
-
- # The filters database has invalid permissions
- # set, so return an error.
-
- kiriwrite_error("filtersdbpermissions");
-
- }
-
- # Define some variables for later.
-
- my $database_handle;
- my $string_handle;
- my $filter_id_sql = kiriwrite_convert($filter_id, "kiriwrite");
- my $filter_id_out = kiriwrite_convert($filter_id, "normal_display");
- my $filter_priority;
- my $filter_priority_sql;
- my $filter_priority_out;
- my $filter_find;
- my $filter_find_sql;
- my $filter_find_out;
- my $filter_replace;
- my $filter_replace_sql;
- my $filter_replace_out;
- my $filter_notes;
- my $filter_notes_sql;
- my $filter_notes_out;
-
- # Check if the action to edit a filter has been
- # confirmed.
-
- # Load the SQLite database.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=filters.db");
-
- if ($confirm eq 1){
-
- # The action to edit a filter has been confirmed so
- # edit the selected filter.
-
- # Check if changes to the database can be written to.
-
- $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 1);
-
- if ($filters_permissions eq 1){
-
- # The filters database has invalid permissions
- # set, so return an error.
-
- kiriwrite_error("filtersdbpermissions");
-
- }
-
- # Define some variables for later.
-
- my @database_filter;
- my $filter_exists = 0;
-
- # Check if the filter exists.
-
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters WHERE id = \'' . $filter_id_sql . '\' LIMIT 1') or kiriwrite_error("filtersdbinvalidformat");
- $string_handle->execute();
-
- while (@database_filter = $string_handle->fetchrow_array()){
-
- # The filter exists.
-
- $filter_exists = 1;
-
- }
-
- # Check if the filter really doesn't exist.
-
- if ($filter_exists eq 0){
-
- # The filter really does not exist so
- # return an error.
-
- kiriwrite_error("filterdoesnotexist");
-
- }
-
- # First, check the variables recieved are UTF8
- # copliant.
-
- kiriwrite_variablecheck($filter_new_find, "utf8", 0, 0);
- kiriwrite_variablecheck($filter_new_replace, "utf8", 0, 0);
- kiriwrite_variablecheck($filter_new_priority, "utf8", 0, 0);
- kiriwrite_variablecheck($filter_new_notes, "utf8", 0, 0);
-
- # Convert the UTF8 values so that the length can
- # checked properly.
-
- $filter_find = kiriwrite_utf8convert($filter_new_find);
- $filter_replace = kiriwrite_utf8convert($filter_new_replace);
- $filter_priority = kiriwrite_utf8convert($filter_new_priority);
- $filter_notes = kiriwrite_utf8convert($filter_new_notes);
-
- # Check if the find filter is blank and return an error
- # if it is.
-
- if (!$filter_new_find){
-
- # The find filter given is blank so return an
- # error.
-
- kiriwrite_error("blankfindfilter");
-
- }
-
- if (!$filter_new_priority){
-
- # The filter priority is blank so set it
- # to 1.
-
- $filter_new_priority = 1;
-
- }
-
- # Check the length and contents of the values given
- # to make sure they are valid.
-
- my $filterfind_maxlength_check = kiriwrite_variablecheck($filter_new_find, "maxlength", 1024, 1);
- my $filterreplace_maxlength_check = kiriwrite_variablecheck($filter_new_replace, "maxlength", 1024, 1);
- my $filterpriority_maxlength_check = kiriwrite_variablecheck($filter_new_priority, "maxlength", 5, 1);
- my $filterpriority_numbers_check = kiriwrite_variablecheck($filter_new_priority, "numbers", 0, 1);
-
- # Check if the result of the tests to see if they
- # are valid.
-
- if ($filterfind_maxlength_check eq 1){
-
- # The find filter is too long, so return
- # an error.
-
- kiriwrite_error("findfiltertoolong");
-
- }
-
- if ($filterreplace_maxlength_check eq 1){
-
- # The replace filter is too long, so
- # return an error.
-
- kiriwrite_error("replacefiltertoolong");
-
- }
-
- if ($filterpriority_maxlength_check eq 1){
-
- # The length of the filter priority
- # given is too long, so return an
- # error.
-
- kiriwrite_error("filterprioritytoolong");
-
- }
-
- if ($filterpriority_numbers_check eq 1){
-
- # The priority of the filter given
- # contains characters other than
- # numbers.
-
- kiriwrite_error("filterpriorityinvalidchars");
-
- }
-
- # Check if the filter priority is less than 1
- # and more than 10000 and return an error
- # if it is.
-
- if ($filter_new_priority < 1 || $filter_new_priority > 50000){
-
- # The filter priority is less than 1 and
- # more than 10000, so return an error.
-
- kiriwrite_error("filterpriorityinvalid");
-
- }
-
- # Convert the new information about the filter given
- # so that it can be added to the SQL query properly.
-
- $filter_find_sql = kiriwrite_convert($filter_find, "kiriwrite");
- $filter_replace_sql = kiriwrite_convert($filter_replace, "kiriwrite");
- $filter_priority_sql = kiriwrite_convert($filter_priority, "kiriwrite");
- $filter_notes_sql = kiriwrite_convert($filter_notes, "kiriwrite");
-
- # Edit the filter using the information provided.
-
- $string_handle = $database_handle->prepare('UPDATE kiriwrite_filters SET priority = \'' . $filter_priority_sql . '\', findsetting = \'' . $filter_find_sql . '\', replacesetting = \'' . $filter_replace_sql . '\', notes = \'' . $filter_notes_sql . '\' WHERE id = \'' . $filter_id_sql . '\'');
- $string_handle->execute();
-
- # Write a message saying that the filter was edited.
-
- $pagedata = $pagedata . "<h2>Filter edited</h2>";
- $pagedata = $pagedata . "The selected filter was edited.<br><br>";
- $pagedata = $pagedata . "<a href=\"kiriwrite.cgi?mode=filter\">Return to the list of filters.</a>";
-
- return $pagedata;
-
- } elsif ($confirm eq 0){
-
- # The action to edit a filter has not been confirmed
- # so write a form for editing the filter with.
-
- # Define some variables for later.
-
- my @database_filter;
- my $filter_exists = 0;
-
- # Check if the filter exists.
-
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters WHERE id = \'' . $filter_id_sql . '\' LIMIT 1') or kiriwrite_error("filtersdbinvalidformat");
- $string_handle->execute();
-
- while (@database_filter = $string_handle->fetchrow_array()){
-
- # The filter exists.
-
- $filter_exists = 1;
-
- }
-
- # Check if the filter really doesn't exist.
-
- if ($filter_exists eq 0){
-
- # The filter really does not exist so
- # return an error.
-
- kiriwrite_error("filterdoesnotexist");
-
- }
-
- # Get the filter information.
-
- $string_handle->execute();
-
- @database_filter = $string_handle->fetchrow_array();
-
- # Get the required information.
-
- $filter_priority = $database_filter[1];
- $filter_find = $database_filter[2];
- $filter_replace = $database_filter[3];
- $filter_notes = $database_filter[4];
-
- $filter_priority_out = kiriwrite_convert($filter_priority, "normal_display");
- $filter_find_out = kiriwrite_convert($filter_find, "normal_display");
- $filter_replace_out = kiriwrite_convert($filter_replace, "normal_display");
- $filter_notes_out = kiriwrite_convert($filter_notes, "normal_display");
-
- # Write out the form.
-
- $pagedata = $pagedata . "<h2>Edit Filter</h2>";
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"filter\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"edit\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"filter\" value=\"" . $filter_id_out . "\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"confirm\" value=\"1\">";
- $pagedata = $pagedata . "<table cellpadding=\"5\" cellspacing=\"0\">";
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Setting</td><td class=\"tablecellheader\">Value</td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Find...</td><td class=\"tablecell2\"><input type=\"text\" name=\"filterfind\" size=\"64\" maxlength=\"1024\" value=\"" . $filter_find_out . "\"></td><tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Replace With...</td><td class=\"tablecell2\"><input type=\"text\" name=\"filterreplace\" size=\"64\" maxlength=\"1024\" value=\"" . $filter_replace_out . "\"></td><tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Filter Priority</td><td class=\"tablecell2\"><input type=\"text\" name=\"priority\" size=\"5\" maxlength=\"5\" value=\"" . $filter_priority_out . "\"><ul><li>If no filter priority is specified, the filter priority will be set to 1.</li></ul></td><tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Filter Notes</td><td class=\"tablecell2\"><textarea name=\"notes\" rows=\"10\" cols=\"50\">" . $filter_notes_out . "</textarea></td><tr>";
- $pagedata = $pagedata . "</table><br>";
- $pagedata = $pagedata . "<input type=\"submit\" value=\"Edit filter\"> | <input type=\"reset\" value=\"Restore filter settings\"> | <a href=\"kiriwrite.cgi?mode=filter\">Return to the filter database.</a>";
- $pagedata = $pagedata . "</form>";
-
- return $pagedata;
-
- } else {
-
- # A confirm value other than 0 or 1 has been
- # specified, so return an error.
-
- kiriwrite_error("invalidvalue");
-
- }
-
-}
-
-sub kiriwrite_filter_delete{
-#################################################################################
-# kiriwrite_filter_delete: Deletes a filter from the filter list. #
-# #
-# Usage: #
-# #
-# kiriwrite_filter_delete(number, confirm); #
-# #
-# number Specifies the filter line number to delete. #
-# confirm Confirms the deletion of the selected filter. #
-#################################################################################
-
- # Get the values that were passed to this subroutine.
-
- my ($filter_id, $confirm) = @_;
-
- # Load the needed Perl modules.
-
- use DBI;
-
- # Check the confirm value to make sure it is no more than
- # one character long.
-
- kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
-
- # Define the page data value for later.
-
- my $pagedata = "";
-
- # Check if the confirm value is blank and if it is
- # srt the confirm value to 0.
-
- if (!$confirm){
-
- # The confirm value does not have any value
- # set so set it to 0.
-
- $confirm = 0;
-
- }
-
- # Check if the filter identification number is blank,
- # contains characters other than numbers and is more
- # than seven characters long.
-
- if (!$filter_id){
-
- # The filter identification number is blank,
- # so return an error.
-
- kiriwrite_error("filteridblank");
-
- }
-
- my $filter_id_numbers_check = kiriwrite_variablecheck($filter_id, "numbers", 0, 1);
-
- if ($filter_id_numbers_check eq 1){
-
- # The filter identification number contains
- # characters other than numbers, so return
- # an error.
-
- kiriwrite_error("filteridinvalid");
-
- }
-
- my $filter_id_maxlength_check = kiriwrite_variablecheck($filter_id, "maxlength", 7, 1);
-
- if ($filter_id_maxlength_check eq 1){
-
- # The filter identification number given
- # is more than seven characters long, so
- # return an error.
-
- kiriwrite_error("filteridtoolong");
-
- }
-
- # Check if the filters database exists and the
- # permissions for it are valid.
-
- my $filters_exists = kiriwrite_fileexists("filters.db");
-
- if ($filters_exists eq 1){
-
- # The filters database does not exist, so
- # return an error.
-
- kiriwrite_error("filtersdbmissing");
-
- }
-
- my $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 0);
-
- if ($filters_permissions eq 1){
-
- # The filters database has invalid permissions
- # set, so return an error.
-
- kiriwrite_error("filtersdbpermissions");
-
- }
-
- # Define some values for later.
-
- my @database_filter;
- my $filterid_sql = kiriwrite_convert($filter_id, "kiriwrite");
- my $filterid_out = kiriwrite_convert($filter_id, "normal_display");
- my $database_handle;
- my $string_handle;
- my $filter_exists = 0;
-
- # Load the SQLite database.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=filters.db");
-
- # Check if the confirm integer has a value of '1'.
-
- if ($confirm eq 1){
-
- # The action to delete a filter has been confirmed.
-
- # Check the permissions of the filters database is
- # valid (for writing).
-
- $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 1);
-
- if ($filters_permissions eq 1){
-
- # The filters database has invalid permissions
- # set, so return an error.
-
- kiriwrite_error("filtersdbpermissions");
-
- }
-
- # Check if the filter exists.
-
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters WHERE id = \'' . $filterid_sql . '\' LIMIT 1') or kiriwrite_error("filtersdbinvalidformat");
- $string_handle->execute();
-
- while (@database_filter = $string_handle->fetchrow_array()){
-
- # The filter exists.
-
- $filter_exists = 1;
-
- }
-
- # Check if the filter really doesn't exist.
-
- if ($filter_exists eq 0){
-
- # The filter really does not exist so
- # return an error.
-
- kiriwrite_error("filterdoesnotexist");
-
- }
-
- # Delete the filter from the filters database.
-
- $string_handle = $database_handle->prepare('DELETE FROM kiriwrite_filters where id = \'' . $filterid_sql . '\'') or kiriwrite_error("filtersdbinvalidformat");
- $string_handle->execute();
-
- # Write a message saying that the filter was deleted
- # from the filters database.
-
- $pagedata = $pagedata . "<h2>Delete Filter</h2>";
- $pagedata = $pagedata . "The selected filter was deleted from the filters database.<br><br>";
- $pagedata = $pagedata . "<a href=\"kiriwrite.cgi?mode=filter\">Return to the filters database.</a>";
-
- } elsif ($confirm eq 0) {
-
- # The action to delete a filter has not been confirmed so write
- # a form asking for the user to confirm the deletion of the
- # filter.
-
- # Check if the filter exists.
-
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters WHERE id = \'' . $filterid_sql . '\' LIMIT 1') or kiriwrite_error("filtersdbinvalidformat");
- $string_handle->execute();
-
- while (@database_filter = $string_handle->fetchrow_array()){
-
- # The filter exists.
-
- $filter_exists = 1;
-
- }
-
- # Check if the filter really doesn't exist.
-
- if ($filter_exists eq 0){
-
- # The filter really does not exist so
- # return an error.
-
- kiriwrite_error("filterdoesnotexist");
-
- }
-
- # The confirm integer is '0', so continue write out
- # a form asking the user to confirm the deletion
- # pf the filter.
-
- $pagedata = $pagedata . "<h2>Confirm deletion</h2>";
- $pagedata = $pagedata . "Are you sure you want to delete the selected filter?<br><br>";
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"filter\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"delete\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"filter\" value=\"" . $filterid_out . "\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"confirm\" value=\"1\">";
- $pagedata = $pagedata . "<input type=\"submit\" value=\"Yes, delete the selected filter\"> | <a href=\"kiriwrite.cgi?mode=filter\">No, return to the filters list.</a>";
- $pagedata = $pagedata . "</form>";
-
- } else {
-
- kiriwrite_error("invalidvalue");
-
- }
-
- return $pagedata;
-
-}
-
-sub kiriwrite_compile_makepages{
-#################################################################################
-# kiriwrite_compile_makepages: Compile the selected pages and place them in the #
-# specified output directory. #
-# #
-# Usage: #
-# #
-# kiriwrite_compile_makepages(type, selectedlist, confirm); #
-# #
-# type Specifies if single or multiple databases are to be compiled. #
-# confirm Specifies if the action to compile the databases should really #
-# be done. #
-# selectedlist Specifies the databases to compile from as an array. #
-#################################################################################
-
- # Get the values that have been passed to the subroutine.
-
- my ($type, $confirm, @selectedlist) = @_;
-
- # Check if the confirm value is more than one
- # character long.
-
- kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
-
- # Check if the confirm value is blank and if it
- # is then set the confirm value to 0.
-
- if (!$confirm){
-
- # The confirm value is blank, so set the
- # confirm value to 0.
-
- $confirm = 0;
-
- }
-
- # Check if there are any databases selected
- # and return an error if there isn't.
-
- if (!@selectedlist){
-
- # There are no databases in the array
- # so return an error.
-
- kiriwrite_error("nodatabaseselected");
-
- }
-
- # Check if the type given is no more than
- # 7 characters long.
-
- my $type_maxlength_check = kiriwrite_variablecheck($type, "maxlength", 8, 1);
-
- if ($type_maxlength_check eq 1){
-
- # The type length given is too long so
- # return an error.
-
- kiriwrite_error("variabletoolong");
-
- }
-
- # Define the following values for later.
-
- my $pagedata = "";
-
- # Check if the action to compile the databases
- # has been confirmed.
-
- if ($confirm eq 1){
-
- # The action to compile the datavases has
- # been confirmed.
-
- # Define some variables for later.
-
- my %templatefiles;
- my @databaseinfo;
- my @databasepages;
- my @filterslist;
- my @findfilter;
- my @replacefilter;
- my @templateslist;
- my @pagedirectories;
- my $messages = "";
- my $warning_count = 0;
- my $error_count = 0;
- my $pages_count = 0;
- my $filters_count = 0;
- my $filters_find_blank_warning = 0;
- my $database_handle;
- my $string_handle;
- my $filter_find;
- my $filter_replace;
- my $database;
- my $database_out;
- my $database_name;
- my $database_name_out;
- my $page_filename;
- my $page_filename_out;
- my $page_filename_check;
- my $page_filename_char = "";
- my $page_filename_directory;
- my $page_filename_length = 0;
- my $page_filename_seek = 0;
- my $page_filename_dircount = 0;
- my $page_directory_name;
- my $page_directory_path;
- my $page_name;
- my $page_name_out;
- my $page_description;
- my $page_section;
- my $page_template;
- my $page_template_out;
- my $page_content;
- my $page_settings;
- my $page_lastmodified;
- my $page_title;
- my $page_final;
- my $page_autosection;
- my $page_autotitle;
- my $database_filename_check = 0;
- my $database_maxlength_check = 0;
- my $output_exists = 0;
- my $output_permissions = 0;
- my $filters_exists = 0;
- my $filters_permissions = 0;
- my $filters_skip = 0;
- my $templates_exists = 0;
- my $templates_permissions = 0;
- my $templates_skip = 0;
- my $database_exists = 0;
- my $database_permissions = 0;
- my $information_prefix = "[Information] ";
- my $error_prefix = "[Error] ";
- my $warning_prefix = "[Warning] ";
-
- # Check if the output directory exists and has
- # valid permissions set.
-
- $output_exists = kiriwrite_fileexists($kiriwrite_config{'directory_data_output'});
-
- if ($output_exists ne 0){
-
- # The output directory does not exist so
- # return an error.
-
- kiriwrite_error("outputdirectorymissing");
-
- }
-
- $output_permissions = kiriwrite_filepermissions($kiriwrite_config{'directory_data_output'}, 1, 1);
-
- if ($output_permissions ne 0){
-
- # The output directory has invalid
- # permissions set so return an error.
-
- kiriwrite_error("outputdirectoryinvalidpermissions");
-
- }
-
- # Check if the filters database exists and has valid
- # permissions set.
-
- $filters_exists = kiriwrite_fileexists("filters.db");
-
- if ($filters_exists ne 0){
-
- # The filters database does not exist
- # so write a warning.
-
- $messages = $messages . $warning_prefix . "The filters database does not exist. No filters will be used." . "<br>";
- $filters_skip = 1;
- $warning_count++;
-
- }
-
- $filters_permissions = kiriwrite_filepermissions("filters.db", 1, 0);
-
- if ($filters_permissions ne 0 && $filters_exists eq 0){
-
- # The filters database has invalid
- # permissions set so write a warning.
-
- $messages = $messages . $warning_prefix . "The filters database has invalid permissions set. No filters will be used." . "<br>";
- $filters_skip = 1;
- $warning_count++;
-
- }
-
- # Load the filters database (if the filters skip
- # value isn't set to 1).
-
- if ($filters_skip eq 0){
-
- # Load the filters database.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=filters.db");
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_filters ORDER BY priority ASC') or $messages = $messages . $error_prefix . "The filters database is in an invalid format. No filters will be used." . "<br>", $error_count++, $filters_skip = 1;
-
- # Check if the filters skip value is set to 0
- # before executing the query.
-
- if ($filters_skip eq 0){
-
- # Get the filters.
-
- $string_handle->execute();
- while (@filterslist = $string_handle->fetchrow_array()){
-
- # Check if the find filter is blank and
- # if it is then write a warning message.
-
- if (!$filterslist[2]){
-
- if ($filters_find_blank_warning ne 1){
-
- $messages = $messages . $warning_prefix . "One (or more) of the find filters from the filters database is blank." . "<br>";
- $filters_find_blank_warning = 1;
- }
- next;
-
- } else {
-
- # Add each find and replace filter.
-
- $findfilter[$filters_count] = $filterslist[2];
- $replacefilter[$filters_count] = $filterslist[3];
-
- }
-
- $filters_count++;
-
- }
- $messages = $messages . $information_prefix . "The filters database has been loaded." . "<br>";
-
- }
-
- }
-
- # Check if the templates database exists and has
- # valid permissions set.
-
- $templates_exists = kiriwrite_fileexists("templates.db");
-
- if ($templates_exists ne 0){
-
- # The template database does not exist
- # so write a warning.
-
- $messages = $messages . $warning_prefix . "The templates database does not exist. Pages will be compiled without templates being used." . "<br>";
- $templates_skip = 1;
- $warning_count++;
-
- }
-
- $templates_permissions = kiriwrite_filepermissions("templates.db", 1, 0);
-
- if ($templates_permissions ne 0 && $templates_exists eq 0){
-
- # The template database has invalid
- # permissions set so write a warning.
-
- $messages = $messages . $warning_prefix . "The templates database has invalid permissions set. Pages will be compiled without templates being used." . "<br>";
- $templates_skip = 1;
- $warning_count++;
-
- }
-
- # Load the templates database (if the template
- # skip value isn't set to 1).
-
- if ($templates_skip eq 0){
-
- # Load the templates database.
-
- $database_handle = DBI->connect('dbi:SQLite:dbname=templates.db');
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_templates') or $messages = $messages . $error_prefix . "The templates database is in an invalid format. Pages will be compiled without templates being used." . "<br>", $error_count++, $templates_skip = 1;
-
- # Check if the templates skip value is set to
- # 0 before executing the query.
-
- if ($templates_skip eq 0){
-
- # Get the templates and place them into the
- # template files hash.
-
- $string_handle->execute();
- while(@templateslist = $string_handle->fetchrow_array()){
-
- # Place each template file into the hash.
-
- $templatefiles{$templateslist[0]}{template} = $templateslist[3];
- $templatefiles{$templateslist[0]}{valid} = 1;
-
- }
- $messages = $messages . $information_prefix . "The templates database has been loaded." . "<br>";
-
- }
-
- }
-
- # Process each database.
-
- foreach $database (@selectedlist){
-
- # Check if the database filename and length
- # are valid.
-
- $messages = $messages . "<hr>";
-
- $database_out = kiriwrite_convert($database, "normal_display");
- $database_filename_check = kiriwrite_variablecheck($database, "page_filename", "", 1);
- $database_maxlength_check = kiriwrite_variablecheck($database, "maxlength", 64, 1);
-
- if ($database_filename_check ne 0){
-
- # The database filename is invalid, so process
- # the next database.
-
- $messages = $messages . $error_prefix . "The database filename '" . $database_out . ".db' is invalid. Skipping this database..." . "<br>";
- $error_count++;
- next;
-
- }
-
- if ($database_maxlength_check ne 0){
-
- # The database file is too long, so process the
- # next database.
-
- $messages = $messages . $error_prefix . "The database with the filename '" . $database_out . ".db' is too long. Skipping this database..." . "<br>";
- $error_count++;
- next;
-
- }
-
- # Check if the database exists and has valid
- # permissions set.
-
- $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db');
-
- if ($database_exists ne 0){
-
- # The database does not exist so process
- # the next database.
-
- $messages = $messages . $error_prefix . "The database with the filename '" . $database_out . ".db' does not exist. Skipping this database..." . "<br>";
- $error_count++;
- next;
-
- }
-
- $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $database . '.db', 1, 0);
-
- if ($database_permissions ne 0){
-
- # The permissions for the database are invalid
- # so process the next database.
-
- $messages = $messages . $error_prefix . "The database with the filename '" . $database_out . ".db' has invalid permissions set. Skipping this database..." . "<br>";
- $error_count++;
- next;
-
- }
-
- # Load the SQLite database.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $database . '.db');
-
- # Get the database name.
-
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or $messages = $messages . $error_prefix . "The database with the filename '" . $database_out . ".db' is in an invalid format. Skipping this database..." . "<br>", 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..." . "<br>";
-
- # Get the pages in the database.
-
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_pages') or $messages = $messages . $error_prefix . "The database with the filename '" . $database_out . ".db' is in an invalid format. Skipping this database..." . "<br>", next;
- $string_handle->execute();
-
- while(@databasepages = $string_handle->fetchrow_array()){
-
- # Convert the values so that they can be
- # used in the messages list.
-
- $page_filename = $databasepages[0];
- $page_name = $databasepages[1];
- $page_description = $databasepages[2];
- $page_section = $databasepages[3];
- $page_template = $databasepages[4];
- $page_content = $databasepages[5];
- $page_settings = $databasepages[6];
- $page_lastmodified = $databasepages[7];
-
- $page_filename_out = kiriwrite_convert($page_filename, "normal_display");
- $page_name_out = kiriwrite_convert($page_name, "normal_display");
- $page_template_out = kiriwrite_convert($page_template, "normal_display");
-
- # Check if the filename is valid.
-
- $page_filename_check = kiriwrite_variablecheck($page_filename, "page_filename");
-
- if ($page_filename_check ne 0){
-
- # The file name is not valid so write a
- # error and process the next page.
-
- $messages = $messages . $error_prefix . "The page '" . $page_name_out . "' has an invalid filename. Page skipped." . "<br>";
- next;
-
- }
-
- # Check if the template with the filename does not exist
- # in the template files hash and write a message and
- # process the next page.
-
- if (!$templatefiles{$page_template}{valid} && $page_template ne "!none" && $templates_skip eq 0){
-
- $messages = $messages . $error_prefix . "The template with the filename '" . $page_template_out . "' for '" . $page_name_out . "' (" . $page_filename_out . ") does not exist." . "<br>";
- $error_count++;
- next;
-
- $page_final = $page_content;
-
- } elsif ($page_template eq "!none"){
-
- $page_final = $page_content;
-
- } else {
-
- $page_final = $templatefiles{$page_template}{template};
- $page_final =~ s/<kiriwrite:pagecontent>/$page_content/g;
-
- }
-
- # Create the combined page title (if needed).
-
- if ($page_settings eq 0){
-
- # Don't use page name or section name.
-
- $page_final =~ s/<kiriwrite:pagetitle>//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/<kiriwrite:pagetitle>/$page_title/g;
-
- } elsif ($page_settings eq 2){
-
- # Use the page name only.
-
- $page_autotitle = "(" . $page_name . ")";
- $page_final =~ s/<kiriwrite:pagetitle>/$page_name/g;
-
- } elsif ($page_settings eq 3){
-
- # Use the section name only.
-
- if ($page_section){
- $page_autotitle = "(" . $page_section . ")";
- }
- $page_final =~ s/<kiriwrite:pagetitle>/$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 <kiriwrite> value with the apporiate page
- # values.
-
- $page_final =~ s/<kiriwrite:pagename>/$page_name/g;
- $page_final =~ s/<kiriwrite:pagedescription>/$page_description/g;
- $page_final =~ s/<kiriwrite:pagesection>/$page_section/g;
- $page_final =~ s/<kiriwrite:autosection>/$page_autosection/g;
- $page_final =~ s/<kiriwrite:autotitle>/$page_autotitle/g;
-
- # Process the filters on the page data.
-
- if ($filters_skip eq 0){
-
- $filters_count = 0;
-
- foreach $filter_find (@findfilter){
-
- # Get the replace filter and process each
- # filter on the page.
-
- $filter_replace = $replacefilter[$filters_count];
- $page_final =~ s/$filter_find/$filter_replace/g;
- $filters_count++;
-
- }
-
- }
-
- # Process the page filename and check what directories
- # need to be created.
-
- $page_filename_length = int(length($page_filename));
-
- do {
-
- $page_filename_char = substr($page_filename, $page_filename_seek, 1);
-
- # Check if a forward slash appears and add it to
- # the list of directories array.
-
- if ($page_filename_char eq '/'){
-
- # Append the directory name to the list of
- # directories array.
-
- $pagedirectories[$page_filename_dircount] = $page_filename_directory;
- $page_filename_directory = "";
- $page_filename_char = "";
- $page_filename_dircount++;
-
- } else {
-
- # Append the character to the directory/filename.
-
- $page_filename_directory = $page_filename_directory . $page_filename_char;
-
- }
-
- $page_filename_seek++;
-
- } until ($page_filename_length eq $page_filename_seek);
-
- foreach $page_directory_name (@pagedirectories){
-
- # Check if the directory exists and create
- # the directory if it doesn't exist.
-
- $page_directory_path = $page_directory_path . '/' . $page_directory_name;
-
- mkdir($kiriwrite_config{"directory_data_output"} . '/' . $page_directory_path);
-
- }
-
- # Write the file to the output directory.
-
- open(PAGE, "> " . $kiriwrite_config{"directory_data_output"} . '/' . $page_filename);
- print PAGE $page_final;
- close(PAGE);
-
- # Write a message saying the page has been compiled.
-
- $messages = $messages . $information_prefix . "'" . $page_name_out . "' (" . $page_filename_out . ") was compiled." . "<br>";
- $pages_count++;
-
- # Reset certain values.
-
- $page_autotitle = "";
- $page_autosection = "";
- $page_filename_seek = 0;
- $page_filename_dircount = 0;
-
- $page_filename_directory = "";
- $page_directory_path = "";
- $page_directory_name = "";
- @pagedirectories = ();
-
- }
-
- # Write a message saying that the database has
- # been processed.
-
- $messages = $messages . $information_prefix . "Finished compiling pages in the '" . $database_name_out . "' database..." . "<br>";
-
- }
-
- $messages = $messages . "<hr>";
- $messages = $messages . $pages_count . " pages compiled, " . $error_count . " errors, " . $warning_count . " warnings.";
- $pagedata = $pagedata . "<h2>Compile databases</h2>";
- $pagedata = $pagedata . "<div class=\"datalist\">";
- $pagedata = $pagedata . $messages;
- $pagedata = $pagedata . "</div>";
-
- return $pagedata;
-
- } elsif ($confirm eq 0){
-
- # The action to compile the databases has
- # not been confirmed so check what type
- # is being used.
-
- if ($type eq "single"){
-
- # The type is a single database selected so
- # process that database.
-
- # Define some variables for later.
-
- my $database_handle;
- my $string_handle;
- my @database_info;
- my $database_filename_check;
- my $database_maxlength_check;
- my $databasefilename;
- my $databasefilename_out;
- my $database_name;
- my $database_name_out;
-
- # Check that the database name and length are
- # valid and return an error if they aren't.
-
- $databasefilename = $selectedlist[0];
- $databasefilename_out = kiriwrite_convert($databasefilename, "normal_display");
- $database_filename_check = kiriwrite_variablecheck($databasefilename, "filename", "", 1);
- $database_maxlength_check = kiriwrite_variablecheck($databasefilename, "maxlength", 64, 1);
-
- if ($database_filename_check ne 0){
-
- # The database filename is invalid, so
- # return an error.
-
- kiriwrite_error("databasefilenameinvalid");
-
- }
-
- if ($database_maxlength_check ne 0){
-
- # The database filename is too long, so
- # return an error.
-
- kiriwrite_error("databasefilenametoolong");
-
- }
-
- # Check if the database exists and has valid permissions
- # set and skip them if they don't.
-
- my $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $databasefilename . '.db');
- my $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $databasefilename . '.db', 1, 0);
-
- if ($database_exists ne 0){
-
- # The database filename does not exist, so
- # return an error.
-
- kiriwrite_error("databasemissingfile");
-
- }
-
- if ($database_permissions ne 0){
-
- # The database permissions are invalid, so
- # return an error.
-
- kiriwrite_error("databaseinvalidpermissions");
-
- }
-
- # Load the SQLite database.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $databasefilename . '.db');
-
- # Get the database name.
-
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1');
- $string_handle->execute();
- @database_info = $string_handle->fetchrow_array();
- $database_name = $database_info[0];
- $database_name_out = kiriwrite_convert($database_name, "normal_display");
-
- # Write out a form asking the user to confirm if the
- # user wants to compile the selected database.
-
- $pagedata = $pagedata . "<h2>Compile database</h2>";
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"compile\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"compile\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"type\" value=\"multiple\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"id[1]\" value=\"" . $databasefilename_out . "\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"name[1]\" value=\"on\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"confirm\" value=\"1\">";
- $pagedata = $pagedata . "Are you sure you want to compile the '" . $database_name_out . "' database?<br><br>";
- $pagedata = $pagedata . "<input type=\"submit\" value=\"Compile database\"> | <a href=\"kiriwrite.cgi?mode=compile\">Return to the list of databases for compiling.</a>";
- $pagedata = $pagedata . "</form>";
-
- return $pagedata;
-
- } elsif ($type eq "multiple"){
-
- # The type is multiple databases selected
- # so process each database.
-
- # Define some variables for later.
-
- my $database_handle;
- my $databasename;
- my $databasename_out;
- my @database_info;
- my $database_filename_check;
- my $database_maxlength_check;
- my $database_exists;
- my $database_permissions;
- my $database_count = 0;
- my $string_handle;
- my $database_info_name;
- my $database_info_name_out;
- my $databaselist = "";
-
- foreach $databasename (@selectedlist){
-
- # Check if the database is in the database
- # directory and skip it if it isn't.
-
- $database_filename_check = kiriwrite_variablecheck($databasename, "filename", "", 1);
- $database_maxlength_check = kiriwrite_variablecheck($databasename, "maxlength", 64, 1);
-
- if ($database_filename_check ne 0 || $database_maxlength_check ne 0){
-
- # The database filename given is invalid or
- # the database filename given is too long
- # so process the next database.
-
- next;
-
- }
-
- # Check if the database exists and has valid permissions
- # set and skip them if they don't.
-
- $database_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_db"} . '/' . $databasename . '.db');
- $database_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"} . '/' . $databasename . '.db', 1, 0);
-
- if ($database_exists ne 0 || $database_permissions ne 0){
-
- # The database does not exist or the permissions
- # for the database are invalid so process the
- # next database.
-
- next;
-
- }
-
- # Get the database name.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=" . $kiriwrite_config{"directory_data_db"} . '/' . $databasename . '.db');
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or next;
- $string_handle->execute();
-
- # Increment the amount of databases to compile.
-
- $database_count++;
-
- # Get the database name, convert it so that it can
- # be displayed properly and add it to the list of
- # databases to be compiled.
-
- @database_info = $string_handle->fetchrow_array();
- $database_info_name = $database_info[0];
- $database_info_name_out = kiriwrite_convert($database_info_name, "normal_display");
- $databasename_out = kiriwrite_convert($databasename, "normal_display");
-
- $databaselist = $databaselist . "<input type=\"hidden\" name=\"id[" . $database_count . "]\" value=\"" . $databasename_out . "\"><input type=\"hidden\" name=\"name[" . $database_count . "]\" value=\"on\">" . $database_info_name_out . "<br>";
-
- }
-
- # Check if any databases are available to be compiled.
-
- if ($database_count eq 0){
-
- # No databases are available to be compiled.
-
- kiriwrite_error("nodatabaseselected");
-
- }
-
- # Write out the form for compiling the database.
-
- $pagedata = $pagedata . "<h2>Compile selected databases</h2>";
- $pagedata = $pagedata . "Do you want to compile the following databases?<br><br>";
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"compile\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"compile\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"type\" value=\"multiple\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"count\" value=\"" . $database_count . "\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"confirm\" value=\"1\">";
- $pagedata = $pagedata . "<div class=\"datalist\">";
- $pagedata = $pagedata . $databaselist;
- $pagedata = $pagedata . "</div><br>";
- $pagedata = $pagedata . "<input type=\"submit\" value=\"Compile selected databases\"> | <a href=\"kiriwrite.cgi?mode=compile\">Return to the database list.</a>";
- $pagedata = $pagedata . "</form>";
-
- return $pagedata;
-
- } else {
-
- # The type is something else other than
- # single or multiple, so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- } else {
-
- # The confirm value is neither 0 or 1, so
- # return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
-}
-
-sub kiriwrite_compile_all{
-#################################################################################
-# kiriwrite_compile_all: Compile all of the databases in the database #
-# directory. #
-# #
-# Usage: #
-# #
-# kiriwrite_compile_all(); #
-#################################################################################
-
- # Get the list of databases to compile.
-
- opendir(DATABASE, $kiriwrite_config{"directory_data_db"});
- my @database_list = grep /m*\.db/, readdir(DATABASE);
- closedir(DATABASE);
-
- # Define some variables for later.
-
- my $databaseformdata;
- my $database_name = "";
- my $database_name_filename_check;
- my $database_name_length = 0;
- my $database_name_final_length = 0;
- my $database_name_final = "";
- my $database_count = 1;
-
- foreach $database_name (@database_list){
-
- # Check if the database filename is valid before
- # using the database.
-
- $database_name_filename_check = kiriwrite_variablecheck($database_name, "filename", 0, 1);
-
- if ($database_name_filename_check ne 0){
-
- # The database filename is invalid so process
- # the next database.
-
- next;
-
- }
-
- # Get the database name without the extension.
-
- $database_name_length = length($database_name);
- $database_name_final_length = $database_name_length - 3;
- $database_name_final = substr($database_name, 0, $database_name_final_length);
-
- # Process the final database name into form values.
-
- $databaseformdata = $databaseformdata . "<input type=\"hidden\" name=\"id[" . $database_count . "]\" value=\"" . $database_name_final . "\">";
- $databaseformdata = $databaseformdata . "<input type=\"hidden\" name=\"name[" . $database_count . "]\" value=\"on\">";
-
- $database_count++;
-
- }
-
- # Check the list of databases to compile to see if it is blank,
- # if it is then return an error.
-
- if ($database_count eq 0){
-
- # The list of database is blank so return an error.
-
- kiriwrite_error("nodatabasesavailable");
-
- }
-
- # Write out a form for confirming the action to compile all of the databases.
-
- my $pagedata = "<h2>Compile all databases</h2>";
- $pagedata = $pagedata . "Do you want to compile all of the databases in the database directory?<br><br>";
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"compile\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"compile\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"type\" value=\"multiple\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"count\" value=\"" . $database_count . "\">";
- $pagedata = $pagedata . $databaseformdata;
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"confirm\" value=\"1\">";
- $pagedata = $pagedata . "<input type=\"submit\" value=\"Compile all databases\"> | <a href=\"kiriwrite.cgi?mode=compile\">Return to the compile database list.</a>";
- $pagedata = $pagedata . "</form>";
-
- return $pagedata;
-
-}
-
-sub kiriwrite_selectedlist{
-#################################################################################
-# kiriwrite_page_selectedlist: Get the list of selected pages to use. #
-# #
-# Usage: #
-# #
-# kiriwrite_page_selectedlist(); #
-#################################################################################
-
- # Load the required Perl modules.
-
- my $query = new CGI;
-
- my $count = $query->param('count');
-
- # Check if the list of files has a value and if not set it 0.
-
- if (!$count){
-
- $count = 0;
-
- }
-
- # Define some values for later.
-
- my @filename_list;
- my @selected_list;
- my @final_list;
-
- my $filename;
- my $selected;
-
- my $final_count = 0;
- my $seek = 0;
-
- # Get the list of filenames.
-
- do {
-
- # Get the values from id[]
-
- $seek++;
-
- $filename = $query->param('id[' . $seek . ']');
- $filename_list[$seek] = $filename;
-
- } until ($seek eq $count || $count eq 0);
-
- # Get the list of selected filenames.
-
- $seek = 0;
-
- do {
-
- # Get the values from name[]
-
- $seek++;
-
- $selected = $query->param('name[' . $seek . ']');
-
- if (!$selected){
-
- $selected = 'off';
-
- }
-
- $selected_list[$seek] = $selected;
-
- } until ($seek eq $count || $count eq 0);
-
- # Create a final list of filenames to be used for
- # processing.
-
- $seek = 0;
-
- do {
-
- # Check if the selected value is on and include
- # the filename in the final list.
-
- $seek++;
-
- $selected = $selected_list[$seek];
-
- if ($selected eq "on"){
-
- $filename = $filename_list[$seek];
- $final_list[$final_count] = $filename;
- $final_count++;
-
- }
-
- } until ($seek eq $count || $count eq 0);
-
- return @final_list;
-
-}
-
-sub kiriwrite_compile_list{
-#################################################################################
-# kiriwrite_compile_list: Shows a list of databases that can be compiled. #
-# #
-# Usage: #
-# #
-# kiriwrite_compile_list(); #
-#################################################################################
-
- # Load the required Perl modules.
-
- use DBI;
-
- # Check the directory to make sure the permissions are settings are valid
- # and return an error if the permission settings are invalid.
-
- my $data_directory_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_db"}, 1, 0);
-
- if ($data_directory_permissions eq 1){
-
- # The data directory has invalid permissions set, so return an error.
-
- kiriwrite_error("datadirectoryinvalidpermissions");
-
- }
-
- # Open the directory and get the list of all files ending with .xml and
- # put them into the data_directory array.
-
- opendir(DATADIR, $kiriwrite_config{"directory_data_db"});
- my @data_directory = grep /m*\.db/, readdir(DATADIR);
- closedir(DATADIR);
-
- # Declare the following variables that are going to be used before using
- # the foreach function.
-
- my $pagedata = "";
- my $database_count = 0;
- my $database_handle = "";
- my $database_filename = "";
- my $database_filename_friendly = "";
- my $database_filename_length = 0;
- my $database_permissions = "";
- my $database_name_out = "";
- my $database_description_out = "";
- my $data_file = "";
- my $string_handle = "";
- my @database_info;
- my $table_style = 0;
- my $table_style_name = "";
- my $tabledata = "";
- my $permissions_warning = 0;
- my $permissions_list = "";
- my $select_menu = "";
- my $invalid_warning = 0;
- my $invalid_list = "";
-
- # Begin creating the table for the list of databases.
-
- $pagedata = "<h2>Compile Pages</h2>\r\n";
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"compile\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"compile\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"type\" value=\"multiple\">";
-
- $select_menu = "<input type=\"reset\" value=\"Select None\"> | <input type=\"submit\" value=\"Compile selected\">";
-
- foreach $data_file (@data_directory){
- # Check the database file permissions before opening it.
-
- $database_filename = $kiriwrite_config{"directory_data_db"} . '/' . $data_file;
- $database_permissions = kiriwrite_filepermissions($database_filename, 1, 0, 0);
-
- if ($database_permissions eq 1){
- $permissions_warning = 1;
- $permissions_list = $permissions_list . $data_file . "<br>\r\n";
- next;
- }
-
- # Load the SQLite database.
-
- $database_handle = DBI->connect("dbi:SQLite:dbname=" . $database_filename);
-
- # Query the SQLite database or return an error (meaning that the database is in
- # a invalid format).
-
- $string_handle = $database_handle->prepare('SELECT * FROM kiriwrite_database_info LIMIT 1') or (
- $invalid_list = $invalid_list . $data_file . "<br>\r\n",
- $invalid_warning = 1,
- next
- );
-
- $string_handle->execute();
- @database_info = $string_handle->fetchrow_array();
-
- # Check the style to be used with.
-
- if ($table_style eq 0){
-
- # Use the first style and set the style value
- # to use the next style, the next time the
- # if statement is checked.
-
- $table_style_name = "tablecell1";
- $table_style = 1;
- } else {
-
- # Use the second style and set the style
- # value to use the first style, the next
- # time if statement is checked.
-
- $table_style_name = "tablecell2";
- $table_style = 0;
- }
-
- $database_name_out = kiriwrite_convert($database_info[0], "normal_display");
- $database_description_out = kiriwrite_convert($database_info[1], "normal_display");
-
- # Create a friendly name for the database.
-
- $database_filename_length = length($data_file);
- $database_filename_friendly = substr($data_file, 0, $database_filename_length - 3);
-
- $database_count++;
-
- # Append the database information to the table.
-
- $tabledata = $tabledata . "<tr><td class=\"" . $table_style_name . "\"><input type=\"hidden\" name=\"id[" . $database_count . "]\" value=\"" . $database_filename_friendly . "\"><input type=\"checkbox\" name=\"name[" . $database_count . "]\"></td><td class=\"" . $table_style_name . "\"><a href=\"kiriwrite.cgi?mode=page&action=view&database=" . $database_filename_friendly . "\">" . $database_name_out . "</a></td><td class=\"" . $table_style_name . "\">" . $database_description_out . "</td><td class=\"" . $table_style_name . "\"><a href=\"kiriwrite.cgi?mode=compile&action=compile&type=single&database=" . $database_filename_friendly . "\">Compile</a></td></tr>\r\n";
-
- }
-
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"count\" value=\"" . $database_count . "\">";
-
- $pagedata = $pagedata . $select_menu . "<br><br>";
-
- $pagedata = $pagedata . "<table cellpadding=\"5\" cellspacing=\"0\"><tr><td class=\"tablecellheader\"></td><td class=\"tablecellheader\">Database Name</td><td class=\"tablecellheader\">Database Description</td><td class=\"tablecellheader\">Options</td></tr>\r\n";
-
- $pagedata = $pagedata . $tabledata;
-
- $pagedata = $pagedata . "</table>\r\n<br />";
-
- $pagedata = $pagedata . $select_menu;
- $pagedata = $pagedata . "</form>";
-
- # Check if there are no valid databases are if there is no
- # valid databases then write a message saying that no
- # valid databases are available.
-
- if ($database_count eq 0){
-
- #
-
- $pagedata = "<h2>Database List</h2><p>";
- $pagedata = $pagedata . "<div class=\"errorbox\">There are no databases that can be used for compiling.</div><p>";
-
- }
-
- # 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 . "<h4>Databases with invalid permissions</h4>";
- $pagedata = $pagedata . "The following databases have invalid permissions set:<br><br>";
- $pagedata = $pagedata . $permissions_list;
-
- }
-
- if ($invalid_warning eq 1){
-
- $pagedata = $pagedata . "<h4>Databases with invalid formats</h4>";
- $pagedata = $pagedata . "The following databases are in a invalid format:<br><br>";
- $pagedata = $pagedata . $invalid_list;
-
- }
-
- return $pagedata;
-
-}
-
-sub kiriwrite_compile_clean{
-#################################################################################
-# kiriwrite_compile_clean: Deletes the contents of the output directory. #
-# #
-# Usage: #
-# #
-# kiriwrite_compile_clean(confirm); #
-# #
-# confirm Confirms the deletion of files from the output directory. #
-#################################################################################
-
- # Get the values passed to the subroutine.
-
- my ($confirm) = @_;
-
- # Define some variables for later.
-
- my $file_permissions;
- my $output_directory_exists;
- my $output_directory_permissions;
- my $warning_message;
- my $pagedata = "";
-
- # Check if the output directory exists.
-
- $output_directory_exists = kiriwrite_fileexists($kiriwrite_config{"directory_data_output"});
-
- if ($output_directory_exists eq 1){
-
- # The output directory does not exist so return
- # an error.
-
- kiriwrite_error("outputdirectorymissing");
-
- }
-
- # Check if the output directory has invalid
- # permissions set.
-
- $output_directory_permissions = kiriwrite_filepermissions($kiriwrite_config{"directory_data_output"});
-
- if ($output_directory_permissions eq 1){
-
- # The output directory has invalid permissions
- # set, so return an error.
-
- kiriwrite_error("outputdirectoryinvalidpermissions");
-
- }
-
- if ($confirm) {
-
- if ($confirm eq 1){
-
- # The action to clean the output directory has been
- # confirmed.
-
- # Remove the list of files and directories from the
- # output directory.
-
- $file_permissions = kiriwrite_compile_clean_helper($kiriwrite_config{"directory_data_output"}, 1);
-
- if ($file_permissions eq 1){
-
- # One of the files or directories has invalid
- # permissions set so write a warning message.
-
- }
-
- $pagedata = "<h2>Clean Output Directory</h2>";
-
- 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.<br><br>";
-
- } else {
-
- $pagedata = $pagedata . "The contents of the output directory have been removed.<br><br>";
-
- }
-
- $pagedata = $pagedata . "<a href=\"kiriwrite.cgi?mode=compile\">Return to the compile databases list.</a>";
-
- return $pagedata;
-
- } else {
-
- # A value other than 1 is set for the confirm value
- # (which it shouldn't be) so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- }
-
- # Print out a form for cleaning the output directory.
-
- $pagedata = "<h2>Clean Output Directory</h2>";
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"compile\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"clean\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"confirm\" value=\"1\">";
- $pagedata = $pagedata . "Are you sure you want to clean the output directory?<br><br>";
- $pagedata = $pagedata . "<input type=\"submit\" value=\"Yes, clean output directory\"> | <a href=\"kiriwrite.cgi?mode=compile\">Return to compile list.</a>";
- $pagedata = $pagedata . "</form>";
-
- return $pagedata;
-
-}
-
-sub kiriwrite_compile_clean_helper{
-#################################################################################
-# kiriwrite_compile_clean_helper: Helper for cleaning out the output directory. #
-# This command sometimes is called recursively (when a directory is found). #
-# #
-# Usage: #
-# #
-# kiriwrite_compile_clean_helper(directory, removedirectory, [permissions]); #
-# #
-# directory Specifies the directory to remove files (and #
-# sub-directories) from. #
-# keepdirectory Keeps the directory itself after all files have been #
-# removed. #
-# permissions Used recursively for error checking. #
-#################################################################################
-
- # Get the values passed to the subroutine.
-
- my ($directory, $directory_keep, $permissions) = @_;
-
- # Check if the directory_keep is only one charater long.
-
- my $directory_file = "";
- my @directory_list;
- my $file_permissions = 0;
- my $debug = 0;
-
- # Check if the file permissions value is blank.
-
- if (!$permissions){
-
- # The file permissions value is blank.
-
- $permissions = 0;
-
- }
-
- # Open the directory specified, read the contents of
- # the directory and then close the directory.
-
- opendir(DIRECTORY, $directory);
- @directory_list = readdir(DIRECTORY);
- closedir(DIRECTORY);
-
- # Remove each file and directory.
-
- foreach $directory_file (@directory_list){
-
- # Check if the filename is '.' or '..' and if it
- # is skip those files.
-
- if ($directory_file eq "." || $directory_file eq ".."){
-
- # The filename is '.' or '..' so skip processing
- # these files.
-
- } else {
-
- # Check if the permissions on the file or directory has
- # valid permissions set.
-
- $file_permissions = kiriwrite_filepermissions($directory . '/' . $directory_file, 1, 1);
-
- if ($file_permissions eq 1){
-
- # The file or directory has invalid permissions set.
-
- $permissions = 1;
- next;
-
- }
-
- # Check if the filename is a directory.
-
- if (-d $directory . '/' . $directory_file){
-
- # The filename is a directory so send the directory name
- # and this subroutine again (recursively).
-
- kiriwrite_compile_clean_helper($directory . '/' . $directory_file, 0, $permissions);
-
- } else {
-
- # The file is not a directory but an actual file so
- # remove as normal (in terms of the Perl language).
-
- ($directory) = $directory =~ m/^([a-zA-Z0-9\/.]+)$/ig;
- ($directory_file) = $directory_file =~ m/^([a-zA-Z0-9.]+)$/ig;
-
- unlink($directory . '/' . $directory_file);
-
- }
-
- }
-
- }
-
- # Check if the directory should be kept.
-
- if ($directory_keep eq 1){
-
- # The directory_keep value is set as 1 so the directory
- # specified should be kept.
-
- } elsif ($directory_keep eq 0) {
-
- # The directory_keep value is set as 0 so remove the
- # directory specified.
-
- ($directory) = $directory =~ m/^([a-zA-Z0-9\/.]+)$/ig;
- rmdir($directory);
-
- } else {
-
- # A value other than 0 or 1 was specified so return
- # an error,
-
- kiriwrite_error('invalidvalue');
-
- }
-
- return $permissions;
-
-}
-
-sub kiriwrite_settings_view{
-#################################################################################
-# kiriwrite_options_view: Writes out the list of options and variables. #
-# #
-# Usage: #
-# #
-# kiriwrite_settings_view(); #
-#################################################################################
-
- # Get the settings.
-
- my $settings_directory_db = $kiriwrite_config{"directory_data_db"};
- my $settings_directory_output = $kiriwrite_config{"directory_data_output"};
- my $settings_noncgi_images = $kiriwrite_config{"directory_noncgi_images"};
- my $settings_system_datetime = $kiriwrite_config{"system_datetime"};
- my $settings_system_language = $kiriwrite_config{"system_language"};
- my $settings_system_output = $kiriwrite_config{"system_output"};
-
- # CONTINUE: Write out convert things.
-
- my $settings_directory_db_out = kiriwrite_convert($settings_directory_db, "normal_display");
- my $settings_directory_output_out = kiriwrite_convert($settings_directory_output, "normal_display");
- my $settings_noncgi_images_out = kiriwrite_convert($settings_noncgi_images, "normal_display");
- my $settings_system_datetime_out = kiriwrite_convert($settings_system_datetime, "normal_display");
- my $settings_system_language_out = kiriwrite_convert($settings_system_language, "normal_display");
- my $settings_system_output_out = kiriwrite_convert($settings_system_output, "normal_display");
-
- my $pagedata = "<h2>View Settings</h2>";
-
- $pagedata = $pagedata . "The current settings being used are the following:";
-
- $pagedata = $pagedata . "<br><br><table cellpadding=\"5\" cellspacing=\"0\">";
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Setting</td><td class=\"tablecellheader\">Value</td></tr>";
-
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Directories</td><td class=\"tablecellheader\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Database Directory</td><td class=\"tablecell2\">" . $settings_directory_db_out . "</td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Output Directory</td><td class=\"tablecell2\">" . $settings_directory_output_out . "</td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Images (URI path)</td><td class=\"tablecell2\">" . $settings_noncgi_images_out . "</td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Date</td><td class=\"tablecellheader\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Date format</td><td class=\"tablecell2\">" . $settings_system_datetime_out . "</td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Language</td><td class=\"tablecellheader\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">System Language</td><td class=\"tablecell2\">" . $settings_system_language_out . "</td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Output</td><td class=\"tablecellheader\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Output System</td><td class=\"tablecell2\">" . $settings_system_output_out . "</td></tr>";
- $pagedata = $pagedata . "</table><br>";
-
- $pagedata = $pagedata . "To alter the current settings, select the Edit Settings option at the top of the page.";
-
- return $pagedata;
-
-}
-
-sub kiriwrite_settings_edit{
-#################################################################################
-# kiriwrite_options_edit: Edits the options. #
-# #
-# Usage: #
-# #
-# kiriwrite_options_edit(dbdirectory, outputdirectory, imagesuri, #
-# languagesystem, outputsystem, confirm); #
-# #
-# dbdirectory Specifies the new database directory to use. #
-# outputdirectory Specifies the new output directory to use. #
-# imagesuri Specifies the new URI path for images. #
-# datetimeformat Specifies the new date and time format. #
-# languagesystem Specifies the new language to use for Kiriwrite. #
-# outputsystem Specifies the new output system to use for Kiriwrite. #
-# confirm Confirms the action to edit the settings. #
-#################################################################################
-
- # Get the values that have been passed to the subroutine.
-
- my ($settings_dbdirectory, $settings_outputdirectory, $settings_imagesuri, $settings_datetimeformat, $settings_languagesystem, $settings_outputsystem, $confirm) = @_;
-
- # Load the required Perl modules.
-
- my $xsl = XML::Simple->new();
-
- if (!$confirm){
-
- # If the confirm value is blank, then set the confirm
- # value to 0.
-
- $confirm = 0;
-
- }
-
- if ($confirm eq "1"){
-
- # The action to edit the settings has been confirmed.
- # Start by checking each variable about to be placed
- # in the settings file is valid.
-
- # Deinfe some variables for later.
-
- my @kiriwrite_new_settings;
-
- # Check the length of the directory names.
-
- kiriwrite_variablecheck($settings_dbdirectory, "maxlength", 64, 0);
- kiriwrite_variablecheck($settings_outputdirectory, "maxlength", 64, 0);
- kiriwrite_variablecheck($settings_imagesuri, "maxlength", 512, 0);
- kiriwrite_variablecheck($settings_datetimeformat, "maxlength", 32, 0);
-
- kiriwrite_variablecheck($settings_languagesystem, "language_filename", "", 0);
- kiriwrite_variablecheck($settings_outputsystem, "outputmodule", 0, 1);
-
- # Check if the directory names only contain letters and numbers and
- # return a specific error if they don't.
-
- my $kiriwrite_dbdirectory_check = kiriwrite_variablecheck($settings_dbdirectory, "directory", 0, 1);
- my $kiriwrite_outputdirectory_check = kiriwrite_variablecheck($settings_outputdirectory, "directory", 0, 1);
- kiriwrite_variablecheck($settings_datetimeformat, "datetime", 0, 0);
-
- if ($kiriwrite_dbdirectory_check eq 1){
-
- # The database directory name is blank, so return
- # an error.
-
- kiriwrite_error("dbdirectoryblank");
-
- } elsif ($kiriwrite_dbdirectory_check eq 2){
-
- # The database directory name is invalid, so return
- # an error.
-
- kiriwrite_error("dbdirectoryinvalid");
-
- }
-
- if ($kiriwrite_outputdirectory_check eq 1){
-
- # The output directory name is blank, so return
- # an error.
-
- kiriwrite_error("outputdirectoryblank");
-
- } elsif ($kiriwrite_outputdirectory_check eq 2){
-
- # The output directory name is invalid, so return
- # an error.
-
- kiriwrite_error("outputdirectoryinvalid");
-
- }
-
- # Place the settings into the array.
-
- $kiriwrite_new_settings[0] = $settings_dbdirectory;
- $kiriwrite_new_settings[1] = $settings_outputdirectory;
- $kiriwrite_new_settings[2] = $settings_imagesuri;
- $kiriwrite_new_settings[3] = $settings_datetimeformat;
- $kiriwrite_new_settings[4] = $settings_languagesystem;
- $kiriwrite_new_settings[5] = $settings_outputsystem;
-
- # Write the new settings to the XML file.
-
- kiriwrite_output_xml("kiriwrite.xml", "config", @kiriwrite_new_settings);
-
- # Write a confirmation message.
-
- my $pagedata = "<h2>Edit Settings</h2>";
- $pagedata = $pagedata . "The page settings have been changed and will take effect on the next page load of Kiriwrite.<br><br>";
- $pagedata = $pagedata . "<a href=\"kiriwrite.cgi?mode=settings\">Return to the list of settings.</a>";
-
- return $pagedata;
-
- }
-
- # Get the list of languages available.
-
- my @language_directory = "";
- my $language_filename = "";
- my $language_file_xml = "";
- my $language_file_systemname = "";
- my $language_file_localname = "";
- my $language_file_localname_out = "";
- my $language_file_seek = 0;
- my $language_flie_dot = 0;
- my $language_file_length = 0;
- my $language_file_char = "";
- my $language_file_friendly = "";
- my $language_selectlist = "";
-
- opendir(LANGUAGEDIR, "lang");
- @language_directory = grep /m*\.xml/, readdir(LANGUAGEDIR);
- closedir(LANGUAGEDIR);
-
- # Process each language by loading the XML configuration file
- # used for each language and then get the System name and
- # the local name of the language.
-
- $language_selectlist = "<select name=\"language\">";
-
- foreach $language_filename (@language_directory){
-
- # Load the language file currently selected.
-
- $language_file_xml = $xsl->XMLin("lang" . '/' . $language_filename, SuppressEmpty => 1);
-
- # Get the system name and the local name of the language.
-
- $language_file_localname = $language_file_xml -> {about} -> {name};
-
- # Check if either the system name or the local name of the language
- # is blank and if it is, then don't add the language to the list.
-
- if ($language_file_localname eq ""){
-
- # The system name or the local name is blank so don't add
- # the language to the list.
-
- } else {
-
- # Get the 'friendly' name of the language file name (basically
- # remove the .xml part from the filename.
-
- $language_file_length = length($language_filename);
-
- do {
-
- # Get a character from the language filename and currently
- # set by the seek counter.
-
- $language_file_char = substr($language_filename, $language_file_seek, 1);
-
- # Check if the character is a dot and if it is then set the
- # last dot value to the seek counter value.
-
- if ($language_file_char eq "."){
-
- # Current chatacter is a dot so set the last dot value
- # to what is currently the seek counter.
-
- $language_flie_dot = $language_file_seek;
-
- } else {
-
- # Current character is not a dot, so do nothing.
-
- }
-
- # Increment the seek counter.
-
- $language_file_seek++;
-
- } until ($language_file_seek eq $language_file_length);
-
- # Reset the seek counter.
-
- $language_file_seek = 0;
-
- # Process the file name again and this time process the file
- # name until it reaches the last dot found.
-
- do {
-
- # Get the character the seek counter is currently set at.
-
- $language_file_char = substr($language_filename, $language_file_seek, 1);
-
- # Append the character to the friendly file name.
-
- $language_file_friendly = $language_file_friendly . $language_file_char;
-
- # Increment the seek counter.
-
- $language_file_seek++;
-
- } until ($language_file_seek eq $language_flie_dot);
-
- # Append the language to the available languages list.
-
- $language_file_localname_out = kiriwrite_convert($language_file_localname, "normal_display");
- $language_selectlist = $language_selectlist . "<option value=\"" . $language_file_friendly . "\">" . $language_file_localname_out . "</option>";
-
- # Reset certain counters and values before continuing.
-
- $language_file_seek = 0;
- $language_flie_dot = 0;
- $language_file_length = 0;
- $language_file_char = "";
- $language_file_friendly = "";
-
- }
-
- }
-
- $language_selectlist = $language_selectlist . "</select>";
-
- # Get the list of output systems available.
-
- my @outputsys_directory = "";
- my $outputsys_file = "";
- my $outputsys_char = "";
- my $outputsys_dot = 0;
- my $outputsys_firstdot = 0;
- my $outputsys_firstdotfound = "";
- my $outputsys_seek = 0;
- my $outputsys_length = 0;
- my $outputsys_friendly = "";
- my $outputsys_selectlist = "";
- my $outputsys_config = $kiriwrite_config{"system_output"};
-
- # Open and get the list of output systems (perl modules) by filtering
- # out the
-
- opendir(OUTPUTSYSTEMDIR, "Modules/Output");
- @outputsys_directory = grep /m*\.pm/, readdir(OUTPUTSYSTEMDIR);
- closedir(OUTPUTSYSTEMDIR);
-
- $outputsys_selectlist = "<select name=\"outputsys\">";
-
- # Process each output system and add them to the list of available
- # output systems.
-
- foreach $outputsys_file (@outputsys_directory){
-
- # Get the length of the output system (perl module) filename.
-
- $outputsys_length = length($outputsys_file);
-
- # Get the friendly name of the Perl module (by getting rid of the
- # .pm part of the filename).
-
- do {
-
- $outputsys_char = substr($outputsys_file, $outputsys_seek, 1);
-
- # Check if the current character is a dot and if it is then
- # set the last dot found number to the current seek number.
-
- if ($outputsys_char eq "."){
-
- # Put the seek value as the last dot found number.
-
- $outputsys_dot = $outputsys_seek;
-
- }
-
- # Increment the seek counter.
-
- $outputsys_seek++;
-
- } until ($outputsys_seek eq $outputsys_length);
-
- # Reset the seek counter as it is going to be used again.
-
- $outputsys_seek = 0;
-
- # Get the friendly name of the Perl module by the processing the file
- # name to the last dot the previous 'do' tried to find.
-
- do {
-
- # Get the character the seek counter is currently set at.
-
- $outputsys_char = substr($outputsys_file, $outputsys_seek, 1);
-
- # Append the character to the friendly name of the output system.
-
- $outputsys_friendly = $outputsys_friendly . $outputsys_char;
-
- # Increment the seek counter.
-
- $outputsys_seek++;
-
- } until ($outputsys_seek eq $outputsys_dot);
-
- # Append the option to tbe list of available output systems.
-
- # Check if the current friendly output module name matches with the
- # output module name used in the configuration file.
-
- if ($outputsys_friendly eq $outputsys_config){
-
- # The output module friendly name matches with the output
- # module name used in the configuration file.
-
- $outputsys_selectlist = $outputsys_selectlist . "<option value=\"" . $outputsys_friendly . "\" selected>" . $outputsys_friendly . "</option>";
-
- } else {
-
- # The output module friendly name does not match with the
- # output module name used in the configuration file.
-
- $outputsys_selectlist = $outputsys_selectlist . "<option value=\"" . $outputsys_friendly . "\">" . $outputsys_friendly . "</option>";
-
- }
-
- # Reset the following values.
-
- $outputsys_seek = 0;
- $outputsys_length = 0;
- $outputsys_char = "";
- $outputsys_friendly = "";
-
-
- }
-
- $outputsys_selectlist = $outputsys_selectlist . "</select>";
-
- # Get the directory settings.
-
- my $directory_settings_database = $kiriwrite_config{"directory_data_db"};
- my $directory_settings_output = $kiriwrite_config{"directory_data_output"};
- my $directory_settings_imagesuri = $kiriwrite_config{"directory_noncgi_images"};
- my $datetime_setting = $kiriwrite_config{"system_datetime"};
-
- my $directory_settings_database_out = kiriwrite_convert($directory_settings_database, "normal_display");
- my $directory_settings_output_out = kiriwrite_convert($directory_settings_output, "normal_display");
- my $directory_settings_imagesuri_out = kiriwrite_convert($directory_settings_imagesuri, "normal_display");
- my $datetime_setting_out = kiriwrite_convert($datetime_setting, "normal_display");
-
- # Print out a form for editing the settings.
-
- my $pagedata = "<h2>Edit Settings</h2>";
- $pagedata = $pagedata . "<b>Warning:</b> Settings that have changed take effect after clicking on the 'Change Settings' button and viewing the confirmation message.<br><br>";
-
- $pagedata = $pagedata . "<form action=\"kiriwrite.cgi\" method=\"POST\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"mode\" value=\"settings\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"action\" value=\"edit\">";
- $pagedata = $pagedata . "<input type=\"hidden\" name=\"confirm\" value=\"1\">";
- $pagedata = $pagedata . "<table cellpadding=\"5\" cellspacing=\"0\">";
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Directories</td><td class=\"tablecellheader\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Database Directory</td><td class=\"tablecell2\"><input type=\"text\" name=\"databasedir\" value=\"" . $directory_settings_database_out . "\" size=\"32\" maxlength=\"64\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Output Directory</td><td class=\"tablecell2\"><input type=\"text\" name=\"outputdir\" value=\"" . $directory_settings_output_out . "\" size=\"32\" maxlength=\"64\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Images (URI path)</td><td class=\"tablecell2\"><input type=\"text\" name=\"imagesuripath\" value=\"" . $directory_settings_imagesuri_out . "\" size=\"32\" maxlength=\"64\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Date</td><td class=\"tablecellheader\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Date format</td><td class=\"tablecell2\"><input type=\"text\" name=\"datetime\" value=\"" . $datetime_setting_out . "\" size=\"32\" maxlength=\"32\"><br><br>";
- $pagedata = $pagedata . "<div class=\"datalist\">D - Show single digit day if day value is less than 10.<br>
- DD - Show double digit day if day value is less than 10.<br>
- M - Show single digit month if month value is less than 10.<br>
- MM - Show double digit month if month value is less than 10.<br>
- Y - Show double digit year value.<br>
- YY - Show four digit year value.<br><br>
- h - Show single digit hour if hour value is less than 10.<br>
- hh - Show double digit hour if hour value is less than 10.<br>
- m - Show single digit minute if minute value is less than 10.<br>
- mm - Show double digit minute if minute value is less than 10.<br>
- s - Show single digit second if second value is less than 10.<br>
- ss - Show double digit second if second value is less than 10.<br><br>
- Other Characters: / - ( ) :
- </div>";
- $pagedata = $pagedata . "</td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Languages</td><td class=\"tablecellheader\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">System Language</td><td class=\"tablecell2\">" . $language_selectlist . "</td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecellheader\">Output</td><td class=\"tablecellheader\"></td></tr>";
- $pagedata = $pagedata . "<tr><td class=\"tablecell1\">Output System</td><td class=\"tablecell2\">" . $outputsys_selectlist . "</td></tr>";
- $pagedata = $pagedata . "</table><br>";
- $pagedata = $pagedata . "<input type=\"submit\" value=\"Change Settings\"> | <input type=\"reset\" value=\"Revert Settings\">";
- $pagedata = $pagedata . "</form>";
-
- return $pagedata;
-
-}
-
-sub kiriwrite_settings_load{
-#################################################################################
-# kiriwrite_settings_load: Load the configuration settings into the global #
-# variables. #
-# #
-# Usage: #
-# #
-# kiriwrite_settings_load(); #
-#################################################################################
-
- # Load the required Perl modules.
-
- use XML::Simple;
- my $xsl = XML::Simple->new();
-
- # Check if the Kiriwrite configuration file exists before using it and
- # return a critical error if it doesn't exist.
-
- my $kiriwrite_conf_exist = kiriwrite_fileexists("kiriwrite.xml");
-
- if ($kiriwrite_conf_exist eq 1){
-
- # The configuration really does not exist so return an critical error.
-
- kiriwrite_critical("configfilemissing");
-
- }
-
- # Check if the Kiriwrite configuration file has valid permission settings
- # before using it and return a critical error if it doesn't have the
- # valid permission settings.
-
- my $kiriwrite_conf_permissions = kiriwrite_filepermissions("kiriwrite.xml", 1, 0);
-
- if ($kiriwrite_conf_permissions eq 1){
-
- # The permission settings for the Kiriwrite configuration file are
- # invalid, so return an critical error.
-
- kiriwrite_critical("configfileinvalidpermissions");
-
- }
-
- # Converts the XML file into meaningful data for later on in this subroutine.
-
- my $kiriwrite_conf_file = 'kiriwrite.xml';
- my $kiriwrite_conf_data = $xsl->XMLin($kiriwrite_conf_file, SuppressEmpty => 1);
-
- # Go and fetch the settings and place them into a hash (that is global).
-
- %kiriwrite_config = (
-
- "directory_data_db" => $kiriwrite_conf_data->{settings}->{directories}->{database},
- "directory_data_output" => $kiriwrite_conf_data->{settings}->{directories}->{output},
- "directory_noncgi_images" => $kiriwrite_conf_data->{settings}->{directories}->{images},
-
- "system_language" => $kiriwrite_conf_data->{settings}->{language}->{type},
- "system_output" => $kiriwrite_conf_data->{settings}->{system}->{output},
- "system_datetime" => $kiriwrite_conf_data->{settings}->{system}->{datetime}
-
- );
-
- # Do a validation check on all of the variables that were loaded into the global configuration hash.
-
- kiriwrite_variablecheck($kiriwrite_config{"directory_data_db"}, "maxlength", 64, 0);
- kiriwrite_variablecheck($kiriwrite_config{"directory_data_output"}, "maxlength", 64, 0);
- kiriwrite_variablecheck($kiriwrite_config{"directory_noncgi_images"}, "maxlength", 512, 0);
- kiriwrite_variablecheck($kiriwrite_config{"directory_data_template"}, "maxlength", 64, 0);
-
- kiriwrite_variablecheck($kiriwrite_config{"system_language"}, "language_filename", "", 0);
- kiriwrite_variablecheck($kiriwrite_config{"system_output"}, "outputmodule", 0, 0);
-
- # Check if the output system module does exist before loading it and return an critical error
- # if the output system module does not exist.
-
- my $kiriwrite_config_systemoutput_fileexists = kiriwrite_fileexists("Modules/Output/" . $kiriwrite_config{"system_output"} . ".pm");
-
- if ($kiriwrite_config_systemoutput_fileexists eq 1){
-
- # Output system module does not exist so return an critical error.
-
- kiriwrite_critical("outputsystemmissing");
-
- }
-
- # Check if the output system module does have the valid permission settings and return an
- # critical error if the output system module contains invalid permission settings.
-
- my $kiriwrite_config_systemoutput_permissions = kiriwrite_filepermissions("Modules/Output/" . $kiriwrite_config{"system_output"} . ".pm", 1, 0);
-
- if ($kiriwrite_config_systemoutput_permissions eq 1){
-
- # Output system contains invalid permissions so return an critical error.
-
- kiriwrite_critical("outputsysteminvalidpermissions");
-
- }
-
- return;
-
-}
-
-sub kiriwrite_variablecheck{
-#################################################################################
-# kiriwrite_variablecheck: Checks the variables for any invalid characters. #
-# #
-# Usage: #
-# #
-# kiriwrite_variablecheck(variablename, type, length, noerror); #
-# #
-# variablename Specifies the variable to be checked. #
-# type Specifies what type the variable is. #
-# option Specifies the maximum/minimum length of the variable #
-# (if minlength/maxlength is used) or if the filename should be #
-# checked to see if it is blank. #
-# noerror Specifies if Kiriwrite should return an error or not on #
-# certain values. #
-#################################################################################
-
- # Get the values that were passed to the subroutine.
-
- my ($variable_data, $variable_type, $variable_option, $variable_noerror) = @_;
-
- if ($variable_type eq "numbers"){
-
- # Check for numbers and return an error if there is anything else than numebrs.
-
- my $variable_data_validated = $variable_data; # Copy the variable_data to variable_data_validated.
- $variable_data_validated =~ tr/0-9//d; # Take away all of the numbers and from the variable.
- # If it only contains numbers then it should be blank.
-
- if ($variable_data_validated eq ""){
- # The validated variable is blank. So continue to the end of this section where the return function should be.
- } else {
- # The variable is not blank, so check if the no error value is set
- # to 1 or not.
-
- if ($variable_noerror eq 1){
-
- # The validated variable is not blank and the noerror
- # value is set to 1. So return an value of 1.
- # (meaning that the data is invalid).
-
- return 1;
-
- } elsif ($variable_noerror eq 0) {
-
- # The validated variable is not blank and the noerror
- # value is set to 0.
-
- kiriwrite_error("invalidvariable");
-
- } else {
-
- # The variable noerror value is something else
- # pther than 1 or 0. So return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- }
-
- return 0;
-
- } elsif ($variable_type eq "lettersnumbers"){
-
- # Check for letters and numbers and return an error if there is anything else other
- # than letters and numbers.
-
- my $variable_data_validated = $variable_data; # Copy the variable_data to variable_data_validated
- $variable_data_validated =~ tr/a-zA-Z0-9.//d;
- $variable_data_validated =~ s/\s//g;
-
- if ($variable_data_validated eq ""){
- # The validated variable is blank. So continue to the end of this section where the return function should be.
- } else {
- # The variable is not blank, so check if the no error value is set
- # to 1 or not.
-
- if ($variable_noerror eq 1){
-
- # The validated variable is not blank and the noerror
- # value is set to 1. So return an value of 1.
- # (meaning that the data is invalid).
-
- return 1;
-
- } elsif ($variable_noerror eq 0) {
-
- # The validated variable is not blank and the noerror
- # value is set to 0.
-
- kiriwrite_error("invalidvariable");
-
- } else {
-
- # The variable noerror value is something else
- # pther than 1 or 0. So return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- }
-
- return 0;
-
- } elsif ($variable_type eq "maxlength"){
- # Check for the length of the variable, return an error if it is longer than the length specified.
-
- # Check if the variable_data string is blank, if it is then set the variable_data_length
- # to '0'.
-
- my $variable_data_length = 0;
-
- if (!$variable_data){
-
- # Set variable_data_length to '0'.
- $variable_data_length = 0;
-
- } else {
-
- # Get the length of the variable recieved.
- $variable_data_length = length($variable_data);
-
- }
-
-
-
- if ($variable_data_length > $variable_option){
-
- # The variable length is longer than it should be so check if
- # the no error value is set 1.
-
- if ($variable_noerror eq 1){
-
- # The no error value is set to 1, so return an
- # value of 1 (meaning tha the variable is
- # too long to be used).
-
- return 1;
-
- } elsif ($variable_noerror eq 0){
-
- # The no error value is set to 0, so return
- # an error.
-
- kiriwrite_error("variabletoolong");
-
- } else {
-
- # The no error value is something else other
- # than 0 or 1, so return an error.
-
- kiriwrite_error("variabletoolong");
-
- }
-
- } else {
-
- # The variable length is exactly or shorter than specified, so continue to end of this section where
- # the return function should be.
-
- }
-
- return 0;
-
- } elsif ($variable_type eq "blank"){
- # Check if the variable is blank and if it is blank, then return an error.
-
- if (!$variable_data){
-
- # The variable data really is blank, so check what
- # the no error value is set.
-
- if ($variable_noerror eq 1){
-
- # The no error value is set to 1, so return
- # a value of 1 (saying that the variable was
- # blank).
-
- return 1;
-
- } elsif ($variable_noerror eq 0){
-
- # The no error value is set to 0, so return
- # an error.
-
- kiriwrite_error("blankvariable");
-
- } else {
-
- # The no error value is something else other
- # than 0 or 1, so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- }
-
- return 0;
-
- } elsif ($variable_type eq "filename"){
- # Check for letters and numbers, if anything else than letters and numbers is there (including spaces) return
- # an error.
-
- # Check if the filename passed is blank, if it is then return with an error.
-
- if ($variable_data eq ""){
-
- # The filename specified is blank, so check what the
- # noerror value is set.
-
- if ($variable_noerror eq 1){
-
- # The no error value is set to 1 so return
- # a value of 1 (meaning that the filename
- # was blank).
-
- return 1;
-
- } elsif ($variable_noerror eq 0){
-
- # The no error value is set to 1 so return
- # an error.
-
- kiriwrite_error("blankfilename");
-
- } else {
-
- # The no error value is something else other
- # than 0 or 1, so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- } else {
-
-
- }
-
- my $variable_data_validated = $variable_data;
- $variable_data_validated =~ tr/a-zA-Z0-9\.//d;
-
- # Check if the validated data variable is blank, if it is
- # then continue to the end of this section where the return
- # function should be, otherwise return an error.
-
- if ($variable_data_validated eq ""){
-
- # The validated data variable is blank, meaning that
- # it only contained letters and numbers.
-
- } else {
-
- # The validated data variable is not blank, meaning
- # that it contains something else, so return an error
- # (or a value).
-
- if ($variable_noerror eq 1){
-
- # The no error value is set to 1 so return
- # an value of 2. (meaning that the filename
- # is invalid).
-
-
- return 2;
-
- } elsif ($variable_noerror eq 0){
-
- # The no error value is set to 0 so return
- # an error.
-
- kiriwrite_error("invalidfilename");
-
- } else {
-
- # The no error value is something else other
- # than 0 or 1 so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- }
-
- return 0;
-
- } elsif ($variable_type eq "filenameindir"){
- # Check if the filename is in the directory and return an
- # error if it isn't.
-
- if ($variable_data eq ""){
-
- # The filename specified is blank, so check what the
- # noerror value is set.
-
- if ($variable_noerror eq 1){
-
- # The no error value is set to 1 so return
- # a value of 1 (meaning that the filename
- # was blank).
-
- return 1;
-
- } elsif ($variable_noerror eq 0){
-
- # The no error value is set to 1 so return
- # an error.
-
- kiriwrite_error("blankfilename");
-
- } else {
-
- # The no error value is something else other
- # than 0 or 1, so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- } else {
-
-
- }
-
- # Set the following variables for later on.
-
- my $variable_data_length = 0;
- my $variable_data_char = "";
- my $variable_data_validated = "";
- my $variable_data_seek = 0;
- my $variable_data_directory = "";
- my $variable_data_directorycurrent = "";
- my $variable_data_firstlevel = 1;
-
- # Get the length of the variable recieved.
-
- $variable_data_length = length($variable_data);
-
- # Check if the database filename contains the directory command
- # for up a directory level and if it is, return an error
- # or return with a number.
-
- do {
-
- # Get a character from the filename passed to this subroutine.
-
- $variable_data_char = substr($variable_data, $variable_data_seek, 1);
-
- # Check if the current character is the forward slash character.
-
- if ($variable_data_char eq "/"){
-
- # Check if the current directory is blank (and on the first level), or if the
- # current directory contains two dots or one dot, if it does return an error.
-
- if ($variable_data_directorycurrent eq "" && $variable_data_firstlevel eq 1 || $variable_data_directorycurrent eq ".." || $variable_data_directorycurrent eq "."){
-
- # Check if the noerror value is set to 1, if it is return an
- # number, else return an proper error.
-
- if ($variable_noerror eq 1){
-
- # Page filename contains invalid characters and
- # the no error value is set to 1 so return a
- # value of 2 (meaning that the page filename
- # is invalid).
-
- return 2;
-
- } elsif ($variable_noerror eq 0) {
-
- # Page filename contains invalid characters and
- # the no error value is set to 0 so return an
- # error.
-
- kiriwrite_error("invalidfilename");
-
- } else {
-
- # The no error value is something else other
- # than 0 or 1 so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- }
-
- # Append the forward slash, clear the current directory name and set
- # the first directory level value to 0.
-
- $variable_data_directory = $variable_data_directory . $variable_data_char;
- $variable_data_directorycurrent = "";
- $variable_data_firstlevel = 0;
-
- } else {
-
- # Append the current character to the directory name and to the current
- # directory name.
-
- $variable_data_directory = $variable_data_directory . $variable_data_char;
- $variable_data_directorycurrent = $variable_data_directorycurrent . $variable_data_char;
-
- }
-
- # Increment the seek counter.
-
- $variable_data_seek++;
-
- } until ($variable_data_seek eq $variable_data_length);
-
- return 0;
-
- } elsif ($variable_type eq "datetime"){
- # Check if the date and time setting format is valid.
-
- if ($variable_data eq ""){
-
- if ($variable_noerror eq 1){
-
- # The no error value is set to 1 so return
- # a value of 1 (meaning that the date and
- # time format was blank).
-
- return 1;
-
- } elsif ($variable_noerror eq 0){
-
- # The no error value is set to 1 so return
- # an error.
-
- kiriwrite_error("blankdatetimeformat");
-
- } else {
-
- # The no error value is something else other
- # than 0 or 1, so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- }
-
- my $variable_data_validated = $variable_data;
- $variable_data_validated =~ tr|dDmMyYhms/():[ ]||d;
-
- if ($variable_data_validated eq ""){
-
- # The date and time format is valid. So
- # skip this bit.
-
- } else {
-
- # The validated data variable is not blank, meaning
- # that it contains something else, so return an error
- # (or a value).
-
- if ($variable_noerror eq 1){
-
- # The no error value is set to 1 so return
- # an value of 2. (meaning that the date and
- # time format was invalid).
-
- return 2;
-
- } elsif ($variable_noerror eq 0){
-
- # The no error value is set to 0 so return
- # an error.
-
- kiriwrite_error("invaliddatetimeformat");
-
- } else {
-
- # The no error value is something else other
- # than 0 or 1 so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- }
-
- return 0;
-
- } elsif ($variable_type eq "directory"){
- # Check if the directory only contains letters and numbers and
- # return an error if anything else appears.
-
- my $variable_data_validated = $variable_data;
- $variable_data_validated =~ tr/a-zA-Z0-9//d;
-
- if ($variable_data eq ""){
-
- if ($variable_noerror eq 1){
-
- # The no error value is set to 1 so return
- # a value of 1 (meaning that the directory
- # name was blank).
-
- return 1;
-
- } elsif ($variable_noerror eq 0){
-
- # The no error value is set to 1 so return
- # an error.
-
- kiriwrite_error("blankdirectory");
-
- } else {
-
- # The no error value is something else other
- # than 0 or 1, so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- }
-
- if ($variable_data_validated eq ""){
-
- # The validated data variable is blank, meaning that
- # it only contains letters and numbers.
-
- } else {
-
- # The validated data variable is not blank, meaning
- # that it contains something else, so return an error
- # (or a value).
-
- if ($variable_noerror eq 1){
-
- # The no error value is set to 1 so return
- # an value of 2. (meaning that the directory
- # name is invalid).
-
- return 2;
-
- } elsif ($variable_noerror eq 0){
-
- # The no error value is set to 0 so return
- # an error.
-
- kiriwrite_error("invaliddirectory");
-
- } else {
-
- # The no error value is something else other
- # than 0 or 1 so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- }
-
- return 0;
-
- } elsif ($variable_type eq "language_filename"){
-
- # The variable type is a language filename type.
- # Check if the language file name is blank and
- # if it is then return an error (or value).
-
- if ($variable_data eq ""){
-
- # The language filename is blank so check the
- # no error value and return an error (or value).
-
- if ($variable_noerror eq 1){
-
- # Language filename is blank and the no error value
- # is set as 1, so return a value of 1 (saying that
- # the language filename is blank).
-
- return 1;
-
- } elsif ($variable_noerror eq 0) {
-
- # Language filename is blank and the no error value
- # is not set as 1, so return an error.
-
- kiriwrite_error("emptylanguagefilename");
-
- } else {
-
- # The noerror value is something else other
- # than 0 or 1 so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- }
-
- # Set the following variables for later on.
-
- my $variable_data_length = 0;
- my $variable_data_char = "";
- my $variable_data_seek = 0;
-
- # Get the length of the language file name.
-
- $variable_data_length = length($variable_data);
-
- do {
-
- # Get a character from the language filename passed to this
- # subroutine and the character the seek counter value is set
- # to.
-
- $variable_data_char = substr($variable_data, $variable_data_seek, 1);
-
- # Check if the language filename contains a forward slash or a dot,
- # if the selected character is a forward slash then return an error
- # (or value).
-
- if ($variable_data_char eq "/" || $variable_data_char eq "."){
-
- # The language filename contains a forward slash or
- # a dot so depending on the no error value, return
- # an error or a value.
-
- if ($variable_noerror eq 1){
-
- # Language filename contains a forward slash or a dot
- # and the no error value has been set to 1, so return
- # an value of 2 (saying that the language file name is
- # invalid).
-
- return 2;
-
- } elsif ($variable_noerror eq 0) {
-
- # Language filename contains a forward slash and the no
- # error value has not been set to 1, so return an error.
-
- kiriwrite_error("invalidlanguagefilename");
-
- } else {
-
- # The noerror value is something else other than
- # 1 or 0 so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- }
-
- # Increment the seek counter.
-
- $variable_data_seek++;
-
- } until ($variable_data_seek eq $variable_data_length);
-
- return 0;
-
- } elsif ($variable_type eq "pagesetting"){
-
- # The variable type is a page setting, so check if the page
- # setting has one of the valid options.
-
- if ($variable_data eq 0 || $variable_data eq 1 || $variable_data eq 2 || $variable_data eq 3){
-
- # The variable is one of the options above, so continue
- # to the end of this section.
-
- } else {
-
- # The variable is not one of the options above, so check
- # and see if a error or a value should be returned.
-
- if ($variable_noerror eq 1){
-
- # The page setting is invalid and the no error
- # value is set 1, so return a value of 1
- # (saying that the page setting value is
- # invalid).
-
- return 1;
-
- } elsif ($variable_noerror eq 0) {
-
- # Page setting is invalid and the no error value
- # is not 1, so return an error.
-
- kiriwrite_error("invalidvariable");
-
- } else {
-
- # The no error value is something else other
- # than 0 or 1 so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- }
-
- return 0;
-
- } elsif ($variable_type eq "page_filename"){
-
- # The variable type is a page filename type. Check
- # if the data is empty and if it is then return an
- # error (or value).
-
- if ($variable_data eq ""){
-
- # The filename is blank so check the no error
- # value and depending on it return an value
- # or an error.
-
- if ($variable_noerror eq 1){
-
- # Page filename is blank and the no error value
- # is set as 1, so return a value of 1 (saying
- # the filename is blank).
-
- return 1;
-
- } elsif ($variable_noerror eq 0) {
-
- # Page filename is blank and the no error value
- # is not 1, so return an error.
-
- kiriwrite_error("emptypagefilename");
-
- } else {
-
- # The no error value is something else other
- # than 0 or 1 so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
- }
-
- # Set the following variables for later on.
-
- my $variable_data_length = 0;
- my $variable_data_char = "";
- my $variable_data_validated = "";
- my $variable_data_seek = 0;
- my $variable_data_directory = "";
- my $variable_data_directorycurrent = "";
- my $variable_data_firstlevel = 1;
-
- # Get the length of the filename.
-
- $variable_data_length = length($variable_data);
-
- # Check that only valid characters should be appearing in
- # the filename.
-
- $variable_data_validated = $variable_data;
- $variable_data_validated =~ tr|a-zA-Z0-9\.\/||d;
-
- if ($variable_data_validated ne ""){
-
- # The validated variable is not blank, meaning the
- # variable contains invalid characters, so return
- # an error.
-
- kiriwrite_error("invalidfilename");
-
- }
-
- # Check if the page filename contains the directory command
- # for up a directory level and if it is, return an error
- # or return with a number.
-
- do {
-
- # Get a character from the filename passed to this subroutine.
-
- $variable_data_char = substr($variable_data, $variable_data_seek, 1);
-
- # Check if the current character is the forward slash character.
-
- if ($variable_data_char eq "/"){
-
- # Check if the current directory is blank (and on the first level), or if the
- # current directory contains two dots or one dot, if it does return an error.
-
- if ($variable_data_directorycurrent eq "" && $variable_data_firstlevel eq 1 || $variable_data_directorycurrent eq ".." || $variable_data_directorycurrent eq "."){
-
- # Check if the noerror value is set to 1, if it is return an
- # number, else return an proper error.
-
- if ($variable_noerror eq 1){
-
- # Page filename contains invalid characters and
- # the no error value is set to 1 so return a
- # value of 2 (meaning that the page filename
- # is invalid).
-
- return 2;
-
- } elsif ($variable_noerror eq 0) {
-
- # Page filename contains invalid characters and
- # the no error value is set to 0 so return an
- # error.
-
- kiriwrite_error("invalidfilename");
-
- } else {
-
- # The no error value is something else other
- # than 0 or 1 so return an error.
-
- kiriwrite_error("invalidvariable");
-
- }
-
- }
-
- # Append the forward slash, clear the current directory name and set
- # the first directory level value to 0.
-
- $variable_data_directory = $variable_data_directory . $variable_data_char;
- $variable_data_directorycurrent = "";
- $variable_data_firstlevel = 0;
-
- } else {
-
- # Append the current character to the directory name and to the current
- # directory name.
-
- $variable_data_directory = $variable_data_directory . $variable_data_char;
- $variable_data_directorycurrent = $variable_data_directorycurrent . $variable_data_char;
-
- }
-
- # Increment the seek counter.
-
- $variable_data_seek++;
-
- } until ($variable_data_seek eq $variable_data_length);
-
- return 0;
-
- } elsif ($variable_type eq "outputmodule"){
-
- # The variable type is a output module filename.
-
- # Check if the variable_data is blank and if it is
- # return an error.
-
- if ($variable_data eq ""){
-
- # The output module is blank so check if an error
- # value should be returned or a number should be
- # returned.
-
- } else {
-
- }
-
- my $variable_data_validated = $variable_data;
- $variable_data_validated =~ tr/a-zA-Z0-9//d;
-
- if ($variable_data_validated eq ""){
-
- } else {
-
- kiriwrite_error("outputmoduleinvalid");
-
- }
-
- return 0;
-
- } elsif ($variable_type eq "utf8"){
-
- # The variable type is a UTF8 string.
-
- # Check if the string is a valid UTF8 string.
-
- if ($variable_data =~ m/^(
- [\x09\x0A\x0D\x20-\x7E] # ASCII
- | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
- | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
- | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
- | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
- | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
- | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
- | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
- )*$/x){
-
- # The UTF-8 string is valid.
-
- } else {
-
- # The UTF-8 string is not valid, check if the no error
- # value is set to 1 and return an error if it isn't.
-
- if ($variable_noerror eq 1){
-
- # The no error value has been set to 1, so return
- # a value of 1 (meaning that the UTF-8 string is
- # invalid).
-
- return 1;
-
- } elsif ($variable_noerror eq 0) {
-
- # The no error value has been set to 0, so return
- # an error.
-
- kiriwrite_error("invalidutf8");
-
- } else {
-
- # The no error value is something else other than 0
- # or 1, so return an error.
-
- kiriwrite_error("invalidoption");
-
- }
-
- }
-
- return 0;
-
- } else {
- # Another type than the valid ones above has been specified so return an error specifying an invalid option.
- kiriwrite_error("invalidoption");
- }
-
-}
-
-sub kiriwrite_convert{
-#################################################################################
-# kiriwrite_convert: Converts certain characters. #
-# #
-# Usage; #
-# #
-# kiriwrite_convert(data, type); #
-# #
-# data Specifies the data to be used with #
-# type The type of conversion to make (convert from or to kiriwrite #
-# values. #
-#################################################################################
-
- # Get the data that was passed to the subroutine.
- my ($data, $type) = @_;
-
- if ($type eq "kiriwrite"){
-
- # Convert to into the Kiriwrite format.
-
- $data =~ s/'/''/g;
- $data =~ s/\b//g;
-
- } elsif ($type eq "normal_display"){
-
- # Convert into a viewable format.
-
- $data =~ s/&/&/g;
- $data =~ s/\"/"/g;
- $data =~ s/'/'/g;
- $data =~ s/>/>/g;
- $data =~ s/</</g;
- $data =~ s/\0//g;
- $data =~ s/\b//g;
-
- } elsif ($type eq "normal_out"){
-
- # Convert into the original format.
-
- $data =~ s/\0//g;
- $data =~ s/\b//g;
-
- } elsif ($type eq "date"){
-
- # Convert the date given into the proper date.
-
- # Create the following varialbes to be used later.
-
- my $date;
- my $time;
- my $day;
- my $day_full;
- my $month;
- my $month_check;
- my $month_full;
- my $year;
- my $year_short;
- my $hour;
- my $hour_full;
- my $minute;
- my $minute_full;
- my $second;
- my $second_full;
- my $seek = 0;
- my $timelength;
- my $datelength;
- my $daylength;
- my $secondlength;
- my $startchar = 0;
- my $char;
- my $length;
- my $count = 0;
-
- # Split the date and time.
-
- $length = length($data);
-
- if ($length > 0){
-
- do {
-
- # Get the character and check if it is a space.
-
- $char = substr($data, $seek, 1);
-
- if ($char eq ' '){
-
- # The character is a space, so get the date and time.
-
- $date = substr($data, 0, $seek);
- $timelength = $length - $seek - 1;
- $time = substr($data, $seek + 1, $timelength);
-
- }
-
- $seek++;
-
- } until ($seek eq $length);
-
- # Get the year, month and date.
-
- $length = length($date);
- $seek = 0;
-
- do {
-
- # Get the character and check if it is a dash.
-
- $char = substr($date, $seek, 1);
-
- if ($char eq '-'){
-
- # The character is a dash, so get the year, month or day.
-
- $datelength = $seek - $startchar;
-
- if ($count eq 0){
-
- # Get the year from the date.
-
- $year = substr($date, 0, $datelength) + 1900;
- $startchar = $seek;
- $count = 1;
-
- # Get the last two characters to get the short year
- # version.
-
- $year_short = substr($year, 2, 2);
-
- } elsif ($count eq 1){
-
- # Get the month and day from the date.
-
- $month = substr($date, $startchar + 1, $datelength - 1) + 1;
-
- # Check if the month is less then 10, if it is
- # add a zero to the value.
-
- if ($month < 10){
-
- $month_full = '0' . $month;
-
- } else {
-
- $month_full = $month;
-
- }
-
- $startchar = $seek;
- $count = 2;
-
- $daylength = $length - $seek + 1;
- $day = substr($date, $startchar + 1, $daylength);
-
- # Check if the day is less than 10, if it is
- # add a zero to the value.
-
- if ($day < 10){
-
- $day_full = '0' . $day;
-
- } else {
-
- $day_full = $day;
-
- }
-
- }
-
- }
-
- $seek++;
-
- } until ($seek eq $length);
-
- # Get the length of the time value and reset certain
- # values to 0.
-
- $length = length($time);
- $seek = 0;
- $count = 0;
- $startchar = 0;
-
- do {
-
- # Get the character and check if it is a colon.
-
- $char = substr($time, $seek, 1);
-
- if ($char eq ':'){
-
- # The character is a colon, so get the hour, minute and day.
-
- $timelength = $seek - $startchar;
-
- if ($count eq 0){
-
- # Get the hour from the time.
-
- $hour = substr($time, 0, $timelength);
- $count = 1;
- $startchar = $seek;
-
- # If the hour is less than ten then add a
- # zero.
-
- if ($hour < 10){
-
- $hour_full = '0' . $hour;
-
- } else {
-
- $hour_full = $hour;
-
- }
-
- } elsif ($count eq 1){
-
- # Get the minute and second from the time.
-
- $minute = substr($time, $startchar + 1, $timelength - 1);
- $count = 2;
-
- # If the minute is less than ten then add a
- # zero.
-
- if ($minute < 10){
-
- $minute_full = '0' . $minute;
-
- } else {
-
- $minute_full = $minute;
-
- }
-
- $startchar = $seek;
-
- $secondlength = $length - $seek + 1;
- $second = substr($time, $startchar + 1, $secondlength);
-
- # If the second is less than ten then add a
- # zero.
-
- if ($second < 10){
-
- $second_full = '0' . $second;
-
- } else {
-
- $second_full = $second;
-
- }
-
- }
-
- }
-
- $seek++;
-
- } until ($seek eq $length);
-
- # Get the setting for displaying the date and time.
-
- $data = $kiriwrite_config{"system_datetime"};
-
- # Process the setting for displaying the date and time
- # using regular expressions
-
- $data =~ s/DD/$day_full/g;
- $data =~ s/D/$day/g;
- $data =~ s/MM/$month_full/g;
- $data =~ s/M/$month/g;
- $data =~ s/YY/$year/g;
- $data =~ s/Y/$year_short/g;
-
- $data =~ s/hh/$hour_full/g;
- $data =~ s/h/$hour/g;
- $data =~ s/mm/$minute_full/g;
- $data =~ s/m/$minute/g;
- $data =~ s/ss/$second_full/g;
- $data =~ s/s/$second/g;
-
- }
-
- } else {
- kiriwrite_error("invalidoption");
- }
-
- return $data;
-
-}
-
-sub kiriwrite_output_header{
-#################################################################################
-# kiriwrite_output_header: Outputs the header to the browser/stdout/console. #
-# #
-# Usage: #
-# #
-# kiriwrite_output_header(mimetype); #
-# #
-# mimetype Specifies the mime type of the header. #
-#################################################################################
-
- # Print a header saying that the page expires immediately since the
- # date is set in the past.
-
- #print "Expires: Sunday, 01-Jan-06 00:00:00 GMT\n";
- #print "Content-Type: text/html; charset=utf-8\n";
- #print header();
- print header(-Expires=>'Sunday, 01-Jan-06 00:00:00 GMT', -charset=>'utf-8');
- return;
-}
-
-sub kiriwrite_processfilename{
-#################################################################################
-# kiriwrite_processfilename: Processes a name and turns it into a filename that #
-# can be used by Kiriwrite. #
-# #
-# Usage: #
-# #
-# kiriwrite_processfilename(text); #
-# #
-# text Specifies the text to be used in the process for creating a new #
-# filename. #
-#################################################################################
-
- # Get the values that have been passed to the subroutine.
-
- my ($process_text) = @_;
-
- # Define some variables that will be used later on.
-
- my $processed_stageone = "";
- my $processed_stagetwo = "";
- my $processed_length = "";
- my $processed_char = "";
- my $processed_seek = 0;
- my $processed_filename = "";
-
- # Set the first stage value of the processed filename to the
- # process filename and then filter it out to only contain
- # numbers and letters (no spaces) and then convert the
- # capitals to small letters.
-
- $processed_stageone = $process_text;
- $processed_stageone =~ tr#a-zA-Z0-9##cd;
- $processed_stageone =~ tr/A-Z/a-z/;
-
- # Now set the second stage value of the processed filename
- # to the first stage value of the processed filename and
- # then limit the filename down to 64 characters.
-
- $processed_stagetwo = $processed_stageone;
- $processed_length = length($processed_stagetwo);
-
- # Process the second stage filename into the final
- # filename and do so until the seek counter is 64
- # or reaches the length of the second stage filename.
-
- do {
-
- # Get the character that is the seek counter
- # is set at.
-
- $processed_char = substr($processed_stagetwo, $processed_seek, 1);
-
- # Append to the final processed filename.
-
- $processed_filename = $processed_filename . $processed_char;
-
- # Increment the seek counter.
-
- $processed_seek++;
-
- } until ($processed_seek eq 64 || $processed_seek eq $processed_length);
-
- return $processed_filename;
-
-}
-
-sub kiriwrite_error{
-#################################################################################
-# kiriwrite_error: Prints out an error message. #
-# #
-# Usage: #
-# #
-# kiriwrite_error(errortype); #
-# #
-# errortype Specifies the type of error that occured. #
-#################################################################################
-
- # Get the error type from the subroutine.
-
- my ($error_type) = @_;
-
- # Load the list of error messages.
-
- my ($kiriwrite_error, %kiriwrite_error);
-
- %kiriwrite_error = (
- # Catch all error message.
- "generic" => "An error has occured but not an error that is known to Kiriwrite.",
-
- # Standard error messages.
- "blankfilename" => "The filename specified was blank.",
- "blankvariable" => "A blank variable was specified.",
- "fileexists" => "A filename specified already exists.",
- "internalerror" => "An internal error has occured within Kiriwrite.",
- "invalidoption" => "An invalid option was given.",
- "invalidaction" => "An invalid action was specified.",
- "invalidfilename" => "The filename given contains invalid characters.",
- "invalidmode" => "An invalid mode was specified.",
- "invalidutf8" => "A UTF-8 string is invalid.",
- "invalidvariable" => "An variable with invalid data has been found.",
- "variabletoolong" => "A variable given is too long.",
-
- # Specific error messages.
- "blankcompiletype" => "The compile type specified is blank",
- "blankdatabasepageadd" => "No database was specified when trying to add a page.",
- "blankdirectory" => "The directory name specified was blank.",
- "blankfindfilter" => "The find filter was blank.",
- "blankdatetimeformat" => "The date and time format given is blank.",
- "databasecategoriestoolong" => "The database categories list is too long.",
- "databasecopysame" => "The database that the pages are being copied to is the same database that the pages are copied from.",
- "datadirectoryinvalidpermissions" => "The database directory has invalid permission settings.",
- "databasedescriptiontoolong" => "The database description is too long.",
- "databasefilenameinvalid" => "The database filename is invalid.",
- "databasefilenametoolong" => "The database filename is too long.",
- "databasefileinvalid" => "The database file is in an invalid format.",
- "databaseinvalidpermissions" => "The database has invalid permission settings.",
- "databasenameinvalid" => "The database name contains invalid characters.",
- "databasenametoolong" => "The database name is too long.",
- "databasenameblank" => "The database name is blank.",
- "databasemissingfile" => "The database file is missing.",
- "databasemovemissingfile" => "The database that the pages are moving to is missing.",
- "databasemovesame" => "The database that the pages are being moved to is the same database that the pages are moving from.",
- "dbdirectoryblank" => "The database directory name given was blank.",
- "dbdirectoryinvalid" => "The database directory name given was invalid.",
- "filtersdatabasefilenotcreated" => "The filters database was not created because of the invalid permissions set for directory where Kiriwrite is being run from.",
- "filtersdbinvalidformat" => "The filters database is an invalid format.",
- "filtersdbpermissions" => "The filters database has invalid permission settings.",
- "filtersdbmissing" => "The filters database is missing.",
- "filteridblank" => "The filter identification number given is blank.",
- "filterdoesnotexist" => "The filter with the identification number given does not exist.",
- "filteridinvalid" => "The filter identification number given is invalid.",
- "filteridtoolong" => "The filter identification number given is too long.",
- "findfiltertoolong" => "The find filter given is too long.",
- "filterpriorityinvalid" => "The filter priority number given is invalid.",
- "filterpriorityinvalidchars" => "The filter priority given contains invalid characters.",
- "filterprioritytoolong" => "The filter priority given is too long.",
- "invalidcompiletype" => "The compile type given is invalid.",
- "invalidpagenumber" => "The page number specified is invalid.",
- "nopagesselected" => "No pages were selected.",
- "invaliddirectory" => "The directory name specified was invalid.",
- "invaliddatetimeformat" => "The date and time format given is invalid.",
- "invalidlanguagefilename" => "An invalid language filename was given.",
- "newcopydatabasedoesnotexist" => "The database that the selected pages are being copied to does not exist.",
- "newcopydatabasefileinvalidpermissions" => "The database that the selected pages are being copied has invalid permissions set.",
- "newcopydatabasefileinvalid" => "The database that the selected pages are being copied to is in an invalid format.",
- "newmovedatabasedoesnotexist" => "The database that the selected pages are moving to does not exist.",
- "newmovedatabasefileinvalidpermissions" => "The database that the selected pages are moving to has invalid permissions set.",
- "newmovedatabasefileinvalid" => "The database that the selected pages are moving to is in an invalid format.",
- "nodatabasesavailable" => "No databases are available for compiling.",
- "nodatabaseselected" => "No databases were selected for compiling.",
- "noeditvaluesselected" => "No values will be changed on the selected pages as no values for changing were selected.",
- "oldcopydatabasedoesnotexist" => "The database that the selected pages are being copied to does not exist.",
- "oldcopydatabasefileinvalidpermissions" => "The database that the selected pages are being copied to has invalid permissions set.",
- "oldcopydatabasefileinvalid" => "The database that the selected pages are being copied to is in an invalid format.",
- "oldmovedatabasedoesnotexist" => "The database that the selected pages are moving from does not exist.",
- "oldmovedatabasefileinvalidpermissions" => "The database that the selected pages are moving from has invalid permissions set.",
- "oldmovedatabasefileinvalid" => "The database that the selected pages are moving from is in an invalid format.",
- "outputdirectoryblank" => "The output directory name given was blank.",
- "outputdirectoryinvalid" => "The output directory name given was invalid.",
- "outputdirectorymissing" => "The output directory is missing",
- "outputdirectoryinvalidpermissions" => "The output directory has invalid permissions set.",
- "outputmoduleblank" => "The output module name given is blank.",
- "outputmoduleinvalid" => "The output module name given is invalid.",
- "pagefilenamedoesnotexist" => "The page with the filename given does not exist.",
- "pagefilenameexists" => "The page filename given already exists",
- "pagefilenameinvalid" => "The page filename given is invalid.",
- "pagefilenametoolong" => "The page filename given is too long.",
- "pagefilenameblank" => "The page filename given is blank.",
- "pagetitletoolong" => "The page title given is too long.",
- "pagedescriptiontoolong" => "The page description given is too long.",
- "pagesectiontoolong" => "The page section given is too long.",
- "pagedatabasefilenametoolong" => "The page database filename given is too long.",
- "pagesettingstoolong" => "The page settings given is too long.",
- "pagesettingsinvalid" => "The page settings given are invalid.",
- "pagetemplatefilenametoolong" => "The page template filename given was too long.",
- "replacefiltertoolong" => "The replace filter given is too long",
- "templatenameblank" => "The template name given is blank.",
- "templatefilenameexists" => "A template with the given filename already exists.",
- "templatefilenameinvalid" => "The template filename given is invalid.",
- "templatedatabaseinvalidpermissions" => "The template database has invalid permissions.",
- "templatedatabaseinvalidformat" => "The template database is in a invalid format.",
- "templatedirectoryblank" => "The template directory name given was blank.",
- "templatedirectoryinvalid" => "The template directory name given was invalid.",
- "templatedatabasefilenotcreated" => "The template database was not created because of the invalid permissions set for the directory where Kiriwrite is being run from.",
- "templatefilenametoolong" => "The template filename given is too long",
- "templatenametoolong" => "The template name given is too long",
- "templatedescriptiontoolong" => "The template description given is too long",
- "templatedatabasemissing" => "The template database is missing.",
- "templatedoesnotexist" => "The template filename given does not exist in the templates database.",
- "templatefilenameblank" => "The template filename given was blank.",
- );
-
- # Check if the specified error is blank and if it is
- # use the generic error messsage.
-
- if (!$kiriwrite_error{$error_type}){
- $error_type = "generic";
- }
-
- my $pagedata = "<div class=\"errorbox\"><font class=\"errorheader\">Error!</font><br /><font class=\"errortext\">" . $kiriwrite_error{$error_type} . "</font></div>";
-
- kiriwrite_output_header;
- kiriwrite_output_page("Error!", $pagedata, "none");
-
- exit;
-
-}
-
-sub kiriwrite_get_templates{
-#################################################################################
-# kiriwrite_get_templates: Get the list of templates available (and valid) from #
-# the template directory. #
-# #
-# Usage: #
-# #
-# kiriwrite_get_templates(); #
-#################################################################################
-
- # Open the template folder and get the list of database configuration files.
-
- opendir(TEMPLATEDIR, $kiriwrite_config{"directory_data_template"});
- my @templatedir = grep /m*\.xml/, readdir(TEMPLATEDIR);
- closedir(TEMPLATEDIR);
-
- # Get the actual filename of the template by removing the .xml part from
- # the filename.
-
- my $templatedir_filename = "";
- my $templatedir_filename_originallength = "";
- my $templatedir_filename_char = "";
- my $templatedir_filename_processed = "";
- my $templatedir_filename_seek = 0;
- my $templatedir_filename_length = 0;
- my $templatedir_filename_finallength = 0;
- my @templatelist_processed;
- my $templatedir_processed_filename = "";
- my @templatelist_final;
- my $templatelist_final_count = 0;
-
- foreach $templatedir_filename (@templatedir){
-
- # Get the length of the original filename.
-
- $templatedir_filename_length = length($templatedir_filename);
- $templatedir_filename_finallength = $templatedir_filename_length - 4;
-
- # Get the filename minus the last four characters and put the processed
- # filename into the array of processed filenames.
-
- $templatedir_filename_processed = substr($templatedir_filename, 0, $templatedir_filename_finallength);
-
- $templatelist_processed[$templatedir_filename_seek] = $templatedir_filename_processed;
-
- # Increment the counter.
-
- $templatedir_filename_seek++;
-
- # Clear certain variables before using them again.
-
- $templatedir_filename_processed = "";
- $templatedir_filename_length = 0;
- $templatedir_filename_finallength = 0;
-
- }
-
- # Check that each template really does exist and put each valid
- # template into the final list.
-
- foreach $templatedir_processed_filename (@templatelist_processed){
-
- if (-e $kiriwrite_config{"directory_data_template"} . '/' . $templatedir_processed_filename){
-
- # The template does exist, so add the template to the list of valid templates.
-
- $templatelist_final[$templatelist_final_count] = $templatedir_processed_filename;
- $templatelist_final_count++;
-
- }
-
- }
-
- # Return the list of valid templates.
-
- return @templatelist_final;
-
-}
-
-sub kiriwrite_fileexists{
-#################################################################################
-# kiriwrite_fileexists: Check if a file exists and returns a value depending on #
-# if the file exists or not. #
-# #
-# Usage: #
-# #
-# kiriwrite_fileexists(filename); #
-# #
-# filename Specifies the file name to check if it exists or not. #
-#################################################################################
-
- # Get the value that was passed to the subroutine.
-
- my ($filename) = @_;
-
- # Check if the filename exists, if it does, return a value of 1, else
- # return a value of 0, meaning that the file was not found.
-
- if (-e $filename){
-
- # Specified file does exist so return a value of 1.
-
- return 0;
-
- } else {
-
- # Specified file does not exist so return a value of 0.
-
- return 1;
-
- }
-
-}
-
-sub kiriwrite_filepermissions{
-#################################################################################
-# kiriwrite_filepermissions: Check if the file permissions of a file and return #
-# either a 1 saying that the permissions are valid or return a 0 saying that #
-# the permissions are invalid. #
-# #
-# Usage: #
-# #
-# kiriwrite_filepermissions(filename, [read], [write], [filemissingskip]); #
-# #
-# filename Specifies the filename to check for permissions. #
-# read Preform check that the file is readable. #
-# write Preform check that the file is writeable. #
-# filemissingskip Skip the check of seeing if it can read or write if the #
-# file is missing. #
-#################################################################################
-
- # Get the values that was passed to the subroutine.
-
- my ($filename, $readpermission, $writepermission, $ignorechecks) = @_;
-
- # Check to make sure that the read permission and write permission values
- # are only 1 character long.
-
- kiriwrite_variablecheck($readpermission, "maxlength", 1, 0);
- kiriwrite_variablecheck($writepermission, "maxlength", 1, 0);
- kiriwrite_variablecheck($ignorechecks, "maxlength", 1, 0);
-
- my $ignorechecks_result = 0;
-
- # Check if the file should be ignored for read and write checking if
- # it doesn't exist.
-
- if ($ignorechecks){
-
- if (-e $filename){
-
- # The file exists so the checks are to be done.
-
- $ignorechecks_result = 0;
-
- } else {
-
- # The file does not exist so the checks don't need to
- # be done to prevent false positives.
-
- $ignorechecks_result = 1;
-
- }
-
- } else {
-
- $ignorechecks_result = 0;
-
- }
-
- # Check if the file should be checked to see if it can be read.
-
- if ($readpermission && $ignorechecks_result eq 0){
-
- # The file should be checked to see if it does contain read permissions
- # and return a 0 if it is invalid.
-
- if (-r $filename){
-
- # The file is readable, so do nothing.
-
- } else {
-
- # The file is not readable, so return 1.
-
- return 1;
-
- }
-
- }
-
- # Check if the file should be checked to see if it can be written.
-
- if ($writepermission && $ignorechecks_result eq 0){
-
- # The file should be checked to see if it does contain write permissions
- # and return a 0 if it is invalid.
-
- if (-w $filename){
-
- # The file is writeable, so do nothing.
-
- } else {
-
- # The file is not writeable, so return 1.
-
- return 1;
-
- }
-
- }
-
- # No problems have occured, so return 0.
-
- return 0;
-
-}
-
-sub kiriwrite_utf8convert{
-#################################################################################
-# kiriwrite_utf8convert: Properly converts values into UTF-8 and make sure #
-# that the size of the string is correct when doing input validation. #
-# #
-# Usage: #
-# #
-# utfstring # The UTF-8 string to convert. #
-#################################################################################
-
- # Get the values passed to the subroutine.
-
- my ($utfstring) = @_;
-
- # Load the Encode perl module.
-
- use Encode;
-
- # Convert the string.
-
- my $finalutf8 = Encode::decode_utf8( $utfstring );
-
- return $finalutf8;
-
-}
-
-sub kiriwrite_critical{
-#################################################################################
-# kiriwrite_critical: Displays a critical error message that cannot be #
-# normally by the kiriwrite_error subroutine. #
-# #
-# Usage: #
-# #
-# errortype Specifies the type of critical error that has occured. #
-#################################################################################
-
- # Get the value that was passed to the subroutine.
-
- my ($error_type) = @_;
-
- # Get the error type from the errortype string.
-
- if ($error_type eq "configfilemissing"){
-
- # The error is that the Kiriwrite configuration file is missing.
- # Print the header, error message and then end the script.
-
- print header();
- print "Critical Error: The Kiriwrite configuration file is missing! Running the setup script for Kiriwrite is recommended.";
- exit;
-
- } elsif ($error_type eq "configfileinvalidpermissions") {
-
- # The error is that the Kiriwrite configuration file has invalid
- # permission settings. Print the header, error messsage and then
- # end the script.
-
- print header();
- print "Critical Error: The Kiriwrite configuration file contains invalid permission settings! Please set the valid permission settings for the configuration file.";
- exit;
-
- } elsif ($error_type eq "outputsystemmissing") {
-
- # The error is that the output system module is missing. Print the
- # header, error message and then end the script.
-
- print header();
- print "Critical Error: The output system module is missing! Running the setup script for Kiriwrite is recommended.";
- exit;
-
- } elsif ($error_type eq "outputsysteminvalidpermissions"){
-
- # The error is that the output system module has invalid permissions
- # set. Print the header, error message and then end the script.
-
- print header();
- print "Critical Error: The output system module contains invalid permission settings! Please set the valid permission settings for the output module.";
- exit;
-
- }else {
-
- # The error type is unspecified, so return a generic error message.
-
- print header();
- print "Critical Error: An unspecified critical error has occured.";
- exit;
-
- }
-
-}
-
-sub kiriwrite_output_page{
-#################################################################################
-# kiriwrite_output_page: Outputs the page to the browser/stdout/console. #
-# #
-# Usage: #
-# #
-# kiriwrite_output_page(pagetitle, pagedata, menutype); #
-# #
-# pagetitle Specifies the page title. #
-# pagedata Specifies the page data. #
-# menutype Prints out which menu to use. #
-#################################################################################
-
- my ($pagetitle, $pagedata, $menutype) = @_;
-
- # Open the script page template and load it into the scriptpage variable,
- # while declaring the variable.
-
- open (SCRIPTPAGE, 'page.html');
- my @scriptpage = <SCRIPTPAGE>;
- close (SCRIPTPAGE);
-
- # Define the variables required.
-
- my $scriptpageline = "";
- my $pageoutput = "";
- my $menuoutput = "";
-
- # Print out the main menu for Kiriwrite.
-
- $menuoutput = "<a href=\"kiriwrite.cgi?mode=db\">View Databases</a> | <a href=\"kiriwrite.cgi?mode=page\">View Pages</a> | <a href=\"kiriwrite.cgi?mode=filter\">View Filters</a> | <a href=\"kiriwrite.cgi?mode=template\">View Templates</a> | <a href=\"kiriwrite.cgi?mode=compile\">Compile Pages</a> | <a href=\"kiriwrite.cgi?mode=settings\">View Settings</a>\r\n<br />";
-
- # 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 . "<a href=\"kiriwrite.cgi?mode=db\">Show Databases</a> | <a href=\"kiriwrite.cgi?mode=db&action=new\">Add Database</a>";
-
- } 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 . "<a href=\"kiriwrite.cgi?mode=page&action=add&database=" . $db_filename . "\">Add Page</a>";
-
- }
-
- } elsif ($menutype eq "filter"){
-
- # If the menu type is filters then print out the filter sub-menu.
- $menuoutput = $menuoutput . "<a href=\"kiriwrite.cgi?mode=filter\">Show Filters</a> | <a href=\"kiriwrite.cgi?mode=filter&action=add\">Add Filter</a>";
-
- } elsif ($menutype eq "settings"){
-
- # If the menu type is options then print out the options sub-menu.
- $menuoutput = $menuoutput . "<a href=\"kiriwrite.cgi?mode=settings\">Show Settings</a> | <a href=\"kiriwrite.cgi?mode=settings&action=edit\">Edit Settings</a>";
-
- } elsif ($menutype eq "template"){
-
- # If the menu type is template then print out the template sub-menu.
- $menuoutput = $menuoutput . "<a href=\"kiriwrite.cgi?mode=template\">Show Templates</a> | <a href=\"kiriwrite.cgi?mode=template&action=add\">Add Template</a>";
-
- } elsif ($menutype eq "compile"){
-
- # If the menu type is compile then print out the compile sub-menu.
- $menuoutput = $menuoutput . "<a href=\"kiriwrite.cgi?mode=compile&action=all\">Compile All</a> | <a href=\"kiriwrite.cgi?mode=compile&action=clean\">Clean Output Directory</a>";
-
- }
-
- # Find <kiriwrite> tages and replace with the apporiate variables.
-
- foreach $scriptpageline (@scriptpage){
-
- $scriptpageline =~ s/<kiriwrite:menu>/$menuoutput/g;
- $scriptpageline =~ s/<kiriwrite:pagedata>/$pagedata/g;
-
-
- # Check if page title specified is blank, otherwise add a page title
- # to the title.
-
- if ($pagetitle eq ""){
- $scriptpageline =~ s/<kiriwrite:title>//g;
- } else {
- $scriptpageline =~ s/<kiriwrite:title>/ ($pagetitle)/g;
- }
-
- # Append processed line to the pageoutput variable.
-
- $pageoutput = $pageoutput . $scriptpageline;
-
- }
-
- # Print out the page to the browser/console/stdout.
-
- print $pageoutput;
-
- return;
-
-}
-
-sub kiriwrite_output_xml{
-#################################################################################
-# kiriwrite_output_xml: Outputs several types of data to an XML file #
-# #
-# Usage: #
-# #
-# kiriwrite_output_xml(filename, type, data); #
-# #
-# filename Specifies the filename of the XML file. #
-# type Specifies the type of the XML file to be written. #
-# newsettings Specifies the new settings for the XML file. #
-#################################################################################
-
- # Get the variables passed from the subroutine.
-
- my ($xml_filename, $xml_type, @newsettings) = @_;
-
- # Check if filename is blank, if it is then return an error.
-
- if ($xml_filename eq ""){
- # Filename is blank, return an error.
- kiriwrite_error("blankfilename");
- }
-
- # Validate the XML filename to make sure nothing supicious is being passed.
-
- kiriwrite_variablecheck($xml_filename, "maxlength", 64, 0);
- kiriwrite_variablecheck($xml_filename, "filename", "", 0);
-
- # Check what type of XML data to output.
-
- if ($xml_type eq "config") {
-
- # The type of XML data to output is a Kiriwrite configuration file.
-
- # Get the data that has been passed to xml_data from the subroutine and
- # split them into seperate values.
-
- my ($xml_config_databasedir, $xml_config_outputdir, $xml_config_imagesuri, $xml_config_datetime, $xml_config_systemlanguage, $xml_config_outputsystem) = @newsettings;
-
- # Create the XML data layout.
-
- my $xmldata = "<?xml version=\"1.0\"?>\r\n\r\n<kiriwrite-config>\r\n";
-
- $xmldata = $xmldata . "<!-- This file was automatically generated by Kiriwrite, please feel free to edit to your own needs. -->\r\n";
- $xmldata = $xmldata . "\t<settings>\r\n\t\t<directories>\r\n";
-
- $xmldata = $xmldata . "\t\t\t<database>" . $xml_config_databasedir . "</database>\r\n";
- $xmldata = $xmldata . "\t\t\t<output>" . $xml_config_outputdir . "</output>\r\n";
- $xmldata = $xmldata . "\t\t\t<images>" . $xml_config_imagesuri . "</images>\r\n";
- $xmldata = $xmldata . "\t\t</directories>\r\n";
-
- $xmldata = $xmldata . "\t\t<language>\r\n";
- $xmldata = $xmldata . "\t\t\t<type>" . $xml_config_systemlanguage . "</type>\r\n";
- $xmldata = $xmldata . "\t\t</language>\r\n";
-
- $xmldata = $xmldata . "\t\t<system>\r\n";
- $xmldata = $xmldata . "\t\t\t<output>" . $xml_config_outputsystem . "</output>\r\n";
- $xmldata = $xmldata . "\t\t\t<datetime>" . $xml_config_datetime . "</datetime>\r\n";
- $xmldata = $xmldata . "\t\t</system>\r\n";
-
- $xmldata = $xmldata . "\t</settings>\r\n";
-
- $xmldata = $xmldata . "</kiriwrite-config>";
-
- # Open the Kiriwrite XML configuration file and write the new settings to the
- # configuration file.
-
- open(XMLCONFIG, "> kiriwrite.xml");
- print XMLCONFIG $xmldata;
- close(XMLCONFIG);
-
- } else {
-
- # The type of XML data is something else that is not supported by
- # Kiriwrite, so return an error.
-
- kiriwrite_error("invalidoption");
-
- }
-
- return;
-
-}
-
-#################################################################################
-# End listing the functions needed. #
-#################################################################################
-
-#################################################################################
-# Begin proper script execution. #
-#################################################################################
-
-kiriwrite_settings_load; # Load the configuration options.
-
-my $query = new CGI; # Easily fetch variables from the HTTP string.
-
-
-
-# Check if a mode has been specified and if a mode has been specified, continue
-# and work out what mode has been specified.
-
-if ($query->param('mode')){
- my $http_query_mode = $query->param('mode');
-
- if ($http_query_mode eq "db"){
-
- # If mode is 'db' (database), then check what action is required.
-
- 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"){
- # Value is correct, collect the variables to pass onto the database variable.
-
- # Load the XML::Simple module.
-
- use XML::Simple;
- my $xsl = XML::Simple->new();
-
- # Get the variables from the HTTP query.
-
- my $newdatabasename = $query->param('databasename');
- my $newdatabasedescription = $query->param('databasedescription');
- my $newdatabasefilename = $query->param('databasefilename');
- my $databasename = $query->param('olddatabasename');
- my $databasedescription = $query->param('olddatabasedescription');
- my $databaseshortname = $query->param('database');
- my $databasenotes = $query->param('databasenotes');
- my $databasecategories = $query->param('databasecategories');
-
- # Check the permissions of the database configuration file and return
- # an error if the database permissions are invalid.
-
- # 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");
- 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");
- 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");
-
- 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");
-
- 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");
- 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");
- 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.
-
- } 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 $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.
- 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');
- my $http_query_description = $query->param('pagedescription');
- my $http_query_section = $query->param('pagesection');
- my $http_query_template = $query->param('pagetemplate');
- my $http_query_settings = $query->param('pagesettings');
- my $http_query_content = $query->param('pagecontent');
-
- my $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.
- 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.
- 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');
- my $http_query_name = $query->param('pagename');
- my $http_query_description = $query->param('pagedescription');
- my $http_query_section = $query->param('pagesection');
- my $http_query_template = $query->param('pagetemplate');
- my $http_query_settings = $query->param('pagesettings');
- my $http_query_content = $query->param('pagecontent');
-
- # 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.
-
- }
-
- # 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.
- 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.
- 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.
- exit; # End the script.
-
-
- } elsif ($http_query_action eq "multidelete"){
-
- # The action selected was to delete multiple pages from a
- # database.
-
- my $http_query_database = $query->param('database');
- my $http_query_confirm = $query->param('confirm');
-
- my @filelist;
- my $pagedata;
-
- if ($http_query_confirm){
-
- # The action to delete multiple pages from the selected
- # database has been confirmed.
-
- @filelist = kiriwrite_selectedlist();
- $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.
- exit; # End the script.
-
- }
-
- # Get the list of selected pages and pass them to the
- # multiple page delete subroutine.
-
- @filelist = kiriwrite_selectedlist();
- $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.
- exit; # End the script.
-
- } elsif ($http_query_action eq "multimove"){
-
- # The action selected was to move multiple pages from a
- # database.
-
- my $http_query_database = $query->param('database');
- my $http_query_newdatabase = $query->param('newdatabase');
- my $http_query_confirm = $query->param('confirm');
-
- my @filelist;
- my $pagedata;
-
- if ($http_query_confirm){
-
- # The action to move multiple pages from the selected
- # database has been confirmed.
-
- @filelist = kiriwrite_selectedlist();
- $pagedata = kiriwrite_page_multimove($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
-
- kiriwrite_output_header; # Output the header to browser/console/stdout.
- kiriwrite_output_page("Move selected pages", $pagedata, "pages"); # Output the page to browser/console/stdout.
- exit; # End the script.
-
- }
-
- # Get the list of selected pages and pass them to the
- # multiple page move subroutine.
-
- @filelist = kiriwrite_selectedlist();
- $pagedata = kiriwrite_page_multimove($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
-
- kiriwrite_output_header; # Output the header to browser/console/stdout.
- kiriwrite_output_page("Move selected pages", $pagedata, "pages"); # Output the page to browser/console/stdout.
- exit; # End the script.
-
- } elsif ($http_query_action eq "multicopy"){
-
- # The action selected was to copy multiple pages from a
- # database.
-
- my $http_query_database = $query->param('database');
- my $http_query_newdatabase = $query->param('newdatabase');
- my $http_query_confirm = $query->param('confirm');
-
- my @filelist;
- my $pagedata;
-
- if ($http_query_confirm){
-
- # The action to copy multiple pages from the selected
- # database has been confirmed.
-
- @filelist = kiriwrite_selectedlist();
- $pagedata = kiriwrite_page_multicopy($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
-
- kiriwrite_output_header; # Output the header to browser/console/stdout.
- kiriwrite_output_page("Copy selected pages", $pagedata, "pages"); # Output the page to browser/console/stdout.
- exit; # End the script.
-
- }
-
- # Get the list of selected pages and pass them to the
- # multiple page copy subroutine.
-
- @filelist = kiriwrite_selectedlist();
- $pagedata = kiriwrite_page_multicopy($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
-
- kiriwrite_output_header; # Output the header to browser/console/stdout.
- kiriwrite_output_page("Copy selected pages", $pagedata, "pages"); # Output the page to browser/console/stdout.
- exit; # End the script.
-
- } elsif ($http_query_action eq "multiedit"){
-
- # The action selected was to edit multiple pages from a
- # database.
-
- my $http_query_database = $query->param('database');
- my $http_query_newsection = $query->param('newsection');
- my $http_query_altersection = $query->param('altersection');
- my $http_query_newtemplate = $query->param('newtemplate');
- my $http_query_altertemplate = $query->param('altertemplate');
- my $http_query_newsettings = $query->param('newsettings');
- my $http_query_altersettings = $query->param('altersettings');
- my $http_query_confirm = $query->param('confirm');
-
- my @filelist;
- my $pagedata;
-
- if (!$http_query_confirm){
-
- @filelist = kiriwrite_selectedlist();
- $pagedata = kiriwrite_page_multiedit($http_query_database, $http_query_newsection, $http_query_altersection, $http_query_newtemplate, $http_query_altertemplate, $http_query_newsettings, $http_query_altersettings, $http_query_confirm, @filelist);
-
- kiriwrite_output_header; # Output the header to browser/console/stdout.
- kiriwrite_output_page("Edit selected pages", $pagedata, "pages"); # Output the page to browser/console/stdout.
- exit;
-
- }
-
- # Get the list of selected pages and pass them to the
- # multiple page edit subroutine.
-
- @filelist = kiriwrite_selectedlist();
- $pagedata = kiriwrite_page_multiedit($http_query_database, $http_query_newsection, $http_query_altersection, $http_query_newtemplate, $http_query_altertemplate, $http_query_newsettings, $http_query_altersettings, $http_query_confirm, @filelist);
-
- kiriwrite_output_header; # Output the header to browser/console/stdout.
- kiriwrite_output_page("Edit selected pages", $pagedata, "pages"); # Output the page to browser/console/stdout.
- exit; # End the script.
-
- } else {
- kiriwrite_error("invalidaction");
- }
-
- } else {
-
- # If there the action option is left blank, then print out a form where the database
- # can be selected to view pages from.
-
- my $pagedata = kiriwrite_page_list;
-
- kiriwrite_output_header; # Output the header to browser/console/stdout.
- kiriwrite_output_page("Database Selection", $pagedata, "pages"); # Output the page to browser/console/stdout.
- exit; # End the script.
-
- }
-
- # No action has been specified, do the default action of listing pages from
- # the first database found in the directory.
-
- } elsif ($http_query_mode eq "filter"){
-
- # If there's a value for action in the HTTP query, then
- # get that value that is in the HTTP query.
-
- if ($query->param('action')){
-
- # 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.
- 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.
- 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.
- 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.
- 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.
- exit; # End the script
-
- }
-
- my $pagedata = kiriwrite_filter_delete($http_query_number);
-
- kiriwrite_output_header; # Output the header to browser/console/stdout.
- kiriwrite_output_page("Delete Filter", $pagedata, "filter"); # Output the page to browser/console/stdout.
- exit; # End the script.
-
- } else {
-
- # 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.
- 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 ""){
- # 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.
- 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.
-
- }
-
- } 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.
- 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.
- exit; # End the script.
-
- }
-
- } elsif ($http_query_action eq "edit") {
-
- # Get the required parameters from the HTTP query.
-
- my $http_query_templatefile = $query->param('template');
- my $http_query_confirm = $query->param('confirm');
-
- # 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.
- 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.
- 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
- # return an error.
-
- kiriwrite_error("invalidaction");
-
- }
-
- } else {
-
- # If the action option is left blank, then print out a form where the list
- # of templates are available.
-
- my $pagedata = kiriwrite_template_list;
-
- kiriwrite_output_header; # Output the header to browser/console/stdout.
- kiriwrite_output_page("View Templates", $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.
-
- if (!$http_query_type){
-
- # Compile type is blank so return an error.
-
- kiriwrite_error("blankcompiletype");
-
- }
-
- 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.
- 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.
- exit; # End the script.
-
- }
-
- } elsif ($http_query_type eq "single"){
-
- my $http_query_database = $query->param('database');
- my @selectedlist;
- $selectedlist[0] = $http_query_database;
- 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");
- exit; # End the script.
-
- } else {
-
- kiriwrite_error("invalidcompiletype");
-
- }
-
- } elsif ($http_query_action eq "all"){
-
- # The selected action is to compile all of the databases
- # in the database directory. Check if the action to
- # compile all of the databases has been confirmed.
-
- my $http_query_confirm = $query->param('confirm');
-
- if (!$http_query_confirm){
-
- # The http_query_confirm variable is uninitalised, so place a
- # '0' (meaning an unconfirmed action).
-
- $http_query_confirm = 0;
-
- }
-
- if ($http_query_confirm eq 1){
-
- # The action to compile all the databases has been confirmed.
-
- }
-
- my $pagedata = kiriwrite_compile_all();
-
- kiriwrite_output_header; # Output the header to browser/console/stdout.
- kiriwrite_output_page("Compile All Databases", $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.
- 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.
- exit; # End the script.
-
- } else {
-
- # The action specified was something else other than those
- # above, so return an error.
-
- kiriwrite_error("invalidaction");
-
- }
- }
-
- my $pagedata = kiriwrite_compile_list;
-
- kiriwrite_output_header; # Output the header to browser/console/stdout.
- kiriwrite_output_page("Compile Pages", $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){
-
- # The confirm value is blank, so set it to 0.
-
- $http_query_confirm = 0;
-
- }
-
- if ($http_query_confirm eq 1){
-
- # The action to edit the settings has been confirmed. Get the
- # required settings from the HTTP query.
-
- my $http_query_database = $query->param('databasedir');
- my $http_query_output = $query->param('outputdir');
- my $http_query_imagesuri = $query->param('imagesuripath');
- my $http_query_datetimeformat = $query->param('datetime');
- my $http_query_systemlanguage = $query->param('language');
- my $http_query_outputsystem = $query->param('outputsys');
-
- my $pagedata = kiriwrite_settings_edit($http_query_database, $http_query_output, $http_query_imagesuri, $http_query_datetimeformat, $http_query_systemlanguage, $http_query_outputsystem, $http_query_confirm);
-
- kiriwrite_output_header; # Output the header to browser/console/stdout.
- kiriwrite_output_page("Edit Settings", $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.
- exit; # End the script.
-
- } else {
-
- # The action specified was something else other than those
- # above, so return an error.
-
- kiriwrite_error("invalidaction");
-
- }
-
- }
-
- # No action has been specified, so print out the list of settings currently being used.
-
- my $pagedata = kiriwrite_settings_view;
-
- kiriwrite_output_header; # Output the header to browser/console/stdout.
- kiriwrite_output_page("View Settings", $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.
-