1 package Modules::System::Compile;
3 use Modules::System::Common;
8 our @ISA = qw(Exporter);
9 our @EXPORT = qw(kiriwrite_compile_makepages kiriwrite_compile_all kiriwrite_compile_list kiriwrite_compile_clean kiriwrite_compile_clean_helper);
11 sub kiriwrite_compile_makepages{
12 #################################################################################
13 # kiriwrite_compile_makepages: Compile the selected pages and place them in the #
14 # specified output directory. #
18 # kiriwrite_compile_makepages(type, selectedlist, override, overridetemplate, #
21 # type Specifies if single or multiple databases are to be #
23 # confirm Specifies if the action to compile the databases should #
25 # override Specifies if the template should be overriden. #
26 # overridetemplate Specifies the name of the template to override with. #
27 # selectedlist Specifies the databases to compile from as an array. #
28 #################################################################################
30 # Get the values that have been passed to the subroutine.
32 my ($type, $confirm, $override, $override_template, @selectedlist) = @_;
34 # Check if the confirm value is more than one
37 kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
39 # Check if the value for enabling the override feature
40 # is "on" or blank and if it is something else then
49 if ($override eq "on"){
50 } elsif (!$override || $override eq "off"){
53 # The override value is invalid so return an error.
55 kiriwrite_error("overridetemplatevalueinvalid");
59 # Check if the override template filename is valid and
60 # return an error if it isn't.
62 kiriwrite_variablecheck($override_template, "utf8", 0, 0);
63 $override_template = kiriwrite_utf8convert($override_template);
64 my $kiriwrite_overridetemplatefilename_length_check = kiriwrite_variablecheck($override_template, "maxlength", 64, 1);
65 my $kiriwrite_overridetemplatefilename_filename_check = kiriwrite_variablecheck($override_template, "filename", "", 1);
67 if ($kiriwrite_overridetemplatefilename_length_check eq 1){
69 # The override template filename given is too long
72 kiriwrite_error("overridetemplatetoolong");
76 if ($kiriwrite_overridetemplatefilename_filename_check eq 2 && $override_template ne "!none"){
78 # The override template filename is invalid so
81 kiriwrite_error("overridetemplateinvalid");
85 # Check if the confirm value is blank and if it
86 # is then set the confirm value to 0.
90 # The confirm value is blank, so set the
97 # Check if there are any databases selected
98 # and return an error if there isn't.
102 # There are no databases in the array
103 # so return an error.
105 kiriwrite_error("nodatabaseselected");
109 # Check if the type given is no more than
112 my $type_maxlength_check = kiriwrite_variablecheck($type, "maxlength", 8, 1);
114 if ($type_maxlength_check eq 1){
116 # The type length given is too long so
119 kiriwrite_error("variabletoolong");
123 # Check if the action to compile the databases
124 # has been confirmed.
128 # The action to compile the datavases has
131 # Define some variables for later.
146 my @database_filters;
147 my $warning_count = 0;
151 my $filters_count = 0;
152 my $filters_find_blank_warning = 0;
158 my $page_filename_check;
159 my $page_filename_char = "";
160 my $page_filename_directory;
161 my $page_filename_length = 0;
162 my $page_filename_seek = 0;
163 my $page_filename_dircount = 0;
164 my $page_filename_exists = 0;
165 my $page_filename_permissions = 0;
166 my $page_directory_name;
167 my $page_directory_path;
169 my $page_description;
174 my $page_lastmodified;
177 my $page_autosection;
180 my $database_filename_check = 0;
181 my $database_maxlength_check = 0;
182 my $output_exists = 0;
183 my $output_permissions = 0;
184 my $filters_exists = 0;
185 my $filters_permissions = 0;
186 my $filters_skip = 0;
188 my $templates_skip = 0;
189 my $information_prefix = $main::kiriwrite_lang{compile}{informationprefix};
190 my $error_prefix = $main::kiriwrite_lang{compile}{errorprefix};
191 my $warning_prefix = $main::kiriwrite_lang{compile}{warningprefix};
194 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{compiledatabases}, { Style => "pageheader" });
195 $main::kiriwrite_presmodule->addlinebreak();
196 $main::kiriwrite_presmodule->addlinebreak();
197 $main::kiriwrite_presmodule->startbox("datalist");
199 # Check if the output directory exists and has
200 # valid permissions set.
202 $output_exists = kiriwrite_fileexists($main::kiriwrite_config{'directory_data_output'});
204 if ($output_exists ne 0){
206 # The output directory does not exist so
209 kiriwrite_error("outputdirectorymissing");
213 $output_permissions = kiriwrite_filepermissions($main::kiriwrite_config{'directory_data_output'}, 1, 1);
215 if ($output_permissions ne 0){
217 # The output directory has invalid
218 # permissions set so return an error.
220 kiriwrite_error("outputdirectoryinvalidpermissions");
224 # Connect to the database server.
226 $main::kiriwrite_dbmodule->connect();
228 # Check if any errors occured while connecting to the database server.
230 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
232 # A database connection error has occured so return
235 kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
239 # Connect to the filter database.
241 $main::kiriwrite_dbmodule->connectfilter();
243 # Check if any error has occured while connecting to the filter
246 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){
248 # The filter database does not exist so write a warning message.
250 $main::kiriwrite_presmodule->addtext($warning_prefix . $main::kiriwrite_lang{compile}{filterdatabasemissing});
251 $main::kiriwrite_presmodule->addlinebreak();
255 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){
257 # The filter database has invalid permissions set so write a
260 $main::kiriwrite_presmodule->addtext($error_prefix . $main::kiriwrite_lang{compile}{filterdatabasepermissions});
261 $main::kiriwrite_presmodule->addlinebreak();
267 # Load the filter database (if the filters skip
268 # value isn't set to 1).
270 if ($filters_skip eq 0){
272 # Get the list of available filters.
274 @database_filters = $main::kiriwrite_dbmodule->getfilterlist();
276 # Check if any errors occured while getting the list of filters.
278 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
280 # A database error has occured with the filter database.
282 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{filterdatabaseerror}, $main::kiriwrite_dbmodule->geterror(1)));
283 $main::kiriwrite_presmodule->addlinebreak();
288 # Check if the filters skip value is set to 0
289 # before executing the query.
291 if ($filters_skip eq 0){
293 foreach $filter (@database_filters){
295 # Get the filter information.
297 %filter_info = $main::kiriwrite_dbmodule->getfilterinfo({ FilterID => $filter, Reduced => 1 });
299 # Check if the filter is enabled and if it isn't then process
302 if (!$filter_info{"FilterEnabled"}){
304 # The filter is not enabled so process the next filter.
310 # Check if any errors occured while getting the filter information.
312 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
314 # A database error occured while using the filter database.
316 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{filterdatabaseerror}, $main::kiriwrite_dbmodule->geterror(1)));
317 $main::kiriwrite_presmodule->addlinebreak();
321 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDoesNotExist"){
323 # The filter does not exist so process the next filter.
329 # Check if the find filter is blank and
330 # if it is then write a warning message.
332 if (!$filter_info{"FilterFind"}){
334 if ($filters_find_blank_warning ne 1){
336 $main::kiriwrite_presmodule->addtext($warning_prefix . $main::kiriwrite_lang{compile}{findfilterblank});
337 $main::kiriwrite_presmodule->addlinebreak();
338 $filters_find_blank_warning = 1;
344 # Add each find and replace filter.
346 $findfilter[$filters_count] = $filter_info{"FilterFind"};
347 $replacefilter[$filters_count] = $filter_info{"FilterReplace"};
355 $main::kiriwrite_presmodule->addtext($information_prefix . $main::kiriwrite_lang{compile}{finishfilterdatabase});
356 $main::kiriwrite_presmodule->addlinebreak();
362 # Disconnect from the filter database.
364 $main::kiriwrite_dbmodule->disconnectfilter();
366 # Connect to the template database.
368 $main::kiriwrite_dbmodule->connecttemplate();
370 # Check if any errors occured while connecting to the template database.
372 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
374 # The template database does not exist so set the template
377 $main::kiriwrite_presmodule->addtext($warning_prefix . $main::kiriwrite_lang{compile}{templatedatabasemissing});
378 $main::kiriwrite_presmodule->addlinebreak();
382 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
384 # The template database has invalid permissions set so write
385 # the template warning message.
387 $main::kiriwrite_presmodule->addtext($error_prefix . $main::kiriwrite_lang{compile}{templatedatabasepermissions});
388 $main::kiriwrite_presmodule->addlinebreak();
394 # Check if the template skip value isn't set and if it isn't
395 # then get the list of templates.
397 if (!$templates_skip){
399 @templateslist = $main::kiriwrite_dbmodule->gettemplatelist();
401 # Check if any errors had occured.
403 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
405 # A database error occured while getting the list
406 # of templates so return a warning message with the
407 # extended error information.
409 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{templatedatabaseerror}, $main::kiriwrite_dbmodule->geterror(1)));
415 # Check if the template skip value isn't set and if it isn't
416 # then process each template.
418 if (!$templates_skip){
420 # Process each template.
422 foreach $template (@templateslist){
424 # Get information about the template.
426 %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template });
428 # Check if any error occured while getting the template information.
430 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
432 # A database error has occured, so return an error.
434 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{templatedatabaseerror}, $main::kiriwrite_dbmodule->geterror(1)));
437 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
439 # The template does not exist, so process the next template.
445 # Place each template file into the hash.
447 $templatefiles{$template_info{"TemplateFilename"}}{template} = $template_info{"TemplateLayout"};
448 $templatefiles{$template_info{"TemplateFilename"}}{valid} = 1;
452 $main::kiriwrite_presmodule->addtext($information_prefix . $main::kiriwrite_lang{compile}{finishtemplatedatabase});
453 $main::kiriwrite_presmodule->addlinebreak();
459 # Disconnect from the template database.
461 $main::kiriwrite_dbmodule->disconnecttemplate();
463 # Process each database.
465 foreach $database (@selectedlist){
467 # Check if the database filename and length
470 $main::kiriwrite_presmodule->addhorizontalline();
472 $database_filename_check = kiriwrite_variablecheck($database, "page_filename", "", 1);
473 $database_maxlength_check = kiriwrite_variablecheck($database, "maxlength", 32, 1);
475 if ($database_filename_check ne 0){
477 # The database filename is invalid, so process
480 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{databasefilenameinvalidcharacters}, $database));
481 $main::kiriwrite_presmodule->addlinebreak();
487 if ($database_maxlength_check ne 0){
489 # The database file is too long, so process the
492 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{databasefilenametoolong}, $database));
493 $main::kiriwrite_presmodule->addlinebreak();
499 # Select the database.
501 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
503 # Check if any errors had occured while selecting the database.
505 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
507 # The database does not exist, so write a warning message.
509 $main::kiriwrite_presmodule->addtext($warning_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{databasemissing}, $database));
510 $main::kiriwrite_presmodule->addlinebreak();
514 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
516 # The database has invalid permissions set, so write
519 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{databaseinvalidpermissions}, $database));
520 $main::kiriwrite_presmodule->addlinebreak();
526 # Get information about the database.
528 my %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
530 # Check if any error occured while getting the database information.
532 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
534 # A database error has occured so write an error.
536 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{databaseerror}, $database, $main::kiriwrite_dbmodule->geterror(1)));
537 $main::kiriwrite_presmodule->addlinebreak();
543 # Get the database name.
545 $database_name = $database_info{"DatabaseName"};
547 $main::kiriwrite_presmodule->addtext($information_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{compilingpages}, $database_name));
548 $main::kiriwrite_presmodule->addlinebreak();
550 # Get the list of pages in the database.
552 @databasepages = $main::kiriwrite_dbmodule->getpagelist();
554 # Check if any errors occured while getting the list of pages.
556 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
558 # A database error has occured so return an error and
559 # also the extended error information.
561 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{databasepageerror}, $database, $main::kiriwrite_dbmodule->geterror(1)));
562 $main::kiriwrite_presmodule->addlinebreak();
568 foreach $page (@databasepages) {
570 # Get information about the page.
572 %page_info = $main::kiriwrite_dbmodule->getpageinfo({ PageFilename => $page });
574 $page_filename = $page_info{"PageFilename"};
575 $page_name = $page_info{"PageName"};
576 $page_description = $page_info{"PageDescription"};
577 $page_section = $page_info{"PageSection"};
578 $page_template = $page_info{"PageTemplate"};
579 $page_content = $page_info{"PageContent"};
580 $page_settings = $page_info{"PageSettings"};
581 $page_lastmodified = $page_info{"PageLastModified"};
583 # Check if the filename is valid.
585 $page_filename_check = kiriwrite_variablecheck($page_filename, "page_filename", 0, 1);
587 if ($page_filename_check ne 0){
589 # The file name is not valid so write a
590 # error and process the next page.
592 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{invalidpagefilename}, $page_name));
593 $main::kiriwrite_presmodule->addlinebreak();
599 # Check if the template with the filename does not exist
600 # in the template files hash and write a message and
601 # process the next page.
603 if ($override eq "on"){
605 $page_template = $override_template;
609 if (!$templatefiles{$page_template}{valid} && $page_template ne "!none" && $templates_skip eq 0){
611 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{templatefilemissing}, $page_template, $page_name, $page_filename));
612 $main::kiriwrite_presmodule->addlinebreak();
616 $page_final = $page_content;
618 } elsif ($page_template eq "!none"){
620 $page_final = $page_content;
624 $page_final = $templatefiles{$page_template}{template};
630 $page_final =~ s/<kiriwrite:pagecontent>/$page_content/g;
634 # Create the combined page title (if needed).
636 if ($page_settings eq 0 || $page_settings > 3){
638 # Don't use page name or section name.
640 $page_final =~ s/<kiriwrite:pagetitle>//g;
642 } elsif ($page_settings eq 1){
644 # Use the page name and section name.
646 $page_autotitle = "(" . $page_section . " - " . $page_name . ")";
647 $page_title = $page_section . " - " . $page_name;
648 $page_final =~ s/<kiriwrite:pagetitle>/$page_title/g;
650 } elsif ($page_settings eq 2){
652 # Use the page name only.
654 $page_autotitle = "(" . $page_name . ")";
655 $page_final =~ s/<kiriwrite:pagetitle>/$page_name/g;
657 } elsif ($page_settings eq 3){
659 # Use the section name only.
662 $page_autotitle = "(" . $page_section . ")";
664 $page_final =~ s/<kiriwrite:pagetitle>/$page_section/g;
668 # Check if the section name is not blank and
669 # place brackets inbetween if it is.
673 $page_autosection = "(" . $page_section . ")";
677 # Replace each <kiriwrite> value with the apporiate page
680 $page_final =~ s/<kiriwrite:pagename>/$page_name/g;
681 $page_final =~ s/<kiriwrite:pagedescription>/$page_description/g;
682 $page_final =~ s/<kiriwrite:pagesection>/$page_section/g;
683 $page_final =~ s/<kiriwrite:autosection>/$page_autosection/g;
684 $page_final =~ s/<kiriwrite:autotitle>/$page_autotitle/g;
686 # Process the filters on the page data.
688 if ($filters_skip eq 0){
692 foreach $filter_find (@findfilter){
694 # Get the replace filter and process each
695 # filter on the page.
697 $filter_replace = $replacefilter[$filters_count];
698 $page_final =~ s/$filter_find/$filter_replace/g;
705 # Process the page filename and check what directories
706 # need to be created.
708 $page_filename_length = int(length($page_filename));
712 $page_filename_char = substr($page_filename, $page_filename_seek, 1);
714 # Check if a forward slash appears and add it to
715 # the list of directories array.
717 if ($page_filename_char eq '/'){
719 # Append the directory name to the list of
722 $pagedirectories[$page_filename_dircount] = $page_filename_directory;
723 $page_filename_directory = "";
724 $page_filename_char = "";
725 $page_filename_dircount++;
729 # Append the character to the directory/filename.
731 $page_filename_directory = $page_filename_directory . $page_filename_char;
735 $page_filename_seek++;
737 } until ($page_filename_length eq $page_filename_seek);
739 foreach $page_directory_name (@pagedirectories){
741 # Check if the directory name is undefined and if it
742 # is then set it blank.
744 if (!$page_directory_name){
745 $page_directory_name = "";
748 if (!$page_directory_path){
749 $page_directory_path = "";
752 # Check if the directory exists and create
753 # the directory if it doesn't exist.
755 $page_directory_path = $page_directory_path . '/' . $page_directory_name;
757 mkdir($main::kiriwrite_config{"directory_data_output"} . '/' . $page_directory_path);
761 # Check if the file already exists and if it does then check
762 # the permissions of the file and return an error if the
763 # permissions set are invalid.
765 $page_filename_exists = kiriwrite_fileexists($main::kiriwrite_config{"directory_data_output"} . '/' . $page_filename);
767 if ($page_filename_exists eq 0){
769 # The page filename exists, so check if the permissions given are
772 $page_filename_permissions = kiriwrite_filepermissions($main::kiriwrite_config{"directory_data_output"} . '/' . $page_filename, 1, 1);
774 if ($page_filename_permissions eq 1){
776 # The file has invalid permissions set.
778 $main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{pageinvalidpermissions}, $page_filename));
779 $main::kiriwrite_presmodule->addlinebreak();
782 # Reset certain values.
784 $page_autotitle = "";
785 $page_autosection = "";
786 $page_filename_seek = 0;
787 $page_filename_dircount = 0;
789 $page_filename_directory = "";
790 $page_directory_path = "";
791 $page_directory_name = "";
792 @pagedirectories = ();
800 # Reset certain values.
802 $page_autotitle = "";
803 $page_autosection = "";
804 $page_filename_seek = 0;
805 $page_filename_dircount = 0;
807 $page_filename_directory = "";
808 $page_directory_path = "";
809 $page_directory_name = "";
810 @pagedirectories = ();
812 # Write the file to the output directory.
814 ($page_filename) = $page_filename =~ m/^(.*)$/g;
815 ($main::kiriwrite_config{"directory_data_output"}) = $main::kiriwrite_config{"directory_data_output"} =~ m/^(.*)$/g;
817 open($filehandle_page, "> ", $main::kiriwrite_config{"directory_data_output"} . '/' . $page_filename) or ($main::kiriwrite_presmodule->addtext($error_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{pagenotwritten}, $page_filename, $!)), $main::kiriwrite_presmodule->addlinebreak(), $error_count++, next);
825 binmode $filehandle_page, ':utf8';
826 print $filehandle_page $page_final;
827 close($filehandle_page);
829 # Write a message saying the page has been compiled. Check
830 # to see if the page name is blank and write a message
831 # saying there's no page name.
834 $main::kiriwrite_presmodule->addtext($information_prefix . ' ');
835 $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{noname} . ' ');
836 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{compile}{compiledpageblankname}, $page_filename));
838 $main::kiriwrite_presmodule->addtext($information_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{compiledpage}, $page_name, $page_filename));
842 $main::kiriwrite_presmodule->addlinebreak();
847 # Write a message saying that the database has
850 $main::kiriwrite_presmodule->addtext($information_prefix . kiriwrite_language($main::kiriwrite_lang{compile}{databasefinish}, $database_name));
851 $main::kiriwrite_presmodule->addlinebreak();
855 # Disconnect from the database server.
857 $main::kiriwrite_dbmodule->disconnect();
859 $main::kiriwrite_presmodule->addhorizontalline();
860 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{compile}{compileresults}, $pages_count, $error_count, $warning_count));
861 $main::kiriwrite_presmodule->endbox();
862 $main::kiriwrite_presmodule->addlinebreak();
863 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $main::kiriwrite_lang{compile}{returncompilelist} });
865 return $main::kiriwrite_presmodule->grab();
867 } elsif ($confirm eq 0){
869 # The action to compile the databases has
870 # not been confirmed so check what type
873 # Get the list of templates for overwriting the
874 # template if needed.
876 my $templateoverride_skip = 0;
877 my $templatedbwarning = "";
879 my $template_filename;
883 tie(%template_dblist, "Tie::IxHash");
885 if ($type eq "single"){
887 # The type is a single database selected so
888 # process that database.
890 # Define some variables for later.
893 my $database_filename_check;
894 my $database_maxlength_check;
895 my $databasefilename;
898 # Check that the database name and length are
899 # valid and return an error if they aren't.
901 $databasefilename = $selectedlist[0];
903 # Connect to the database server.
905 $main::kiriwrite_dbmodule->connect();
907 # Check if any errors occured while connecting to the database server.
909 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
911 # A database connection error has occured so return
914 kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
918 # Select the database.
920 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $databasefilename });
922 # Check if any errors had occured while selecting the database.
924 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
926 # The database does not exist, so return an error.
928 kiriwrite_error("databasemissingfile");
930 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
932 # The database has invalid permissions set, so return
935 kiriwrite_error("databaseinvalidpermissions");
939 # Get information about the database.
941 %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
943 # Check if any error occured while getting the database information.
945 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
947 # A database error has occured so return an error and
948 # also the extended error information.
950 kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
954 $database_name = $database_info{"DatabaseName"};
956 $main::kiriwrite_dbmodule->connecttemplate();
958 # Check if any errors occured while connecting to the
961 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
963 # The template database does not exist so skip processing
964 # the list of templates in the template database.
966 $templateoverride_skip = 1;
967 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedbmissing};
969 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
971 # The template database has invalid permissions set so
972 # skip processing the list of templates in the
975 $templateoverride_skip = 1;
976 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedbinvalidpermissions};
980 # Get the list of available templates if no errors had
983 if ($templateoverride_skip ne 1){
985 @template_list = $main::kiriwrite_dbmodule->gettemplatelist();
987 # Check if any errors occured while getting the list of templates.
989 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
991 # A template database error has occured so skip processing the
992 # list of templates in the template database.
994 $templateoverride_skip = 1;
995 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedberror};
999 if ($templateoverride_skip ne 1){
1001 foreach $template_file (@template_list){
1003 %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_file });
1005 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
1009 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1015 $template_dblist{$template_file} = $template_info{"TemplateName"};
1023 # Disconnect from the template database and database server.
1025 $main::kiriwrite_dbmodule->disconnecttemplate();
1026 $main::kiriwrite_dbmodule->disconnect();
1028 # Write out a form asking the user to confirm if the
1029 # user wants to compile the selected database.
1031 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{compiledatabase}, { Style => "pageheader" });
1032 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1033 $main::kiriwrite_presmodule->startbox();
1034 $main::kiriwrite_presmodule->addhiddendata("mode", "compile");
1035 $main::kiriwrite_presmodule->addhiddendata("action", "compile");
1036 $main::kiriwrite_presmodule->addhiddendata("type", "multiple");
1037 $main::kiriwrite_presmodule->addhiddendata("id[1]", $databasefilename);
1038 $main::kiriwrite_presmodule->addhiddendata("name[1]", "on");
1039 $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
1040 $main::kiriwrite_presmodule->addlinebreak();
1041 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{compile}{compiledatabasemessage}, $database_name));
1042 $main::kiriwrite_presmodule->addlinebreak();
1043 $main::kiriwrite_presmodule->addlinebreak();
1045 if ($templateoverride_skip eq 1){
1047 # Add message saying why template can't be overridden.
1048 $main::kiriwrite_presmodule->addtext($templatedbwarning);
1052 # Add overwrite template data.
1053 $main::kiriwrite_presmodule->addcheckbox("enableoverride", { OptionDescription => $main::kiriwrite_lang{compile}{overridetemplate}, LineBreak => 1 });
1054 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{replacecurrenttemplate});
1055 $main::kiriwrite_presmodule->addselectbox("overridetemplate");
1057 foreach $template_file (keys %template_dblist){
1059 $main::kiriwrite_presmodule->addoption($template_dblist{$template_file} . " (" . $template_file . ")", { Value => $template_file });
1063 $main::kiriwrite_presmodule->addoption($main::kiriwrite_lang{compile}{dontusetemplate}, { Value => "!none" });
1064 $main::kiriwrite_presmodule->endselectbox();
1068 $main::kiriwrite_presmodule->addlinebreak();
1069 $main::kiriwrite_presmodule->addlinebreak();
1070 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{compile}{compiledatabasebutton});
1071 $main::kiriwrite_presmodule->addtext(" | ");
1072 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $main::kiriwrite_lang{compile}{returncompilelist} });
1073 $main::kiriwrite_presmodule->endbox();
1074 $main::kiriwrite_presmodule->endform();
1076 return $main::kiriwrite_presmodule->grab();
1078 } elsif ($type eq "multiple"){
1080 # The type is multiple databases selected
1081 # so process each database.
1083 # Define some variables for later.
1088 my $database_filename_check;
1089 my $database_maxlength_check;
1090 my $database_count = 0;
1091 my $database_info_name;
1093 # Connect to the database server.
1095 $main::kiriwrite_dbmodule->connect();
1097 # Check if any errors occured while connecting to the database server.
1099 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1101 # A database connection error has occured so return
1104 kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
1108 foreach $databasename (@selectedlist){
1110 # Check if the database is in the database
1111 # directory and skip it if it isn't.
1113 $database_filename_check = kiriwrite_variablecheck($databasename, "filename", "", 1);
1114 $database_maxlength_check = kiriwrite_variablecheck($databasename, "maxlength", 32, 1);
1116 if ($database_filename_check ne 0 || $database_maxlength_check ne 0){
1118 # The database filename given is invalid or
1119 # the database filename given is too long
1120 # so process the next database.
1126 # Select the database to add the page to.
1128 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $databasename });
1130 # Check if any errors had occured while selecting the database.
1132 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
1134 # The database does not exist, so process the next database.
1138 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
1140 # The database has invalid permissions set, so process
1141 # the next database.
1147 # Get information about the database.
1149 my %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
1151 # Check if any error occured while getting the database information.
1153 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
1155 # A database error has occured so process the next
1162 $database_list{$database_count}{Name} = $database_info{"DatabaseName"};
1163 $database_list{$database_count}{Filename} = $databasename;
1169 # Check if any databases are available to be compiled.
1171 if ($database_count eq 0){
1173 # No databases are available to be compiled.
1175 kiriwrite_error("nodatabaseselected");
1179 # Write out the form for compiling the database.
1181 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{compileselecteddatabases}, { Style => "pageheader" });
1182 $main::kiriwrite_presmodule->addlinebreak();
1183 $main::kiriwrite_presmodule->addlinebreak();
1184 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1185 $main::kiriwrite_presmodule->startbox();
1186 $main::kiriwrite_presmodule->addhiddendata("mode", "compile");
1187 $main::kiriwrite_presmodule->addhiddendata("action", "compile");
1188 $main::kiriwrite_presmodule->addhiddendata("type", "multiple");
1189 $main::kiriwrite_presmodule->addhiddendata("count", $database_count);
1190 $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
1191 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{compileselecteddatabasesmessage});
1192 $main::kiriwrite_presmodule->addlinebreak();
1193 $main::kiriwrite_presmodule->addlinebreak();
1194 $main::kiriwrite_presmodule->startbox("datalist");
1196 $database_count = 0;
1198 # write out the list of databases to compile.
1200 foreach $database (keys %database_list){
1204 $main::kiriwrite_presmodule->addhiddendata("id[" . $database_count . "]", $database_list{$database}{Filename});
1205 $main::kiriwrite_presmodule->addhiddendata("name[" . $database_count . "]", "on");
1207 # Check if the database name is undefined and if it is
1208 # then write a message saying the database name is blank.
1210 if (!$database_list{$database}{Name}){
1211 $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{compile}{blankdatabasename});
1213 $main::kiriwrite_presmodule->addtext($database_list{$database}{Name});
1216 $main::kiriwrite_presmodule->addlinebreak();
1220 $main::kiriwrite_presmodule->endbox();
1222 $main::kiriwrite_presmodule->addlinebreak();
1224 $main::kiriwrite_dbmodule->connecttemplate();
1226 # Check if any errors occured while connecting to the
1227 # template database.
1229 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
1231 # The template database does not exist so skip processing
1232 # the list of templates in the template database.
1234 $templateoverride_skip = 1;
1235 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedbmissing};
1237 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
1239 # The template database has invalid permissions set so
1240 # skip processing the list of templates in the
1241 # template database.
1243 $templateoverride_skip = 1;
1244 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedbinvalidpermissions};
1248 # Get the list of available templates if no errors had
1251 if ($templateoverride_skip ne 1){
1253 @template_list = $main::kiriwrite_dbmodule->gettemplatelist();
1255 # Check if any errors occured while getting the list of templates.
1257 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1259 # A template database error has occured so skip processing the
1260 # list of templates in the template database.
1262 $templateoverride_skip = 1;
1263 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedberror};
1267 if ($templateoverride_skip ne 1){
1269 foreach $template_file (@template_list){
1271 %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_file });
1273 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
1277 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1283 $template_dblist{$template_file} = $template_info{"TemplateName"};
1291 if ($templateoverride_skip eq 1){
1293 # Add message saying why template can't be overridden.
1294 $main::kiriwrite_presmodule->addtext($templatedbwarning);
1298 # Add overwrite template data.
1299 $main::kiriwrite_presmodule->addcheckbox("enableoverride", { OptionDescription => $main::kiriwrite_lang{compile}{overridetemplate}, LineBreak => 1 });
1300 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{replacecurrenttemplate});
1301 $main::kiriwrite_presmodule->addselectbox("overridetemplate");
1303 foreach $template_file (keys %template_dblist){
1305 $main::kiriwrite_presmodule->addoption($template_dblist{$template_file} . " (" . $template_file . ")", { Value => $template_file });
1309 $main::kiriwrite_presmodule->addoption($main::kiriwrite_lang{compile}{dontusetemplate}, { Value => "!none" });
1310 $main::kiriwrite_presmodule->endselectbox();
1314 # Disconnect from the template database and database server.
1316 $main::kiriwrite_dbmodule->disconnecttemplate();
1317 $main::kiriwrite_dbmodule->disconnect();
1319 $main::kiriwrite_presmodule->addlinebreak();
1320 $main::kiriwrite_presmodule->addlinebreak();
1321 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{compile}{compileselecteddatabasesbutton});
1322 $main::kiriwrite_presmodule->addtext(" | ");
1323 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $main::kiriwrite_lang{compile}{returncompilelist} });
1324 $main::kiriwrite_presmodule->endbox();
1325 $main::kiriwrite_presmodule->endform();
1327 return $main::kiriwrite_presmodule->grab();
1331 # The type is something else other than
1332 # single or multiple, so return an error.
1334 kiriwrite_error("invalidvariable");
1340 # The confirm value is neither 0 or 1, so
1343 kiriwrite_error("invalidvariable");
1349 sub kiriwrite_compile_all{
1350 #################################################################################
1351 # kiriwrite_compile_all: Compile all of the databases in the database #
1356 # kiriwrite_compile_all(); #
1357 #################################################################################
1359 # Connect to the database server.
1361 $main::kiriwrite_dbmodule->connect();
1363 # Check if any errors occured while connecting to the database server.
1365 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1367 # A database connection error has occured so return
1370 kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
1374 # Get the list of available databases.
1376 my @database_list = $main::kiriwrite_dbmodule->getdblist();
1378 # Check if any errors occured while getting the databases.
1380 if ($main::kiriwrite_dbmodule->geterror eq "DataDirMissing"){
1382 # The database directory is missing so return an error.
1384 kiriwrite_error("datadirectorymissing");
1386 } elsif ($main::kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){
1388 # The database directory has invalid permissions set so return
1391 kiriwrite_error("datadirectoryinvalidpermissions");
1395 # Define some variables for later.
1398 my $database_name_filename_check;
1399 my $database_count = 0;
1401 # Check the list of databases to compile to see if it is blank,
1402 # if it is then return an error.
1404 if (!@database_list){
1406 # The list of database is blank so return an error.
1408 kiriwrite_error("nodatabasesavailable");
1412 # Write out a form for confirming the action to compile all of the databases.
1414 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{compilealldatabases}, { Style => "pageheader" });
1415 $main::kiriwrite_presmodule->addlinebreak();
1416 $main::kiriwrite_presmodule->addlinebreak();
1418 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1419 $main::kiriwrite_presmodule->startbox();
1420 $main::kiriwrite_presmodule->addhiddendata("mode", "compile");
1421 $main::kiriwrite_presmodule->addhiddendata("action", "compile");
1422 $main::kiriwrite_presmodule->addhiddendata("type", "multiple");
1424 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{compilealldatabasesmessage});
1425 $main::kiriwrite_presmodule->addlinebreak();
1426 $main::kiriwrite_presmodule->addlinebreak();
1428 foreach $database (@database_list){
1430 # Check if the database filename is blank.
1432 if ($database eq ""){
1434 # The database filename is blank so process
1435 # the next database.
1441 # Check if the database filename is valid before
1442 # using the database.
1444 $database_name_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1);
1446 if ($database_name_filename_check ne 0){
1448 # The database filename is invalid so process
1449 # the next database.
1456 $main::kiriwrite_presmodule->addhiddendata("id[" . $database_count . "]", $database);
1457 $main::kiriwrite_presmodule->addhiddendata("name[" . $database_count . "]", "on");
1461 $main::kiriwrite_presmodule->addhiddendata("count", $database_count);
1463 my $templateoverride_skip = 0;
1464 my $templatedbwarning = "";
1466 my $template_filename;
1468 my %template_dblist;
1470 tie(%template_dblist, "Tie::IxHash");
1472 $main::kiriwrite_dbmodule->connecttemplate();
1474 # Check if any errors occured while connecting to the
1475 # template database.
1477 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
1479 # The template database does not exist so skip processing
1480 # the list of templates in the template database.
1482 $templateoverride_skip = 1;
1483 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedbmissing};
1485 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
1487 # The template database has invalid permissions set so
1488 # skip processing the list of templates in the
1489 # template database.
1491 $templateoverride_skip = 1;
1492 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedbinvalidpermissions};
1496 # Get the list of available templates if no errors had
1499 if ($templateoverride_skip ne 1){
1501 @template_list = $main::kiriwrite_dbmodule->gettemplatelist();
1503 # Check if any errors occured while getting the list of templates.
1505 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1507 # A template database error has occured so skip processing the
1508 # list of templates in the template database.
1510 $templateoverride_skip = 1;
1511 $templatedbwarning = $main::kiriwrite_lang{compile}{templatedberror};
1515 if ($templateoverride_skip ne 1){
1517 foreach $template_file (@template_list){
1519 %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_file });
1521 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
1525 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1531 $template_dblist{$template_file} = $template_info{"TemplateName"};
1539 if ($templateoverride_skip eq 1){
1541 # Add message saying why template can't be overridden.
1542 $main::kiriwrite_presmodule->addtext($templatedbwarning);
1546 # Add overwrite template data.
1547 $main::kiriwrite_presmodule->addcheckbox("enableoverride", { OptionDescription => $main::kiriwrite_lang{compile}{overridetemplate}, LineBreak => 1 });
1548 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{replacecurrenttemplate});
1549 $main::kiriwrite_presmodule->addselectbox("overridetemplate");
1551 foreach $template_file (keys %template_dblist){
1553 $main::kiriwrite_presmodule->addoption($template_dblist{$template_file} . " (" . $template_file . ")", { Value => $template_file });
1557 $main::kiriwrite_presmodule->addoption($main::kiriwrite_lang{compile}{dontusetemplate}, { Value => "!none" });
1558 $main::kiriwrite_presmodule->endselectbox();
1562 # Disconnect from the template database and database server.
1564 $main::kiriwrite_dbmodule->disconnecttemplate();
1565 $main::kiriwrite_dbmodule->disconnect();
1567 $main::kiriwrite_presmodule->addlinebreak();
1568 $main::kiriwrite_presmodule->addlinebreak();
1570 $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
1571 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{compile}{compilealldatabasesbutton});
1572 $main::kiriwrite_presmodule->addtext(" | ");
1573 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $main::kiriwrite_lang{compile}{returncompilelist} });
1574 $main::kiriwrite_presmodule->endbox();
1575 $main::kiriwrite_presmodule->endform();
1577 return $main::kiriwrite_presmodule->grab();
1582 sub kiriwrite_compile_list{
1583 #################################################################################
1584 # kiriwrite_compile_list: Shows a list of databases that can be compiled. #
1588 # kiriwrite_compile_list(); #
1589 #################################################################################
1591 # Define the following variables that are going to be used before using
1592 # the foreach function.
1596 my $database_count = 0;
1597 my $database_filename = "";
1598 my $database_filename_friendly = "";
1599 my $database_permissions = "";
1600 my $database_name = "";
1601 my $database_description = "";
1603 my @permissions_list;
1605 my $table_style = 0;
1606 my $table_style_name = "";
1609 tie(%database_list, 'Tie::IxHash');
1611 # Connect to the database server.
1613 $main::kiriwrite_dbmodule->connect();
1615 # Check if any errors occured while connecting to the database server.
1617 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1619 # A database connection error has occured so return
1622 kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
1626 # Get the list of available databases and process any errors that
1627 # might have occured.
1629 my @database_list = $main::kiriwrite_dbmodule->getdblist();
1631 if ($main::kiriwrite_dbmodule->geterror eq "DataDirMissing"){
1633 # The database directory is missing so return an error.
1635 kiriwrite_error("datadirectorymissing");
1637 } elsif ($main::kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){
1639 # The database directory has invalid permissions set so return
1642 kiriwrite_error("datadirectoryinvalidpermissions");
1646 # Begin creating the table for the list of databases.
1648 foreach $data_file (@database_list){
1650 # Select the database.
1652 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $data_file });
1654 # Check if any error occured while selecting the database.
1656 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
1658 # The database does not exist, so process the next
1663 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet") {
1665 # The database has invalid permissions settings, so
1666 # add the database to the list of databases with
1667 # invalid permissions set and process the next
1670 push(@permissions_list, $data_file);
1675 # Get information about the database.
1677 %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
1679 # Check if any error occured while getting information from the
1682 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
1684 # A database error has occured, add the database and specific
1685 # error message to the list of databases with errors and
1686 # process the next database.
1688 push(@error_list, $data_file . ": " . $main::kiriwrite_dbmodule->geterror(1));
1693 $database_name = $database_info{"DatabaseName"};
1694 $database_description = $database_info{"Description"};
1696 # Create a friendly name for the database.
1698 $database_filename_friendly = $data_file;
1700 # Append the database information to the table.
1702 $database_list{$database_count}{Filename} = $database_filename_friendly;
1703 $database_list{$database_count}{Name} = $database_name;
1704 $database_list{$database_count}{Description} = $database_description;
1710 # Check if there are no valid databases are if there is no
1711 # valid databases then write a message saying that no
1712 # valid databases are available.
1714 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{compilepages}, { Style => "pageheader" });
1715 $main::kiriwrite_presmodule->addlinebreak();
1716 $main::kiriwrite_presmodule->addlinebreak();
1718 if ($database_count eq 0){
1720 # There are no databases available for compiling so
1721 # write a message instead.
1723 $main::kiriwrite_presmodule->startbox("errorbox");
1724 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{nodatabasesavailable});
1725 $main::kiriwrite_presmodule->endbox();
1729 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1730 $main::kiriwrite_presmodule->startbox();
1731 $main::kiriwrite_presmodule->addhiddendata("mode", "compile");
1732 $main::kiriwrite_presmodule->addhiddendata("action", "compile");
1733 $main::kiriwrite_presmodule->addhiddendata("type", "multiple");
1735 $main::kiriwrite_presmodule->addreset($main::kiriwrite_lang{common}{selectnone});
1736 $main::kiriwrite_presmodule->addtext(" | ");
1737 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{compile}{compileselectedbutton});
1738 $main::kiriwrite_presmodule->addlinebreak();
1739 $main::kiriwrite_presmodule->addlinebreak();
1740 $main::kiriwrite_presmodule->addhiddendata("count", $database_count);
1741 $main::kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
1743 $main::kiriwrite_presmodule->startheader();
1744 $main::kiriwrite_presmodule->addheader("", { Style => "tablecellheader" });
1745 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{database}{databasename}, { Style => "tablecellheader" });
1746 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{database}{databasedescription}, { Style => "tablecellheader" });
1747 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{options}, { Style => "tablecellheader" });
1748 $main::kiriwrite_presmodule->endheader();
1750 $database_count = 1;
1752 foreach $database (keys %database_list){
1754 # Check the style to be used with.
1756 if ($table_style eq 0){
1758 # Use the first style and set the style value
1759 # to use the next style, the next time the
1760 # if statement is checked.
1762 $table_style_name = "tablecell1";
1767 # Use the second style and set the style
1768 # value to use the first style, the next
1769 # time if statement is checked.
1771 $table_style_name = "tablecell2";
1775 # Add the template to the list of available
1776 # templates to compile.
1778 $main::kiriwrite_presmodule->startrow();
1779 $main::kiriwrite_presmodule->addcell($table_style_name);
1780 $main::kiriwrite_presmodule->addhiddendata("id[" . $database_count . "]", $database_list{$database}{Filename});
1781 $main::kiriwrite_presmodule->addcheckbox("name[" . $database_count . "]");
1782 $main::kiriwrite_presmodule->endcell();
1783 $main::kiriwrite_presmodule->addcell($table_style_name);
1785 if (!$database_list{$database}{Name}){
1786 $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}) });
1788 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database_list{$database}{Filename}, { Text => $database_list{$database}{Name} });
1791 $main::kiriwrite_presmodule->endcell();
1792 $main::kiriwrite_presmodule->addcell($table_style_name);
1794 if (!$database_list{$database}{Description}){
1795 $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{nodescription});
1797 $main::kiriwrite_presmodule->addtext($database_list{$database}{Description});
1800 $main::kiriwrite_presmodule->endcell();
1801 $main::kiriwrite_presmodule->addcell($table_style_name);
1802 $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} });
1803 $main::kiriwrite_presmodule->endcell();
1804 $main::kiriwrite_presmodule->endrow();
1810 $main::kiriwrite_presmodule->endtable();
1811 $main::kiriwrite_presmodule->endbox();
1812 $main::kiriwrite_presmodule->endform();
1816 # Disconnect from the database server.
1818 $main::kiriwrite_dbmodule->disconnect();
1820 # Check if any databases with problems have appeared and if they
1821 # have, print out a message saying which databases have problems.
1823 if (@permissions_list){
1825 $main::kiriwrite_presmodule->addlinebreak();
1827 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databaseinvalidpermissions}, { Style => "smallpageheader" });
1828 $main::kiriwrite_presmodule->addlinebreak();
1829 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databaseinvalidpermissionstext});
1830 $main::kiriwrite_presmodule->addlinebreak();
1832 foreach $database (@permissions_list){
1834 $main::kiriwrite_presmodule->addlinebreak();
1835 $main::kiriwrite_presmodule->addtext($database);
1839 $main::kiriwrite_presmodule->addlinebreak();
1845 $main::kiriwrite_presmodule->addlinebreak();
1847 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databaseerrors}, { Style => "smallpageheader" });
1848 $main::kiriwrite_presmodule->addlinebreak();
1849 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databaseerrorstext});
1850 $main::kiriwrite_presmodule->addlinebreak();
1852 foreach $database (@error_list){
1854 $main::kiriwrite_presmodule->addlinebreak();
1855 $main::kiriwrite_presmodule->addtext($database);
1861 return $main::kiriwrite_presmodule->grab();
1865 sub kiriwrite_compile_clean{
1866 #################################################################################
1867 # kiriwrite_compile_clean: Deletes the contents of the output directory. #
1871 # kiriwrite_compile_clean(confirm); #
1873 # confirm Confirms the deletion of files from the output directory. #
1874 #################################################################################
1876 # Get the values passed to the subroutine.
1880 # Define some variables for later.
1882 my $file_permissions;
1883 my $output_directory_exists;
1884 my $output_directory_permissions;
1885 my $warning_message;
1887 # Check if the output directory exists.
1889 $output_directory_exists = kiriwrite_fileexists($main::kiriwrite_config{"directory_data_output"});
1891 if ($output_directory_exists eq 1){
1893 # The output directory does not exist so return
1896 kiriwrite_error("outputdirectorymissing");
1900 # Check if the output directory has invalid
1903 $output_directory_permissions = kiriwrite_filepermissions($main::kiriwrite_config{"directory_data_output"});
1905 if ($output_directory_permissions eq 1){
1907 # The output directory has invalid permissions
1908 # set, so return an error.
1910 kiriwrite_error("outputdirectoryinvalidpermissions");
1918 # The action to clean the output directory has been
1921 # Remove the list of files and directories from the
1924 $file_permissions = kiriwrite_compile_clean_helper($main::kiriwrite_config{"directory_data_output"}, 1);
1926 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{cleanoutputdirectory}, { Style => "pageheader" });
1928 if ($file_permissions eq 1){
1930 $main::kiriwrite_presmodule->addlinebreak();
1931 $main::kiriwrite_presmodule->addlinebreak();
1932 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{somecontentnotremoved});
1933 $main::kiriwrite_presmodule->addlinebreak();
1934 $main::kiriwrite_presmodule->addlinebreak();
1938 $main::kiriwrite_presmodule->addlinebreak();
1939 $main::kiriwrite_presmodule->addlinebreak();
1940 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{contentremoved});
1941 $main::kiriwrite_presmodule->addlinebreak();
1942 $main::kiriwrite_presmodule->addlinebreak();
1946 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $main::kiriwrite_lang{compile}{returncompilelist} });
1948 return $main::kiriwrite_presmodule->grab();
1952 # A value other than 1 is set for the confirm value
1953 # (which it shouldn't be) so return an error.
1955 kiriwrite_error("invalidvariable");
1961 # Print out a form for cleaning the output directory.
1963 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{cleanoutputdirectory}, { Style => "pageheader" });
1964 $main::kiriwrite_presmodule->addlinebreak();
1965 $main::kiriwrite_presmodule->addlinebreak();
1966 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1967 $main::kiriwrite_presmodule->startbox();
1968 $main::kiriwrite_presmodule->addhiddendata("mode", "compile");
1969 $main::kiriwrite_presmodule->addhiddendata("action", "clean");
1970 $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
1971 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{compile}{cleanoutputdirectorymessage});
1972 $main::kiriwrite_presmodule->addlinebreak();
1973 $main::kiriwrite_presmodule->addlinebreak();
1974 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{compile}{cleanoutputdirectorybutton});
1975 $main::kiriwrite_presmodule->addtext(" | ");
1976 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=compile", { Text => $main::kiriwrite_lang{compile}{returncompilelist}});
1977 $main::kiriwrite_presmodule->endbox();
1978 $main::kiriwrite_presmodule->endform();
1980 return $main::kiriwrite_presmodule->grab();
1984 sub kiriwrite_compile_clean_helper{
1985 #################################################################################
1986 # kiriwrite_compile_clean_helper: Helper for cleaning out the output directory. #
1987 # This command sometimes is called recursively (when a directory is found). #
1991 # kiriwrite_compile_clean_helper(directory, removedirectory, [permissions]); #
1993 # directory Specifies the directory to remove files (and #
1994 # sub-directories) from. #
1995 # keepdirectory Keeps the directory itself after all files have been #
1997 # permissions Used recursively for error checking. #
1998 #################################################################################
2000 # Get the values passed to the subroutine.
2002 my ($directory, $directory_keep, $permissions) = @_;
2004 # Check if the directory_keep is only one charater long.
2006 my $directory_file = "";
2008 my $file_permissions = 0;
2011 # Check if the file permissions value is blank.
2015 # The file permissions value is blank.
2021 # Open the directory specified, read the contents of
2022 # the directory and then close the directory.
2024 opendir(DIRECTORY, $directory);
2025 @directory_list = readdir(DIRECTORY);
2026 closedir(DIRECTORY);
2028 # Remove each file and directory.
2030 foreach $directory_file (@directory_list){
2032 # Check if the filename is '.' or '..' and if it
2033 # is skip those files.
2035 if ($directory_file eq "." || $directory_file eq ".."){
2037 # The filename is '.' or '..' so skip processing
2042 # Check if the permissions on the file or directory has
2043 # valid permissions set.
2045 $file_permissions = kiriwrite_filepermissions($directory . '/' . $directory_file, 1, 1);
2047 if ($file_permissions eq 1){
2049 # The file or directory has invalid permissions set.
2056 # Check if the filename is a directory.
2058 if (-d $directory . '/' . $directory_file){
2060 # The filename is a directory so send the directory name
2061 # and this subroutine again (recursively).
2063 kiriwrite_compile_clean_helper($directory . '/' . $directory_file, 0, $permissions);
2067 # The file is not a directory but an actual file so
2068 # remove as normal (in terms of the Perl language).
2070 ($directory) = $directory =~ m/^(.*)$/g;
2071 ($directory_file) = $directory_file =~ m/^(.*)$/g;
2073 # Check if the directory is undefined and if it is then
2080 if (!$directory_file){
2081 $directory_file = "";
2084 unlink($directory . '/' . $directory_file);
2092 # Check if the directory should be kept.
2094 if ($directory_keep eq 1){
2096 # The directory_keep value is set as 1 so the directory
2097 # specified should be kept.
2099 } elsif ($directory_keep eq 0) {
2101 # The directory_keep value is set as 0 so remove the
2102 # directory specified.
2104 ($directory) = $directory =~ m/^(.*)$/g;
2109 # A value other than 0 or 1 was specified so return
2112 kiriwrite_error('invalidvalue');
2116 return $permissions;