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 / Compile.pm
1 package Modules::System::Compile;
3 use Modules::System::Common;
4 use strict;
5 use warnings;
6 use Exporter;
8 our @ISA = qw(Exporter);
9 our @EXPORT = qw(kiriwrite_compile_getoutputmodules kiriwrite_compile_makepages kiriwrite_compile_all kiriwrite_compile_list kiriwrite_compile_clean kiriwrite_compile_clean_helper kiriwrite_compile_loadhash);
11 my %formdata = ();
13 sub kiriwrite_compile_getoutputmodules{
14 #################################################################################
15 # kiriwrite_compile_getoutputmodules: Gets the list of available output modules.#
16 #                                                                               #
17 # Usage:                                                                        #
18 #                                                                               #
19 # @outputmodules = kiriwrite_compile_getoutputmodules;                          #
20 #################################################################################
22         my (@outputmoduleslist, @outputmoduleslist_final);
23         my $outputmodulefile;
25         opendir(OUTPUTMODULEDIR, "Modules/Output");
26         @outputmoduleslist = grep /m*\.pm$/, readdir(OUTPUTMODULEDIR);
27         closedir(OUTPUTMODULEDIR);
29         foreach $outputmodulefile (@outputmoduleslist){
30                 $outputmodulefile =~ s/.pm$//;
31                 push(@outputmoduleslist_final, $outputmodulefile);
32         }
34         return @outputmoduleslist_final;
36 }
38 sub kiriwrite_compile_makepages{
39 #################################################################################
40 # kiriwrite_compile_makepages: Compile the selected pages and place them in the #
41 # specified output directory.                                                   #
42 #                                                                               #
43 # Usage:                                                                        #
44 #                                                                               #
45 # kiriwrite_compile_makepages(type, selectedlist, override, overridetemplate,   #
46 #                               confirm);                                       #
47 #                                                                               #
48 # type                  Specifies if single or multiple databases are to be     #
49 #                       compiled.                                               #
50 # confirm               Specifies if the action to compile the databases should #
51 #                       really be done.                                         #
52 # override              Specifies if the template should be overriden.          #
53 # overridetemplate      Specifies the name of the template to override with.    #
54 # outputmodule          Specifies the output module.                            #
55 # selectedlist          Specifies the databases to compile from as an array.    #
56 #################################################################################
58         # Get the values that have been passed to the subroutine.
60         my ($type, $confirm, $override, $override_template, $outputmodule, @selectedlist) = @_;
61         #my $type = shift;
62         #my $confirm = shift;
63         #my $override = shift;
64         #my $override_template = shift;
65         #my $outputmodule = shift;
66         #my @selectedlist = shift;
67         #my %formdata = shift;
69         # Check if the confirm value is more than one
70         # character long.
72         kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
74         # Check if the value for enabling the override feature
75         # is "on" or blank and if it is something else then
76         # return an error.
78         if (!$override){
80                 $override = "off";
82         }
84         if ($override eq "on"){
85         } elsif (!$override || $override eq "off"){
86         } else {
88                 # The override value is invalid so return an error.
90                 kiriwrite_error("overridetemplatevalueinvalid");
92         }
94         # Check if the override template filename is valid and
95         # return an error if it isn't.
97         kiriwrite_variablecheck($override_template, "utf8", 0, 0);
98         $override_template      = kiriwrite_utf8convert($override_template);
99         my $kiriwrite_overridetemplatefilename_length_check     = kiriwrite_variablecheck($override_template, "maxlength", 64, 1);
100         my $kiriwrite_overridetemplatefilename_filename_check   = kiriwrite_variablecheck($override_template, "filename", "", 1);
102         if ($kiriwrite_overridetemplatefilename_length_check eq 1){
104                 # The override template filename given is too long
105                 # so return an error.
107                 kiriwrite_error("overridetemplatetoolong");
109         }
111         if ($kiriwrite_overridetemplatefilename_filename_check eq 2 && $override_template ne "!none"){
113                 # The override template filename is invalid so
114                 # return an error.
116                 kiriwrite_error("overridetemplateinvalid");
118         }
120         # Check if the confirm value is blank and if it
121         # is then set the confirm value to 0.
123         if (!$confirm){
125                 # The confirm value is blank, so set the
126                 # confirm value to 0.
128                 $confirm = 0;
130         }
132         # Check if there are any databases selected
133         # and return an error if there isn't.
135         if (!@selectedlist){
137                 # There are no databases in the array
138                 # so return an error.
140                 kiriwrite_error("nodatabaseselected");
142         }
144         # Check if the type given is no more than
145         # 7 characters long.
147         my $type_maxlength_check = kiriwrite_variablecheck($type, "maxlength", 8, 1);
149         if ($type_maxlength_check eq 1){
151                 # The type length given is too long so
152                 # return an error.
154                 kiriwrite_error("variabletoolong");
156         }
158         if (!$outputmodule){
159                 $outputmodule = $main::kiriwrite_config{'system_outputmodule'};
160         }
162         # Check if the output module name is valid.
164         my $outputmodule_maxlength_check = kiriwrite_variablecheck($outputmodule, "maxlength", 64, 1);
166         if ($outputmodule_maxlength_check eq 1){
168                 # The length of the output module name is too
169                 # long so return an error.
171                 kiriwrite_error("outputmodulenametoolong");
173         }
175         my $outputmodule_filename_check = kiriwrite_variablecheck($outputmodule, "filename", "", 1);
177         if ($outputmodule_maxlength_check eq 1){
179                 # The length of the output module name is too
180                 # long so return an error.
182                 kiriwrite_error("outputmodulenameinvalid");
184         }
186         # Set up the output module.
188         ($outputmodule) = $outputmodule =~ m/^(.*)$/g;
189         my $outputmodulename = "Modules::Output::" . $outputmodule;
190         eval "use " . $outputmodulename;
191         my $kiriwrite_outputmodule = $outputmodulename->new();
192         my ($outputmodule_options, %outputmodule_options);
193         tie(%outputmodule_options, "Tie::IxHash");
194         $kiriwrite_outputmodule->initialise();
195         %outputmodule_options = $kiriwrite_outputmodule->getoptions();
197         # Check if the action to compile the databases
198         # has been confirmed.
200         if ($confirm eq 1){
202                 # The action to compile the databases has
203                 # been confirmed.
205                 # Define some variables for later.
207                 my %database_info;
208                 my %filter_info;
209                 my %template_info;
210                 my %page_info;
211                 my %templatefiles;
212                 my @page_filenames;
213                 my @databaseinfo;
214                 my @databasepages;
215                 my @filterslist;
216                 my @findfilter;
217                 my @replacefilter;
218                 my @templateslist;
219                 my @database_filters;
220                 my $warning_count               = 0;
221                 my $error_count                 = 0;
222                 my $pages_count                 = 0;
223                 my $page_compile_errorflag      = 0;
224                 my $filter;
225                 my $filters_count               = 0;
226                 my $filters_find_blank_warning  = 0;
227                 my $filter_find;
228                 my $filter_replace;
229                 my $database;
230                 my $database_name;
231                 my $page_filename;
232                 my $page_filename_check;
233                 my $page_name;
234                 my $page_description;
235                 my $page_section;
236                 my $page_template;
237                 my $page_content;
238                 my $page_settings;
239                 my $page_lastmodified;
240                 my $page_title;
241                 my $page_final;
242                 my $page_autosection;
243                 my $page_autotitle;
244                 my $page;
245                 my $database_filename_check     = 0;
246                 my $database_maxlength_check    = 0;
247                 my $output_exists               = 0;
248                 my $output_permissions          = 0;
249                 my $filters_exists              = 0;
250                 my $filters_permissions         = 0;
251                 my $filters_skip                = 0;
252                 my $template;
253                 my $templates_skip              = 0;
254                 my $information_prefix          = $main::kiriwrite_lang{compile}{informationprefix};
255                 my $error_prefix                = $main::kiriwrite_lang{compile}{errorprefix};
256                 my $warning_prefix              = $main::kiriwrite_lang{compile}{warningprefix};
258                 # Get the settings for the output module and load them into the
259                 # output module.
261                 use Hash::Search;
262                 my $hs = new Hash::Search;
264                 $hs->hash_search("^outputmodule_", %formdata);
266                 my %outputmodulesettings = $hs->hash_search_resultdata;
267                 my $language_name = $main::kiriwrite_config{'system_language'};
269                 $kiriwrite_outputmodule->loadsettings($language_name, %outputmodulesettings);
271                 # Check if the settings for the output module were loaded correctly.
273                 if ($kiriwrite_outputmodule->errorflag eq 1){
275                         # The settings for the output module were not loaded correctly
276                         # so return an error.
278                         kiriwrite_error("outputmodulesettingerror", $kiriwrite_outputmodule->errormessage);             
280                 }
282                 $kiriwrite_outputmodule->clearflag;
284                 # Write a page title and start the box for the data list.
286                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{compiledatabases}, { Style => "pageheader" });
287                 $main::kiriwrite_presmodule->addlinebreak();
288                 $main::kiriwrite_presmodule->addlinebreak();
289                 $main::kiriwrite_presmodule->startbox("datalist");
291                 # Check if the output directory exists and has
292                 # valid permissions set.
294                 $output_exists          = kiriwrite_fileexists($main::kiriwrite_config{'directory_data_output'});
296                 if ($output_exists ne 0){
298                         # The output directory does not exist so
299                         # return an error.
301                         kiriwrite_error("outputdirectorymissing");
303                 }
305                 $output_permissions     = kiriwrite_filepermissions($main::kiriwrite_config{'directory_data_output'}, 1, 1);
307                 if ($output_permissions ne 0){
309                         # The output directory has invalid
310                         # permissions set so return an error.
312                         kiriwrite_error("outputdirectoryinvalidpermissions");
314                 }
316                 # Connect to the database server.
318                 $main::kiriwrite_dbmodule->connect();
320                 # Check if any errors occured while connecting to the database server.
322                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
324                         # A database connection error has occured so return
325                         # an error.
327                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
329                 }
331                 # Connect to the filter database.
333                 $main::kiriwrite_dbmodule->connectfilter();
335                 # Check if any error has occured while connecting to the filter
336                 # database.
338                 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){
340                         # The filter database does not exist so write a warning message.
342                         $main::kiriwrite_presmodule->addtext($warning_prefix . $main::kiriwrite_lang{compile}{filterdatabasemissing});
343                         $main::kiriwrite_presmodule->addlinebreak();
344                         $filters_skip = 1;
345                         $warning_count++;
347                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){
349                         # The filter database has invalid permissions set so write a
350                         # an error message.
352                         $main::kiriwrite_presmodule->addtext($error_prefix . $main::kiriwrite_lang{compile}{filterdatabasepermissions});
353                         $main::kiriwrite_presmodule->addlinebreak();
354                         $filters_skip = 1;
355                         $error_count++;
357                 }
359                 # Load the filter database (if the filters skip
360                 # value isn't set to 1).
362                 if ($filters_skip eq 0){
364                         # Get the list of available filters.
366                         @database_filters       = $main::kiriwrite_dbmodule->getfilterlist();
368                         # Check if any errors occured while getting the list of filters.
370                         if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
372                                 # A database error has occured with the filter database.
374                                 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{filterdatabaseerror}, $main::kiriwrite_dbmodule->geterror(1)));
375                                 $main::kiriwrite_presmodule->addlinebreak();
376                                 $error_count++;
378                         }
380                         # Check if the filters skip value is set to 0
381                         # before executing the query.
383                         if ($filters_skip eq 0){
385                                 foreach $filter (@database_filters){
387                                         # Get the filter information.
389                                         %filter_info = $main::kiriwrite_dbmodule->getfilterinfo({ FilterID => $filter, Reduced => 1 });
391                                         # Check if the filter is enabled and if it isn't then process
392                                         # the next filter.
394                                         if (!$filter_info{"FilterEnabled"}){
396                                                 # The filter is not enabled so process the next filter.
398                                                 next;
400                                         }
402                                         # Check if any errors occured while getting the filter information.
404                                         if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
406                                                 # A database error occured while using the filter database.
408                                                 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{filterdatabaseerror}, $main::kiriwrite_dbmodule->geterror(1)));
409                                                 $main::kiriwrite_presmodule->addlinebreak();
410                                                 $error_count++;
411                                                 next;
413                                         } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDoesNotExist"){
415                                                 # The filter does not exist so process the next filter.
417                                                 next;
419                                         }
421                                         # Check if the find filter is blank and
422                                         # if it is then write a warning message.
424                                         if (!$filter_info{"FilterFind"}){
426                                                 if ($filters_find_blank_warning ne 1){
428                                                         $main::kiriwrite_presmodule->addtext($warning_prefix . $main::kiriwrite_lang{compile}{findfilterblank});
429                                                         $main::kiriwrite_presmodule->addlinebreak();
430                                                         $filters_find_blank_warning = 1;
431                                                 }
432                                                 next;
434                                         } else {
436                                                 # Add each find and replace filter.
438                                                 $findfilter[$filters_count]     = $filter_info{"FilterFind"};
439                                                 $replacefilter[$filters_count]  = $filter_info{"FilterReplace"};
441                                         }
443                                         $filters_count++;
445                                 }
447                                 $main::kiriwrite_presmodule->addtext($information_prefix . $main::kiriwrite_lang{compile}{finishfilterdatabase});
448                                 $main::kiriwrite_presmodule->addlinebreak();
450                         }
452                 }
454                 # Disconnect from the filter database.
456                 $main::kiriwrite_dbmodule->disconnectfilter();
458                 # Connect to the template database.
460                 $main::kiriwrite_dbmodule->connecttemplate();
462                 # Check if any errors occured while connecting to the template database.
464                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
466                         # The template database does not exist so set the template
467                         # warning message.
469                         $main::kiriwrite_presmodule->addtext($warning_prefix . $main::kiriwrite_lang{compile}{templatedatabasemissing});
470                         $main::kiriwrite_presmodule->addlinebreak();
471                         $templates_skip = 1;
472                         $warning_count++;
474                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
476                         # The template database has invalid permissions set so write
477                         # the template warning message.
478  
479                         $main::kiriwrite_presmodule->addtext($error_prefix . $main::kiriwrite_lang{compile}{templatedatabasepermissions});
480                         $main::kiriwrite_presmodule->addlinebreak();
481                         $templates_skip = 1;
482                         $error_count++;
484                 }
486                 # Check if the template skip value isn't set and if it isn't
487                 # then get the list of templates.
489                 if (!$templates_skip){
491                         @templateslist = $main::kiriwrite_dbmodule->gettemplatelist();
493                         # Check if any errors had occured.
495                         if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
497                                 # A database error occured while getting the list
498                                 # of templates so return a warning message with the 
499                                 # extended error information.
501                                 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{templatedatabaseerror}, $main::kiriwrite_dbmodule->geterror(1)));
502                                 $templates_skip = 1;
503                                 $error_count++;
505                         }
507                         # Check if the template skip value isn't set and if it isn't
508                         # then process each template.
510                         if (!$templates_skip){
512                                 # Process each template.
514                                 foreach $template (@templateslist){
516                                         # Get information about the template.
518                                         %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template });
520                                         # Check if any error occured while getting the template information.
522                                         if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
524                                                 # A database error has occured, so return an error.
526                                                 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{templatedatabaseerror}, $main::kiriwrite_dbmodule->geterror(1)));
527                                                 $error_count++;
529                                         } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
531                                                 # The template does not exist, so process the next template.
533                                                 next;
535                                         }
537                                         # Place each template file into the hash.
539                                         $templatefiles{$template_info{"TemplateFilename"}}{template}    = $template_info{"TemplateLayout"};
540                                         $templatefiles{$template_info{"TemplateFilename"}}{valid}       = 1;
542                                 }
544                                 $main::kiriwrite_presmodule->addtext($information_prefix . $main::kiriwrite_lang{compile}{finishtemplatedatabase});
545                                 $main::kiriwrite_presmodule->addlinebreak();
547                         }
549                 }
551                 # Disconnect from the template database.
553                 $main::kiriwrite_dbmodule->disconnecttemplate();
555                 # Process each database.
557                 foreach $database (@selectedlist){
559                         # Clear the error flag for the output module.
561                         $kiriwrite_outputmodule->clearflag;
563                         # Check if the database filename and length
564                         # are valid.
566                         $main::kiriwrite_presmodule->addhorizontalline();
568                         $database_filename_check        = kiriwrite_variablecheck($database, "page_filename", "", 1);
569                         $database_maxlength_check       = kiriwrite_variablecheck($database, "maxlength", 32, 1);
571                         if ($database_filename_check ne 0){
573                                 # The database filename is invalid, so process
574                                 # the next database.
576                                 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{databasefilenameinvalidcharacters}, $database));
577                                 $main::kiriwrite_presmodule->addlinebreak();
578                                 $error_count++;
579                                 next;
581                         }
583                         if ($database_maxlength_check ne 0){
585                                 # The database file is too long, so process the
586                                 # next database.
588                                 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{databasefilenametoolong}, $database));
589                                 $main::kiriwrite_presmodule->addlinebreak();
590                                 $error_count++;
591                                 next;
593                         }
595                         # Select the database.
597                         $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
599                         # Check if any errors had occured while selecting the database.
601                         if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
603                                 # The database does not exist, so write a warning message.
605                                 $main::kiriwrite_presmodule->addtext($warning_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{databasemissing}, $database));
606                                 $main::kiriwrite_presmodule->addlinebreak();
607                                 $warning_count++;
608                                 next;
610                         } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
612                                 # The database has invalid permissions set, so write
613                                 # an error message.
615                                 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{databaseinvalidpermissions}, $database));
616                                 $main::kiriwrite_presmodule->addlinebreak();
617                                 $error_count++;
618                                 next;
620                         }
622                         # Get information about the database.
624                         my %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
626                         # Check if any error occured while getting the database information.
628                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
630                                 # A database error has occured so write an error.
632                                 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{databaseerror}, $database, $main::kiriwrite_dbmodule->geterror(1)));
633                                 $main::kiriwrite_presmodule->addlinebreak();
634                                 $error_count++;
635                                 next;
637                         };
639                         # Get the database name.
641                         $database_name = $database_info{"DatabaseName"};
643                         $main::kiriwrite_presmodule->addtext($information_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{compilingpages}, $database_name));
644                         $main::kiriwrite_presmodule->addlinebreak();
646                         # Get the list of pages in the database.
648                         @databasepages = $main::kiriwrite_dbmodule->getpagelist();
650                         # Check if any errors occured while getting the list of pages.
652                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
654                                 # A database error has occured so return an error and
655                                 # also the extended error information.
657                                 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{databasepageerror}, $database, $main::kiriwrite_dbmodule->geterror(1)));
658                                 $main::kiriwrite_presmodule->addlinebreak();
659                                 $error_count++;
660                                 next;
662                         }
664                         foreach $page (@databasepages) {
666                                 # Clear the error flag for the output module..
668                                 $kiriwrite_outputmodule->clearflag;
670                                 # Reset certain values.
672                                 $page_autotitle = "";
673                                 $page_autosection = "";
675                                 # Get information about the page.
677                                 %page_info = $main::kiriwrite_dbmodule->getpageinfo({ PageFilename => $page });
679                                 $page_filename          = $page_info{"PageFilename"};
680                                 $page_name              = $page_info{"PageName"};
681                                 $page_description       = $page_info{"PageDescription"};
682                                 $page_section           = $page_info{"PageSection"};
683                                 $page_template          = $page_info{"PageTemplate"};
684                                 $page_content           = $page_info{"PageContent"};
685                                 $page_settings          = $page_info{"PageSettings"};
686                                 $page_lastmodified      = $page_info{"PageLastModified"};
688                                 # Check if the filename is valid.
690                                 $page_filename_check = kiriwrite_variablecheck($page_filename, "page_filename", 0, 1);
692                                 if ($page_filename_check ne 0){
694                                         # The file name is not valid so write a
695                                         # error and process the next page.
697                                         $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{invalidpagefilename}, $page_name));
698                                         $main::kiriwrite_presmodule->addlinebreak();
699                                         $error_count++;
700                                         next;
702                                 }
704                                 # Check if the template with the filename does not exist
705                                 # in the template files hash and write a message and
706                                 # process the next page.
708                                 if ($override eq "on"){
710                                         $page_template = $override_template;
712                                 }
714                                 if (!$templatefiles{$page_template}{valid} && $page_template ne "!none" && $templates_skip eq 0){
716                                         $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{templatefilemissing}, $page_template, $page_name, $page_filename));
717                                         $main::kiriwrite_presmodule->addlinebreak();
718                                         $error_count++;
719                                         next;
721                                         $page_final = $page_content;
723                                 } elsif ($templates_skip eq 1 || $page_template eq "!none"){
725                                         $page_final = $page_content;
727                                 } else {
729                                         $page_final = $templatefiles{$page_template}{template};
731                                         if (!$page_final){
732                                                 $page_final = "";
733                                         }
735                                         $page_final =~ s/<kiriwrite:pagecontent>/$page_content/g;
737                                 }
739                                 # Create the combined page title (if needed).
741                                 if ($page_settings eq 0 || $page_settings > 3){
743                                         # Don't use page name or section name.
745                                         $page_final =~ s/<kiriwrite:pagetitle>//g;
747                                 } elsif ($page_settings eq 1){
749                                         # Use the page name and section name.
751                                         $page_autotitle = "(" . $page_section . " - " . $page_name . ")";
752                                         $page_title = $page_section . " - " . $page_name;
753                                         $page_final =~ s/<kiriwrite:pagetitle>/$page_title/g;
755                                 } elsif ($page_settings eq 2){
757                                         # Use the page name only.
759                                         $page_autotitle = "(" . $page_name . ")";
760                                         $page_final =~ s/<kiriwrite:pagetitle>/$page_name/g;
762                                 } elsif ($page_settings eq 3){
764                                         # Use the section name only.
766                                         if ($page_section){
767                                                 $page_autotitle = "(" . $page_section . ")";
768                                         }
769                                         $page_final =~ s/<kiriwrite:pagetitle>/$page_section/g;
771                                 }
773                                 # Check if the section name is not blank and
774                                 # place brackets inbetween if it is.
776                                 if ($page_section){
778                                         $page_autosection = "(" . $page_section . ")";
780                                 }
782                                 # Replace each <kiriwrite> value with the apporiate page
783                                 # values.
785                                 $page_final =~ s/<kiriwrite:pagename>/$page_name/g;
786                                 $page_final =~ s/<kiriwrite:pagedescription>/$page_description/g;
787                                 $page_final =~ s/<kiriwrite:pagesection>/$page_section/g;
788                                 $page_final =~ s/<kiriwrite:autosection>/$page_autosection/g;
789                                 $page_final =~ s/<kiriwrite:autotitle>/$page_autotitle/g;
791                                 # Process the filters on the page data.
793                                 if ($filters_skip eq 0){
795                                         $filters_count = 0;
797                                         foreach $filter_find (@findfilter){
799                                                 # Get the replace filter and process each
800                                                 # filter on the page.
802                                                 $filter_replace = $replacefilter[$filters_count];
803                                                 $page_final =~ s/$filter_find/$filter_replace/g;
804                                                 $filters_count++;
806                                         }
808                                 }
810                                 # Convert the date into a format that can be used by Kiriwrite.
812                                 # PUT SOME CODE HERE! XO
814                                 $kiriwrite_outputmodule->addpage({ Page => $page_filename, Data => $page_final, Title => $page_name, Section => $page_section, LastModified => $page_lastmodified, Database => $database });
816                                 # Check if any errors occured while adding the page.
818                                 if ($kiriwrite_outputmodule->errorflag eq 1){
820                                         $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{pagenotwritten}, $page_filename, $kiriwrite_outputmodule->errormessage));
821                                         $main::kiriwrite_presmodule->addlinebreak();
822                                         $error_count++;
823                                         next;
825                                 }
827                                 $kiriwrite_outputmodule->outputpage({ Page => $page_filename, Data => $page_final, Title => $page_name, Section => $page_section, LastModified => $page_lastmodified, Database => $database });
829                                 if ($kiriwrite_outputmodule->errorflag eq 1){
831                                         $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{pagenotwritten}, $page_filename, $kiriwrite_outputmodule->errormessage));
832                                         $main::kiriwrite_presmodule->addlinebreak();
833                                         $error_count++;
834                                         next;
836                                 }
838                                 # Write a message saying the page has been compiled. Check
839                                 # to see if the page name is blank and write a message
840                                 # saying there's no page name.
842                                 if (!$page_name){
843                                         $main::kiriwrite_presmodule->addtext($information_prefix . ' ');
844                                         $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{noname} . ' ');
845                                         $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{compile}{compiledpageblankname}, $page_filename));
846                                 } else {
847                                         $main::kiriwrite_presmodule->addtext($information_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{compiledpage}, $page_name, $page_filename));
848                                 }
851                                 $main::kiriwrite_presmodule->addlinebreak();
852                                 $pages_count++;
854                         }
856                         # Output all the pages (if required).
858                         $kiriwrite_outputmodule->outputall();
860                         if ($kiriwrite_outputmodule->errorflag eq 1){
862                                 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{outputallerror}, $page_filename, $kiriwrite_outputmodule->errormessage));
863                                 $main::kiriwrite_presmodule->addlinebreak();
864                                 $error_count++;
865                                 next;
867                         }
869                         # Write a message saying that the database has
870                         # been processed.
872                         $main::kiriwrite_presmodule->addtext($information_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{databasefinish}, $database_name));
873                         $main::kiriwrite_presmodule->addlinebreak();
875                 }
877                 # This is the last time outputall is going to be called.
879                 $kiriwrite_outputmodule->outputall({ FinishedProcessing => 1 });
881                 if ($kiriwrite_outputmodule->errorflag eq 1){
883                         $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{outputallerror}, $page_filename, $kiriwrite_outputmodule->errormessage));
884                         $main::kiriwrite_presmodule->addlinebreak();
885                         $error_count++;
886                         next;
888                 }
890                 # Disconnect from the database server.
892                 $main::kiriwrite_dbmodule->disconnect;
894                 # Run the finish subroutine for the output module.
896                 $kiriwrite_outputmodule->finish;
898                 $main::kiriwrite_presmodule->addhorizontalline();
899                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{compile}{compileresults}, $pages_count, $error_count, $warning_count));
900                 $main::kiriwrite_presmodule->endbox();
901                 $main::kiriwrite_presmodule->addlinebreak();
902                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $main::kiriwrite_lang{compile}{returncompilelist} });
904                 return $main::kiriwrite_presmodule->grab();
906         } elsif ($confirm eq 0){
908                 # The action to compile the databases has
909                 # not been confirmed so check what type
910                 # is being used.
912                 # Get the list of templates for overwriting the
913                 # template if needed.
915                 my $templateoverride_skip       = 0;
916                 my $templatedbwarning           = "";
917                 my @template_list;
918                 my $template_filename;
919                 my $template_file;
920                 my @outputmodule_comboboxnames;
921                 my @outputmodule_comboboxvalues;
922                 my $outputmodule_comboboxname;
923                 my $outputmodule_comboboxvalue;
924                 my $outputmodule_selected       = 0;
925                 my $combobox_count              = 0;
926                 my $outputmoduleslist_name;
927                 my $option_name;
928                 my %template_info;
929                 my %template_dblist;
930                 tie(%template_dblist, "Tie::IxHash");
932                 if ($type eq "single"){
934                         # The type is a single database selected so
935                         # process that database.
937                         # Define some variables for later.
939                         my %database_info; 
940                         my $database_filename_check;
941                         my $database_maxlength_check;
942                         my $databasefilename;
943                         my $database_name;
945                         # Check that the database name and length are
946                         # valid and return an error if they aren't.
948                         $databasefilename = $selectedlist[0];
950                         # Connect to the database server.
952                         $main::kiriwrite_dbmodule->connect();
954                         # Check if any errors occured while connecting to the database server.
956                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
958                                 # A database connection error has occured so return
959                                 # an error.
961                                 kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
963                         }
965                         # Select the database.
967                         $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $databasefilename });
969                         # Check if any errors had occured while selecting the database.
971                         if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
973                                 # The database does not exist, so return an error.
975                                 kiriwrite_error("databasemissingfile");
977                         } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
979                                 # The database has invalid permissions set, so return
980                                 # an error.
982                                 kiriwrite_error("databaseinvalidpermissions");
984                         }
986                         # Get information about the database.
988                         %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
990                         # Check if any error occured while getting the database information.
992                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
994                                 # A database error has occured so return an error and
995                                 # also the extended error information.
997                                 kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
999                         };
1001                         $database_name = $database_info{"DatabaseName"};
1003                         $main::kiriwrite_dbmodule->connecttemplate();
1005                         # Check if any errors occured while connecting to the
1006                         # template database.
1008                         if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
1010                                 # The template database does not exist so skip processing
1011                                 # the list of templates in the template database.
1013                                 $templateoverride_skip = 1;
1014                                 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedbmissing};
1016                         } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
1018                                 # The template database has invalid permissions set so
1019                                 # skip processing the list of templates in the
1020                                 # template database.
1022                                 $templateoverride_skip = 1;
1023                                 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedbinvalidpermissions};
1025                         }
1027                         # Get the list of available templates if no errors had
1028                         # occured.
1030                         if ($templateoverride_skip ne 1){
1032                                 @template_list = $main::kiriwrite_dbmodule->gettemplatelist();
1034                                 # Check if any errors occured while getting the list of templates.
1036                                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1038                                         # A template database error has occured so skip processing the
1039                                         # list of templates in the template database.
1041                                         $templateoverride_skip = 1;
1042                                         $templatedbwarning = $main::kiriwrite_lang{compile}{templatedberror};
1044                                 }
1046                                 if ($templateoverride_skip ne 1){
1048                                         foreach $template_file (@template_list){
1050                                                 %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_file });
1051                                                 
1052                                                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
1054                                                         next;
1056                                                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1058                                                         next;
1060                                                 }
1062                                                 $template_dblist{$template_file} = $template_info{"TemplateName"};
1064                                         }
1066                                 }
1068                         }
1070                         # Disconnect from the template database and database server.
1072                         $main::kiriwrite_dbmodule->disconnecttemplate();
1073                         $main::kiriwrite_dbmodule->disconnect();
1075                         # Get the list of output modules.
1077                         my @outputmoduleslist = kiriwrite_compile_getoutputmodules;
1079                         # Write out a form asking the user to confirm if the
1080                         # user wants to compile the selected database.
1082                         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{compiledatabase}, { Style => "pageheader" });
1084                         # Write out a form selecting the output module.
1086                         $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1087                         $main::kiriwrite_presmodule->addlinebreak();
1088                         $main::kiriwrite_presmodule->addhiddendata("mode", "compile");
1089                         $main::kiriwrite_presmodule->addhiddendata("action", "compile");
1090                         $main::kiriwrite_presmodule->addhiddendata("type", "single");
1091                         $main::kiriwrite_presmodule->addhiddendata("database", $databasefilename);
1092                         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{selectoutputmodule});
1093                         $main::kiriwrite_presmodule->addselectbox("outputmodule");
1095                         # Process the output modules found.
1097                         foreach $outputmoduleslist_name (@outputmoduleslist){
1099                                 # Print each option and check if the module name is the selected module.
1101                                 if ($outputmodule eq $outputmoduleslist_name){
1103                                         $main::kiriwrite_presmodule->addoption($outputmoduleslist_name, { Value => $outputmoduleslist_name, Selected => 1 });
1105                                 } else {
1107                                         $main::kiriwrite_presmodule->addoption($outputmoduleslist_name, { Value => $outputmoduleslist_name });
1109                                 }
1111                         }
1113                         $main::kiriwrite_presmodule->endselectbox();
1114                         $main::kiriwrite_presmodule->addtext(" | ");
1115                         $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{compile}{selectbutton});
1116                         $main::kiriwrite_presmodule->endform();
1118                         # Write out another form for compiling the pages.
1120                         $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1121                         $main::kiriwrite_presmodule->startbox();
1122                         $main::kiriwrite_presmodule->addhiddendata("mode", "compile");
1123                         $main::kiriwrite_presmodule->addhiddendata("action", "compile");
1124                         $main::kiriwrite_presmodule->addhiddendata("type", "multiple");
1125                         $main::kiriwrite_presmodule->addhiddendata("outputmodule", $outputmodule);
1126                         $main::kiriwrite_presmodule->addhiddendata("id[1]", $databasefilename);
1127                         $main::kiriwrite_presmodule->addhiddendata("name[1]", "on");
1128                         $main::kiriwrite_presmodule->addhiddendata("count", 1);
1129                         $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
1130                         $main::kiriwrite_presmodule->addlinebreak();
1131                         $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{compile}{compiledatabasemessage}, $database_name));
1132                         $main::kiriwrite_presmodule->addlinebreak();
1133                         $main::kiriwrite_presmodule->addlinebreak();
1135                         if ($templateoverride_skip eq 1){
1137                                 # Add message saying why template can't be overridden.
1138                                 $main::kiriwrite_presmodule->addtext($templatedbwarning);
1140                         } else {
1142                                 # Add overwrite template data.
1143                                 $main::kiriwrite_presmodule->addcheckbox("enableoverride", { OptionDescription => $main::kiriwrite_lang{compile}{overridetemplate}, LineBreak => 1 });
1144                                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{replacecurrenttemplate});
1145                                 $main::kiriwrite_presmodule->addselectbox("overridetemplate");
1147                                 foreach $template_file (keys %template_dblist){
1149                                         $main::kiriwrite_presmodule->addoption($template_dblist{$template_file} . " (" . $template_file . ")", { Value => $template_file });
1151                                 }
1153                                 $main::kiriwrite_presmodule->addoption($main::kiriwrite_lang{compile}{dontusetemplate}, { Value => "!none" });
1154                                 $main::kiriwrite_presmodule->endselectbox();
1156                         }
1158                         # Print out the list of options for the output module.
1160                         $main::kiriwrite_presmodule->addlinebreak();
1161                         $main::kiriwrite_presmodule->addlinebreak();
1162                         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{outputmodulesettings}, { Style => "smallpageheader" });
1163                         $main::kiriwrite_presmodule->addlinebreak();
1165                         foreach $option_name (keys %outputmodule_options){
1167                                 $main::kiriwrite_presmodule->addlinebreak();
1169                                 # Check if the option is a checkbox option.
1171                                 if ($outputmodule_options{$option_name}{type} eq "checkbox"){
1173                                         $main::kiriwrite_presmodule->addcheckbox("outputmodule_" . $option_name, { OptionDescription => $outputmodule_options{$option_name}{string} });
1175                                 }
1177                                 # Check if the option is a string option.
1179                                 if ($outputmodule_options{$option_name}{type} eq "textbox"){
1181                                         if (!$outputmodule_options{$option_name}{password}){
1182                                                 $outputmodule_options{$option_name}{password} = 0;
1183                                         }
1185                                         $main::kiriwrite_presmodule->addtext($outputmodule_options{$option_name}{string} . " ");
1186                                         $main::kiriwrite_presmodule->addinputbox("outputmodule_" . $option_name, { Size => $outputmodule_options{$option_name}{size}, MaxLength => $outputmodule_options->{$option_name}{maxlength}, Value => $outputmodule_options{$option_name}{value}, Password => $outputmodule_options{$option_name}{password} });
1188                                 }
1190                                 # Check if the option is a combobox option.
1192                                 if ($outputmodule_options{$option_name}{type} eq "combobox"){
1194                                         $combobox_count         = 0;
1196                                         @outputmodule_comboboxnames = split(/\|/, $outputmodule_options{$option_name}{optionnames});
1197                                         @outputmodule_comboboxvalues = split(/\|/, $outputmodule_options{$option_name}{optionvalues});
1199                                         $main::kiriwrite_presmodule->addtext($outputmodule_options{$option_name}{string} . " ");
1200                                         $main::kiriwrite_presmodule->addselectbox("outputmodule_" . $option_name);
1202                                         foreach $outputmodule_comboboxname (@outputmodule_comboboxnames){
1204                                                 $main::kiriwrite_presmodule->addoption($outputmodule_comboboxname, { Value => $outputmodule_comboboxvalues[$combobox_count] });
1205                                                 $combobox_count++;
1207                                         }
1209                                         $main::kiriwrite_presmodule->endselectbox;
1211                                 }
1213                                 # Check if the option is a radio option.
1215                                 if ($outputmodule_options{$option_name}{type} eq "radio"){
1217                                         # Check if the selected value is blank and if it is then
1218                                         # set it to 0.
1220                                         if (!$outputmodule_options{$option_name}{selected}){
1221                                                 $outputmodule_selected = 0;
1222                                         } else {
1223                                                 $outputmodule_selected = 1;
1224                                         }
1226                                         $main::kiriwrite_presmodule->addradiobox("outputmodule_" . $outputmodule_options{$option_name}{name}, { Description => $outputmodule_options{$option_name}{string}, Value => $outputmodule_options{$option_name}{value}, Selected => $outputmodule_selected });
1228                                 }
1230                         }
1232                         $main::kiriwrite_presmodule->addlinebreak();
1233                         $main::kiriwrite_presmodule->addlinebreak();
1234                         $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{compile}{compiledatabasebutton});
1235                         $main::kiriwrite_presmodule->addtext(" | ");
1236                         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $main::kiriwrite_lang{compile}{returncompilelist} });
1237                         $main::kiriwrite_presmodule->endbox();
1238                         $main::kiriwrite_presmodule->endform();
1240                         return $main::kiriwrite_presmodule->grab();
1242                 } elsif ($type eq "multiple"){
1244                         # The type is multiple databases selected
1245                         # so process each database.
1247                         # Define some variables for later.
1249                         my %database_list;
1250                         my $databasename;
1251                         my $database;
1252                         my $database_filename_check;
1253                         my $database_maxlength_check;
1254                         my $database_count = 0;
1255                         my $database_info_name;
1257                         # Connect to the database server.
1259                         $main::kiriwrite_dbmodule->connect();
1261                         # Check if any errors occured while connecting to the database server.
1263                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1265                                 # A database connection error has occured so return
1266                                 # an error.
1268                                 kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
1270                         }
1272                         foreach $databasename (@selectedlist){
1274                                 # Check if the database is in the database
1275                                 # directory and skip it if it isn't.
1276  
1277                                 $database_filename_check        = kiriwrite_variablecheck($databasename, "filename", "", 1);
1278                                 $database_maxlength_check       = kiriwrite_variablecheck($databasename, "maxlength", 32, 1);
1279  
1280                                 if ($database_filename_check ne 0 || $database_maxlength_check ne 0){
1281  
1282                                         # The database filename given is invalid or
1283                                         # the database filename given is too long
1284                                         # so process the next database.
1285  
1286                                         next;
1287  
1288                                 }
1290                                 # Select the database to add the page to.
1292                                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $databasename });
1294                                 # Check if any errors had occured while selecting the database.
1296                                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
1298                                         # The database does not exist, so process the next database.
1300                                         next;
1302                                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
1304                                         # The database has invalid permissions set, so process
1305                                         # the next database.
1307                                         next;
1309                                 }
1311                                 # Get information about the database.
1313                                 my %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
1315                                 # Check if any error occured while getting the database information.
1317                                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
1319                                         # A database error has occured so process the next
1320                                         # database.
1322                                         next;
1324                                 };
1326                                 $database_list{$database_count}{Name}           = $database_info{"DatabaseName"};
1327                                 $database_list{$database_count}{Filename}       = $databasename;
1329                                 $database_count++;
1331                         }
1333                         # Check if any databases are available to be compiled.
1335                         if ($database_count eq 0){
1337                                 # No databases are available to be compiled.
1339                                 kiriwrite_error("nodatabaseselected");
1341                         }
1343                         # Get the list of output modules.
1345                         my @outputmoduleslist = kiriwrite_compile_getoutputmodules;
1347                         # Write out the form for compiling the database.
1349                         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{compileselecteddatabases}, { Style => "pageheader" });
1351                         # Write out a form selecting the output module.
1353                         $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1354                         $main::kiriwrite_presmodule->addlinebreak();
1355                         $main::kiriwrite_presmodule->addhiddendata("mode", "compile");
1356                         $main::kiriwrite_presmodule->addhiddendata("action", "compile");
1357                         $main::kiriwrite_presmodule->addhiddendata("type", "multiple");
1359                         $database_count = 0;
1361                         # Write out the list of databases to compile.
1363                         foreach $database (keys %database_list){
1365                                 $database_count++;
1367                                 $main::kiriwrite_presmodule->addhiddendata("id[" . $database_count . "]", $database_list{$database}{Filename});
1368                                 $main::kiriwrite_presmodule->addhiddendata("name[" . $database_count . "]", "on");
1370                         }
1372                         $main::kiriwrite_presmodule->addhiddendata("count", $database_count);
1373                         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{selectoutputmodule});
1374                         $main::kiriwrite_presmodule->addselectbox("outputmodule");
1376                         # Process the output modules found.
1378                         foreach $outputmoduleslist_name (@outputmoduleslist){
1380                                 # Print each option and check if the module name is the selected module.
1382                                 if ($outputmodule eq $outputmoduleslist_name){
1384                                         $main::kiriwrite_presmodule->addoption($outputmoduleslist_name, { Value => $outputmoduleslist_name, Selected => 1 });
1386                                 } else {
1388                                         $main::kiriwrite_presmodule->addoption($outputmoduleslist_name, { Value => $outputmoduleslist_name });
1390                                 }
1392                         }
1394                         $main::kiriwrite_presmodule->endselectbox();
1395                         $main::kiriwrite_presmodule->addtext(" | ");
1396                         $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{compile}{selectbutton});
1397                         $main::kiriwrite_presmodule->endform();
1399                         $main::kiriwrite_presmodule->addlinebreak();
1401                         $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1402                         $main::kiriwrite_presmodule->startbox();
1403                         $main::kiriwrite_presmodule->addhiddendata("mode", "compile");
1404                         $main::kiriwrite_presmodule->addhiddendata("action", "compile");
1405                         $main::kiriwrite_presmodule->addhiddendata("type", "multiple");
1406                         $main::kiriwrite_presmodule->addhiddendata("count", $database_count);
1407                         $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
1408                         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{compileselecteddatabasesmessage});
1409                         $main::kiriwrite_presmodule->addlinebreak();
1410                         $main::kiriwrite_presmodule->addlinebreak();
1411                         $main::kiriwrite_presmodule->startbox("datalist");
1413                         $database_count = 0;
1415                         # Write out the list of databases to compile.
1417                         foreach $database (keys %database_list){
1419                                 $database_count++;
1421                                 $main::kiriwrite_presmodule->addhiddendata("id[" . $database_count . "]", $database_list{$database}{Filename});
1422                                 $main::kiriwrite_presmodule->addhiddendata("name[" . $database_count . "]", "on");
1424                                 # Check if the database name is undefined and if it is
1425                                 # then write a message saying the database name is blank.
1427                                 if (!$database_list{$database}{Name}){
1428                                         $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{compile}{blankdatabasename});
1429                                 } else {
1430                                         $main::kiriwrite_presmodule->addtext($database_list{$database}{Name});
1431                                 }
1433                                 $main::kiriwrite_presmodule->addlinebreak();
1435                         }
1437                         $main::kiriwrite_presmodule->endbox();
1439                         $main::kiriwrite_presmodule->addlinebreak();
1441                         $main::kiriwrite_dbmodule->connecttemplate();
1443                         # Check if any errors occured while connecting to the
1444                         # template database.
1446                         if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
1448                                 # The template database does not exist so skip processing
1449                                 # the list of templates in the template database.
1451                                 $templateoverride_skip = 1;
1452                                 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedbmissing};
1454                         } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
1456                                 # The template database has invalid permissions set so
1457                                 # skip processing the list of templates in the
1458                                 # template database.
1460                                 $templateoverride_skip = 1;
1461                                 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedbinvalidpermissions};
1463                         }
1465                         # Get the list of available templates if no errors had
1466                         # occured.
1468                         if ($templateoverride_skip ne 1){
1470                                 @template_list = $main::kiriwrite_dbmodule->gettemplatelist();
1472                                 # Check if any errors occured while getting the list of templates.
1474                                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1476                                         # A template database error has occured so skip processing the
1477                                         # list of templates in the template database.
1479                                         $templateoverride_skip = 1;
1480                                         $templatedbwarning = $main::kiriwrite_lang{compile}{templatedberror};
1482                                 }
1484                                 if ($templateoverride_skip ne 1){
1486                                         foreach $template_file (@template_list){
1488                                                 %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_file });
1489                                                 
1490                                                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
1492                                                         next;
1494                                                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1496                                                         next;
1498                                                 }
1500                                                 $template_dblist{$template_file} = $template_info{"TemplateName"};
1502                                         }
1504                                 }
1506                         }
1508                         if ($templateoverride_skip eq 1){
1510                                 # Add message saying why template can't be overridden.
1511                                 $main::kiriwrite_presmodule->addtext($templatedbwarning);
1513                         } else {
1515                                 # Add overwrite template data.
1516                                 $main::kiriwrite_presmodule->addcheckbox("enableoverride", { OptionDescription => $main::kiriwrite_lang{compile}{overridetemplate}, LineBreak => 1 });
1517                                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{replacecurrenttemplate});
1518                                 $main::kiriwrite_presmodule->addselectbox("overridetemplate");
1520                                 foreach $template_file (keys %template_dblist){
1522                                         $main::kiriwrite_presmodule->addoption($template_dblist{$template_file} . " (" . $template_file . ")", { Value => $template_file });
1524                                 }
1526                                 $main::kiriwrite_presmodule->addoption($main::kiriwrite_lang{compile}{dontusetemplate}, { Value => "!none" });
1527                                 $main::kiriwrite_presmodule->endselectbox();
1529                         }
1531                         # Disconnect from the template database and database server.
1533                         $main::kiriwrite_dbmodule->disconnecttemplate();
1534                         $main::kiriwrite_dbmodule->disconnect();
1536                         # Print out the list of options for the output module.
1538                         $main::kiriwrite_presmodule->addlinebreak();
1539                         $main::kiriwrite_presmodule->addlinebreak();
1540                         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{outputmodulesettings}, { Style => "smallpageheader" });
1541                         $main::kiriwrite_presmodule->addlinebreak();
1543                         foreach $option_name (keys %outputmodule_options){
1545                                 $main::kiriwrite_presmodule->addlinebreak();
1547                                 # Check if the option is a checkbox option.
1549                                 if ($outputmodule_options{$option_name}{type} eq "checkbox"){
1551                                         $main::kiriwrite_presmodule->addcheckbox("outputmodule_" . $option_name, { OptionDescription => $outputmodule_options{$option_name}{string} });
1553                                 }
1555                                 # Check if the option is a string option.
1557                                 if ($outputmodule_options{$option_name}{type} eq "string"){
1559                                         if (!$outputmodule_options{$option_name}{password}){
1560                                                 $outputmodule_options{$option_name}{password} = 0;
1561                                         }
1563                                         $main::kiriwrite_presmodule->addtext($outputmodule_options{$option_name}{string} . " ");
1564                                         $main::kiriwrite_presmodule->addinputbox("outputmodule_" . $option_name, { Size => $outputmodule_options{$option_name}{size}, MaxLength => $outputmodule_options->{$option_name}{maxlength}, Value => $outputmodule_options{$option_name}{value}, Password => $outputmodule_options{$option_name}{password} });
1566                                 }
1568                                 # Check if the option is a combobox option.
1570                                 if ($outputmodule_options{$option_name}{type} eq "combobox"){
1572                                         $combobox_count         = 0;
1574                                         @outputmodule_comboboxnames = split(/\|/, $outputmodule_options{$option_name}{optionnames});
1575                                         @outputmodule_comboboxvalues = split(/\|/, $outputmodule_options{$option_name}{optionvalues});
1577                                         $main::kiriwrite_presmodule->addtext($outputmodule_options{$option_name}{string} . " ");
1578                                         $main::kiriwrite_presmodule->addselectbox("outputmodule_" . $option_name);
1580                                         foreach $outputmodule_comboboxname (@outputmodule_comboboxnames){
1582                                                 $main::kiriwrite_presmodule->addoption($outputmodule_comboboxname, { Value => $outputmodule_comboboxvalues[$combobox_count] });
1583                                                 $combobox_count++;
1585                                         }
1587                                         $main::kiriwrite_presmodule->endselectbox;
1589                                 }
1591                                 # Check if the option is a radio option.
1593                                 if ($outputmodule_options{$option_name}{type} eq "radio"){
1595                                         # Check if the selected value is blank and if it is then
1596                                         # set it to 0.
1598                                         if (!$outputmodule_options{$option_name}{selected}){
1599                                                 $outputmodule_selected = 0;
1600                                         } else {
1601                                                 $outputmodule_selected = 1;
1602                                         }
1604                                         $main::kiriwrite_presmodule->addradiobox("outputmodule_" . $outputmodule_options{$option_name}{name}, { Description => $outputmodule_options{$option_name}{string}, Value => $outputmodule_options{$option_name}{value}, Selected => $outputmodule_selected });
1606                                 }
1608                         }
1611                         $main::kiriwrite_presmodule->addlinebreak();
1612                         $main::kiriwrite_presmodule->addlinebreak();
1613                         $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{compile}{compileselecteddatabasesbutton});
1614                         $main::kiriwrite_presmodule->addtext(" | ");
1615                         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $main::kiriwrite_lang{compile}{returncompilelist} });
1616                         $main::kiriwrite_presmodule->endbox();
1617                         $main::kiriwrite_presmodule->endform();
1619                         return $main::kiriwrite_presmodule->grab();
1621                 } else {
1623                         # The type is something else other than
1624                         # single or multiple, so return an error.
1626                         kiriwrite_error("invalidvariable");
1628                 }
1630         } else {
1632                 # The confirm value is neither 0 or 1, so
1633                 # return an error.
1635                 kiriwrite_error("invalidvariable");
1637         }
1641 sub kiriwrite_compile_all{
1642 #################################################################################
1643 # kiriwrite_compile_all: Compile all of the databases in the database           #
1644 # directory.                                                                    #
1645 #                                                                               #
1646 # Usage:                                                                        #
1647 #                                                                               #
1648 # kiriwrite_compile_all(outputmodule);                                          #
1649 #                                                                               #
1650 # outputmodule          Specifies the output module to use.                     #
1651 #################################################################################
1653         # Get the parameters passed to this subroutine.
1655         my $outputmodule = shift;
1657         if (!$outputmodule){
1658                 $outputmodule = $main::kiriwrite_config{'system_outputmodule'};
1659         }
1661         # Check if the output module name is valid.
1663         my $outputmodule_maxlength_check = kiriwrite_variablecheck($outputmodule, "maxlength", 64, 1);
1665         if ($outputmodule_maxlength_check eq 1){
1667                 # The length of the output module name is too
1668                 # long so return an error.
1670                 kiriwrite_error("outputmodulenametoolong");
1672         }
1674         my $outputmodule_filename_check = kiriwrite_variablecheck($outputmodule, "filename", "", 1);
1676         if ($outputmodule_maxlength_check eq 1){
1678                 # The length of the output module name is too
1679                 # long so return an error.
1681                 kiriwrite_error("outputmodulenameinvalid");
1683         }
1685         # Set up the output module.
1687         ($outputmodule) = $outputmodule =~ m/^(.*)$/g;
1688         my $outputmodulename = "Modules::Output::" . $outputmodule;
1689         eval "use " . $outputmodulename;
1690         my $kiriwrite_outputmodule = $outputmodulename->new();
1691         my ($outputmodule_options, %outputmodule_options);
1692         tie(%outputmodule_options, "Tie::IxHash");
1693         $kiriwrite_outputmodule->initialise();
1694         %outputmodule_options = $kiriwrite_outputmodule->getoptions();
1695         my @outputmodule_comboboxnames;
1696         my @outputmodule_comboboxvalues;
1697         my $outputmodule_comboboxname;
1698         my $outputmodule_comboboxvalue;
1699         my $outputmodule_selected       = 0;
1700         my $combobox_count              = 0;
1701         my $outputmoduleslist_name;
1702         my $option_name;
1704         # Connect to the database server.
1706         $main::kiriwrite_dbmodule->connect();
1708         # Check if any errors occured while connecting to the database server.
1710         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1712                 # A database connection error has occured so return
1713                 # an error.
1715                 kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
1717         }
1719         my @outputmoduleslist = kiriwrite_compile_getoutputmodules;
1721         # Get the list of available databases.
1723         my @database_list = $main::kiriwrite_dbmodule->getdblist();
1725         # Check if any errors occured while getting the databases.
1727         if ($main::kiriwrite_dbmodule->geterror eq "DataDirMissing"){
1729                 # The database directory is missing so return an error.
1731                 kiriwrite_error("datadirectorymissing");
1733         } elsif ($main::kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){
1735                 # The database directory has invalid permissions set so return
1736                 # an error.
1738                 kiriwrite_error("datadirectoryinvalidpermissions");
1740         }
1742         # Define some variables for later.
1744         my $database;
1745         my $database_name_filename_check;
1746         my $database_count              = 0;
1748         # Check the list of databases to compile to see if it is blank,
1749         # if it is then return an error.
1751         if (!@database_list){
1753                 # The list of database is blank so return an error.
1755                 kiriwrite_error("nodatabasesavailable");
1757         }
1759         # Write out a form for confirming the action to compile all of the databases.
1761         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{compilealldatabases}, { Style => "pageheader" });
1762         $main::kiriwrite_presmodule->addlinebreak();
1763         $main::kiriwrite_presmodule->addlinebreak();
1765         $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1766         $main::kiriwrite_presmodule->addhiddendata("mode", "compile");
1767         $main::kiriwrite_presmodule->addhiddendata("action", "all");
1768         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{selectoutputmodule});
1769         $main::kiriwrite_presmodule->addselectbox("outputmodule");
1771         # Process the output modules found.
1773         foreach $outputmoduleslist_name (@outputmoduleslist){
1775                 # Print each option and check if the module name is the selected module.
1777                 if ($outputmodule eq $outputmoduleslist_name){
1779                         $main::kiriwrite_presmodule->addoption($outputmoduleslist_name, { Value => $outputmoduleslist_name, Selected => 1 });
1781                 } else {
1783                         $main::kiriwrite_presmodule->addoption($outputmoduleslist_name, { Value => $outputmoduleslist_name });
1785                 }
1787         }
1789         $main::kiriwrite_presmodule->endselectbox();
1790         $main::kiriwrite_presmodule->addtext(" | ");
1791         $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{compile}{selectbutton});
1792         $main::kiriwrite_presmodule->endform();
1794         $main::kiriwrite_presmodule->addlinebreak();
1796         $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1797         $main::kiriwrite_presmodule->addhiddendata("mode", "compile");
1798         $main::kiriwrite_presmodule->addhiddendata("action", "compile");
1799         $main::kiriwrite_presmodule->addhiddendata("type", "multiple");
1800         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{compilealldatabasesmessage});
1801         $main::kiriwrite_presmodule->addlinebreak();
1802         $main::kiriwrite_presmodule->addlinebreak();
1804         foreach $database (@database_list){
1806                 # Check if the database filename is blank.
1808                 if ($database eq ""){
1810                         # The database filename is blank so process
1811                         # the next database.
1813                         next;
1815                 }
1817                 # Check if the database filename is valid before
1818                 # using the database.
1820                 $database_name_filename_check   = kiriwrite_variablecheck($database, "filename", 0, 1);
1822                 if ($database_name_filename_check ne 0){
1824                         # The database filename is invalid so process
1825                         # the next database.
1827                         next;
1829                 }
1831                 $database_count++;
1832                 $main::kiriwrite_presmodule->addhiddendata("id[" . $database_count . "]", $database);
1833                 $main::kiriwrite_presmodule->addhiddendata("name[" . $database_count . "]", "on");
1835         }
1837         $main::kiriwrite_presmodule->addhiddendata("count", $database_count);
1839         my $templateoverride_skip       = 0;
1840         my $templatedbwarning           = "";
1841         my @template_list;
1842         my $template_filename;
1843         my %template_info;
1844         my %template_dblist;
1845         my $template_file;
1846         tie(%template_dblist, "Tie::IxHash");
1848         $main::kiriwrite_dbmodule->connecttemplate();
1850         # Check if any errors occured while connecting to the
1851         # template database.
1853         if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
1855                 # The template database does not exist so skip processing
1856                 # the list of templates in the template database.
1858                 $templateoverride_skip = 1;
1859                 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedbmissing};
1861         } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
1863                 # The template database has invalid permissions set so
1864                 # skip processing the list of templates in the
1865                 # template database.
1867                 $templateoverride_skip = 1;
1868                 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedbinvalidpermissions};
1870         }
1872         # Get the list of available templates if no errors had
1873         # occured.
1875         if ($templateoverride_skip ne 1){
1877                 @template_list = $main::kiriwrite_dbmodule->gettemplatelist();
1879                 # Check if any errors occured while getting the list of templates.
1881                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1883                         # A template database error has occured so skip processing the
1884                         # list of templates in the template database.
1886                         $templateoverride_skip = 1;
1887                         $templatedbwarning = $main::kiriwrite_lang{compile}{templatedberror};
1889                 }
1891                 if ($templateoverride_skip ne 1){
1893                         foreach $template_file (@template_list){
1895                                 %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_file });
1896                                 
1897                                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
1899                                         next;
1901                                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1903                                         next;
1905                                 }
1907                                 $template_dblist{$template_file} = $template_info{"TemplateName"};
1909                         }
1911                 }
1913         }
1915         if ($templateoverride_skip eq 1){
1917                 # Add message saying why template can't be overridden.
1918                 $main::kiriwrite_presmodule->addtext($templatedbwarning);
1920         } else {
1922                 # Add overwrite template data.
1923                 $main::kiriwrite_presmodule->addcheckbox("enableoverride", { OptionDescription => $main::kiriwrite_lang{compile}{overridetemplate}, LineBreak => 1 });
1924                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{replacecurrenttemplate} . " ");
1925                 $main::kiriwrite_presmodule->addselectbox("overridetemplate");
1927                 foreach $template_file (keys %template_dblist){
1929                         $main::kiriwrite_presmodule->addoption($template_dblist{$template_file} . " (" . $template_file . ")", { Value => $template_file });
1931                 }
1933                 $main::kiriwrite_presmodule->addoption($main::kiriwrite_lang{compile}{dontusetemplate}, { Value => "!none" });
1934                 $main::kiriwrite_presmodule->endselectbox();
1936         }
1938         # Disconnect from the template database and database server.
1940         $main::kiriwrite_dbmodule->disconnecttemplate();
1941         $main::kiriwrite_dbmodule->disconnect();
1943         # Print out the list of options for the output module.
1945         $main::kiriwrite_presmodule->addlinebreak();
1946         $main::kiriwrite_presmodule->addlinebreak();
1947         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{outputmodulesettings}, { Style => "smallpageheader" });
1948         $main::kiriwrite_presmodule->addlinebreak();
1950         foreach $option_name (keys %outputmodule_options){
1952                 $main::kiriwrite_presmodule->addlinebreak();
1954                 # Check if the option is a checkbox option.
1956                 if ($outputmodule_options{$option_name}{type} eq "checkbox"){
1958                         $main::kiriwrite_presmodule->addcheckbox("outputmodule_" . $option_name, { OptionDescription => $outputmodule_options{$option_name}{string} });
1960                 }
1962                 # Check if the option is a string option.
1964                 if ($outputmodule_options{$option_name}{type} eq "string"){
1966                         if (!$outputmodule_options{$option_name}{password}){
1967                                 $outputmodule_options{$option_name}{password} = 0;
1968                         }
1970                         $main::kiriwrite_presmodule->addtext($outputmodule_options{$option_name}{string} . " ");
1971                         $main::kiriwrite_presmodule->addinputbox("outputmodule_" . $option_name, { Size => $outputmodule_options{$option_name}{size}, MaxLength => $outputmodule_options->{$option_name}{maxlength}, Value => $outputmodule_options{$option_name}{value}, Password => $outputmodule_options{$option_name}{password} });
1973                 }
1975                 # Check if the option is a combobox option.
1977                 if ($outputmodule_options{$option_name}{type} eq "combobox"){
1979                         $combobox_count         = 0;
1981                         @outputmodule_comboboxnames = split(/\|/, $outputmodule_options{$option_name}{optionnames});
1982                         @outputmodule_comboboxvalues = split(/\|/, $outputmodule_options{$option_name}{optionvalues});
1984                         $main::kiriwrite_presmodule->addtext($outputmodule_options{$option_name}{string} . " ");
1985                         $main::kiriwrite_presmodule->addselectbox("outputmodule_" . $option_name);
1987                         foreach $outputmodule_comboboxname (@outputmodule_comboboxnames){
1989                                 $main::kiriwrite_presmodule->addoption($outputmodule_comboboxname, { Value => $outputmodule_comboboxvalues[$combobox_count] });
1990                                 $combobox_count++;
1992                         }
1994                         $main::kiriwrite_presmodule->endselectbox;
1996                 }
1998                 # Check if the option is a radio option.
2000                 if ($outputmodule_options{$option_name}{type} eq "radio"){
2002                         # Check if the selected value is blank and if it is then
2003                         # set it to 0.
2005                         if (!$outputmodule_options{$option_name}{selected}){
2006                                 $outputmodule_selected = 0;
2007                         } else {
2008                                 $outputmodule_selected = 1;
2009                         }
2011                         $main::kiriwrite_presmodule->addradiobox("outputmodule_" . $outputmodule_options{$option_name}{name}, { Description => $outputmodule_options{$option_name}{string}, Value => $outputmodule_options{$option_name}{value}, Selected => $outputmodule_selected });
2013                 }
2015         }
2017         $main::kiriwrite_presmodule->addlinebreak;
2018         $main::kiriwrite_presmodule->addlinebreak;
2020         $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
2021         $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{compile}{compilealldatabasesbutton});
2022         $main::kiriwrite_presmodule->addtext(" | ");
2023         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $main::kiriwrite_lang{compile}{returncompilelist} });
2024         $main::kiriwrite_presmodule->endform();
2026         return $main::kiriwrite_presmodule->grab();
2031 sub kiriwrite_compile_list{
2032 #################################################################################
2033 # kiriwrite_compile_list: Shows a list of databases that can be compiled.       #
2034 #                                                                               #
2035 # Usage:                                                                        #
2036 #                                                                               #
2037 # kiriwrite_compile_list();                                                     #
2038 #################################################################################
2040         # Define the following variables that are going to be used before using 
2041         # the foreach function.
2043         my %database_info;
2044         my %database_list;
2045         my $database_count = 0;
2046         my $database_filename = "";
2047         my $database_filename_friendly = "";
2048         my $database_permissions = "";
2049         my $database_name = "";
2050         my $database_description = "";
2051         my $data_file = "";
2052         my @permissions_list;
2053         my @error_list;
2054         my $table_style = 0;
2055         my $table_style_name = "";
2056         my $database;
2058         tie(%database_list, 'Tie::IxHash');
2060         # Connect to the database server.
2062         $main::kiriwrite_dbmodule->connect();
2064         # Check if any errors occured while connecting to the database server.
2066         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
2068                 # A database connection error has occured so return
2069                 # an error.
2071                 kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
2073         }
2075         # Get the list of available databases and process any errors that
2076         # might have occured.
2078         my @database_list = $main::kiriwrite_dbmodule->getdblist();
2080         if ($main::kiriwrite_dbmodule->geterror eq "DataDirMissing"){
2082                 # The database directory is missing so return an error.
2084                 kiriwrite_error("datadirectorymissing");
2086         } elsif ($main::kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){
2088                 # The database directory has invalid permissions set so return
2089                 # an error.
2091                 kiriwrite_error("datadirectoryinvalidpermissions");
2093         }
2095         # Begin creating the table for the list of databases.
2097         foreach $data_file (@database_list){
2099                 # Select the database.
2101                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $data_file });
2103                 # Check if any error occured while selecting the database.
2105                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
2107                         # The database does not exist, so process the next
2108                         # database.
2110                         next;
2112                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet") {
2114                         # The database has invalid permissions settings, so
2115                         # add the database to the list of databases with
2116                         # invalid permissions set and process the next
2117                         # database.
2119                         push(@permissions_list, $data_file);
2120                         next;
2122                 }
2124                 # Get information about the database.
2126                 %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
2128                 # Check if any error occured while getting information from the
2129                 # database.
2131                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
2133                         # A database error has occured, add the database and specific
2134                         # error message to the list of databases with errors and
2135                         # process the next database.
2137                         push(@error_list, $data_file . ": " . $main::kiriwrite_dbmodule->geterror(1));
2138                         next;
2140                 }
2142                 $database_name          = $database_info{"DatabaseName"};
2143                 $database_description   = $database_info{"Description"};
2145                 # Create a friendly name for the database.
2147                 $database_filename_friendly = $data_file;
2149                 # Append the database information to the table.
2151                 $database_list{$database_count}{Filename}       = $database_filename_friendly;
2152                 $database_list{$database_count}{Name}           = $database_name;
2153                 $database_list{$database_count}{Description}    = $database_description;
2155                 $database_count++;
2157         }
2159         # Check if there are no valid databases are if there is no
2160         # valid databases then write a message saying that no
2161         # valid databases are available.
2163         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{compilepages}, { Style => "pageheader" });
2164         $main::kiriwrite_presmodule->addlinebreak();
2165         $main::kiriwrite_presmodule->addlinebreak();
2167         if ($database_count eq 0){
2169                 # There are no databases available for compiling so
2170                 # write a message instead.
2172                 $main::kiriwrite_presmodule->startbox("errorbox");
2173                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{nodatabasesavailable});
2174                 $main::kiriwrite_presmodule->endbox();
2176         } else {
2178                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
2179                 $main::kiriwrite_presmodule->startbox();
2180                 $main::kiriwrite_presmodule->addhiddendata("mode", "compile");
2181                 $main::kiriwrite_presmodule->addhiddendata("action", "compile");
2182                 $main::kiriwrite_presmodule->addhiddendata("type", "multiple");
2184                 $main::kiriwrite_presmodule->addreset($main::kiriwrite_lang{common}{selectnone});
2185                 $main::kiriwrite_presmodule->addtext(" | ");
2186                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{compile}{compileselectedbutton});
2187                 $main::kiriwrite_presmodule->addlinebreak();
2188                 $main::kiriwrite_presmodule->addlinebreak();
2189                 $main::kiriwrite_presmodule->addhiddendata("count", $database_count);
2190                 $main::kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
2192                 $main::kiriwrite_presmodule->startheader();
2193                 $main::kiriwrite_presmodule->addheader("", { Style => "tablecellheader" });
2194                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{database}{databasename}, { Style => "tablecellheader" });
2195                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{database}{databasedescription}, { Style => "tablecellheader" });
2196                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{options}, { Style => "tablecellheader" });
2197                 $main::kiriwrite_presmodule->endheader();
2199                 $database_count = 1;
2201                 foreach $database (keys %database_list){
2203                         # Check the style to be used with.
2205                         if ($table_style eq 0){
2207                                 # Use the first style and set the style value
2208                                 # to use the next style, the next time the
2209                                 # if statement is checked.
2211                                 $table_style_name = "tablecell1";
2212                                 $table_style = 1;
2214                         } else {
2216                                 # Use the second style and set the style
2217                                 # value to use the first style, the next
2218                                 # time if statement is checked.
2220                                 $table_style_name = "tablecell2";
2221                                 $table_style = 0;
2222                         }
2224                         # Add the template to the list of available
2225                         # templates to compile.
2227                         $main::kiriwrite_presmodule->startrow();
2228                         $main::kiriwrite_presmodule->addcell($table_style_name);
2229                         $main::kiriwrite_presmodule->addhiddendata("id[" . $database_count . "]", $database_list{$database}{Filename});
2230                         $main::kiriwrite_presmodule->addcheckbox("name[" . $database_count . "]");
2231                         $main::kiriwrite_presmodule->endcell();
2232                         $main::kiriwrite_presmodule->addcell($table_style_name);
2234                         if (!$database_list{$database}{Name}){
2235                                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=compile&action=compile&type=single&database=" . $database_list{$database}{Filename}, { Text => $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{noname}) });
2236                         } else {
2237                                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database_list{$database}{Filename}, { Text => $database_list{$database}{Name} });
2238                         }
2240                         $main::kiriwrite_presmodule->endcell();
2241                         $main::kiriwrite_presmodule->addcell($table_style_name);
2243                         if (!$database_list{$database}{Description}){
2244                                 $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{nodescription});
2245                         } else {
2246                                 $main::kiriwrite_presmodule->addtext($database_list{$database}{Description});
2247                         }
2249                         $main::kiriwrite_presmodule->endcell();
2250                         $main::kiriwrite_presmodule->addcell($table_style_name);
2251                         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=compile&action=compile&type=single&database=" . $database_list{$database}{Filename}, { Text => $main::kiriwrite_lang{options}{compile} });
2252                         $main::kiriwrite_presmodule->endcell();
2253                         $main::kiriwrite_presmodule->endrow();
2255                         $database_count++;
2257                 }
2259                 $main::kiriwrite_presmodule->endtable();
2260                 $main::kiriwrite_presmodule->endbox();
2261                 $main::kiriwrite_presmodule->endform();
2263         }
2265         # Disconnect from the database server.
2267         $main::kiriwrite_dbmodule->disconnect();
2269         # Check if any databases with problems have appeared and if they
2270         # have, print out a message saying which databases have problems.
2272         if (@permissions_list){
2274                 $main::kiriwrite_presmodule->addlinebreak();
2276                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databaseinvalidpermissions}, { Style => "smallpageheader" });
2277                 $main::kiriwrite_presmodule->addlinebreak();
2278                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databaseinvalidpermissionstext});
2279                 $main::kiriwrite_presmodule->addlinebreak();
2280  
2281                 foreach $database (@permissions_list){
2282  
2283                         $main::kiriwrite_presmodule->addlinebreak();
2284                         $main::kiriwrite_presmodule->addtext($database);
2285  
2286                 }
2288                 $main::kiriwrite_presmodule->addlinebreak();
2289  
2290         }
2292         if (@error_list){
2294                 $main::kiriwrite_presmodule->addlinebreak();
2296                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databaseerrors}, { Style => "smallpageheader" });
2297                 $main::kiriwrite_presmodule->addlinebreak();
2298                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databaseerrorstext});
2299                 $main::kiriwrite_presmodule->addlinebreak();
2301                 foreach $database (@error_list){
2303                         $main::kiriwrite_presmodule->addlinebreak();
2304                         $main::kiriwrite_presmodule->addtext($database);
2306                 }
2308         }
2310         return $main::kiriwrite_presmodule->grab();
2314 sub kiriwrite_compile_clean{
2315 #################################################################################
2316 # kiriwrite_compile_clean: Deletes the contents of the output directory.        #
2317 #                                                                               #
2318 # Usage:                                                                        #
2319 #                                                                               #
2320 # kiriwrite_compile_clean(confirm);                                             #
2321 #                                                                               #
2322 # confirm       Confirms the deletion of files from the output directory.       #
2323 #################################################################################
2325         # Get the values passed to the subroutine.
2327         my ($confirm) = @_;
2329         # Define some variables for later.
2331         my $file_permissions;
2332         my $output_directory_exists;
2333         my $output_directory_permissions;
2334         my $warning_message;
2336         # Check if the output directory exists.
2338         $output_directory_exists         = kiriwrite_fileexists($main::kiriwrite_config{"directory_data_output"});
2340         if ($output_directory_exists eq 1){
2342                 # The output directory does not exist so return
2343                 # an error.
2345                 kiriwrite_error("outputdirectorymissing");
2347         }
2349         # Check if the output directory has invalid
2350         # permissions set.
2352         $output_directory_permissions   = kiriwrite_filepermissions($main::kiriwrite_config{"directory_data_output"});
2354         if ($output_directory_permissions eq 1){
2356                 # The output directory has invalid permissions
2357                 # set, so return an error.
2359                 kiriwrite_error("outputdirectoryinvalidpermissions");
2361         }
2363         if ($confirm) {
2365                 if ($confirm eq 1){
2367                         # The action to clean the output directory has been
2368                         # confirmed.
2370                         # Remove the list of files and directories from the
2371                         # output directory.
2373                         $file_permissions = kiriwrite_compile_clean_helper($main::kiriwrite_config{"directory_data_output"}, 1);
2375                         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{cleanoutputdirectory}, { Style => "pageheader" });
2377                         if ($file_permissions eq 1){
2379                                 $main::kiriwrite_presmodule->addlinebreak();
2380                                 $main::kiriwrite_presmodule->addlinebreak();
2381                                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{somecontentnotremoved});
2382                                 $main::kiriwrite_presmodule->addlinebreak();
2383                                 $main::kiriwrite_presmodule->addlinebreak();
2385                         } else {
2387                                 $main::kiriwrite_presmodule->addlinebreak();
2388                                 $main::kiriwrite_presmodule->addlinebreak();
2389                                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{contentremoved});
2390                                 $main::kiriwrite_presmodule->addlinebreak();
2391                                 $main::kiriwrite_presmodule->addlinebreak();
2393                         }
2395                         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $main::kiriwrite_lang{compile}{returncompilelist} });
2397                         return $main::kiriwrite_presmodule->grab();
2399                 } else {
2401                         # A value other than 1 is set for the confirm value
2402                         # (which it shouldn't be) so return an error.
2404                         kiriwrite_error("invalidvariable");
2406                 }
2408         }
2410         # Print out a form for cleaning the output directory.
2412         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{cleanoutputdirectory}, { Style => "pageheader" });
2413         $main::kiriwrite_presmodule->addlinebreak();
2414         $main::kiriwrite_presmodule->addlinebreak();
2415         $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
2416         $main::kiriwrite_presmodule->startbox();
2417         $main::kiriwrite_presmodule->addhiddendata("mode", "compile");
2418         $main::kiriwrite_presmodule->addhiddendata("action", "clean");
2419         $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
2420         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{cleanoutputdirectorymessage});
2421         $main::kiriwrite_presmodule->addlinebreak();
2422         $main::kiriwrite_presmodule->addlinebreak();
2423         $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{compile}{cleanoutputdirectorybutton});
2424         $main::kiriwrite_presmodule->addtext(" | ");
2425         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $main::kiriwrite_lang{compile}{returncompilelist}});
2426         $main::kiriwrite_presmodule->endbox();
2427         $main::kiriwrite_presmodule->endform();
2429         return $main::kiriwrite_presmodule->grab();
2433 sub kiriwrite_compile_clean_helper{
2434 #################################################################################
2435 # kiriwrite_compile_clean_helper: Helper for cleaning out the output directory. #
2436 # This command sometimes is called recursively (when a directory is found).     #
2437 #                                                                               #
2438 # Usage:                                                                        #
2439 #                                                                               #
2440 # kiriwrite_compile_clean_helper(directory, removedirectory, [permissions]);    #
2441 #                                                                               #
2442 # directory             Specifies the directory to remove files (and            #
2443 #                       sub-directories) from.                                  #
2444 # keepdirectory         Keeps the directory itself after all files have been    #
2445 #                       removed.                                                #
2446 # permissions           Used recursively for error checking.                    #
2447 #################################################################################
2449         # Get the values passed to the subroutine.
2451         my ($directory, $directory_keep, $permissions) = @_;
2453         # Check if the directory_keep is only one charater long.
2455         my $directory_file = "";
2456         my @directory_list;
2457         my $file_permissions = 0;
2458         my $debug = 0;
2460         # Check if the file permissions value is blank.
2462         if (!$permissions){
2464                 # The file permissions value is blank.
2466                 $permissions = 0;
2468         }
2470         # Open the directory specified, read the contents of
2471         # the directory and then close the directory.
2473         opendir(DIRECTORY, $directory);
2474         @directory_list = readdir(DIRECTORY);
2475         closedir(DIRECTORY);
2477         # Remove each file and directory.
2479         foreach $directory_file (@directory_list){
2481                 # Check if the filename is '.' or '..' and if it
2482                 # is skip those files.
2484                 if ($directory_file eq "." || $directory_file eq ".."){
2486                         # The filename is '.' or '..' so skip processing
2487                         # these files.
2489                 } else {
2491                         # Check if the permissions on the file or directory has
2492                         # valid permissions set.
2494                         $file_permissions = kiriwrite_filepermissions($directory . '/' . $directory_file, 1, 1);
2496                         if ($file_permissions eq 1){
2498                                 # The file or directory has invalid permissions set.
2500                                 $permissions = 1;
2501                                 next;
2503                         }
2505                         # Check if the filename is a directory.
2507                         if (-d $directory . '/' . $directory_file){
2509                                 # The filename is a directory so send the directory name
2510                                 # and this subroutine again (recursively).
2512                                 kiriwrite_compile_clean_helper($directory . '/' . $directory_file, 0, $permissions);
2514                         } else {
2516                                 # The file is not a directory but an actual file so
2517                                 # remove as normal (in terms of the Perl language).
2519                                 ($directory) = $directory =~ m/^(.*)$/g;
2520                                 ($directory_file) = $directory_file =~ m/^(.*)$/g;
2522                                 # Check if the directory is undefined and if it is then
2523                                 # set it to blank.
2525                                 if (!$directory){
2526                                         $directory = "";
2527                                 }
2529                                 if (!$directory_file){
2530                                         $directory_file = "";
2531                                 }
2533                                 unlink($directory . '/' . $directory_file);
2535                         }
2537                 }
2539         }
2541         # Check if the directory should be kept.
2543         if ($directory_keep eq 1){
2545                 # The directory_keep value is set as 1 so the directory
2546                 # specified should be kept.
2548         } elsif ($directory_keep eq 0) {
2550                 # The directory_keep value is set as 0 so remove the
2551                 # directory specified.
2553                 ($directory) = $directory =~ m/^(.*)$/g;
2554                 rmdir($directory);
2556         } else {
2558                 # A value other than 0 or 1 was specified so return
2559                 # an error,
2561                 kiriwrite_error('invalidvalue');
2563         }
2565         return $permissions;
2569 sub kiriwrite_compile_loadhash{
2570 #################################################################################
2571 # kiriwrite_compile_loadhash: Loads the hash used for the Output Module.        #
2572 #                                                                               #
2573 # Usage:                                                                        #
2574 #                                                                               #
2575 # kiriwrite_compile_loadhash(hash);                                             #
2576 #                                                                               #
2577 # hash          The hash to be passed on for the output moudle.                 #
2578 #################################################################################
2580         my (%passedhash) = @_;
2582         %formdata = %passedhash;
2586 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