Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Commit of recent work in preperation for Kiriwrite 0.5.0
[kiriwrite/.git] / cgi-files / Modules / System / Common.pm
1 package Modules::System::Common;
3 use strict;
4 use warnings;
5 use Exporter;
6 use CGI::Lite;
8 our @ISA = qw(Exporter);
9 our @EXPORT = qw(kiriwrite_initalise kiriwrite_settings_load kiriwrite_fileexists kiriwrite_filepermissions kiriwrite_output_header kiriwrite_output_page kiriwrite_variablecheck kiriwrite_processconfig kiriwrite_processfilename kiriwrite_utf8convert kiriwrite_language kiriwrite_error kiriwrite_selectedlist);
11 sub kiriwrite_selectedlist{
12 #################################################################################
13 # kiriwrite_page_selectedlist: Get the list of selected pages to use.           #
14 #                                                                               #
15 # Usage:                                                                        #
16 #                                                                               #
17 # kiriwrite_page_selectedlist();                                                #
18 #################################################################################
20         my $form_data = shift;
22         my $count = $form_data->{'count'};
24         # Check if the list of files has a value and if not set it 0.
26         if (!$count){
28                 $count = 0;
30         }
32         # Define some values for later.
34         my @filename_list; 
35         my @selected_list;
36         my @final_list;
38         my $filename;
39         my $selected;
41         my $final_count = 0;
42         my $seek = 0;
44         # Get the list of filenames.
46         do {
48                 # Get the values from id[]
50                 $seek++;
52                 $filename               = $form_data->{'id[' . $seek . ']'};
53                 $filename_list[$seek]   = $filename;
55         } until ($seek eq $count || $count eq 0);
57         # Get the list of selected filenames.
59         $seek = 0;
61         do {
63                 # Get the values from name[]
65                 $seek++;
67                 $selected       = $form_data->{'name[' . $seek . ']'};
69                 if (!$selected){
71                         $selected = 'off';
73                 }
75                 $selected_list[$seek]   = $selected;
77         } until ($seek eq $count || $count eq 0);
79         # Create a final list of filenames to be used for
80         # processing.
82         $seek = 0;
84         do {
86                 # Check if the selected value is on and include
87                 # the filename in the final list.
89                 $seek++;
91                 $selected       = $selected_list[$seek];
93                 if ($selected eq "on"){
95                         $filename       = $filename_list[$seek];
96                         $final_list[$final_count] = $filename;
97                         $final_count++;
99                 }
101         } until ($seek eq $count || $count eq 0);
103         return @final_list;
107 sub kiriwrite_initalise{
108 #################################################################################
109 # kiriwrite_initalise: Get the enviroment stuff.                                #
110 #################################################################################
112         # Get the script filename.
114         my $env_script_name = $ENV{'SCRIPT_NAME'};
116         # Process the script filename until there is only the
117         # filename itself.
119         my $env_script_name_length = length($env_script_name);
120         my $filename_seek = 0;
121         my $filename_char = "";
122         my $filename_last = 0;
124         do {
125                 $filename_char = substr($env_script_name, $filename_seek, 1);
126                 if ($filename_char eq "/"){
127                         $filename_last = $filename_seek + 1;
128                 }
129                 $filename_seek++;
130         } until ($filename_seek eq $env_script_name_length || $env_script_name_length eq 0);
132         my $env_script_name_finallength = $env_script_name_length - $filename_last;
133         my $script_filename = substr($env_script_name, $filename_last, $env_script_name_finallength);
135         # Setup the needed enviroment variables for Kiriwrite.
137         %main::kiriwrite_env = (
138                 "script_filename" => $script_filename,
139         );
143 sub kiriwrite_settings_load{
144 #################################################################################
145 # kiriwrite_settings_load: Load the configuration settings into the global      #
146 # variables.                                                                    #
147 #                                                                               #
148 # Usage:                                                                        #
149 #                                                                               #
150 # kiriwrite_settings_load();                                                    #
151 #################################################################################
153         # Check if the Kiriwrite configuration file exists before using it and
154         # return an critical error if it doesn't exist.
156         my ($kiriwrite_settingsfilehandle, @config_data, %config, $config);
157         my $kiriwrite_conf_exist = kiriwrite_fileexists("kiriwrite.cfg");
159         if ($kiriwrite_conf_exist eq 1){
161                 # The configuration really does not exist so return an critical error.
163                 kiriwrite_critical("configfilemissing");
165         }
167         # Check if the Kiriwrite configuration file has valid permission settings
168         # before using it and return an critical error if it doesn't have the
169         # valid permission settings.
171         my $kiriwrite_conf_permissions = kiriwrite_filepermissions("kiriwrite.cfg", 1, 0);
173         if ($kiriwrite_conf_permissions eq 1){
175                 # The permission settings for the Kiriwrite configuration file are
176                 # invalid, so return an critical error.
178                 kiriwrite_critical("configfileinvalidpermissions");
180         }
182         # Converts the XML file into meaningful data for later on in this subroutine.
184         my $kiriwrite_conf_file = 'kiriwrite.cfg';
186         open($kiriwrite_settingsfilehandle, $kiriwrite_conf_file);
187         binmode $kiriwrite_settingsfilehandle, ':utf8';
188         @config_data = <$kiriwrite_settingsfilehandle>;
189         %config = kiriwrite_processconfig(@config_data);
190         close($kiriwrite_settingsfilehandle);
192         # Go and fetch the settings and place them into a hash (that is global).
194         %main::kiriwrite_config = (
196                 "directory_data_db"             => $config{config}{directory_data_db},
197                 "directory_data_output"         => $config{config}{directory_data_output},
198                 "directory_noncgi_images"       => $config{config}{directory_noncgi_images},
200                 "system_language"               => $config{config}{system_language},
201                 "system_presmodule"             => $config{config}{system_presmodule},
202                 "system_dbmodule"               => $config{config}{system_dbmodule},
203                 "system_outputmodule"           => $config{config}{system_outputmodule},
204                 "system_datetime"               => $config{config}{system_datetime},
206                 "display_textarearows"          => $config{config}{display_textarearows},
207                 "display_textareacols"          => $config{config}{display_textareacols},
208                 "display_pagecount"             => $config{config}{display_pagecount},
209                 "display_templatecount"         => $config{config}{display_templatecount},
210                 "display_filtercount"           => $config{config}{display_filtercount},
212                 "database_server"               => $config{config}{database_server},
213                 "database_port"                 => $config{config}{database_port},
214                 "database_protocol"             => $config{config}{database_protocol},
215                 "database_sqldatabase"          => $config{config}{database_sqldatabase},
216                 "database_username"             => $config{config}{database_username},
217                 "database_password"             => $config{config}{database_password},
218                 "database_tableprefix"          => $config{config}{database_tableprefix}
220         );
222         # Do a validation check on all of the variables that were loaded into the global configuration hash.
224         kiriwrite_variablecheck($main::kiriwrite_config{"directory_data_db"}, "maxlength", 64, 0);
225         kiriwrite_variablecheck($main::kiriwrite_config{"directory_data_output"}, "maxlength", 64, 0);
226         kiriwrite_variablecheck($main::kiriwrite_config{"directory_noncgi_images"}, "maxlength", 512, 0);
227         kiriwrite_variablecheck($main::kiriwrite_config{"directory_data_template"}, "maxlength", 64, 0);
229         my $kiriwrite_config_language_filename = kiriwrite_variablecheck($main::kiriwrite_config{"system_language"}, "language_filename", "", 1);
230         my $kiriwrite_config_presmodule_filename = kiriwrite_variablecheck($main::kiriwrite_config{"system_presmodule"}, "module", 0, 1);
231         my $kiriwrite_config_dbmodule_filename = kiriwrite_variablecheck($main::kiriwrite_config{"system_dbmodule"}, "module", 0, 1);
233         my $kiriwrite_config_textarearows_maxlength = kiriwrite_variablecheck($main::kiriwrite_config{"display_textarearows"}, "maxlength", 3, 1);
234         my $kiriwrite_config_textarearows_number = kiriwrite_variablecheck($main::kiriwrite_config{"display_textareacols"}, "numbers", 0, 1);
235         my $kiriwrite_config_textareacols_maxlength = kiriwrite_variablecheck($main::kiriwrite_config{"display_textareacols"}, "maxlength", 3, 1);
236         my $kiriwrite_config_textareacols_number = kiriwrite_variablecheck($main::kiriwrite_config{"display_textareacols"}, "numbers", 0, 1);
237         my $kiriwrite_config_pagecount_maxlength = kiriwrite_variablecheck($main::kiriwrite_config{"display_pagecount"}, "maxlength", 4, 1);
238         my $kiriwrite_config_pagecount_number = kiriwrite_variablecheck($main::kiriwrite_config{"display_pagecount"}, "numbers", 0, 1);
239         my $kiriwrite_config_templatecount_maxlength = kiriwrite_variablecheck($main::kiriwrite_config{"display_templatecount"}, "maxlength", 4, 1);
240         my $kiriwrite_config_templatecount_number = kiriwrite_variablecheck($main::kiriwrite_config{"display_templatecount"}, "numbers", 0, 1);
241         my $kiriwrite_config_filtercount_maxlength = kiriwrite_variablecheck($main::kiriwrite_config{"display_filtercount"}, "maxlength", 4, 1);
242         my $kiriwrite_config_filtercount_number = kiriwrite_variablecheck($main::kiriwrite_config{"display_filtercount"}, "numbers", 0, 1);
244         # Check if the language filename is valid and return an critical error if
245         # they aren't.
247         if ($kiriwrite_config_language_filename eq 1){
249                 # The language filename is blank so return an critical error.
251                 kiriwrite_critical("languagefilenameblank");
253         } elsif ($kiriwrite_config_language_filename eq 2){
255                 # The language filename is invalid so return an critical error.
257                 kiriwrite_critical("languagefilenameinvalid");
259         }
261         # Check if the presentation and database module names are valid and return a critical
262         # error if they aren't.
264         if ($kiriwrite_config_presmodule_filename eq 1){
266                 # The presentation module filename given is blank so return an 
267                 # critical error.
269                 kiriwrite_critical("presmoduleblank");
271         }
273         if ($kiriwrite_config_presmodule_filename eq 2){
275                 # The presentation module filename is invalid so return an
276                 # critical error.
278                 kiriwrite_critical("presmoduleinvalid");
280         }
282         if ($kiriwrite_config_dbmodule_filename eq 1){
284                 # The database module filename given is blank so return an
285                 # critical error.
287                 kiriwrite_critical("dbmoduleblank");
289         }
291         if ($kiriwrite_config_dbmodule_filename eq 2){
293                 # The database module filename given is invalid so return
294                 # an critical error.
296                 kiriwrite_critical("dbmoduleinvalid");
298         }
300         # Check if the text area column and row values are blank and return a critical
301         # error if they are.
303         if (!$main::kiriwrite_config{"display_textarearows"}){
305                 # The text area row value is blank so return
306                 # a critical error.
308                 kiriwrite_critical("textarearowblank");
310         }
312         if (!$main::kiriwrite_config{"display_textareacols"}){
314                 # The text area column value is blank so return
315                 # a critical error.
317                 kiriwrite_critical("textareacolblank");
319         }
321         # Check if the text area column and row values to see if they are valid and return
322         # a critical error if they aren't.
324         if ($kiriwrite_config_textarearows_maxlength eq 1){
326                 # The text area row value is too long so return an
327                 # critical error.
329                 kiriwrite_critical("textarearowtoolong");
331         }
333         if ($kiriwrite_config_textarearows_number eq 1){
335                 # The text area row value is invalid so return an
336                 # critical error.
338                 kiriwrite_critical("textarearowinvalid");
340         }
342         if ($kiriwrite_config_textareacols_maxlength eq 1){
344                 # The text area column value is too long so return
345                 # an critical error.
347                 kiriwrite_critical("textareacoltoolong");
349         }
351         if ($kiriwrite_config_textareacols_number eq 1){
353                 # The text area column value is invalid so return
354                 # an critical error.
356                 kiriwrite_critical("textareacolinvalid");
358         }
360         # Check if the amount of items per view settings are blank and return a critical
361         # error if they are.
363         if (!$main::kiriwrite_config{"display_pagecount"}){
365                 # The display page count is blank so return a
366                 # critical error.
368                 kiriwrite_critical("pagecountblank");
370         }
372         if (!$main::kiriwrite_config{"display_templatecount"}){
374                 # The display template count is blank so return
375                 # a critical error.
377                 kiriwrite_critical("templatecountblank");
379         }
381         if (!$main::kiriwrite_config{"display_filtercount"}){
383                 # The display filter count is blank so return a
384                 # critical error.
386                 kiriwrite_critical("filtercountblank");
388         }
390         # Check if the amount of items per view settings are valid and return a critical
391         # error message if they aren't.
393         if ($kiriwrite_config_pagecount_maxlength eq 1){
395                 # The length of the page count value is too long
396                 # so return a critical error.
398                 kiriwrite_critical("pagecounttoolong");
400         }
402         if ($kiriwrite_config_pagecount_number eq 1){
404                 # The page count value is invalid so return
405                 # a critical error.
407                 kiriwrite_critical("pagecountinvalid");
409         }
411         if ($kiriwrite_config_templatecount_maxlength eq 1){
413                 # The length of the template count value is too
414                 # long so return a critical error.
416                 kiriwrite_critical("filtercounttoolong");
418         }
420         if ($kiriwrite_config_templatecount_number eq 1){
422                 # The template count value is invalid so return
423                 # a critical error.
425                 kiriwrite_critical("filtercountinvalid");
427         }
429         if ($kiriwrite_config_filtercount_maxlength eq 1){
431                 # The length of the filter count value is too
432                 # long so return a critical error.
434                 kiriwrite_critical("templatecounttoolong");
436         }
438         if ($kiriwrite_config_filtercount_number eq 1){
440                 # The filter count value is invalid so return
441                 # a critical error.
443                 kiriwrite_critical("templatecountinvalid");
445         }
447         # Check if the language file does exist before loading it and return an critical error
448         # if it does not exist.
450         my $kiriwrite_config_language_fileexists = kiriwrite_fileexists("lang/" . $main::kiriwrite_config{"system_language"} . ".lang");
452         if ($kiriwrite_config_language_fileexists eq 1){
454                 # Language file does not exist so return an critical error.
456                 kiriwrite_critical("languagefilemissing");
458         }
460         # Check if the language file has valid permission settings and return an critical error if
461         # the language file has invalid permissions settings.
463         my $kiriwrite_config_language_filepermissions = kiriwrite_filepermissions("lang/" . $main::kiriwrite_config{"system_language"} . ".lang", 1, 0);
465         if ($kiriwrite_config_language_filepermissions eq 1){
467                 # Language file contains invalid permissions so return an critical error.
469                 kiriwrite_critical("languagefilenameinvalidpermissions");
471         }
473         # Load the language file.
475         my ($kiriwrite_languagefilehandle, @lang_data);
477         open($kiriwrite_languagefilehandle, "lang/" . $main::kiriwrite_config{"system_language"} . ".lang");
478         @lang_data = <$kiriwrite_languagefilehandle>;
479         %main::kiriwrite_lang = kiriwrite_processconfig(@lang_data);
480         close($kiriwrite_languagefilehandle);
482         # Check if the presentation module does exist before loading it and return an critical error
483         # if the presentation module does not exist.
485         my $kiriwrite_config_presmodule_fileexists = kiriwrite_fileexists("Modules/Presentation/" . $main::kiriwrite_config{"system_presmodule"} . ".pm");
487         if ($kiriwrite_config_presmodule_fileexists eq 1){
489                 # Presentation module does not exist so return an critical error.
491                 kiriwrite_critical("presmodulemissing");
493         }
495         # Check if the presentation module does have the valid permission settings and return a
496         # critical error if the presentation module contains invalid permission settings.
498         my $kiriwrite_config_presmodule_permissions = kiriwrite_filepermissions("Modules/Presentation/" . $main::kiriwrite_config{"system_presmodule"} . ".pm", 1, 0);
500         if ($kiriwrite_config_presmodule_permissions eq 1){
502                 # Presentation module contains invalid permissions so return an critical error.
504                 kiriwrite_critical("presmoduleinvalidpermissions");
506         }
508         # Check if the database module does exist before loading it and return an critical error
509         # if the database module does not exist.
511         my $kiriwrite_config_dbmodule_fileexists = kiriwrite_fileexists("Modules/Database/" . $main::kiriwrite_config{"system_dbmodule"} . ".pm");
513         if ($kiriwrite_config_dbmodule_fileexists eq 1){
515                 # Database module does not exist so return an critical error.
517                 kiriwrite_critical("dbmodulemissing");
519         }
521         # Check if the database module does have the valid permission settings and return an
522         # critical error if the database module contains invalid permission settings.
524         my $kiriwrite_config_dbmodule_permissions = kiriwrite_filepermissions("Modules/Database/" . $main::kiriwrite_config{"system_dbmodule"} . ".pm", 1, 0);
526         if ($kiriwrite_config_dbmodule_permissions eq 1){
528                 # Presentation module contains invalid permissions so return an critical error.
530                 kiriwrite_critical("dbmoduleinvalidpermissions");
532         }
534         # Include the Modules directory.
536         use lib "Modules/";
538         # Load the presentation module.
540         my $presmodulename = "Presentation::" . $main::kiriwrite_config{"system_presmodule"};
541         ($presmodulename) = $presmodulename =~ m/^(.*)$/g;
542         eval "use " . $presmodulename;
543         $presmodulename = "Modules::Presentation::" . $main::kiriwrite_config{"system_presmodule"};
544         $main::kiriwrite_presmodule = $presmodulename->new();
545         $main::kiriwrite_presmodule->clear(); 
547         # Load the database module.
548  
549         my $dbmodulename = "Database::" . $main::kiriwrite_config{"system_dbmodule"};
550         ($dbmodulename) = $dbmodulename =~ m/^(.*)$/g;
551         eval "use " . $dbmodulename;
552         $dbmodulename = "Modules::Database::" . $main::kiriwrite_config{"system_dbmodule"};
553         $main::kiriwrite_dbmodule = $dbmodulename->new();
555         ($main::kiriwrite_config{"directory_data_db"}) = $main::kiriwrite_config{"directory_data_db"} =~ /^([a-zA-Z0-9.]+)$/;
556         ($main::kiriwrite_config{"directory_data_output"}) = $main::kiriwrite_config{"directory_data_output"} =~ /^([a-zA-Z0-9.]+)$/;
558         # Load the following settings to the database module.
560         $main::kiriwrite_dbmodule->loadsettings({ Directory => $main::kiriwrite_config{"directory_data_db"}, DateTime => $main::kiriwrite_config{"system_datetime"}, Server => $main::kiriwrite_config{"database_server"}, Port => $main::kiriwrite_config{"database_port"}, Protocol => $main::kiriwrite_config{"database_protocol"}, Database => $main::kiriwrite_config{"database_sqldatabase"}, Username => $main::kiriwrite_config{"database_username"}, Password => $main::kiriwrite_config{"database_password"}, TablePrefix => $main::kiriwrite_config{"database_tableprefix"} });
562         return;
566 sub kiriwrite_language{
567 #################################################################################
568 # kiriwrite_language: Process language strings that needs certain text inserted.#
569 #                                                                               #
570 # Usage:                                                                        #
571 #                                                                               #
572 # kiriwrite_language(string, [text, text, ...]);                                #
573 #                                                                               #
574 # string        Specifies the string to process.                                #
575 # text          Specifies the text to pass to the string (can be repeated many  #
576 #               times).                                                         #
577 #################################################################################
579         my $string = shift;
580         my $item;
582         foreach $item (@_){
584                 $string =~ s/%s/$item/;
586         }
588         return $string;
592 sub kiriwrite_error{
593 #################################################################################
594 # kiriwrite_error: Prints out an error message.                                 #
595 #                                                                               #
596 # Usage:                                                                        #
597 #                                                                               #
598 # kiriwrite_error(errortype, errorext);                                         #
599 #                                                                               #
600 # errortype     Specifies the type of error that occured.                       #
601 # errorext      Specifies the extended error information.                       #
602 #################################################################################
604         # Get the error type from the subroutine.
606         my ($error_type, $error_extended) = @_;
608         # Disconnect from the database server.
610         if ($main::kiriwrite_dbmodule){
611                 $main::kiriwrite_dbmodule->disconnect();
612         }
614         # Load the list of error messages.
616         my @kiriwrite_error = (
618                 # Catch all error message.
619                 "generic", 
621                 # Standard error messages.
622                 "blankfilename", "blankvariable", "fileexists", "internalerror", "invalidoption", "invalidaction", "invalidfilename", "invalidmode", "invalidutf8", "invalidvariable", "variabletoolong",
624                 # Specific error messages.
625                 "blankcompiletype", "blankdatabasepageadd", "blankdirectory", "blankfindfilter", "blankdatetimeformat", "browsenumbertoolong", "browsenumberinvalid",  "databaseconnectionerror", "databasecategoriestoolong", "databasecopysame", "databasealreadyexists", "datadirectorymissing", "datadirectoryinvalidpermissions", "databasedescriptiontoolong", "databasefilenameinvalid", "databasefilenametoolong", "databaseerror", "databaseinvalidpermissions", "databasenameinvalid", "databasenametoolong", "databasenameblank", "databasemissingfile", "databasemovemissingfile", "databasenorename", "databasemovesame", "dbmoduleblank", "dbmoduleinvalid", "dbdirectoryblank", "dbdirectoryinvalid", "dbmodulemissing", "filtercountinvalid", "filtercounttoolong", "filtersdatabasenotcreated", "filtersdbdatabaseerror", "filtersdbpermissions", "filtersdbmissing", "filteridblank", "filterdoesnotexist", "filteridinvalid", "filteridtoolong", "findfiltertoolong", "filterpriorityinvalid", "filterpriorityinvalidchars", "filterprioritytoolong", "invalidcompiletype", "invalidpagenumber", "nopagesselected",  "invaliddirectory", "invaliddatetimeformat", "invalidlanguagefilename", "languagefilenamemissing", "moduleblank", "moduleinvalid",      "newcopydatabasedatabaseerror", "newcopydatabasedoesnotexist", "newcopydatabasefileinvalidpermissions", "newmovedatabasedatabaseerror", "newmovedatabasedoesnotexist", "newmovedatabasefileinvalidpermissions", "nodatabasesavailable", "nodatabaseselected", "noeditvaluesselected", "oldcopydatabasedatabaseerror", "oldcopydatabasedoesnotexist", "oldcopydatabasefileinvalidpermissions", "oldmovedatabasedatabaseerror",   "oldmovedatabasedoesnotexist", "oldmovedatabasefileinvalidpermissions", "outputmodulenametoolong", "outputmodulenameinvalid", "outputdirectoryblank", "outputdirectoryinvalid", "outputdirectorymissing", "outputdirectoryinvalidpermissions", "overridetemplatevalueinvalid", "overridetemplatetoolong", "overridetemplateinvalid",  "presmoduleblank", "presmoduleinvalid", "presmodulemissing", "pagecountinvalid", "pagecounttoolong",  "pagefilenamedoesnotexist", "pagefilenameexists", "pagefilenameinvalid", "pagefilenametoolong", "pagefilenameblank", "pagetitletoolong", "pagedescriptiontoolong", "pagesectiontoolong", "pagedatabasefilenametoolong", "pagesettingstoolong", "pagesettingsinvalid", "pagetemplatefilenametoolong", "replacefiltertoolong", "servernameinvalid", "servernametoolong", "serverdatabasenameinvalid", "serverdatabasenametoolong", "serverdatabaseusernameinvalid", "serverdatabaseusernametoolong", "serverdatabasepasswordtoolong", "serverdatabasetableprefixinvalid", "serverdatabasetableprefixtoolong", "serverportnumberinvalid", "serverportnumberinvalidcharacters", "serverportnumbertoolong", "serverprotocolnametoolong", "serverprotocolinvalid", "templatecountinvalid", "templatecounttoolong", "templatenameblank", "templatefilenameexists", "templatefilenameinvalid", "templatedatabaseerror", "templatedatabaseinvalidpermissions", "templatedatabaseinvalidformat", "templatedirectoryblank", "templatedirectoryinvalid", "templatedatabasenotcreated", "templatefilenametoolong", "templatenametoolong", "templatedescriptiontoolong", "templatedatabasemissing", "templatedoesnotexist", "templatefilenameblank", "textarearowblank", "textarearowtoolong", "textarearowinvalid", "textareacolblank", "textareacoltoolong", "textareacolinvalid"
627         );
629         # Check if the error message name is a valid error message name
630         # and return the generic error message if it isn't.
632         my $error_string = "";
634         if (grep /^$error_type$/, @kiriwrite_error){
636                 # The error type is valid so get the error language string
637                 # associated with this error messsage name.
639                 $error_string = $main::kiriwrite_lang{error}{$error_type};
641         } else {
643                 # The error type is invalid so set the error language
644                 # string using the generic error message name.
646                 $error_string = $main::kiriwrite_lang{error}{generic};
648         }
650         $main::kiriwrite_presmodule->clear();
652         $main::kiriwrite_presmodule->startbox("errorbox");
653         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{error}{error}, { Style => "errorheader" });
654         $main::kiriwrite_presmodule->addlinebreak();
655         $main::kiriwrite_presmodule->addtext($error_string, { Style => "errortext" });
657         # Check to see if extended error information was passed.
659         if ($error_extended){
661                 # Write the extended error information.
663                 $main::kiriwrite_presmodule->addlinebreak();
664                 $main::kiriwrite_presmodule->addlinebreak();
665                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{error}{extendederror});
666                 $main::kiriwrite_presmodule->addlinebreak();
667                 $main::kiriwrite_presmodule->addlinebreak();
668                 $main::kiriwrite_presmodule->startbox("datalist");
669                 $main::kiriwrite_presmodule->addtext($error_extended);
670                 $main::kiriwrite_presmodule->endbox();
672         }
674         $main::kiriwrite_presmodule->endbox();
676         &kiriwrite_output_header;
677         kiriwrite_output_page($main::kiriwrite_lang{error}{error}, $main::kiriwrite_presmodule->grab(), "none");
679         exit;
683 sub kiriwrite_fileexists{
684 #################################################################################
685 # kiriwrite_fileexists: Check if a file exists and returns a value depending on #
686 # if the file exists or not.                                                    #
687 #                                                                               # 
688 # Usage:                                                                        #
689 #                                                                               #
690 # kiriwrite_fileexists(filename);                                               #
691 #                                                                               #
692 # filename      Specifies the file name to check if it exists or not.           #
693 #################################################################################
695         # Get the value that was passed to the subroutine.
697         my ($filename) = @_;
699         # Check if the filename exists, if it does, return a value of 0, else
700         # return a value of 1, meaning that the file was not found.
702         if (-e $filename){
704                 # Specified file does exist so return a value of 0.
706                 return 0;
708         } else {
710                 # Specified file does not exist so return a value of 1.
712                 return 1;
714         }
718 sub kiriwrite_filepermissions{
719 #################################################################################
720 # kiriwrite_filepermissions: Check if the file permissions of a file and return #
721 # either a 1 saying that the permissions are valid or return a 0 saying that    #
722 # the permissions are invalid.                                                  #
723 #                                                                               #
724 # Usage:                                                                        #
725 #                                                                               #
726 # kiriwrite_filepermissions(filename, [read], [write], [filemissingskip]);      #
727 #                                                                               #
728 # filename              Specifies the filename to check for permissions.        #
729 # read                  Preform check that the file is readable.                #
730 # write                 Preform check that the file is writeable.               #
731 # filemissingskip       Skip the check of seeing if it can read or write if the #
732 #                       file is missing.                                        #
733 #################################################################################
735         # Get the values that was passed to the subroutine.
737         my ($filename, $readpermission, $writepermission, $ignorechecks) = @_;
739         # Check to make sure that the read permission and write permission values
740         # are only 1 character long.
742         kiriwrite_variablecheck($readpermission, "maxlength", 1, 0);
743         kiriwrite_variablecheck($writepermission, "maxlength", 1, 0);
744         kiriwrite_variablecheck($ignorechecks, "maxlength", 1, 0);
746         my $ignorechecks_result = 0;
748         # Check if the file should be ignored for read and write checking if 
749         # it doesn't exist.
751         if ($ignorechecks){
753                 if (-e $filename){
755                         # The file exists so the checks are to be done.
757                         $ignorechecks_result = 0;
759                 } else {
761                         # The file does not exist so the checks don't need to
762                         # be done to prevent false positives.
764                         $ignorechecks_result = 1;
766                 }
768         } else {
770                 $ignorechecks_result = 0;
772         }
774         # Check if the file should be checked to see if it can be read.
776         if ($readpermission && $ignorechecks_result eq 0){
778                 # The file should be checked to see if it does contain read permissions
779                 # and return a 0 if it is invalid.
781                 if (-r $filename){
783                         # The file is readable, so do nothing.
785                 } else {
787                         # The file is not readable, so return 1.
789                         return 1;
791                 }
793         }
795         # Check if the file should be checked to see if it can be written.
797         if ($writepermission && $ignorechecks_result eq 0){
799                 # The file should be checked to see if it does contain write permissions
800                 # and return a 0 if it is invalid.
802                 if (-w $filename){
804                         # The file is writeable, so do nothing.
806                 } else {
808                         # The file is not writeable, so return 1.
810                         return 1;
812                 }
814         }
816         # No problems have occured, so return 0.
818         return 0;
822 sub kiriwrite_utf8convert{
823 #################################################################################
824 # kiriwrite_utf8convert: Properly converts values into UTF-8 values.            #
825 #                                                                               #
826 # Usage:                                                                        #
827 #                                                                               #
828 # utfstring     # The UTF-8 string to convert.                                  #
829 #################################################################################
831         # Get the values passed to the subroutine.
833         my ($utfstring) = @_;
835         # Load the Encode perl module.
837         use Encode qw(decode_utf8);
839         # Convert the string.
841         my $finalutf8 = Encode::decode_utf8( $utfstring );
843         return $finalutf8;
844         #return $utfstring;
848 sub kiriwrite_critical{
849 #################################################################################
850 # kiriwrite_critical: Displays an critical error message that cannot be         #
851 # normally by the kiriwrite_error subroutine.                                   #
852 #                                                                               #
853 # Usage:                                                                        #
854 #                                                                               #
855 # errortype     Specifies the type of critical error that has occured.          #
856 #################################################################################
858         # Get the value that was passed to the subroutine.
860         my ($error_type) = @_;
862         my %error_list;
864         # Get the error type from the errortype string.
866         %error_list = (
868                 # Generic critical error message.
870                 "generic"                       => "A critical error has occured but the error is not known to Kiriwrite.",
872                 # Specific critical error messages.
874                 "configfilemissing"             => "The Kiriwrite configuration file is missing! Running the installer script for Kiriwrite is recommended.",
875                 "configfileinvalidpermissions"  => "The Kiriwrite configuration file has invalid permission settings set! Please set the valid permission settings for the configuration file.",
876                 "dbmodulemissing"               => "The database module is missing! Running the installer script for Kiriwrite is recommended.",
877                 "dbmoduleinvalidpermissions"    => "The database module cannot be used as it has invalid permission settings set! Please set the valid permission settings for the configuration file.",
878                 "dbmoduleinvalid"               => "The database module name given is invalid. Running the installer script for Kiriwrite is recommended.",
879                 "invalidvalue"                  => "An invalid value was passed.",
880                 "languagefilenameblank"         => "The language filename given is blank! Running the installer script for Kiriwrite is recommended.",
881                 "languagefilenameinvalid"       => "The language filename given is invalid! Running the installer script for Kiriwrite is recommended.",
882                 "languagefilemissing"   => "The language filename given does not exist. Running the installer script for Kiriwrite is recommended.",
883                 "languagefilenameinvalidpermissions"    => "The language file with the filename given has invalid permissions set. Please set the valid permission settings for the language file.",
884                 "presmodulemissing"             => "The presentation module is missing! Running the installer script for Kiriwrite is recommended.",
885                 "presmoduleinvalidpermissions"  => "The presentation module cannot be used as it has invalid permission settings set! Please set the valid permission settings for the presentation module.",
886                 "presmoduleinvalid"             => "The presentation module name given is invalid. Running the installer script for Kiriwrite is recommended.",
887                 "textarearowblank"              => "The text area row value given is blank. Running the installer script for Kiriwrite is recommended.",
888                 "textarearowtoolong"            => "The text area row value is too long. Running the installer script for Kiriwrite is recommended.",
889                 "textarearowinvalid"            => "The text area row value is invalid. Running the installer script for Kiriwrite is recommended.",
890                 "textareacolblank"              => "The text area row value given is blank. Running the installer script for Kiriwrite is recommended.",
891                 "textareacoltoolong"            => "The text area column value is too long. Running the installer script for Kiriwrite is recommended.",
892                 "textareacolinvalid"            => "The text area column value is invalid. Running the installer script for Kiriwrite is recommended.",
893                 "pagecountblank"                => "The page count value is blank. Running the installer script for Kiriwrite is recommended.",
894                 "templatecountblank"            => "The template count value is blank. Running the installer script for Kiriwrite is recommended.",
895                 "filtercountblank"              => "The filter count value is blank. Running the installer script for Kiriwrite is recommended.",
896                 "pagecounttoolong"              => "The page count value is too long. Running the installer script for Kiriwrite is recommended.",
897                 "templatecounttoolong"          => "The template count value is too long. Running the installer script for Kiriwrite is recommended.",
898                 "filtercounttoolong"            => "The filter count value is too long. Running the installer script for Kiriwrite is recommended.",
899                 "pagecountinvalid"              => "The page count value is invalid. Running the installer script for Kiriwrite is recommended.",
900                 "templatecountinvalid"          => "The template count value is invalid. Running the installer script for Kiriwrite is recommended.",
901                 "filtercountinvalid"            => "The filter count is invalid. Running the installer script for Kiriwrite is recommended."
903         );
905         if (!$error_list{$error_type}){
907                 $error_type = "generic";
909         }
911         print "Content-Type: text/html; charset=utf-8;\r\n";
912         print "Expires: Sun, 01 Jan 2008 00:00:00 GMT\r\n\r\n";
913         print "Critical Error: " . $error_list{$error_type};
914         exit;
918 sub kiriwrite_variablecheck{
919 #################################################################################
920 # kiriwrite_variablecheck: Checks the variables for any invalid characters.     #
921 #                                                                               #
922 # Usage:                                                                        #
923 #                                                                               #
924 # kiriwrite_variablecheck(variable, type, length, noerror);                     #
925 #                                                                               #
926 # variable      Specifies the variable to be checked.                           #
927 # type          Specifies what type the variable is.                            #
928 # option        Specifies the maximum/minimum length of the variable            #
929 #               (if minlength/maxlength is used) or if the filename should be   #
930 #               checked to see if it is blank.                                  #
931 # noerror       Specifies if Kiriwrite should return an error or not on         #
932 #               certain values.                                                 #
933 #################################################################################
935         # Get the values that were passed to the subroutine.
937         my ($variable_data, $variable_type, $variable_option, $variable_noerror) = @_;
939         if (!$variable_data){
940                 $variable_data = "";
941         }
943         if ($variable_type eq "numbers"){
945                 # Check for numbers and return an error if there is anything else than numebrs.
947                 my $variable_data_validated = $variable_data;   # Copy the variable_data to variable_data_validated.
948                 $variable_data_validated =~ tr/0-9//d;          # Take away all of the numbers and from the variable. 
949                                                                 # If it only contains numbers then it should be blank.
951                 if ($variable_data_validated eq ""){
952                         # The validated variable is blank. So continue to the end of this section where the return function should be.
953                 } else {
954                         # The variable is not blank, so check if the no error value is set
955                         # to 1 or not.
957                         if ($variable_noerror eq 1){
959                                 # The validated variable is not blank and the noerror
960                                 # value is set to 1. So return an value of 1.
961                                 # (meaning that the data is invalid).
963                                 return 1;
965                         } elsif ($variable_noerror eq 0) {
967                                 # The validated variable is not blank and the noerror
968                                 # value is set to 0.
970                                 kiriwrite_error("invalidvariable");
972                         } else {
974                                 # The variable noerror value is something else
975                                 # pther than 1 or 0. So return an error.
977                                 kiriwrite_error("invalidvariable");
979                         }
981                 }
983                 return 0;
985         } elsif ($variable_type eq "lettersnumbers"){
987                 # Check for letters and numbers and return an error if there is anything else other
988                 # than letters and numbers.
990                 my $variable_data_validated = $variable_data;   # Copy the variable_data to variable_data_validated
991                 $variable_data_validated =~ tr/a-zA-Z0-9.//d;
992                 $variable_data_validated =~ s/\s//g;
994                 if ($variable_data_validated eq ""){
995                         # The validated variable is blank. So continue to the end of this section where the return function should be.
996                 } else {
997                         # The variable is not blank, so check if the no error value is set
998                         # to 1 or not.
1000                         if ($variable_noerror eq 1){
1002                                 # The validated variable is not blank and the noerror
1003                                 # value is set to 1. So return an value of 1.
1004                                 # (meaning that the data is invalid).
1006                                 return 1;
1008                         } elsif ($variable_noerror eq 0) {
1010                                 # The validated variable is not blank and the noerror
1011                                 # value is set to 0.
1013                                 kiriwrite_error("invalidvariable");
1015                         } else {
1017                                 # The variable noerror value is something else
1018                                 # pther than 1 or 0. So return an error.
1020                                 kiriwrite_error("invalidvariable");
1022                         }
1024                 }
1026                 return 0;
1028         } elsif ($variable_type eq "maxlength"){
1029                 # Check for the length of the variable, return an error if it is longer than the length specified.
1031                 # Check if the variable_data string is blank, if it is then set the variable_data_length
1032                 # to '0'.
1034                 my $variable_data_length = 0;
1036                 if (!$variable_data){
1038                         # Set variable_data_length to '0'.
1039                         $variable_data_length = 0;
1041                 } else {
1043                         # Get the length of the variable recieved.
1044                         $variable_data_length = length($variable_data);
1046                 }
1050                 if ($variable_data_length > $variable_option){
1052                         # The variable length is longer than it should be so check if
1053                         # the no error value is set 1.
1055                         if ($variable_noerror eq 1){
1057                                 # The no error value is set to 1, so return an
1058                                 # value of 1 (meaning tha the variable is
1059                                 # too long to be used).
1061                                 return 1;
1063                         } elsif ($variable_noerror eq 0){
1065                                 # The no error value is set to 0, so return
1066                                 # an error.
1068                                 kiriwrite_error("variabletoolong");
1070                         } else {
1072                                 # The no error value is something else other
1073                                 # than 0 or 1, so return an error.
1075                                 kiriwrite_error("variabletoolong");
1077                         }
1079                 } else {
1081                         # The variable length is exactly or shorter than specified, so continue to end of this section where
1082                         # the return function should be.
1084                 }
1086                 return 0;
1088         } elsif ($variable_type eq "blank"){
1089                 # Check if the variable is blank and if it is blank, then return an error.
1091                 if (!$variable_data){
1093                         # The variable data really is blank, so check what
1094                         # the no error value is set.
1096                         if ($variable_noerror eq 1){
1098                                 # The no error value is set to 1, so return
1099                                 # a value of 1 (saying that the variable was
1100                                 # blank).
1102                                 return 1;
1104                         } elsif ($variable_noerror eq 0){
1106                                 # The no error value is set to 0, so return
1107                                 # an error.
1109                                 kiriwrite_error("blankvariable");
1111                         } else {
1113                                 # The no error value is something else other
1114                                 # than 0 or 1, so return an error.
1116                                 kiriwrite_error("invalidvariable");
1118                         }
1120                 }
1122                 return 0;
1124         } elsif ($variable_type eq "filename"){
1125                 # Check for letters and numbers, if anything else than letters and numbers is there (including spaces) return
1126                 # an error.
1128                 # Check if the filename passed is blank, if it is then return with an error.
1130                 if ($variable_data eq ""){
1132                         # The filename specified is blank, so check what the
1133                         # noerror value is set.
1135                         if ($variable_noerror eq 1){
1137                                 # The no error value is set to 1 so return
1138                                 # a value of 1 (meaning that the filename
1139                                 # was blank).
1141                                 return 1;
1143                         } elsif ($variable_noerror eq 0){
1145                                 # The no error value is set to 1 so return
1146                                 # an error.
1148                                 kiriwrite_error("blankfilename");
1150                         } else {
1152                                 # The no error value is something else other
1153                                 # than 0 or 1, so return an error.
1155                                 kiriwrite_error("invalidvariable");
1157                         }
1159                 } else {
1162                 }
1164                 my $variable_data_validated = $variable_data;
1165                 $variable_data_validated =~ tr/a-zA-Z0-9\.//d;
1167                 # Check if the validated data variable is blank, if it is 
1168                 # then continue to the end of this section where the return 
1169                 # function should be, otherwise return an error.
1171                 if ($variable_data_validated eq ""){
1173                         # The validated data variable is blank, meaning that 
1174                         # it only contained letters and numbers.
1176                 } else {
1178                         # The validated data variable is not blank, meaning 
1179                         # that it contains something else, so return an error
1180                         # (or a value).
1182                         if ($variable_noerror eq 1){
1184                                 # The no error value is set to 1 so return
1185                                 # an value of 2. (meaning that the filename
1186                                 # is invalid).
1189                                 return 2;
1191                         } elsif ($variable_noerror eq 0){
1193                                 # The no error value is set to 0 so return
1194                                 # an error.
1196                                 kiriwrite_error("invalidfilename");
1198                         } else {
1200                                 # The no error value is something else other
1201                                 # than 0 or 1 so return an error.
1203                                 kiriwrite_error("invalidvariable");
1205                         }
1207                 }
1209                 return 0;
1211         } elsif ($variable_type eq "filenameindir"){
1212                 # Check if the filename is in the directory and return an
1213                 # error if it isn't.
1215                 if ($variable_data eq ""){
1217                         # The filename specified is blank, so check what the
1218                         # noerror value is set.
1220                         if ($variable_noerror eq 1){
1222                                 # The no error value is set to 1 so return
1223                                 # a value of 1 (meaning that the filename
1224                                 # was blank).
1226                                 return 1;
1228                         } elsif ($variable_noerror eq 0){
1230                                 # The no error value is set to 1 so return
1231                                 # an error.
1233                                 kiriwrite_error("blankfilename");
1235                         } else {
1237                                 # The no error value is something else other
1238                                 # than 0 or 1, so return an error.
1240                                 kiriwrite_error("invalidvariable");
1242                         }
1244                 } else {
1247                 }
1249                 # Set the following variables for later on.
1251                 my $variable_data_length = 0;
1252                 my $variable_data_char = "";
1253                 my $variable_data_validated = "";
1254                 my $variable_data_seek = 0;
1255                 my $variable_database_list = "";
1256                 my $variable_database_listcurrent = "";
1257                 my $variable_data_firstlevel = 1;
1259                 # Get the length of the variable recieved.
1261                 $variable_data_length = length($variable_data);
1263                 # Check if the database filename contains the directory command
1264                 # for up a directory level and if it is, return an error
1265                 # or return with a number.
1267                 do {
1269                         # Get a character from the filename passed to this subroutine.
1271                         $variable_data_char = substr($variable_data, $variable_data_seek, 1);
1273                         # Check if the current character is the forward slash character.
1275                         if ($variable_data_char eq "/"){
1277                                 # Check if the current directory is blank (and on the first level), or if the
1278                                 # current directory contains two dots or one dot, if it does return an error.
1280                                 if ($variable_database_listcurrent eq "" && $variable_data_firstlevel eq 1 || $variable_database_listcurrent eq ".." || $variable_database_listcurrent eq "."){
1282                                         # Check if the noerror value is set to 1, if it is return an
1283                                         # number, else return an proper error.
1285                                         if ($variable_noerror eq 1){
1287                                                 # Page filename contains invalid characters and
1288                                                 # the no error value is set to 1 so return a 
1289                                                 # value of 2 (meaning that the page filename
1290                                                 # is invalid).
1292                                                 return 2;
1294                                         } elsif ($variable_noerror eq 0) {
1296                                                 # Page filename contains invalid characters and
1297                                                 # the no error value is set to 0 so return an
1298                                                 # error.
1300                                                 kiriwrite_error("invalidfilename");
1302                                         } else {
1304                                                 # The no error value is something else other
1305                                                 # than 0 or 1 so return an error.
1307                                                 kiriwrite_error("invalidvariable");
1309                                         }
1311                                 }
1313                                 # Append the forward slash, clear the current directory name and set
1314                                 # the first directory level value to 0.
1316                                 $variable_database_list = $variable_database_list . $variable_data_char;
1317                                 $variable_database_listcurrent = "";
1318                                 $variable_data_firstlevel = 0;
1320                         } else {
1322                                 # Append the current character to the directory name and to the current
1323                                 # directory name.
1325                                 $variable_database_list = $variable_database_list . $variable_data_char;
1326                                 $variable_database_listcurrent = $variable_database_listcurrent . $variable_data_char;
1328                         }
1330                         # Increment the seek counter.
1332                         $variable_data_seek++;
1334                 } until ($variable_data_seek eq $variable_data_length);
1336                 return 0;
1338         } elsif ($variable_type eq "datetime"){
1339                 # Check if the date and time setting format is valid.
1341                 if ($variable_data eq ""){
1343                         if ($variable_noerror eq 1){
1345                                 # The no error value is set to 1 so return
1346                                 # a value of 1 (meaning that the date and
1347                                 # time format was blank).
1349                                 return 1;
1351                         } elsif ($variable_noerror eq 0){
1353                                 # The no error value is set to 1 so return
1354                                 # an error.
1356                                 kiriwrite_error("blankdatetimeformat");
1358                         } else {
1360                                 # The no error value is something else other
1361                                 # than 0 or 1, so return an error.
1363                                 kiriwrite_error("invalidvariable");
1365                         }
1367                 }
1369                 my $variable_data_validated = $variable_data;
1370                 $variable_data_validated =~ tr|dDmMyYhms/():[ ]||d;
1372                 if ($variable_data_validated eq ""){
1374                         # The date and time format is valid. So
1375                         # skip this bit.
1377                 } else {
1379                         # The validated data variable is not blank, meaning 
1380                         # that it contains something else, so return an error
1381                         # (or a value).
1383                         if ($variable_noerror eq 1){
1385                                 # The no error value is set to 1 so return
1386                                 # an value of 2. (meaning that the date and
1387                                 # time format was invalid).
1389                                 return 2;
1391                         } elsif ($variable_noerror eq 0){
1393                                 # The no error value is set to 0 so return
1394                                 # an error.
1396                                 kiriwrite_error("invaliddatetimeformat");
1398                         } else {
1400                                 # The no error value is something else other
1401                                 # than 0 or 1 so return an error.
1403                                 kiriwrite_error("invalidvariable");
1405                         }
1407                 }
1409                 return 0;
1411         } elsif ($variable_type eq "directory"){
1412                 # Check if the directory only contains letters and numbers and
1413                 # return an error if anything else appears.
1415                 my $variable_data_validated = $variable_data;
1416                 $variable_data_validated =~ tr/a-zA-Z0-9//d;
1418                 if ($variable_data eq ""){
1420                         if ($variable_noerror eq 1){
1422                                 # The no error value is set to 1 so return
1423                                 # a value of 1 (meaning that the directory
1424                                 # name was blank).
1426                                 return 1;
1428                         } elsif ($variable_noerror eq 0){
1430                                 # The no error value is set to 1 so return
1431                                 # an error.
1433                                 kiriwrite_error("blankdirectory");
1435                         } else {
1437                                 # The no error value is something else other
1438                                 # than 0 or 1, so return an error.
1440                                 kiriwrite_error("invalidvariable");
1442                         }
1444                 }
1446                 if ($variable_data_validated eq ""){
1448                         # The validated data variable is blank, meaning that
1449                         # it only contains letters and numbers.
1451                 } else {
1453                         # The validated data variable is not blank, meaning 
1454                         # that it contains something else, so return an error
1455                         # (or a value).
1457                         if ($variable_noerror eq 1){
1459                                 # The no error value is set to 1 so return
1460                                 # an value of 2. (meaning that the directory
1461                                 # name is invalid).
1463                                 return 2;
1465                         } elsif ($variable_noerror eq 0){
1467                                 # The no error value is set to 0 so return
1468                                 # an error.
1470                                 kiriwrite_error("invaliddirectory");
1472                         } else {
1474                                 # The no error value is something else other
1475                                 # than 0 or 1 so return an error.
1477                                 kiriwrite_error("invalidvariable");
1479                         }
1481                 }
1483                 return 0;
1485         } elsif ($variable_type eq "language_filename"){
1487                 # The variable type is a language filename type.
1488                 # Check if the language file name is blank and 
1489                 # if it is then return an error (or value).
1491                 if ($variable_data eq ""){
1493                         # The language filename is blank so check the
1494                         # no error value and return an error (or value).
1496                         if ($variable_noerror eq 1){
1498                                 # Language filename is blank and the no error value
1499                                 # is set as 1, so return a value of 1 (saying that
1500                                 # the language filename is blank).
1502                                 return 1;
1504                         } elsif ($variable_noerror eq 0) {
1506                                 # Language filename is blank and the no error value
1507                                 # is not set as 1, so return an error.
1509                                 kiriwrite_critical("languagefilenameblank");
1511                         } else {
1513                                 # The noerror value is something else other
1514                                 # than 0 or 1 so return an error.
1516                                 kiriwrite_error("invalidvariable");
1518                         }
1520                 }
1522                 # Set the following variables for later on.
1524                 my $variable_data_length = 0;
1525                 my $variable_data_char = "";
1526                 my $variable_data_seek = 0;
1528                 # Get the length of the language file name.
1530                 $variable_data_length = length($variable_data);
1532                 do {
1534                         # Get a character from the language filename passed to this 
1535                         # subroutine and the character the seek counter value is set
1536                         # to.
1538                         $variable_data_char = substr($variable_data, $variable_data_seek, 1);
1540                         # Check if the language filename contains a forward slash or a dot, 
1541                         # if the selected character is a forward slash then return an error
1542                         # (or value).
1544                         if ($variable_data_char eq "/" || $variable_data_char eq "."){
1546                                 # The language filename contains a forward slash or
1547                                 # a dot so depending on the no error value, return
1548                                 # an error or a value.
1550                                 if ($variable_noerror eq 1){
1552                                         # Language filename contains a forward slash or a dot
1553                                         # and the no error value has been set to 1, so return 
1554                                         # an value of 2 (saying that the language file name is 
1555                                         # invalid).
1557                                         return 2;
1559                                 } elsif ($variable_noerror eq 0) {
1561                                         # Language filename contains a forward slash and the no
1562                                         # error value has not been set to 1, so return an error.
1564                                         kiriwrite_critical("languagefilenameinvalid");
1566                                 } else {
1568                                         # The noerror value is something else other than
1569                                         # 1 or 0 so return an error.
1571                                         kiriwrite_error("invalidvariable");
1573                                 }
1575                         }
1577                         # Increment the seek counter.
1579                         $variable_data_seek++;
1581                 } until ($variable_data_seek eq $variable_data_length);
1583                 return 0;
1585         } elsif ($variable_type eq "pagesetting"){
1587                 # The variable type is a page setting, so check if the page
1588                 # setting has one of the valid options.
1590                 if ($variable_data eq 0 || $variable_data eq 1 || $variable_data eq 2 || $variable_data eq 3){
1592                         # The variable is one of the options above, so continue
1593                         # to the end of this section.
1595                 } else {
1597                         # The variable is not one of the options above, so check
1598                         # and see if a error or a value should be returned.
1600                         if ($variable_noerror eq 1){
1602                                 # The page setting is invalid and the no error
1603                                 # value is set 1, so return a value of 1
1604                                 # (saying that the page setting value is
1605                                 # invalid).
1607                                 return 1;
1609                         } elsif ($variable_noerror eq 0) {
1611                                 # Page setting is invalid and the no error value
1612                                 # is not 1, so return an error.
1614                                 kiriwrite_error("invalidvariable");
1616                         } else {
1618                                 # The no error value is something else other
1619                                 # than 0 or 1 so return an error.
1621                                 kiriwrite_error("invalidvariable");
1623                         }
1625                 }
1627                 return 0;
1629         } elsif ($variable_type eq "page_filename"){
1630          
1631                 # The variable type is a page filename type. Check
1632                 # if the data is empty and if it is then return an
1633                 # error (or value).
1635                 if ($variable_data eq ""){
1637                         # The filename is blank so check the no error
1638                         # value and depending on it return an value
1639                         # or an error.
1641                         if ($variable_noerror eq 1){
1643                                 # Page filename is blank and the no error value
1644                                 # is set as 1, so return a value of 1 (saying
1645                                 # the filename is blank).
1647                                 return 1;
1649                         } elsif ($variable_noerror eq 0) {
1651                                 # Page filename is blank and the no error value
1652                                 # is not 1, so return an error.
1654                                 kiriwrite_error("emptypagefilename");
1656                         } else {
1658                                 # The no error value is something else other
1659                                 # than 0 or 1 so return an error.
1661                                 kiriwrite_error("invalidvariable");
1663                         }
1664                 }
1666                 # Set the following variables for later on.
1669                 my $variable_data_length = 0;
1670                 my $variable_data_slash = 0;
1671                 my $variable_data_char = "";
1672                 my $variable_data_validated = "";
1673                 my $variable_data_seek = 0;
1674                 my $variable_database_list = "";
1675                 my $variable_database_listcurrent = "";
1676                 my $variable_data_firstlevel = 1;
1678                 # Get the length of the filename.
1680                 $variable_data_length = length($variable_data);
1682                 # Check that only valid characters should be appearing in
1683                 # the filename.
1685                 $variable_data_validated = $variable_data;
1686                 $variable_data_validated =~ tr|a-zA-Z0-9\.\/\-_||d;
1688                 if ($variable_data_validated ne ""){
1690                         # The validated variable is not blank, meaning the
1691                         # variable contains invalid characters, so return
1692                         # an error.
1694                         if ($variable_noerror eq 1){
1696                                 # Page filename contains invalid characters and
1697                                 # the no error value is set to 1 so return a 
1698                                 # value of 2 (meaning that the page filename
1699                                 # is invalid).
1701                                 return 2;
1703                         } elsif ($variable_noerror eq 0) {
1705                                 # Page filename contains invalid characters and
1706                                 # the no error value is set to 0 so return an
1707                                 # error.
1709                                 kiriwrite_error("invalidfilename");
1711                         } else {
1713                                 # The no error value is something else other
1714                                 # than 0 or 1 so return an error.
1716                                 kiriwrite_error("invalidvariable");
1718                         }
1720                 }
1722                 # Check if the page filename contains the directory command
1723                 # for up a directory level and if it is, return an error
1724                 # or return with a number.
1726                 do {
1728                         # Get a character from the filename passed to this subroutine.
1730                         $variable_data_char = substr($variable_data, $variable_data_seek, 1);
1732                         # Check if the current character is the forward slash character.
1734                         if ($variable_data_char eq "/"){
1736                                 # Check if the current directory is blank (and on the first level), or if the
1737                                 # current directory contains two dots or one dot, if it does return an error.
1739                                 $variable_data_slash = 1;
1741                                 if ($variable_database_listcurrent eq "" && $variable_data_firstlevel eq 1 || $variable_database_listcurrent eq ".." || $variable_database_listcurrent eq "."){
1743                                         # Check if the noerror value is set to 1, if it is return an
1744                                         # number, else return an proper error.
1746                                         if ($variable_noerror eq 1){
1748                                                 # Page filename contains invalid characters and
1749                                                 # the no error value is set to 1 so return a 
1750                                                 # value of 2 (meaning that the page filename
1751                                                 # is invalid).
1753                                                 return 2;
1755                                         } elsif ($variable_noerror eq 0) {
1757                                                 # Page filename contains invalid characters and
1758                                                 # the no error value is set to 0 so return an
1759                                                 # error.
1761                                                 kiriwrite_error("invalidfilename");
1763                                         } else {
1765                                                 # The no error value is something else other
1766                                                 # than 0 or 1 so return an error.
1768                                                 kiriwrite_error("invalidvariable");
1770                                         }
1772                                 }
1774                                 # Append the forward slash, clear the current directory name and set
1775                                 # the first directory level value to 0.
1777                                 $variable_database_list = $variable_database_list . $variable_data_char;
1778                                 $variable_database_listcurrent = "";
1779                                 $variable_data_firstlevel = 0;
1781                         } else {
1783                                 # Append the current character to the directory name and to the current
1784                                 # directory name.
1786                                 $variable_data_slash = 0;
1788                                 $variable_database_list = $variable_database_list . $variable_data_char;
1789                                 $variable_database_listcurrent = $variable_database_listcurrent . $variable_data_char;
1791                         }
1793                         # Increment the seek counter.
1795                         $variable_data_seek++;
1797                 } until ($variable_data_seek eq $variable_data_length);
1799                 # Check if the last character is a slash and return an
1800                 # error if it is.
1802                 if ($variable_data_slash eq 1){
1804                         if ($variable_noerror eq 1){
1806                                 # Last character is a slash and the no error 
1807                                 # value is set to 1 so return a value of 2 
1808                                 # (meaning that the page filename is invalid).
1810                                 return 2;
1812                         } elsif ($variable_noerror eq 0) {
1814                                 # Page filename contains a slash for the last
1815                                 # character and the no error value is set to 0 
1816                                 # so return an error.
1818                                 kiriwrite_error("invalidfilename");
1820                         } else {
1822                                 # The no error value is something else other
1823                                 # than 0 or 1 so return an error.
1825                                 kiriwrite_error("invalidvariable");
1827                         }
1829                 }
1831                 return 0;
1833         } elsif ($variable_type eq "module"){
1835                 # The variable type is a presentation module filename.
1837                 # Check if the variable_data is blank and if it is
1838                 # return an error.
1840                 if ($variable_data eq ""){
1842                         # The presentation module is blank so check if an error
1843                         # value should be returned or a number should be
1844                         # returned.
1846                         if ($variable_noerror eq 1){
1848                                 # Module name is blank and the no error value 
1849                                 # is set to 1 so return a value of 2 (meaning 
1850                                 # that the page filename is blank).
1852                                 return 1;
1854                         } elsif ($variable_noerror eq 0) {
1856                                 # Module name contains is blank and the no error 
1857                                 # value is set to 0 so return an error.
1859                                 kiriwrite_critical("moduleblank");
1861                         } else {
1863                                 # The no error value is something else other
1864                                 # than 0 or 1 so return an error.
1866                                 kiriwrite_critical("invalidvalue");
1868                         }
1870                 } else {
1872                 }
1874                 my $variable_data_validated = $variable_data;
1875                 $variable_data_validated =~ tr/a-zA-Z0-9//d;
1877                 if ($variable_data_validated eq ""){
1879                 } else {
1881                         if ($variable_noerror eq 1){
1883                                 # Module name contains invalid characters and
1884                                 # the no error value is set to 1 so return a 
1885                                 # value of 2 (meaning that the page filename
1886                                 # is invalid).
1888                                 return 2;
1890                         } elsif ($variable_noerror eq 0) {
1892                                 # Module name contains invalid characters and
1893                                 # the no error value is set to 0 so return an
1894                                 # error.
1896                                 kiriwrite_critical("moduleinvalid");
1898                         } else {
1900                                 # The no error value is something else other
1901                                 # than 0 or 1 so return an error.
1903                                 kiriwrite_error("invalidvalue");
1905                         }
1907                 }
1909                 return 0;
1911         } elsif ($variable_type eq "utf8"){
1913                 # The variable type is a UTF8 string.
1915                 if (!$variable_data){
1917                         $variable_data = "";
1919                 }
1921                 my $chunk = 0;
1922                 my $process = 8192;
1923                 my $length = 0;
1924                 my $chunkdata = "";
1926                 while ($chunk < $length){
1928                         $chunkdata = substr($variable_data, $chunk, $process);
1930                         if ($chunkdata =~ m/\A(
1931                                 [\x09\x0A\x0D\x20-\x7E]            # ASCII
1932                                 | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
1933                                 |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
1934                                 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
1935                                 |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates
1936                                 |  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1937                                 | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1938                                 |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1939                         )*\z/x){
1941                                 # The UTF-8 string is valid.
1942         
1943                         } else {
1944         
1945                                 # The UTF-8 string is not valid, check if the no error
1946                                 # value is set to 1 and return an error if it isn't.
1947         
1948                                 if ($variable_noerror eq 1){
1949         
1950                                         # The no error value has been set to 1, so return
1951                                         # a value of 1 (meaning that the UTF-8 string is
1952                                         # invalid).
1953         
1954                                         return 1; 
1955         
1956                                 } elsif ($variable_noerror eq 0) {
1957         
1958                                         # The no error value has been set to 0, so return
1959                                         # an error.
1960         
1961                                         kiriwrite_error("invalidutf8");
1962         
1963                                 } else {
1964         
1965                                         # The no error value is something else other than 0
1966                                         # or 1, so return an error.
1967         
1968                                         kiriwrite_error("invalidoption");
1969         
1970                                 }
1971         
1972                         }
1975                         $chunk = $chunk + $process;
1977                 }
1979 #               # Check if the string is a valid UTF8 string.
1980
1981 #               if ($variable_data =~ m/^(
1982 #                       [\x09\x0A\x0D\x20-\x7E]              # ASCII
1983 #                       | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
1984 #                       |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
1985 #                       | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
1986 #                       |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates
1987 #                       |  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1988 #                       | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1989 #                       |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1990 #               )*$/x){
1991
1992 #                       # The UTF-8 string is valid.
1993
1994 #               } else {
1995
1996 #                       # The UTF-8 string is not valid, check if the no error
1997 #                       # value is set to 1 and return an error if it isn't.
1998
1999 #                       if ($variable_noerror eq 1){
2000
2001 #                               # The no error value has been set to 1, so return
2002 #                               # a value of 1 (meaning that the UTF-8 string is
2003 #                               # invalid).
2004
2005 #                               return 1; 
2006
2007 #                       } elsif ($variable_noerror eq 0) {
2008
2009 #                               # The no error value has been set to 0, so return
2010 #                               # an error.
2011
2012 #                               kiriwrite_error("invalidutf8");
2013
2014 #                       } else {
2015
2016 #                               # The no error value is something else other than 0
2017 #                               # or 1, so return an error.
2018
2019 #                               kiriwrite_error("invalidoption");
2020
2021 #                       }
2022
2023 #               }
2025                 return 0;
2027         } elsif ($variable_type eq "serverprotocol"){
2029                 # Check if the server protocol is TCP or UDP and return
2030                 # an error if it isn't.
2032                 if ($variable_data ne "tcp" && $variable_data ne "udp"){
2034                         # The protocol given is not valid, check if the no
2035                         # error value is set to 1 and return an error if it isn't.
2037                         if ($variable_noerror eq 1){
2039                                 # The no error value has been set to 1, so return a
2040                                 # value of 1 (meaning that the server protocol is
2041                                 # invalid).
2043                                 return 1;
2045                         } elsif ($variable_noerror eq 0){
2047                                 # The no error value has been set to 0, so return
2048                                 # an error.
2050                                 kiriwrite_error("serverprotocolinvalid");
2052                         } else {
2054                                 # The no error value is something else other than 0
2055                                 # or 1, so return an error.
2057                                 kiriwrite_error("invalidoption");
2059                         }
2061                 }
2063                 return 0;
2065         } elsif ($variable_type eq "port"){
2067                 # Check if the port number given is less than 0 or more than 65535
2068                 # and return an error if it is.
2070                 if ($variable_data < 0 || $variable_data > 65535){
2072                         # The port number is less than 0 and more than 65535 so
2073                         # check if the no error value is set to 1 and return an
2074                         # error if it isn't.
2076                         if ($variable_noerror eq 1){
2078                                 # The no error value has been set to 1, so return a
2079                                 # value of 1 (meaning that the port number is invalid).
2081                                 return 1;
2083                         } elsif ($variable_noerror eq 0){
2085                                 # The no error value has been set to 0, so return
2086                                 # an error.
2088                                 kiriwrite_error("serverportnumberinvalid");
2090                         } else {
2092                                 # The no error value is something else other than 0
2093                                 # or 1, so return an error.
2095                                 kiriwrite_error("invalidoption");
2097                         }
2099                 }
2101                 return 0;
2103         }
2105         # Another type than the valid ones above has been specified so return an error specifying an invalid option.
2106         kiriwrite_error("invalidoption");
2110 sub kiriwrite_output_header{
2111 #################################################################################
2112 # kiriwrite_output_header: Outputs the header to the browser/stdout/console.    #
2113 #                                                                               #
2114 # Usage:                                                                        #
2115 #                                                                               #
2116 # kiriwrite_output_header();                                                    #
2117 #################################################################################
2119         # Print a header saying that the page expires immediately since the
2120         # date is set in the past.
2122         print "Content-Type: text/html; charset=utf8\r\n";
2123         print "Expires: Sun, 01 Jan 2007 00:00:00 GMT\r\n\r\n";
2125         return;
2128 sub kiriwrite_processfilename{
2129 #################################################################################
2130 # kiriwrite_processfilename: Processes a name and turns it into a filename that #
2131 # can be used by Kiriwrite.                                                     #
2132 #                                                                               #
2133 # Usage:                                                                        #
2134 #                                                                               #
2135 # kiriwrite_processfilename(text);                                              #
2136 #                                                                               #
2137 # text          Specifies the text to be used in the process for creating a new #
2138 #               filename.                                                       #
2139 #################################################################################
2141         # Get the values that have been passed to the subroutine.
2143         my ($process_text) = @_;
2145         # Define some variables that will be used later on.
2147         my $processed_stageone  = "";
2148         my $processed_stagetwo  = "";
2149         my $processed_length    = "";
2150         my $processed_char      = "";
2151         my $processed_seek      = 0;
2152         my $processed_filename  = "";
2154         # Set the first stage value of the processed filename to the
2155         # process filename and then filter it out to only contain
2156         # numbers and letters (no spaces) and then convert the
2157         # capitals to small letters.
2159         $processed_stageone = $process_text;
2160         $processed_stageone =~ tr#a-zA-Z0-9##cd;
2161         $processed_stageone =~ tr/A-Z/a-z/;
2163         # Now set the second stage value of the processed filename
2164         # to the first stage value of the processed filename and
2165         # then limit the filename down to 32 characters.
2167         $processed_stagetwo = $processed_stageone;
2168         $processed_length = length($processed_stagetwo);
2170         # Process the second stage filename into the final 
2171         # filename and do so until the seek counter is 32
2172         # or reaches the length of the second stage filename.
2174         do {
2176                 # Get the character that is the seek counter
2177                 # is set at.
2179                 $processed_char = substr($processed_stagetwo, $processed_seek, 1);
2181                 # Append to the final processed filename.
2183                 $processed_filename = $processed_filename . $processed_char;
2185                 # Increment the seek counter.
2187                 $processed_seek++;
2189         } until ($processed_seek eq 32 || $processed_seek eq $processed_length);
2191         return $processed_filename;
2196 sub kiriwrite_processconfig{
2197 #################################################################################
2198 # kiriwrite_processconfig: Processes an INI style configuration file.           #
2199 #                                                                               #
2200 # Usage:                                                                        #
2201 #                                                                               #
2202 # kiriwrite_processconfig(data);                                                #
2203 #                                                                               #
2204 # data  Specifies the data to process.                                          #
2205 #################################################################################
2207         my (@settings) = @_;
2209         my ($settings_line, %settings, $settings, $sectionname, $setting_name, $setting_value);
2211         foreach $settings_line (@settings){
2213                 next if !$settings_line;
2215                 # Check if the first character is a bracket.
2217                 if (substr($settings_line, 0, 1) eq "["){
2218                         $settings_line =~ s/\[//;
2219                         $settings_line =~ s/\](.*)//;
2220                         $settings_line =~ s/\n//;
2221                         $sectionname = $settings_line;
2222                         next;
2223                 }
2225                 $setting_name  = $settings_line;
2226                 $setting_value = $settings_line;
2227                 $setting_name  =~ s/\=(.*)//;
2228                 $setting_name  =~ s/\n//;
2229                 $setting_value =~ s/(.*)\=//;
2230                 $setting_value =~ s/\n//;
2232                 # Remove the spacing before and after the '=' sign.
2234                 $setting_name =~ s/\s+$//;
2235                 $setting_value =~ s/^\s+//;
2236                 $setting_value =~ s/\r//;
2238                 $settings{$sectionname}{$setting_name} = $setting_value;
2240         }
2242         return %settings;
2246 sub kiriwrite_output_page{
2247 #################################################################################
2248 # kiriwrite_output_page: Outputs the page to the browser/stdout/console.        #
2249 #                                                                               #
2250 # Usage:                                                                        #
2251 #                                                                               #
2252 # kiriwrite_output_page(pagetitle, pagedata, menutype);                         #
2253 #                                                                               #
2254 # pagetitle     Specifies the page title.                                       #
2255 # pagedata      Specifies the page data.                                        #
2256 # menutype      Prints out which menu to use.                                   #
2257 #################################################################################
2259         my ($pagetitle, $pagedata, $menutype, $db_filename) = @_;
2261         # Open the script page template and load it into the scriptpage variable,
2262         # while declaring the variable.
2264         open (my $filehandle_scriptpage, "<:utf8", 'page.html');
2265         my @scriptpage = <$filehandle_scriptpage>;
2266         binmode $filehandle_scriptpage, ':utf8';
2267         close ($filehandle_scriptpage);
2269         my $query_lite = new CGI::Lite;
2270         my $form_data = $query_lite->parse_form_data;   
2272         # Define the variables required.
2274         my $scriptpageline = "";
2275         my $pageoutput = "";
2277         $main::kiriwrite_presmodule->clear();
2279         # Print out the main menu for Kiriwrite.
2281         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=db", { Text => $main::kiriwrite_lang{menu}{viewdatabases} });
2282         $main::kiriwrite_presmodule->addtext(" | ");
2283         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=page", { Text => $main::kiriwrite_lang{menu}{viewpages} });
2284         $main::kiriwrite_presmodule->addtext(" | ");
2285         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=filter", { Text => $main::kiriwrite_lang{menu}{viewfilters} });
2286         $main::kiriwrite_presmodule->addtext(" | ");
2287         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=template", { Text => $main::kiriwrite_lang{menu}{viewtemplates} });
2288         $main::kiriwrite_presmodule->addtext(" | ");
2289         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=compile", { Text => $main::kiriwrite_lang{menu}{compilepages} });
2290         $main::kiriwrite_presmodule->addtext(" | ");
2291         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=settings", { Text => $main::kiriwrite_lang{menu}{viewsettings} });
2292         $main::kiriwrite_presmodule->addlinebreak();
2294         # Check what menu is going to be printed along with the default 'top' menu.
2296         if ($menutype eq "database"){
2298                 # If the menu type is database then print out the database sub-menu.
2300                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=db", { Text => $main::kiriwrite_lang{database}{submenu_viewdatabases} });
2301                 $main::kiriwrite_presmodule->addtext(" | ");
2302                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=db&action=new", { Text => $main::kiriwrite_lang{database}{submenu_adddatabase} });
2304         } elsif ($menutype eq "pages"){
2305                 # If the menu type is pages then print out the pages sub-menu.
2307                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=page&action=add&database="  . $db_filename, { Text => $main::kiriwrite_lang{pages}{submenu_addpage} });
2309         } elsif ($menutype eq "filter"){
2311                 # If the menu type is filters then print out the filter sub-menu.
2313                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=filter", { Text => $main::kiriwrite_lang{filter}{submenu_showfilters} });
2314                 $main::kiriwrite_presmodule->addtext(" | ");
2315                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=filter&action=add", { Text => $main::kiriwrite_lang{filter}{submenu_addfilter} });
2317         } elsif ($menutype eq "settings"){
2319                 # If the menu type is options then print out the options sub-menu.
2321                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=settings", { Text => $main::kiriwrite_lang{setting}{submenu_viewsettings} });
2322                 $main::kiriwrite_presmodule->addtext(" | ");
2323                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=settings&action=edit", { Text => $main::kiriwrite_lang{setting}{submenu_editsettings} });
2325         } elsif ($menutype eq "template"){
2327                 # If the menu type is template then print out the template sub-menu.
2329                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=template", { Text => $main::kiriwrite_lang{template}{submenu_showtemplates} });
2330                 $main::kiriwrite_presmodule->addtext(" | ");
2331                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=template&action=add", { Text => $main::kiriwrite_lang{template}{submenu_addtemplate} });
2333         } elsif ($menutype eq "compile"){
2335                 # If the menu type is compile then print out the compile sub-menu.
2337                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=compile", { Text => $main::kiriwrite_lang{compile}{submenu_listdatabases} });
2338                 $main::kiriwrite_presmodule->addtext(" | ");
2339                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=compile&action=all", { Text => $main::kiriwrite_lang{compile}{submenu_compileall} });
2340                 $main::kiriwrite_presmodule->addtext(" | ");
2341                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=compile&action=clean", { Text => $main::kiriwrite_lang{compile}{submenu_cleanoutputdirectory} });
2343         }
2345         my $menuoutput = $main::kiriwrite_presmodule->grab();
2347         # Find <kiriwrite> tages and replace with the apporiate variables.
2349         foreach $scriptpageline (@scriptpage){
2351                 $scriptpageline =~ s/<kiriwrite:menu>/$menuoutput/g;
2352                 $scriptpageline =~ s/<kiriwrite:imagespath>/$main::kiriwrite_config{"directory_noncgi_images"}/g;
2353                 $scriptpageline =~ s/<kiriwrite:pagedata>/$pagedata/g;
2355                 # Check if page title specified is blank, otherwise add a page title
2356                 # to the title.
2358                 if (!$pagetitle || $pagetitle eq ""){
2359                         $scriptpageline =~ s/<kiriwrite:title>//g;
2360                 } else {
2361                         $scriptpageline =~ s/<kiriwrite:title>/ ($pagetitle)/g;
2362                 }
2364                 
2366                 # Append processed line to the pageoutput variable.
2368                 $pageoutput = $pageoutput . $scriptpageline;
2370         }
2372         print $pageoutput;
2375         return;
2379 1;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy