Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Changes made in preperation for Kiriwrite 0.4.0
[kiriwrite/.git] / cgi-files / Modules / System / Page.pm
1 package Modules::System::Page;
3 use Modules::System::Common;
4 use strict;
5 use warnings;
6 use Exporter;
8 our @ISA = qw(Exporter);
9 our @EXPORT = qw(kiriwrite_page_list kiriwrite_page_add kiriwrite_page_edit kiriwrite_page_delete kiriwrite_page_multidelete kiriwrite_page_multimove kiriwrite_page_multicopy kiriwrite_page_multiedit);
11 sub kiriwrite_page_list{
12 #################################################################################
13 # kiriwrite_page_list: Lists pages from an database.                            #
14 #                                                                               #
15 # Usage:                                                                        #
16 #                                                                               #
17 # kiriwrite_page_list([database], [browsernumber]);                             #
18 #                                                                               #
19 # database      Specifies the database to retrieve the pages from.              #
20 # browsenumber  Specifies which list of pages to look at.                       #
21 #################################################################################
23         # Get the database file name from what was passed to the subroutine.
25         my ($database_file, $page_browsenumber) = @_;
27         # Check if the database_file variable is empty, if it is then print out a
28         # select box asking the user to select a database from the list.
30         if (!$database_file) {
32                 # Define the variables required for this section.
34                 my %database_info;
35                 my @database_list;
36                 my @databasefilenames;
37                 my @databasenames;
38                 my $dbseek              = 0;
39                 my $dbfilename          = "";
40                 my $dbname              = "";
41                 my $data_file           = "";
42                 my $data_file_length    = 0;
43                 my $data_file_friendly  = "";
44                 my $database_name       = "";
45                 my $file_permissions    = "";
47                 # Connect to the database server.
49                 $main::kiriwrite_dbmodule->connect();
51                 # Check if any errors occured while connecting to the database server.
53                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
55                         # A database connection error has occured so return
56                         # an error.
58                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
60                 }
62                 # Open the data directory and get all of the databases.
64                 @database_list  = $main::kiriwrite_dbmodule->getdblist();
66                 # Check if any errors occured while trying to get the list of databases.
68                 if ($main::kiriwrite_dbmodule->geterror eq "DataDirMissing"){
70                         # The database directory is missing so return an error.
72                         kiriwrite_error("datadirectorymissing");
74                 } elsif ($main::kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){
76                         # The database directory has invalid permissions set so return
77                         # an error.
79                         kiriwrite_error("datadirectoryinvalidpermissions");
81                 }
83                 # Get the information about each database (the short name and friendly name).
85                 foreach $data_file (@database_list){
87                         $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $data_file });
89                         # Check if any errors occured while selecting the database.
91                         if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
93                                 # The database does not exist, so process the next
94                                 # database.
96                                 next;
98                         } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
100                                 # The database has invalid permissions set, so process
101                                 # the next database.
103                                 next;
105                         }
107                         # Get the database information.
109                         %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
111                         # Check if any errors had occured while getting the database
112                         # information.
114                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
116                                 # A database error has occured, so process the next 
117                                 # database.
119                                 next;
121                         };
123                         # Set the database name.
125                         $database_name          = $database_info{"DatabaseName"};
127                         # Check if the database name is undefined and if it is
128                         # then set it blank.
130                         if (!$database_name){
131                                 $database_name = "";
132                         }
134                         # Append the database to the list of databases available.
136                         push(@databasefilenames, $data_file);
137                         push(@databasenames, $database_name);
139                 }
141                 # Disconnect from the database server.
143                 $main::kiriwrite_dbmodule->disconnect();
145                 # Write the page data.
147                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{viewpages}, { Style => "pageheader" });
148                 $main::kiriwrite_presmodule->addlinebreak();
149                 $main::kiriwrite_presmodule->addlinebreak();
150                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{nodatabaseselected});
151                 $main::kiriwrite_presmodule->addlinebreak();
152                 $main::kiriwrite_presmodule->addlinebreak();
153                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"});
154                 $main::kiriwrite_presmodule->startbox();
155                 $main::kiriwrite_presmodule->addhiddendata("mode", "page");
156                 $main::kiriwrite_presmodule->addhiddendata("action", "view");
157                 $main::kiriwrite_presmodule->addselectbox("database");
158                 foreach $dbfilename (@databasefilenames){
159                         $dbname = $databasenames[$dbseek];
160                         $dbseek++;
161                         $main::kiriwrite_presmodule->addoption($dbname . " (" . $dbfilename . ")", { Value => $dbfilename });
162                 }
163                 $main::kiriwrite_presmodule->endselectbox();
164                 $main::kiriwrite_presmodule->addtext(" | ");
165                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{pages}{viewbutton});
166                 $main::kiriwrite_presmodule->endbox();
167                 $main::kiriwrite_presmodule->endform();
169                 return $main::kiriwrite_presmodule->grab();
171         } else {
173                 my %database_info;
174                 my %page_info;
175                 my @database_pages;
176                 my $pagemultioptions    = "";
177                 my $db_name             = "";
178                 my $tablestyle          = "";
180                 my $page_filename       = "";
181                 my $page_name           = "";
182                 my $page_description    = "";
183                 my $page_modified       = "";
185                 my $tablestyletype      = 0;
186                 my $page_count          = 0;
187                 my $db_file_notblank    = 0;
188                 my $page_split          = $main::kiriwrite_config{"display_pagecount"};
189                 my $page_list           = 0;
190                 my $page_list_count     = 0;
192                 tie(%database_info, 'Tie::IxHash');
193                 tie(%page_info, 'Tie::IxHash');
195                 # The database_file variable is not blank, so print out a list of pages from
196                 # the selected database.
198                 # Preform a variable check on the database filename to make sure that it is
199                 # valid before using it.
201                 kiriwrite_variablecheck($database_file, "filename", "", 0);
202                 kiriwrite_variablecheck($database_file, "maxlength", 32, 0);
204                 if (!$page_browsenumber || $page_browsenumber eq 0){
206                         $page_browsenumber = 1;
208                 }
210                 # Check if the page browse number is valid and if it isn't
211                 # then return an error.
213                 my $kiriwrite_browsenumber_length_check         = kiriwrite_variablecheck($page_browsenumber, "maxlength", 7, 1);
214                 my $kiriwrite_browsenumber_number_check         = kiriwrite_variablecheck($page_browsenumber, "numbers", 0, 1);
216                 if ($kiriwrite_browsenumber_length_check eq 1){
218                         # The browse number was too long so return
219                         # an error.
221                         kiriwrite_error("browsenumbertoolong");
223                 }
225                 if ($kiriwrite_browsenumber_number_check eq 1){
227                         # The browse number wasn't a number so
228                         # return an error.
230                         kiriwrite_error("browsenumberinvalid");
232                 }
234                 # Connect to the database server.
236                 $main::kiriwrite_dbmodule->connect();
238                 # Check if any errors occured while connecting to the database server.
240                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
242                         # A database connection error has occured so return
243                         # an error.
245                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
247                 }
249                 # Select the database.
251                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database_file });
253                 # Check if any errors had occured while selecting the database.
255                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
257                         # The database does not exist, so return an error.
259                         kiriwrite_error("databasemissingfile");
261                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
263                         # The database has invalid permissions set, so return
264                         # an error.
266                         kiriwrite_error("databaseinvalidpermissions");
268                 }
270                 # Get information about the database.
272                 %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
274                 $db_name = $database_info{"DatabaseName"};
276                 # Check if any errors had occured while getting the database
277                 # information.
279                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
281                         # A database error has occured so return an error and
282                         # also the extended error information.
284                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
286                 }
288                 # Get the count of pages in the database.
290                 my $page_total_count = $main::kiriwrite_dbmodule->getpagecount();
292                 # Check if any errors had occured while getting the count of
293                 # pages in the database.
295                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
297                         # A database error has occured so return an error and
298                         # also the extended error information.
300                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
302                 }
304                 # Work out the total amount of page browse numbers.
306                 if ($page_total_count ne 0){
308                         if ($page_total_count eq $page_split){
310                                 $page_list = int(($page_total_count / $page_split));
312                         } else {
314                                 $page_list = int(($page_total_count / $page_split) + 1);
316                         }
318                 }
320                 my $start_from = ($page_browsenumber - 1) * $page_split;
322                 # Get the list of pages.
324                 @database_pages = $main::kiriwrite_dbmodule->getpagelist({ StartFrom => $start_from, Limit => $page_split });
326                 # Check if any errors had occured while getting the list of pages.
328                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
330                         # A database error has occured so return an error and
331                         # also the extended error information.
333                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
335                 }
337                 # Check if there are any page names in the database array.
339                 if (@database_pages){
341                         # Write the start of the page.
343                         $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{pagelist}, $db_name), { Style => "pageheader" });
344                         $main::kiriwrite_presmodule->addlinebreak();
345                         $main::kiriwrite_presmodule->addlinebreak();
346                         $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
347                         $main::kiriwrite_presmodule->startbox();
348                         $main::kiriwrite_presmodule->addhiddendata("mode", "page");
349                         $main::kiriwrite_presmodule->addhiddendata("database", $database_file);
350                         $main::kiriwrite_presmodule->addhiddendata("type", "multiple");
352                         # Write out the page browsing list.
354                         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{showlistpage});
355                         $main::kiriwrite_presmodule->addselectbox("browsenumber");
357                         # Write out the list of available pages to browse.
358                         
359                         while ($page_list_count ne $page_list){
361                                 $page_list_count++;
363                                 if ($page_list_count eq 1 && !$page_browsenumber){
365                                         $main::kiriwrite_presmodule->addoption($page_list_count, { Value => $page_list_count, Selected => 1 });
367                                 } else {
369                                         if ($page_browsenumber eq $page_list_count){
371                                                 $main::kiriwrite_presmodule->addoption($page_list_count, { Value => $page_list_count, Selected => 1 });
373                                         } else {
375                                                 $main::kiriwrite_presmodule->addoption($page_list_count, { Value => $page_list_count });
377                                         }
379                                 }
381                         }
383                         $main::kiriwrite_presmodule->endselectbox();
384                         $main::kiriwrite_presmodule->addbutton("action", { Value => "view", Description => $main::kiriwrite_lang{pages}{show} });
387                         if ($page_list ne $page_browsenumber){
389                                 $main::kiriwrite_presmodule->addtext(" | ");
390                                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database_file . "&browsenumber=" . ($page_browsenumber + 1), { Text => $main::kiriwrite_lang{pages}{nextpage} });
392                         }
394                         # Check if the page browse number is not blank and
395                         # not set as 0 and hide the Previous page link if
396                         # it is.
398                         if ($page_browsenumber > 1){
400                                 $main::kiriwrite_presmodule->addtext(" | ");
401                                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database_file . "&browsenumber=" . ($page_browsenumber - 1), { Text => $main::kiriwrite_lang{pages}{previouspage} });
403                         }
405                         $main::kiriwrite_presmodule->addlinebreak();
407                         # Write the list of multiple selection options.
409                         $main::kiriwrite_presmodule->addreset($main::kiriwrite_lang{common}{selectnone});
410                         $main::kiriwrite_presmodule->addtext(" | ");
411                         $main::kiriwrite_presmodule->addbutton("action", { Value => "multidelete", Description => $main::kiriwrite_lang{pages}{deleteselectedbutton} });
412                         $main::kiriwrite_presmodule->addtext(" | ");
413                         $main::kiriwrite_presmodule->addbutton("action", { Value => "multimove", Description => $main::kiriwrite_lang{pages}{moveselectedbutton} });
414                         $main::kiriwrite_presmodule->addtext(" | ");
415                         $main::kiriwrite_presmodule->addbutton("action", { Value => "multicopy", Description => $main::kiriwrite_lang{pages}{copyselectedbutton} });
416                         $main::kiriwrite_presmodule->addtext(" | ");
417                         $main::kiriwrite_presmodule->addbutton("action", { Value => "multiedit", Description => $main::kiriwrite_lang{pages}{editselectedbutton} });
419                         $main::kiriwrite_presmodule->addlinebreak();
420                         $main::kiriwrite_presmodule->addlinebreak();
421                         $main::kiriwrite_presmodule->endbox();
423                         # Write the table header.
425                         $main::kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
426                         $main::kiriwrite_presmodule->startheader();
427                         $main::kiriwrite_presmodule->addheader("", { Style => "tablecellheader" });
428                         $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{pages}{pagefilename}, { Style => "tablecellheader" });
429                         $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{pages}{pagename}, { Style => "tablecellheader" });
430                         $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{pages}{pagedescription}, { Style => "tablecellheader" });
431                         $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{pages}{lastmodified}, { Style => "tablecellheader" });
432                         $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{options}, { Style => "tablecellheader" });
433                         $main::kiriwrite_presmodule->endheader();
435                         # Process each page filename and get the page information.
437                         foreach $page_filename (@database_pages){
439                                 %page_info = $main::kiriwrite_dbmodule->getpageinfo({ PageFilename => $page_filename, Reduced => 1 });
441                                 # Check if any errors have occured.
443                                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
445                                         # A database error has occured so return an error and
446                                         # also the extended error information.
448                                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
450                                 } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
452                                         # The page does not exist, so process the next page.
454                                         next;
456                                 }
458                                 $page_count++;
460                                 $page_filename          = $page_info{"PageFilename"};
461                                 $page_name              = $page_info{"PageName"};
462                                 $page_description       = $page_info{"PageDescription"};
463                                 $page_modified          = $page_info{"PageLastModified"};
465                                 # Set the table cell style.
467                                 if ($tablestyletype eq 0){
469                                         $tablestyle = "tablecell1";
470                                         $tablestyletype = 1;
472                                 } else {
474                                         $tablestyle = "tablecell2";
475                                         $tablestyletype = 0;
477                                 }
479                                 # Write out the row of data.
481                                 $main::kiriwrite_presmodule->startrow();
482                                 $main::kiriwrite_presmodule->addcell($tablestyle);
483                                 $main::kiriwrite_presmodule->addhiddendata("id[" . $page_count . "]", $page_filename);
484                                 $main::kiriwrite_presmodule->addcheckbox("name[" . $page_count . "]");
485                                 $main::kiriwrite_presmodule->endcell();
486                                 $main::kiriwrite_presmodule->addcell($tablestyle);
487                                 $main::kiriwrite_presmodule->addtext($page_filename);
488                                 $main::kiriwrite_presmodule->endcell();
489                                 $main::kiriwrite_presmodule->addcell($tablestyle);
491                                 if (!$page_name){
493                                         $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{noname});
495                                 } else {
497                                         $main::kiriwrite_presmodule->addtext($page_name);
499                                 }
501                                 $main::kiriwrite_presmodule->endcell();
502                                 $main::kiriwrite_presmodule->addcell($tablestyle);
504                                 if (!$page_description){
506                                         $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{nodescription});
508                                 } else {
510                                         $main::kiriwrite_presmodule->addtext($page_description);
512                                 }
514                                 $main::kiriwrite_presmodule->endcell();
515                                 $main::kiriwrite_presmodule->addcell($tablestyle);
517                                 if (!$page_modified){
519                                         $main::kiriwrite_presmodule->additalictext("No Date");
521                                 } else {
523                                         $main::kiriwrite_presmodule->addtext($page_modified);
525                                 }
527                                 $main::kiriwrite_presmodule->endcell();
528                                 $main::kiriwrite_presmodule->addcell($tablestyle);
529                                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"}  . "?mode=page&action=edit&database=" . $database_file . "&page=" . $page_filename, { Text => $main::kiriwrite_lang{options}{edit} });
530                                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"}  . "?mode=page&action=delete&database=" . $database_file . "&page=" . $page_filename, { Text => $main::kiriwrite_lang{options}{delete} });
531                                 $main::kiriwrite_presmodule->endcell();
532                                 $main::kiriwrite_presmodule->endrow();
534                                 # Increment the counter.
536                         }
538                 }
540                 # Disconnect from the database server.
542                 $main::kiriwrite_dbmodule->disconnect();
544                 $main::kiriwrite_presmodule->endtable();
545                 $main::kiriwrite_presmodule->startbox();
546                 $main::kiriwrite_presmodule->addhiddendata("count", $page_count);
547                 $main::kiriwrite_presmodule->endbox();
548                 $main::kiriwrite_presmodule->endform();
550                 if (!@database_pages && $page_browsenumber > 1){
552                         # There were no values given for the page browse
553                         # number given so write a message saying that
554                         # there were no pages for the page browse number
555                         # given.
557                         $main::kiriwrite_presmodule->clear();
558                         $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{pagelist}, $db_name), { Style => "pageheader" });
559                         $main::kiriwrite_presmodule->addlinebreak();
560                         $main::kiriwrite_presmodule->addlinebreak();
561                         $main::kiriwrite_presmodule->startbox("errorbox");
562                         $main::kiriwrite_presmodule->enterdata($main::kiriwrite_lang{pages}{nopagesinpagebrowse});
563                         $main::kiriwrite_presmodule->addlinebreak();
564                         $main::kiriwrite_presmodule->addlinebreak();
565                         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database_file, { Text => $main::kiriwrite_lang{pages}{returntofirstpagebrowse} });
566                         $main::kiriwrite_presmodule->endbox();  
568                 } elsif (!@database_pages || !$page_count){
570                         # There were no values in the database pages array and 
571                         # the page count had not been incremented so write a
572                         # message saying that there were no pages in the
573                         # database.
575                         $main::kiriwrite_presmodule->clear();
576                         $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{pagelist}, $db_name), { Style => "pageheader" });
577                         $main::kiriwrite_presmodule->addlinebreak();
578                         $main::kiriwrite_presmodule->addlinebreak();
579                         $main::kiriwrite_presmodule->startbox("errorbox");
580                         $main::kiriwrite_presmodule->enterdata($main::kiriwrite_lang{pages}{nopagesindatabase});
581                         $main::kiriwrite_presmodule->endbox();
583                 }
585                 return $main::kiriwrite_presmodule->grab();
587         }
591 sub kiriwrite_page_add{
592 #################################################################################
593 # kiriwrite_page_add: Adds a page to a database                                 #
594 #                                                                               #
595 # Usage:                                                                        #
596 #                                                                               #
597 # kiriwrite_page_add(database, pagefilename, title, description, section,       #
598 #                       template, settings, info, confirm);                     #
599 #                                                                               #
600 # database      Specifies the database name.                                    #
601 # pagefilename  Specifies the page filename.                                    #
602 # title         Specifies the page title to be used.                            #
603 # description   Specifies the short description of the page.                    #
604 # section       Specifies the section assigned to the page.                     #
605 # template      Specifies the template to use.                                  #
606 # settings      Specifies the settings to be used on the page.                  #
607 # data          Specifies the data which consists the page.                     #
608 # confirm       Confirms action to add an page.                                 #
609 #################################################################################
611         # Fetch the required variables that have been passed to the subroutine.
613         my ($pagedatabase, $pagefilename, $pagetitle, $pagedescription, $pagesection, $pagetemplate, $pagesettings, $pagefiledata, $confirm) = @_;
615         # Check if the action to add a new page has been confirmed (or not).
617         if (!$confirm){
619                 $confirm = 0;
621         }
623         kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
625         # Check if the database filename is valid and return an error if
626         # it isn't.
628         my $pagedatabase_filename_check = kiriwrite_variablecheck($pagedatabase, "filename", 0, 1);
630         if ($pagedatabase_filename_check eq 1){
632                 # The database filename is blank, so return an error.
634                 kiriwrite_error("blankdatabasepageadd");
636         } elsif ($pagedatabase_filename_check eq 2){
638                 # The database filename is invalid, so return an error.
640                 kiriwrite_error("databasefilenameinvalid");
642         }
644         # Check the length the database name and return an error if it's
645         # too long.
647         my $pagedatabase_length_check   = kiriwrite_variablecheck($pagedatabase, "maxlength", 32, 1);
649         if ($pagedatabase_length_check eq 1){
651                 # The database name is too long, so return an error.
653                 kiriwrite_error("databasefilenametoolong");
655         }
657         if ($confirm eq "1"){
659                 # Check all the variables to see if they UTF8 valid.
661                 kiriwrite_variablecheck($pagefilename, "utf8", 0, 0);
662                 kiriwrite_variablecheck($pagetitle, "utf8", 0, 0);
663                 kiriwrite_variablecheck($pagedescription, "utf8", 0, 0);
664                 kiriwrite_variablecheck($pagesection, "utf8", 0, 0);
665                 kiriwrite_variablecheck($pagedatabase, "utf8", 0, 0);
666                 kiriwrite_variablecheck($pagesettings, "utf8", 0, 0);
667                 kiriwrite_variablecheck($pagetemplate, "utf8", 0, 0);
668                 kiriwrite_variablecheck($pagefiledata, "utf8", 0, 0);
670                 # Convert the values into proper UTF8 values.
672                 $pagefilename           = kiriwrite_utf8convert($pagefilename);
673                 $pagetitle              = kiriwrite_utf8convert($pagetitle);
674                 $pagedescription        = kiriwrite_utf8convert($pagedescription);
675                 $pagesection            = kiriwrite_utf8convert($pagesection);
676                 $pagedatabase           = kiriwrite_utf8convert($pagedatabase);
677                 $pagesettings           = kiriwrite_utf8convert($pagesettings);
678                 $pagetemplate           = kiriwrite_utf8convert($pagetemplate);
679                 $pagefiledata           = kiriwrite_utf8convert($pagefiledata);
681                 # Check all the variables (except for the page data, filename and settings 
682                 # will be checked more specifically later if needed) that were passed to 
683                 # the subroutine.
685                 my $pagefilename_maxlength_check                = kiriwrite_variablecheck($pagefilename, "maxlength", 256, 1);
686                 my $pagetitle_maxlength_check                   = kiriwrite_variablecheck($pagetitle, "maxlength", 512, 1);
687                 my $pagedescription_maxlength_check             = kiriwrite_variablecheck($pagedescription, "maxlength", 512, 1);
688                 my $pagesection_maxlength_check                 = kiriwrite_variablecheck($pagesection, "maxlength", 256, 1);
689                 my $pagedatabase_maxlength_check                = kiriwrite_variablecheck($pagedatabase, "maxlength", 32, 1);
690                 my $pagesettings_maxlength_check                = kiriwrite_variablecheck($pagesettings, "maxlength", 1, 1);
691                 my $pagetemplate_maxlength_check                = kiriwrite_variablecheck($pagetemplate, "maxlength", 64, 1);
693                 # Check if an value returned is something else other than 0.
695                 if ($pagefilename_maxlength_check eq 1){
697                         # The page filename given is too long, so return an error.
699                         kiriwrite_error("pagefilenametoolong");
701                 }
703                 if ($pagetitle_maxlength_check eq 1){
705                         # The page title given is too long, so return an error.
707                         kiriwrite_error("pagetitletoolong");
709                 }
711                 if ($pagedescription_maxlength_check eq 1){
713                         # The page description given is too long, so return an error.
715                         kiriwrite_error("pagedescriptiontoolong");
717                 }
719                 if ($pagesection_maxlength_check eq 1){
721                         # The page section given is too long, so return an error.
723                         kiriwrite_error("pagesectiontoolong");
725                 }
727                 if ($pagedatabase_maxlength_check eq 1){
729                         # The page database given is too long, so return an error.
731                         kiriwrite_error("pagedatabasefilenametoolong");
733                 }
735                 if ($pagesettings_maxlength_check eq 1){
737                         # The page settings given is too long, so return an error.
739                         kiriwrite_error("pagesettingstoolong");
741                 }
743                 if ($pagetemplate_maxlength_check eq 1){
745                         # The page template given is too long, so return an error.
747                         kiriwrite_error("pagetemplatefilenametoolong");
749                 }
751                 # The action to create a new page has been confirmed, so add the page to the
752                 # selected database.
754                 if (!$pagefilename){
755                         kiriwrite_error("pagefilenameblank");
756                 }
758                 # Check the page filename and page settings.
760                 my $pagefilename_filename_check = kiriwrite_variablecheck($pagefilename, "page_filename", 0, 1);
761                 my $pagesettings_setting_check  = kiriwrite_variablecheck($pagesettings, "pagesetting", 0, 1);
762                 my $pagetemplate_filename_check = 0;
764                 if ($pagetemplate ne "!none"){
766                         # A template is being used so check the filename of the
767                         # template.
769                         $pagetemplate_filename_check    = kiriwrite_variablecheck($pagetemplate, "page_filename", 0, 1);
771                 }
773                 if ($pagefilename_filename_check ne 0){
775                         # The page filename given is invalid, so return an error.
777                         kiriwrite_error("pagefilenameinvalid");
779                 }
781                 if ($pagesettings_setting_check eq 1){
783                         # The page settings given is invalid, so return an error.
785                         kiriwrite_error("pagesettingsinvalid");
787                 }
789                 if ($pagetemplate_filename_check eq 1){
791                         # The template filename given is invalid, so return an error
793                         kiriwrite_error("templatefilenameinvalid");
795                 }
797                 # Connect to the database server.
799                 $main::kiriwrite_dbmodule->connect();
801                 # Check if the database has write permissions.
803                 my $database_permissions = $main::kiriwrite_dbmodule->dbpermissions($pagedatabase, 1, 1);
805                 if ($database_permissions eq 1){
807                         # The database permissions are invalid so return an error.
809                         kiriwrite_error("databaseinvalidpermissions");
811                 }
813                 # Check if any errors occured while connecting to the database server.
815                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
817                         # A database connection error has occured so return
818                         # an error.
820                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
822                 }
824                 # Select the database to add the page to.
826                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $pagedatabase });
828                 # Check if any errors had occured while selecting the database.
830                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
832                         # The database does not exist, so return an error.
834                         kiriwrite_error("databasemissingfile");
836                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
838                         # The database has invalid permissions set, so return
839                         # an error.
841                         kiriwrite_error("databaseinvalidpermissions");
843                 }
845                 # Get information about the database.
847                 my %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
849                 # Check if any error occured while getting the database information.
851                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
853                         # A database error has occured so return an error and
854                         # also the extended error information.
856                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
858                 };
860                 # Add the page to the selected database.
862                 $main::kiriwrite_dbmodule->addpage({ PageFilename => $pagefilename, PageName => $pagetitle, PageDescription => $pagedescription, PageSection => $pagesection, PageTemplate => $pagetemplate, PageContent => $pagefiledata, PageSettings => $pagesettings });
864                 # Check if any errors occured while adding the page.
866                 if ($main::kiriwrite_dbmodule->geterror eq "PageExists"){
868                         # A page with the filename given already exists so
869                         # return an error.
871                         kiriwrite_error("pagefilenameexists");
873                 } elsif ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
875                         # A database error has occured so return an error
876                         # with extended error information.
878                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
880                 }
882                 my $database_name = $database_info{"DatabaseName"};
884                 # Disconnect from the database server.
886                 $main::kiriwrite_dbmodule->disconnect();
888                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{addpage}, { Style => "pageheader" });
889                 $main::kiriwrite_presmodule->addlinebreak();
890                 $main::kiriwrite_presmodule->addlinebreak();
891                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{pageaddedmessage}, $pagetitle, $database_name));
892                 $main::kiriwrite_presmodule->addlinebreak();
893                 $main::kiriwrite_presmodule->addlinebreak();
894                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $pagedatabase, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{returnpagelist}, $database_name) });
896                 return $main::kiriwrite_presmodule->grab();
898         } elsif ($confirm eq 0) {
900                 # The action to create a new page has not been confirmed, so print out a form
901                 # for adding a page to a database.
903                 my %template_list;
904                 my %template_info;
905                 my @templates_list;
906                 my %database_info;
907                 my $template_filename;
908                 my $template_name;
909                 my $template_data = "";
910                 my $template_warningmessage;
911                 my $template_warning = 0;
912                 my $template_count = 0;
913                 my $template;
915                 tie(%template_list, 'Tie::IxHash');
917                 # Connect to the database server.
919                 $main::kiriwrite_dbmodule->connect();
921                 # Check if any errors occured while connecting to the database server.
923                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
925                         # A database connection error has occured so return
926                         # an error.
928                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
930                 }
932                 # Select the database.
934                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $pagedatabase });
936                 # Check if any errors had occured while selecting the database.
938                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
940                         # The database does not exist, so return an error.
942                         kiriwrite_error("databasemissingfile");
944                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
946                         # The database has invalid permissions set, so return
947                         # an error.
949                         kiriwrite_error("databaseinvalidpermissions");
951                 }
953                 # Check if the database has write permissions.
955                 my $database_permissions = $main::kiriwrite_dbmodule->dbpermissions($pagedatabase, 1, 1);
957                 if ($database_permissions eq 1){
959                         # The database permissions are invalid so return an error.
961                         kiriwrite_error("databaseinvalidpermissions");
963                 }
965                 # Get information about the database.
967                 %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
969                 # Check if any error occured while getting the database information.
971                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
973                         # A database error has occured so return an error and
974                         # also the extended error information.
976                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
978                 };
980                 # Connect to the template database.
982                 $main::kiriwrite_dbmodule->connecttemplate();
984                 # Check if any errors occured while connecting to the template database.
986                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
988                         # The template database does not exist so set the template
989                         # warning message.
991                         $template_warningmessage = $main::kiriwrite_lang{pages}{notemplatedatabase};
992                         $template_warning = 1;
994                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
996                         # The template database has invalid permissions set so write
997                         # the template warning message.
999                         $template_warningmessage = $main::kiriwrite_lang{pages}{templatepermissionserror};
1000                         $template_warning = 1;
1002                 }
1004                 if ($template_warning eq 0){
1006                         # Get the list of templates available.
1008                         @templates_list = $main::kiriwrite_dbmodule->gettemplatelist();
1010                         # Check if any errors had occured.
1012                         if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1014                                 # A database error occured while getting the list
1015                                 # of templates so return a warning message with the 
1016                                 # extended error information.
1018                                 $template_warningmessage = kiriwrite_language($main::kiriwrite_lang{pages}{templatedatabaseerror}, $main::kiriwrite_dbmodule->geterror(1));
1019                                 $template_warning = 1;
1021                         }
1023                         if ($template_warning eq 0){
1025                                 # Check to see if there are any templates in the templates
1026                                 # list array.
1028                                 my $template_filename = "";
1029                                 my $template_name = "";
1031                                 foreach $template (@templates_list){
1033                                         # Get information about the template.
1035                                         %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template });
1037                                         # Check if any error occured while getting the template information.
1039                                         if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1041                                                 # A database error has occured, so return an error.
1043                                                 kiriwrite_error("templatedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
1045                                         } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
1047                                                 # The template does not exist, so process the next template.
1049                                                 next;
1051                                         }
1053                                         # Get the template filename and name.
1055                                         $template_filename = $template_info{"TemplateFilename"};
1056                                         $template_name = $template_info{"TemplateName"};
1058                                         $template_list{$template_count}{Filename} = $template_filename;
1059                                         $template_list{$template_count}{Name} = $template_name;
1061                                         $template_count++;
1063                                 }
1065                                 # Check if the final template list is blank.
1067                                 if (!%template_list){
1069                                         # The template list is blank so write the template
1070                                         # warning message.
1072                                         $template_warningmessage = $main::kiriwrite_lang->{pages}->{notemplatesavailable};
1074                                 }
1076                         }
1078                 }
1080                 my $database_name       = $database_info{"DatabaseName"};
1082                 # Disconnect from the template database.
1084                 $main::kiriwrite_dbmodule->disconnecttemplate();
1086                 # Disconnect from the database server.
1088                 $main::kiriwrite_dbmodule->disconnect();
1090                 # write out the form for adding a page.
1092                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{addpage}, { Style => "pageheader" });
1093                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");#
1094                 $main::kiriwrite_presmodule->startbox();
1095                 $main::kiriwrite_presmodule->addhiddendata("mode", "page");
1096                 $main::kiriwrite_presmodule->addhiddendata("action", "add");
1097                 $main::kiriwrite_presmodule->addhiddendata("database", $pagedatabase);
1098                 $main::kiriwrite_presmodule->addhiddendata("confirm", "1");
1099                 $main::kiriwrite_presmodule->addlinebreak();
1100                 $main::kiriwrite_presmodule->endbox();
1101                 $main::kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
1103                 $main::kiriwrite_presmodule->startheader();
1104                 $main::kiriwrite_presmodule->addcell("tablecellheader");
1105                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{setting});
1106                 $main::kiriwrite_presmodule->endcell();
1107                 $main::kiriwrite_presmodule->addcell("tablecellheader");
1108                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{value});
1109                 $main::kiriwrite_presmodule->endcell();
1110                 $main::kiriwrite_presmodule->endheader();
1112                 $main::kiriwrite_presmodule->startrow();
1113                 $main::kiriwrite_presmodule->addcell("tablecell1");
1114                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{database});
1115                 $main::kiriwrite_presmodule->endcell();
1116                 $main::kiriwrite_presmodule->addcell("tablecell2");
1117                 $main::kiriwrite_presmodule->addtext($database_name);
1118                 $main::kiriwrite_presmodule->endcell();
1119                 $main::kiriwrite_presmodule->endrow();
1121                 $main::kiriwrite_presmodule->startrow();
1122                 $main::kiriwrite_presmodule->addcell("tablecell1");
1123                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagename});
1124                 $main::kiriwrite_presmodule->endcell();
1125                 $main::kiriwrite_presmodule->addcell("tablecell2");
1126                 $main::kiriwrite_presmodule->addinputbox("pagename", { Size => 64, MaxLength => 512 });
1127                 $main::kiriwrite_presmodule->endcell();
1128                 $main::kiriwrite_presmodule->endrow();
1130                 $main::kiriwrite_presmodule->startrow();
1131                 $main::kiriwrite_presmodule->addcell("tablecell1");
1132                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagedescription});
1133                 $main::kiriwrite_presmodule->endcell();
1134                 $main::kiriwrite_presmodule->addcell("tablecell2");
1135                 $main::kiriwrite_presmodule->addinputbox("pagedescription", { Size => 64, MaxLength => 512 });
1136                 $main::kiriwrite_presmodule->endcell();
1137                 $main::kiriwrite_presmodule->endrow();
1139                 $main::kiriwrite_presmodule->startrow();
1140                 $main::kiriwrite_presmodule->addcell("tablecell1");
1141                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagesection});
1142                 $main::kiriwrite_presmodule->endcell();
1143                 $main::kiriwrite_presmodule->addcell("tablecell2");
1144                 $main::kiriwrite_presmodule->addinputbox("pagesection", { Size => 64, MaxLength => 256 });
1145                 $main::kiriwrite_presmodule->endcell();
1146                 $main::kiriwrite_presmodule->endrow();
1148                 $main::kiriwrite_presmodule->startrow();
1149                 $main::kiriwrite_presmodule->addcell("tablecell1");
1150                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagetemplate});
1151                 $main::kiriwrite_presmodule->endcell();
1152                 $main::kiriwrite_presmodule->addcell("tablecell2");
1154                 # Check if the template warning value has been set
1155                 # and write the error message in place of the templates
1156                 # list if it is.
1158                 if ($template_warning eq 1){
1160                         $main::kiriwrite_presmodule->addhiddendata("pagetemplate", "!none");
1161                         $main::kiriwrite_presmodule->addtext($template_warningmessage);
1163                 } else {
1165                         my $template_file;
1166                         my $page_filename;
1167                         my $page_name;
1169                         $main::kiriwrite_presmodule->addselectbox("pagetemplate");
1171                         foreach $template_file (keys %template_list){
1173                                 $page_filename  = $template_list{$template_file}{Filename};
1174                                 $page_name      = $template_list{$template_file}{Name};
1175                                 $main::kiriwrite_presmodule->addoption($page_name . " (" . $page_filename . ")", { Value => $page_filename });
1176                                 $template_count++;
1178                                 $template_count = 0;
1179                         }
1181                         $main::kiriwrite_presmodule->addoption($main::kiriwrite_lang{pages}{usenotemplate}, { Value => "!none", Selected => 1 });
1182                         $main::kiriwrite_presmodule->endselectbox();
1184                 }
1186                 $main::kiriwrite_presmodule->endcell();
1187                 $main::kiriwrite_presmodule->endrow();
1189                 $main::kiriwrite_presmodule->startrow();
1190                 $main::kiriwrite_presmodule->addcell("tablecell1");
1191                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagefilename});
1192                 $main::kiriwrite_presmodule->endcell();
1193                 $main::kiriwrite_presmodule->addcell("tablecell2");
1194                 $main::kiriwrite_presmodule->addinputbox("pagefilename", { Size => 64, MaxLength => 256 });
1195                 $main::kiriwrite_presmodule->endcell();
1196                 $main::kiriwrite_presmodule->endrow();
1198                 $main::kiriwrite_presmodule->startrow();
1199                 $main::kiriwrite_presmodule->addcell("tablecell1");
1200                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagecontent});
1201                 $main::kiriwrite_presmodule->endcell();
1202                 $main::kiriwrite_presmodule->addcell("tablecell2");
1203                 $main::kiriwrite_presmodule->addtextbox("pagecontent", { Columns => $main::kiriwrite_config{"display_textareacols"}, Rows => $main::kiriwrite_config{"display_textarearows"} });
1204                 $main::kiriwrite_presmodule->addlinebreak();
1205                 $main::kiriwrite_presmodule->addlinebreak();
1206                 $main::kiriwrite_presmodule->startbox("datalist");
1207                 $main::kiriwrite_presmodule->addboldtext($main::kiriwrite_lang{common}{tags});
1208                 $main::kiriwrite_presmodule->addlinebreak();
1209                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagetitle});
1210                 $main::kiriwrite_presmodule->addlinebreak();
1211                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagename});
1212                 $main::kiriwrite_presmodule->addlinebreak();
1213                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagedescription});
1214                 $main::kiriwrite_presmodule->addlinebreak();
1215                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagesection});
1216                 $main::kiriwrite_presmodule->addlinebreak();
1217                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pageautosection});
1218                 $main::kiriwrite_presmodule->addlinebreak();
1219                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pageautotitle});
1220                 $main::kiriwrite_presmodule->addlinebreak();
1221                 $main::kiriwrite_presmodule->endbox();
1222                 $main::kiriwrite_presmodule->endcell();
1223                 $main::kiriwrite_presmodule->endrow();
1225                 $main::kiriwrite_presmodule->startrow();
1226                 $main::kiriwrite_presmodule->addcell("tablecell1");
1227                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagesettings});
1228                 $main::kiriwrite_presmodule->endcell();
1229                 $main::kiriwrite_presmodule->addcell("tablecell2");
1230                 $main::kiriwrite_presmodule->addradiobox("pagesettings", { Description => $main::kiriwrite_lang{pages}{usepageandsection}, Value => "1", Selected => 1, LineBreak => 1});
1231                 $main::kiriwrite_presmodule->addradiobox("pagesettings", { Description => $main::kiriwrite_lang{pages}{usepagename}, Value => "2", Selected => 0, LineBreak => 1});
1232                 $main::kiriwrite_presmodule->addradiobox("pagesettings", { Description => $main::kiriwrite_lang{pages}{usesectionname}, Value => "3", Selected => 0, LineBreak => 1});
1233                 $main::kiriwrite_presmodule->addradiobox("pagesettings", { Description => $main::kiriwrite_lang{pages}{nopagesection}, Value => "0", Selected => 0, LineBreak => 1});
1234                 $main::kiriwrite_presmodule->endcell();
1235                 $main::kiriwrite_presmodule->endrow();
1237                 $main::kiriwrite_presmodule->endtable();
1239                 $main::kiriwrite_presmodule->startbox();
1240                 $main::kiriwrite_presmodule->addlinebreak();
1241                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{pages}{addpagebutton});
1242                 $main::kiriwrite_presmodule->addtext(" | ");
1243                 $main::kiriwrite_presmodule->addreset($main::kiriwrite_lang{common}{clearvalues});
1244                 $main::kiriwrite_presmodule->addtext(" | ");
1245                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $pagedatabase, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{returnpagelist}, $database_name) });
1246                 $main::kiriwrite_presmodule->endbox();
1247                 $main::kiriwrite_presmodule->endform();
1250                 return $main::kiriwrite_presmodule->grab();
1252         } else {
1254                 # The confirm value is something else than '1' or '0' so
1255                 # return an error.
1257                 kiriwrite_error("invalidvalue");
1259         }
1263 sub kiriwrite_page_edit{
1264 #################################################################################
1265 # kiriwrite_page_edit: Edits a page from a database.                            #
1266 #                                                                               #
1267 # Usage:                                                                        #
1268 #                                                                               #
1269 # kiriwrite_page_edit(database, filename, newfilename, newname, newdescription, #
1270 #                       newsection, newtemplate,  newsettings, newpagecontent   #
1271 #                       confirm);                                               #
1272 #                                                                               #
1273 # database       Specifies the database to edit from.                           #
1274 # filename       Specifies the filename to use.                                 #
1275 # newfilename    Specifies the new page filename to use.                        #
1276 # newname        Specifies the new page name to use.                            #
1277 # newdescription Specifies the new description for the page.                    #
1278 # newsection     Specifies the new section name to use.                         #
1279 # newtemplate    Specifies the new template filename to use.                    #
1280 # newsettings    Specifies the new page settings to use.                        #
1281 # newpagecontent Specifies the new page content to use.                         #
1282 # confirm        Confirms the action to edit the page.                          #
1283 #################################################################################
1285         # Get the values that have been passed to the subroutine.
1287         my ($database, $pagefilename, $pagenewfilename, $pagenewtitle, $pagenewdescription, $pagenewsection, $pagenewtemplate, $pagenewsettings, $pagenewcontent, $confirm) = @_;
1289         # Check if the confirm value is blank and if it is, then set it to '0'.
1291         if (!$confirm){
1293                 $confirm = 0;
1295         }
1297         # Check if the confirm value is more than one character long and if it
1298         # is then return an error.
1300         kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
1302         # Check if the database filename is valid and return an error if
1303         # it isn't.
1305         my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1);
1307         if ($pagedatabase_filename_check eq 1){
1309                 # The database filename is blank, so return an error.
1311                 kiriwrite_error("blankdatabasepageadd");
1313         } elsif ($pagedatabase_filename_check eq 2){
1315                 # The database filename is invalid, so return an error.
1317                 kiriwrite_error("databasefilenameinvalid");
1319         }
1321         # Check the length the database name and return an error if it's
1322         # too long.
1324         my $pagedatabase_length_check   = kiriwrite_variablecheck($database, "maxlength", 32, 1);
1326         if ($pagedatabase_length_check eq 1){
1328                 # The database name is too long, so return an error.
1330                 kiriwrite_error("databasefilenametoolong");
1332         }
1334         # Check if the page identification number is blank (which it shouldn't
1335         # be) and if it is, then return an error.
1337         if (!$pagefilename){
1339                 kiriwrite_error("blankfilename");
1341         }
1343         # Check if the confirm value is '1' and if it is, edit the specified
1344         # page in the database.
1346         if ($confirm eq 1){
1348                 # Check if the new page filename is blank.
1350                 if (!$pagenewfilename){
1352                         # The page filename is blank so return an error.
1354                         kiriwrite_error("pagefilenameblank");
1356                 }
1358                 # The action to edit a page has been confirmed so check the
1359                 # variables recieved are UTF8 compiliant before converting.
1361                 kiriwrite_variablecheck($database, "utf8", 0, 0);
1362                 kiriwrite_variablecheck($pagefilename, "utf8", 0, 0);
1363                 kiriwrite_variablecheck($pagenewfilename, "utf8", 0, 0);
1364                 kiriwrite_variablecheck($pagenewtitle, "utf8", 0, 0);
1365                 kiriwrite_variablecheck($pagenewdescription, "utf8", 0, 0);
1366                 kiriwrite_variablecheck($pagenewsection, "utf8", 0, 0);
1367                 kiriwrite_variablecheck($pagenewsettings, "utf8", 0, 0);
1368                 kiriwrite_variablecheck($pagenewtemplate, "utf8", 0, 0);
1369                 kiriwrite_variablecheck($pagenewcontent, "utf8", 0, 0);
1371                 # Convert the variables into proper UTF8 variables.
1373                 $database               = kiriwrite_utf8convert($database);
1374                 $pagefilename           = kiriwrite_utf8convert($pagefilename);
1375                 $pagenewfilename        = kiriwrite_utf8convert($pagenewfilename);
1376                 $pagenewtitle           = kiriwrite_utf8convert($pagenewtitle);
1377                 $pagenewdescription     = kiriwrite_utf8convert($pagenewdescription);
1378                 $pagenewsection         = kiriwrite_utf8convert($pagenewsection);
1379                 $pagenewsettings        = kiriwrite_utf8convert($pagenewsettings);
1380                 $pagenewtemplate        = kiriwrite_utf8convert($pagenewtemplate);
1381                 $pagenewcontent         = kiriwrite_utf8convert($pagenewcontent);
1383                 # Check the lengths of the variables.
1385                 my $pagenewfilename_maxlength_check     = kiriwrite_variablecheck($pagenewfilename, "maxlength", 256, 1);
1386                 my $pagenewtitle_maxlength_check        = kiriwrite_variablecheck($pagenewtitle, "maxlength", 512, 1);
1387                 my $pagenewdescription_maxlength_check  = kiriwrite_variablecheck($pagenewdescription, "maxlength", 512, 1);
1388                 my $pagenewsection_maxlength_check      = kiriwrite_variablecheck($pagenewsection, "maxlength", 256, 1);
1389                 my $pagenewsettings_maxlength_check     = kiriwrite_variablecheck($pagenewsettings, "maxlength", 1, 1);
1390                 my $pagenewtemplate_maxlength_check     = kiriwrite_variablecheck($pagenewtemplate, "maxlength", 64, 1);
1392                 # Check each result to see if the length of the variable
1393                 # is valid and return an error if it isn't.
1395                 if ($pagenewfilename_maxlength_check eq 1){
1397                         # The new page filename given is too long, so return an error.
1399                         kiriwrite_error("pagefilenametoolong");
1401                 }
1403                 if ($pagenewtitle_maxlength_check eq 1){
1405                         # The new page title given is too long, so return an error.
1407                         kiriwrite_error("pagetitletoolong");
1409                 }
1411                 if ($pagenewdescription_maxlength_check eq 1){
1413                         # The new page description given is too long, so return an error.
1415                         kiriwrite_error("pagedescriptiontoolong");
1417                 }
1419                 if ($pagenewsection_maxlength_check eq 1){
1421                         # The new page section given is too long, so return an error.
1423                         kiriwrite_error("pagesectiontoolong");
1425                 }
1427                 if ($pagenewsettings_maxlength_check eq 1){
1429                         # The new page settings given is too long, so return an error.
1431                         kiriwrite_error("pagesettingstoolong");
1433                 }
1435                 if ($pagenewtemplate_maxlength_check eq 1){
1437                         # The new page template given is too long, so return an error.
1439                         kiriwrite_error("pagetemplatefilenametoolong");
1441                 }
1443                 # Check if the new page filename and new page settings
1444                 # are valid.
1446                 my $pagenewfilename_filename_check      = kiriwrite_variablecheck($pagenewfilename, "page_filename", 0, 1);
1447                 my $pagenewsettings_settings_check      = kiriwrite_variablecheck($pagenewsettings, "pagesetting", 0, 1);
1448                 my $pagetemplate_filename_check = 0;
1450                 if ($pagenewtemplate ne "!none"){
1452                         # A template is being used so check the filename of the
1453                         # template.
1455                         $pagetemplate_filename_check    = kiriwrite_variablecheck($pagenewtemplate, "page_filename", 0, 1);
1457                 }
1459                 # Check each result to see if the variables have passed
1460                 # their tests and return an error if they haven't.
1462                 if ($pagenewfilename_filename_check ne 0){
1464                         # The new page filename is invalid, so return an error.
1466                         kiriwrite_error("pagefilenameinvalid");
1468                 }
1470                 if ($pagenewsettings_settings_check eq 1){
1472                         # The new page settings is invalid, so return an error.
1474                         kiriwrite_error("pagesettingsinvalid");
1476                 }
1478                 if ($pagetemplate_filename_check eq 1){
1480                         # The template filename given is invalid, so return an error
1482                         kiriwrite_error("templatefilenameinvalid");
1484                 }
1486                 # Connect to the database server.
1488                 $main::kiriwrite_dbmodule->connect();
1490                 # Check if any errors occured while connecting to the database server.
1492                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1494                         # A database connection error has occured so return
1495                         # an error.
1497                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
1499                 }
1501                 # Select the database.
1503                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
1505                 # Check if any errors had occured while selecting the database.
1507                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
1509                         # The database does not exist, so return an error.
1511                         kiriwrite_error("databasemissingfile");
1513                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
1515                         # The database has invalid permissions set, so return
1516                         # an error.
1518                         kiriwrite_error("databaseinvalidpermissions");
1520                 }
1522                 # Check if the database has write permissions.
1524                 my $database_permissions = $main::kiriwrite_dbmodule->dbpermissions($database, 1, 1);
1526                 if ($database_permissions eq 1){
1528                         # The database permissions are invalid so return an error.
1530                         kiriwrite_error("databaseinvalidpermissions");
1532                 }
1534                 # Get the database information.
1536                 my %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
1538                 # Check if any errors had occured while getting the database information.
1540                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
1542                         # A database error has occured so return an error and
1543                         # also the extended error information.
1545                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
1547                 };
1549                 my $database_name = $database_info{"DatabaseName"};
1551                 # Edit the selected page.
1553                 $main::kiriwrite_dbmodule->editpage({ PageFilename => $pagefilename, PageNewFilename => $pagenewfilename, PageNewName => $pagenewtitle, PageNewDescription => $pagenewdescription, PageNewSection => $pagenewsection, PageNewTemplate => $pagenewtemplate, PageNewContent => $pagenewcontent, PageNewSettings => $pagenewsettings });
1555                 # Check if any errors occured while editing the page.
1557                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
1559                         # A database error has occured so return an error and
1560                         # also the extended error information.
1562                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
1564                 } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
1566                         # The pages does not exist in the database.
1568                         kiriwrite_error("pagefilenamedoesnotexist");
1570                 } elsif ($main::kiriwrite_dbmodule->geterror eq "PageExists"){
1572                         # A page already exists with the new filename.
1574                         kiriwrite_error("pagefilenameexists");
1576                 }
1578                 # Disconnect from the database server.
1580                 $main::kiriwrite_dbmodule->disconnect();
1582                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{editedpage}, { Style => "pageheader" });
1583                 $main::kiriwrite_presmodule->addlinebreak();
1584                 $main::kiriwrite_presmodule->addlinebreak();
1585                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{editedpagemessage}, $pagenewtitle));
1586                 $main::kiriwrite_presmodule->addlinebreak();
1587                 $main::kiriwrite_presmodule->addlinebreak();
1588                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{returnpagelist}, $database_name) });
1590                 return $main::kiriwrite_presmodule->grab();
1592         } elsif ($confirm eq 0) {
1594                 # Connect to the database server.
1596                 $main::kiriwrite_dbmodule->connect();
1598                 # Check if any errors occured while connecting to the database server.
1600                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1602                         # A database connection error has occured so return
1603                         # an error.
1605                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
1607                 }
1609                 # Select the database.
1611                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
1613                 # Check if any errors had occured while selecting the database.
1615                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
1617                         # The database does not exist, so return an error.
1619                         kiriwrite_error("databasemissingfile");
1621                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
1623                         # The database has invalid permissions set, so return
1624                         # an error.
1626                         kiriwrite_error("databaseinvalidpermissions");
1628                 }
1630                 # Get the information about the database.
1632                 my %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
1634                 # Check if any errors had occured while getting the database information.
1636                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
1638                         # A database error has occured so return an error and
1639                         # also the extended error information.
1641                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
1643                 };
1645                 my $database_name = $database_info{"DatabaseName"};
1647                 # Get the page info.
1649                 my %page_info = $main::kiriwrite_dbmodule->getpageinfo({ PageFilename => $pagefilename });
1651                 # Check if any errors occured while getting the page information.
1653                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
1655                         # A database error has occured so return an error and
1656                         # also the extended error information.
1658                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
1660                 } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
1662                         # The page does not exist, so return an error.
1664                         kiriwrite_error("pagefilenamedoesnotexist");
1666                 }
1668                 # Get the values from the hash.
1670                 my $data_filename               = $page_info{"PageFilename"};
1671                 my $data_name                   = $page_info{"PageName"};
1672                 my $data_description            = $page_info{"PageDescription"};
1673                 my $data_section                = $page_info{"PageSection"};
1674                 my $data_template               = $page_info{"PageTemplate"};
1675                 my $data_content                = $page_info{"PageContent"};
1676                 my $data_settings               = $page_info{"PageSettings"};
1677                 my $data_lastmodified           = $page_info{"PageLastModified"};
1679                 my $template_warning;
1680                 my $page_count = 0;
1681                 my %template_list;
1682                 my %template_info;
1683                 my @database_pages;
1684                 my @database_info;
1685                 my @database_templates;
1686                 my @template_filenames;
1687                 my $template_file;
1688                 my $template_filename;
1689                 my $template_name;
1690                 my $template_count = 0;
1691                 my $template_found = 0;
1693                 tie(%template_list, 'Tie::IxHash');
1695                 # Connect to the template database.
1697                 $main::kiriwrite_dbmodule->connecttemplate();
1699                 # Check if any errors occured while connecting to the template database.
1701                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
1703                         # The template database does not exist so set the template
1704                         # warning message.
1706                         $template_warning = $main::kiriwrite_lang{pages}{notemplatedatabasekeep};
1708                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
1710                         # The template database has invalid permissions set so write
1711                         # the template warning message.
1713                         $template_warning = $main::kiriwrite_lang{pages}{templatepermissionserrorkeep};
1715                 }
1717                 if (!$template_warning){
1719                         # Get the list of available templates.
1721                         @template_filenames = $main::kiriwrite_dbmodule->gettemplatelist();
1723                         # Check if any errors had occured.
1725                         if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1727                                 # A database error occured while getting the list
1728                                 # of templates so return an error with the 
1729                                 # extended error information.
1731                                 $template_warning = kiriwrite_language($main::kiriwrite_lang{pages}{templatedatabaseerrorkeep} , $main::kiriwrite_dbmodule->geterror(1));
1733                         }
1735                         if (!$template_warning){
1737                                 foreach $template_filename (@template_filenames){
1739                                         # Get the information about each template.
1741                                         %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_filename });
1743                                         # Check if any errors occured while getting the template information.
1745                                         if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1747                                                 # A template database error has occured so return a warning message
1748                                                 # with the extended error information.
1750                                                 $template_warning = kiriwrite_language($main::kiriwrite_lang{pages}{templatedatabaseerrorkeep} , $main::kiriwrite_dbmodule->geterror(1));
1751                                                 last;
1753                                         } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
1755                                                 # The template does not exist so process the next template.
1757                                                 next;
1759                                         }
1761                                         # Append the template name and filename to the list of available templates.
1763                                         $template_list{$template_count}{Filename} = $template_info{"TemplateFilename"};
1764                                         $template_list{$template_count}{Name}     = $template_info{"TemplateName"};
1766                                         # Append the template filename and name and make it the selected
1767                                         # template if that is the template the page is using.
1769                                         if ($data_template eq $template_filename && !$template_found){
1771                                                 $template_list{$template_count}{Selected}       = 1;
1772                                                 $template_found = 1;
1774                                         } else {
1776                                                 $template_list{$template_count}{Selected}       = 0;
1778                                         }
1780                                         $template_count++;
1782                                 }
1784                         }
1786                 }
1788                 # Check if certain values are undefined and if they
1789                 # are then set them blank (defined).
1791                 if (!$data_name){
1792                         $data_name = "";
1793                 }
1795                 if (!$data_description){
1796                         $data_description = "";
1797                 }
1799                 if (!$data_section){
1800                         $data_section = "";
1801                 }
1803                 if (!$data_template){
1804                         $data_template = "";
1806                 }
1808                 if (!$data_content){
1809                         $data_content = "";
1810                 }
1812                 if (!$data_settings){
1813                         $data_settings = "";
1814                 }
1816                 if (!$data_lastmodified){
1817                         $data_lastmodified = "";
1818                 }
1820                 # Begin writing out the form for editing the selected page.
1822                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{editpage}, $data_name), { Style => "pageheader" });
1823                 $main::kiriwrite_presmodule->addlinebreak();
1824                 $main::kiriwrite_presmodule->addlinebreak();
1826                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1827                 $main::kiriwrite_presmodule->startbox();
1828                 $main::kiriwrite_presmodule->addhiddendata("mode", "page");
1829                 $main::kiriwrite_presmodule->addhiddendata("action", "edit");
1830                 $main::kiriwrite_presmodule->addhiddendata("database", $database);
1831                 $main::kiriwrite_presmodule->addhiddendata("page", $pagefilename);
1832                 $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
1833                 $main::kiriwrite_presmodule->endbox();
1835                 $main::kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
1837                 $main::kiriwrite_presmodule->startheader();
1838                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{setting}, { Style => "tablecellheader" });
1839                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{value}, { Style => "tablecellheader" });
1840                 $main::kiriwrite_presmodule->endheader();
1842                 $main::kiriwrite_presmodule->startrow();
1843                 $main::kiriwrite_presmodule->addcell("tablecell1");
1844                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{database});
1845                 $main::kiriwrite_presmodule->endcell();
1846                 $main::kiriwrite_presmodule->addcell("tablecell2");
1847                 $main::kiriwrite_presmodule->addtext($database_name);
1848                 $main::kiriwrite_presmodule->endcell();
1849                 $main::kiriwrite_presmodule->endrow();
1851                 $main::kiriwrite_presmodule->startrow();
1852                 $main::kiriwrite_presmodule->addcell("tablecell1");
1853                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagename});
1854                 $main::kiriwrite_presmodule->endcell();
1855                 $main::kiriwrite_presmodule->addcell("tablecell2");
1856                 $main::kiriwrite_presmodule->addinputbox("pagename", { Size => 64, MaxLength => 512, Value => $data_name });
1857                 $main::kiriwrite_presmodule->endcell();
1858                 $main::kiriwrite_presmodule->endrow();
1860                 $main::kiriwrite_presmodule->startrow();
1861                 $main::kiriwrite_presmodule->addcell("tablecell1");
1862                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagedescription});
1863                 $main::kiriwrite_presmodule->endcell();
1864                 $main::kiriwrite_presmodule->addcell("tablecell2");
1865                 $main::kiriwrite_presmodule->addinputbox("pagedescription", { Size => 64, MaxLength => 512, Value => $data_description });
1866                 $main::kiriwrite_presmodule->endcell();
1867                 $main::kiriwrite_presmodule->endrow();
1869                 $main::kiriwrite_presmodule->startrow();
1870                 $main::kiriwrite_presmodule->addcell("tablecell1");
1871                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagesection});
1872                 $main::kiriwrite_presmodule->endcell();
1873                 $main::kiriwrite_presmodule->addcell("tablecell2");
1874                 $main::kiriwrite_presmodule->addinputbox("pagesection", { Size => 64, MaxLength => 256, Value => $data_section });
1875                 $main::kiriwrite_presmodule->endcell();
1876                 $main::kiriwrite_presmodule->endrow();
1878                 $main::kiriwrite_presmodule->startrow();
1879                 $main::kiriwrite_presmodule->addcell("tablecell1");
1880                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagetemplate});
1881                 $main::kiriwrite_presmodule->endcell();
1882                 $main::kiriwrite_presmodule->addcell("tablecell2");
1884                 # Check if any template warnings have occured.
1886                 if ($template_warning){
1888                         $main::kiriwrite_presmodule->addtext($template_warning);
1889                         $main::kiriwrite_presmodule->addlinebreak();
1891                 }
1893                 $main::kiriwrite_presmodule->addselectbox("pagetemplate");
1895                 # Process the list of templates, select one if the
1896                 # template filename for the page matches, else give
1897                 # an option for the user to keep the current template
1898                 # filename.
1900                 $template_count = 0;
1902                 foreach $template_file (keys %template_list){
1904                         if ($template_list{$template_count}{Selected}){
1906                                 $main::kiriwrite_presmodule->addoption($template_list{$template_count}{Name} . " (" . $template_list{$template_count}{Filename} . ")", { Value => $template_list{$template_count}{Filename}, Selected => 1 });
1908                         } else {
1910                                 $main::kiriwrite_presmodule->addoption($template_list{$template_count}{Name} . " (" . $template_list{$template_count}{Filename} . ")", { Value => $template_list{$template_count}{Filename} });
1912                         }
1914                         $template_count++;
1916                 }
1918                 if ($data_template eq "!none"){
1920                         $main::kiriwrite_presmodule->addoption($main::kiriwrite_lang{pages}{usenotemplate}, { Value => "!none", Selected => 1 });
1921                         $template_found = 1;
1923                 } else {
1925                         $main::kiriwrite_presmodule->addoption($main::kiriwrite_lang{pages}{usenotemplate}, { Value => "!none" });
1927                 }
1929                 if ($template_found eq 0 && $data_template ne "!none"){
1931                         # The template with the filename given was not found.
1933                         $main::kiriwrite_presmodule->addoption(kiriwrite_language($main::kiriwrite_lang{pages}{keeptemplatefilename}, $data_template), { Value => $data_template, Selected => 1, Style => "warningoption" });
1935                 }
1937                 # Disconnect from the template database.
1939                 $main::kiriwrite_dbmodule->disconnecttemplate();
1941                 # Disconnect from the database server.
1943                 $main::kiriwrite_dbmodule->disconnect();
1945                 $main::kiriwrite_presmodule->endselectbox();
1947                 $main::kiriwrite_presmodule->endcell();
1948                 $main::kiriwrite_presmodule->endrow();
1950                 $main::kiriwrite_presmodule->startrow();
1951                 $main::kiriwrite_presmodule->addcell("tablecell1");
1952                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagefilename});
1953                 $main::kiriwrite_presmodule->endcell();
1954                 $main::kiriwrite_presmodule->addcell("tablecell2");
1955                 $main::kiriwrite_presmodule->addinputbox("pagefilename", { Size => 64, MaxLength => 256, Value => $data_filename });
1956                 $main::kiriwrite_presmodule->endcell();
1957                 $main::kiriwrite_presmodule->endrow();
1959                 $main::kiriwrite_presmodule->startrow();
1960                 $main::kiriwrite_presmodule->addcell("tablecell1");
1961                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagecontent});
1962                 $main::kiriwrite_presmodule->endcell();
1963                 $main::kiriwrite_presmodule->addcell("tablecell2");
1964                 $main::kiriwrite_presmodule->addtextbox("pagecontent", { Columns => $main::kiriwrite_config{"display_textareacols"}, Rows => $main::kiriwrite_config{"display_textarearows"},  Value => $data_content });
1965                 $main::kiriwrite_presmodule->addlinebreak();
1966                 $main::kiriwrite_presmodule->addlinebreak();
1967                 $main::kiriwrite_presmodule->startbox("datalist");
1968                 $main::kiriwrite_presmodule->addboldtext($main::kiriwrite_lang{common}{tags});
1969                 $main::kiriwrite_presmodule->addlinebreak();
1970                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagetitle});
1971                 $main::kiriwrite_presmodule->addlinebreak();
1972                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagename});
1973                 $main::kiriwrite_presmodule->addlinebreak();
1974                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagedescription});
1975                 $main::kiriwrite_presmodule->addlinebreak();
1976                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagesection});
1977                 $main::kiriwrite_presmodule->addlinebreak();
1978                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pageautosection});
1979                 $main::kiriwrite_presmodule->addlinebreak();
1980                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pageautotitle});
1981                 $main::kiriwrite_presmodule->addlinebreak();
1982                 $main::kiriwrite_presmodule->endbox();
1983                 $main::kiriwrite_presmodule->endcell();
1984                 $main::kiriwrite_presmodule->endrow();
1986                 $main::kiriwrite_presmodule->startrow();
1987                 $main::kiriwrite_presmodule->addcell("tablecell1");
1988                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagesettings});
1989                 $main::kiriwrite_presmodule->endcell();
1990                 $main::kiriwrite_presmodule->addcell("tablecell2");
1992                 # Check if the page settings value is set to a 
1993                 # certain number and select that option based
1994                 # on the number else set the value to 0.
1996                 if ($data_settings eq 1){
1997                         $main::kiriwrite_presmodule->addradiobox("pagesettings", { Description => $main::kiriwrite_lang{pages}{usepageandsection}, Value => "1", Selected => 1, LineBreak => 1});
1998                 } else {
1999                         $main::kiriwrite_presmodule->addradiobox("pagesettings", { Description => $main::kiriwrite_lang{pages}{usepageandsection}, Value => "1", LineBreak => 1});
2000                 }
2002                 if ($data_settings eq 2){
2003                         $main::kiriwrite_presmodule->addradiobox("pagesettings", { Description => $main::kiriwrite_lang{pages}{usepagename}, Value => "2", Selected => 1, LineBreak => 1});
2004                 } else {
2005                         $main::kiriwrite_presmodule->addradiobox("pagesettings", { Description => $main::kiriwrite_lang{pages}{usepagename}, Value => "2", LineBreak => 1});
2006                 }
2008                 if ($data_settings eq 3){
2009                         $main::kiriwrite_presmodule->addradiobox("pagesettings", { Description => $main::kiriwrite_lang{pages}{usesectionname}, Value => "3", Selected => 1, LineBreak => 1});
2010                 } else {
2011                         $main::kiriwrite_presmodule->addradiobox("pagesettings", { Description => $main::kiriwrite_lang{pages}{usesectionname}, Value => "3", LineBreak => 1});
2012                 }
2014                 if ($data_settings eq 0 || ($data_settings ne 1 && $data_settings ne 2 && $data_settings ne 3)){
2015                         $main::kiriwrite_presmodule->addradiobox("pagesettings", { Description => $main::kiriwrite_lang{pages}{nopagesection}, Value => "0", Selected => 1, LineBreak => 1});
2016                 } else {
2017                         $main::kiriwrite_presmodule->addradiobox("pagesettings", { Description => $main::kiriwrite_lang{pages}{nopagesection}, Value => "0", LineBreak => 1});
2018                 }
2020                 $main::kiriwrite_presmodule->endcell();
2021                 $main::kiriwrite_presmodule->endrow();
2022                 $main::kiriwrite_presmodule->endtable();
2024                 $main::kiriwrite_presmodule->startbox();
2025                 $main::kiriwrite_presmodule->addlinebreak();
2026                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{pages}{editpagebutton});
2027                 $main::kiriwrite_presmodule->addtext(" | ");
2028                 $main::kiriwrite_presmodule->addreset($main::kiriwrite_lang{common}{restorecurrent});
2029                 $main::kiriwrite_presmodule->addtext(" | ");
2030                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{returnpagelist}, $database_name) } );
2031                 $main::kiriwrite_presmodule->endbox();
2033                 $main::kiriwrite_presmodule->endform();
2035                 return $main::kiriwrite_presmodule->grab();
2037         } else {
2039                 # The confirm value is a value other than '0' and '1' so
2040                 # return an error.
2042                 kiriwrite_error("invalidvalue");
2044         }
2048 sub kiriwrite_page_delete{
2049 #################################################################################
2050 # kiriwrite_page_delete: Deletes a (single) page from a database.               #
2051 #                                                                               #
2052 # Usage:                                                                        #
2053 #                                                                               #
2054 # kiriwrite_page_delete(database, page, [confirm]);                             #
2055 #                                                                               #
2056 # database      Specifies the database to delete from.                          #
2057 # page          Specifies the page to delete.                                   #
2058 # confirm       Confirms the action to delete the page.                         #
2059 #################################################################################
2061         my ($database, $page, $confirm) = @_;
2063         # Check if the database filename is valid and return an error if
2064         # it isn't.
2066         my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1);
2068         if ($pagedatabase_filename_check eq 1){
2070                 # The database filename is blank, so return an error.
2072                 kiriwrite_error("blankdatabasepageadd");
2074         } elsif ($pagedatabase_filename_check eq 2){
2076                 # The database filename is invalid, so return an error.
2078                 kiriwrite_error("databasefilenameinvalid");
2080         }
2082         # Check the length the database name and return an error if it's
2083         # too long.
2085         my $pagedatabase_length_check   = kiriwrite_variablecheck($database, "maxlength", 32, 1);
2087         if ($pagedatabase_length_check eq 1){
2089                 # The database name is too long, so return an error.
2091                 kiriwrite_error("databasefilenametoolong");
2093         }
2095         # Check if the page name is specified is blank and return an error if
2096         # it is.
2098         if (!$page){
2100                 # The page name is blank, so return an error.
2102                 kiriwrite_error("blankfilename");
2104         }
2106         # If the confirm value is blank, then set the confirm value to 0.
2108         if (!$confirm){
2110                 $confirm = 0;
2112         }
2114         if ($confirm eq 1){
2116                 # The action to delete the selected page from the database
2117                 # has been confirmed.
2119                 # Connect to the database server.
2121                 $main::kiriwrite_dbmodule->connect();
2123                 # Check if any errors occured while connecting to the database server.
2125                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
2127                         # A database connection error has occured so return
2128                         # an error.
2130                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
2132                 }
2134                 # Select the database to delete the page from.
2136                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
2138                 # Check if any errors had occured while selecting the database.
2140                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
2142                         # The database does not exist, so return an error.
2144                         kiriwrite_error("databasemissingfile");
2146                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
2148                         # The database has invalid permissions set, so return
2149                         # an error.
2151                         kiriwrite_error("databaseinvalidpermissions");
2153                 }
2155                 # Check if the database has write permissions.
2157                 my $database_permissions = $main::kiriwrite_dbmodule->dbpermissions($database, 1, 1);
2159                 if ($database_permissions eq 1){
2161                         # The database permissions are invalid so return an error.
2163                         kiriwrite_error("databaseinvalidpermissions");
2165                 }
2167                 # Get the information about the database.
2169                 my %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
2171                 # Check if any error occured while getting the database information.
2173                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
2175                         # A database error has occured so return an error and
2176                         # also the extended error information.
2178                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
2180                 }
2182                 # Get the information about the page that is going to be deleted.
2184                 my %page_info = $main::kiriwrite_dbmodule->getpageinfo({ PageFilename => $page });
2186                 # Check if any errors occured while getting the page information.
2188                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
2190                         # A database error has occured so return an error and
2191                         # also the extended error information.
2193                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
2195                 } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
2197                         # The page does not exist, so return an error.
2199                         kiriwrite_error("pagefilenamedoesnotexist");
2201                 }
2203                 # Delete the page from the database.
2205                 $main::kiriwrite_dbmodule->deletepage({ PageFilename => $page });
2207                 # Check if any errors occured while deleting the page from the database.
2209                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
2211                         # A database error has occured so return an error and
2212                         # also the extended error information.
2214                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
2216                 } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
2218                         # The page does not exist, so return an error.
2220                         kiriwrite_error("pagefilenamedoesnotexist");
2222                 }
2224                 # Get the database name and page name.
2226                 my $database_name       = $database_info{"DatabaseName"};
2227                 my $page_name           = $page_info{"PageName"};
2229                 # Disconnect from the database server.
2231                 $main::kiriwrite_dbmodule->disconnect();
2233                 # Write out a message saying that the selected page from
2234                 # the database has been deleted.
2236                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagedeleted}, { Style => "pageheader" });
2237                 $main::kiriwrite_presmodule->addlinebreak();
2238                 $main::kiriwrite_presmodule->addlinebreak();
2239                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{pagedeletedmessage}, $page_name, $database_name));
2240                 $main::kiriwrite_presmodule->addlinebreak();
2241                 $main::kiriwrite_presmodule->addlinebreak();
2242                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{returnpagelist}, $database_name)});
2244                 return $main::kiriwrite_presmodule->grab();
2246         } elsif ($confirm eq 0){
2248                 # Connect to the database server.
2250                 $main::kiriwrite_dbmodule->connect();
2252                 # Check if any errors occured while connecting to the database server.
2254                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
2256                         # A database connection error has occured so return
2257                         # an error.
2259                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
2261                 }
2263                 # Select the database.
2265                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
2267                 # Check if any errors had occured while selecting the database.
2269                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
2271                         # The database does not exist, so return an error.
2273                         kiriwrite_error("databasemissingfile");
2275                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
2277                         # The database has invalid permissions set, so return
2278                         # an error.
2280                         kiriwrite_error("databaseinvalidpermissions");
2282                 }
2284                 # Get information about the database.
2286                 my %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
2288                 # Check if any errors occured while getting the database information.
2290                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
2292                         # A database error has occured so return an error and
2293                         # also the extended error information.
2295                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
2297                 }
2299                 # Get information about the page that is going to be deleted.
2301                 my %page_info = $main::kiriwrite_dbmodule->getpageinfo({ PageFilename => $page });
2303                 # Check if any errors occured while getting the page information.
2305                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
2307                         # A database error has occured so return an error and
2308                         # also the extended error information.
2310                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
2312                 } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
2314                         # The page does not exist, so return an error.
2316                         kiriwrite_error("pagefilenamedoesnotexist");
2318                 }
2320                 my $database_name       = $database_info{"DatabaseName"};
2321                 my $page_name           = $page_info{"PageName"};
2323                 # Disconnect from the database server.
2325                 $main::kiriwrite_dbmodule->disconnect();
2327                 # Write a message asking the user to confirm the deletion of the
2328                 # page.
2330                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{deletepage}, $page_name), { Style => "pageheader" });
2331                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
2332                 $main::kiriwrite_presmodule->startbox();
2333                 $main::kiriwrite_presmodule->addhiddendata("mode", "page");
2334                 $main::kiriwrite_presmodule->addhiddendata("action", "delete");
2335                 $main::kiriwrite_presmodule->addhiddendata("database", $database);
2336                 $main::kiriwrite_presmodule->addhiddendata("page", $page);
2337                 $main::kiriwrite_presmodule->addhiddendata("confirm", "1");
2338                 $main::kiriwrite_presmodule->addlinebreak();
2339                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{deletepagemessage}, $page_name, $database_name));
2340                 $main::kiriwrite_presmodule->addlinebreak();
2341                 $main::kiriwrite_presmodule->addlinebreak();
2342                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{pages}{deletepagebutton});
2343                 $main::kiriwrite_presmodule->addtext(" | ");
2344                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{deletepagesreturnlink}, $database_name)});
2345                 $main::kiriwrite_presmodule->endbox();
2346                 $main::kiriwrite_presmodule->endform();
2348                 return $main::kiriwrite_presmodule->grab();
2350         } else {
2352                 # Another page deletion type was specified, so return an error.
2354                 kiriwrite_error("invalidoption");
2356         }
2360 sub kiriwrite_page_multidelete{
2361 #################################################################################
2362 # kiriwrite_page_multidelete: Delete mulitple pages from the database.          #
2363 #                                                                               #
2364 # Usage:                                                                        #
2365 #                                                                               #
2366 # kiriwrite_page_multidelete(database, confirm, filelist);                      #
2367 #                                                                               #
2368 # database      Specifies the database to delete multiple pages from.           #
2369 # confirm       Confirms the action to delete the selected pages from the       #
2370 #               database.                                                       #
2371 # filelist      The list of files to delete from the selected database.         #
2372 #################################################################################
2374         # Get the information passed to the subroutine.
2376         my ($database, $confirm, @filelist) = @_;
2378         # Check if the database name is blank and return an error if
2379         # it is.
2381         if (!$database){
2383                 # The database name is blank so return an error.
2385                 kiriwrite_error("databasenameblank");
2387         }
2389         # Check if the file list array has any values and return
2390         # an error if it doesn't.
2392         if (!@filelist){
2394                 # The page list really is blank so return
2395                 # an error.
2397                 kiriwrite_error("nopagesselected");
2398         }
2400         # Check if the database filename is valid and return an error if
2401         # it isn't.
2403         my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1);
2405         if ($pagedatabase_filename_check eq 1){
2407                 # The database filename is blank, so return an error.
2409                 kiriwrite_error("blankdatabasepageadd");
2411         } elsif ($pagedatabase_filename_check eq 2){
2413                 # The database filename is invalid, so return an error.
2415                 kiriwrite_error("databasefilenameinvalid");
2417         }
2419         # Check the length the database name and return an error if it's
2420         # too long.
2422         my $pagedatabase_length_check   = kiriwrite_variablecheck($database, "maxlength", 32, 1);
2424         if ($pagedatabase_length_check eq 1){
2426                 # The database name is too long, so return an error.
2428                 kiriwrite_error("databasefilenametoolong");
2430         }
2432         # Check if the confirm value is blank and if it is, then
2433         # set it to 0.
2435         if (!$confirm){
2437                 # The confirm value is blank so set the confirm value
2438                 # to 0.
2440                 $confirm = 0;
2442         }
2444         if ($confirm eq 1){
2446                 # The action to delete multiple pages from the database has
2447                 # been confirmed.
2449                 # Connect to the database server.
2451                 $main::kiriwrite_dbmodule->connect();
2453                 # Check if any errors occured while connecting to the database server.
2455                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
2457                         # A database connection error has occured so return
2458                         # an error.
2460                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
2462                 }
2464                 # Select the database.
2466                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
2468                 # Check if any errors occured while selecting the database.
2470                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
2472                         # The database does not exist, so return an error.
2474                         kiriwrite_error("databasemissingfile");
2476                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
2478                         # The database has invalid permissions set, so return
2479                         # an error.
2481                         kiriwrite_error("databaseinvalidpermissions");
2483                 }
2485                 # Check if the database has read and write permissions.
2487                 my $database_permissions = $main::kiriwrite_dbmodule->dbpermissions($database, 1, 1);
2489                 if ($database_permissions eq 1){
2491                         # The database permissions are invalid so return an error.
2493                         kiriwrite_error("databaseinvalidpermissions");
2495                 }
2497                 # Get information about the database.
2499                 my %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
2501                 # Check if any errors had occured while getting the database
2502                 # information.
2504                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
2506                         # A database error has occured so return an error and
2507                         # also the extended error information.
2509                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
2511                 };
2513                 my $database_name       = $database_info{"DatabaseName"};
2515                 # Define some variables for later.
2517                 my @database_page;
2518                 my %page_info;
2519                 my $filelist_filename;
2520                 my %deleted_list;
2521                 my $page;
2522                 my $page_name;
2523                 my $page_found = 0;
2524                 my $page_count = 0;
2526                 tie (%deleted_list, 'Tie::IxHash');
2528                 my $deleted_list = "";
2530                 foreach $filelist_filename (@filelist){
2532                         # Get the page information.
2534                         %page_info = $main::kiriwrite_dbmodule->getpageinfo({ PageFilename => $filelist_filename });
2536                         # Check if any errors occured.
2538                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
2540                                 # A database error has occured so return an error and
2541                                 # also the extended error information.
2543                                 kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
2545                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
2547                                 # The page does not exist, so process the next page.
2549                                 next;
2551                         }
2553                         # Add the page to the list of deleted pages.
2555                         $deleted_list{$page_count}{Filename}    = $page_info{"PageFilename"};
2556                         $deleted_list{$page_count}{Name}        = $page_info{"PageName"};
2558                         # Delete the page.
2560                         $main::kiriwrite_dbmodule->deletepage({ PageFilename => $filelist_filename });
2562                         # Check if any errors occured while deleting the page from the database.
2564                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
2566                                 # A database error has occured so return an error and
2567                                 # also the extended error information.
2569                                 kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
2571                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
2573                                 # The page does not exist, so process the next page.
2575                                 next;
2577                         }
2579                         $page_found = 0;
2580                         $page_count++;
2582                 }
2584                 # Disconnect from the database server.
2586                 $main::kiriwrite_dbmodule->disconnect();
2588                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{selectedpagesdeleted}, { Style => "pageheader" });
2589                 $main::kiriwrite_presmodule->addlinebreak();
2590                 $main::kiriwrite_presmodule->addlinebreak();
2591                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{selectedpagesdeletedmessage}, $database_name));
2592                 $main::kiriwrite_presmodule->addlinebreak();
2593                 $main::kiriwrite_presmodule->addlinebreak();
2594                 $main::kiriwrite_presmodule->startbox("datalist");
2596                 foreach $page (keys %deleted_list){
2598                         if (!$deleted_list{$page}{Name}){
2599                                 $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{noname});
2600                                 $main::kiriwrite_presmodule->addtext(" (" . $deleted_list{$page}{Filename} . ")");
2602                         } else {
2603                                 $main::kiriwrite_presmodule->addtext($deleted_list{$page}{Name} . " (" . $deleted_list{$page}{Filename} . ")");
2604                         }
2606                         $main::kiriwrite_presmodule->addlinebreak();
2607                 }
2609                 $main::kiriwrite_presmodule->endbox();
2610                 $main::kiriwrite_presmodule->addlinebreak();
2611                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{returnpagelist}, $database_name)});
2613                 return $main::kiriwrite_presmodule->grab();
2615         } elsif ($confirm eq 0){
2617                 # The action to delete multiple pages from the database has
2618                 # not been confirmed, so write a form asking the user to confirm
2619                 # the deletion of those pages.
2621                 # Connect to the database server.
2623                 $main::kiriwrite_dbmodule->connect();
2625                 # Check if any errors occured while connecting to the database server.
2627                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
2629                         # A database connection error has occured so return
2630                         # an error.
2632                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
2634                 }
2636                 # Select the database.
2638                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
2640                 # Check if any errors occured while selecting the database.
2642                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
2644                         # The database does not exist, so return an error.
2646                         kiriwrite_error("databasemissingfile");
2648                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
2650                         # The database has invalid permissions set, so return
2651                         # an error.
2653                         kiriwrite_error("databaseinvalidpermissions");
2655                 }
2657                 # Check if the database has read and write permissions.
2659                 my $database_permissions = $main::kiriwrite_dbmodule->dbpermissions($database, 1, 1);
2661                 if ($database_permissions eq 1){
2663                         # The database permissions are invalid so return an error.
2665                         kiriwrite_error("databaseinvalidpermissions");
2667                 }
2669                 # Get information about the database.
2671                 my %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
2673                 # Check if any errors had occured while getting the database
2674                 # information.
2676                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
2678                         # A database error has occured so return an error and
2679                         # also the extended error information.
2681                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
2683                 };
2685                 my $database_name       = $database_info{"DatabaseName"};
2687                 # Define some variables for later.
2689                 my %page_info;
2690                 my %delete_list;
2691                 my $pagename;
2692                 my $page = "";
2693                 my $filelist_filename;
2694                 my $filelist_filename_sql;
2695                 my $pageseek = 0;
2697                 tie(%delete_list, 'Tie::IxHash');
2699                 # Process each filename given.
2701                 foreach $filelist_filename (@filelist){
2703                         # Get the page information.
2705                         %page_info = $main::kiriwrite_dbmodule->getpageinfo({ PageFilename => $filelist_filename });
2707                         # Check if any errors occured.
2709                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
2711                                 # A database error has occured so return an error and
2712                                 # also the extended error information.
2714                                 kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
2716                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
2718                                 # The page does not exist, so process the next page.
2720                                 next;
2722                         }
2724                         # Add the page file name and name to the list
2725                         # of pages to delete.
2727                         $delete_list{$pageseek}{Filename}       = $page_info{"PageFilename"};
2728                         $delete_list{$pageseek}{Name}           = $page_info{"PageName"};
2730                         # Increment the page seek counter and reset the
2731                         # page found value.
2733                         $pageseek++;
2735                 }
2737                 # Disconnect from the database server.
2739                 $main::kiriwrite_dbmodule->disconnect();
2741                 # Check if any files were selected and return
2742                 # an error if there wasn't.
2744                 if ($pageseek eq 0){
2746                         # No pages were selected so return an error.
2748                         kiriwrite_error("nopagesselected");
2750                 }
2752                 # Write the form for displaying pages.
2754                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{deletemultiplepages}, { Style => "pageheader" });
2755                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
2756                 $main::kiriwrite_presmodule->startbox();
2757                 $main::kiriwrite_presmodule->addhiddendata("mode", "page");
2758                 $main::kiriwrite_presmodule->addhiddendata("action", "multidelete");
2759                 $main::kiriwrite_presmodule->addhiddendata("database", $database);
2760                 $main::kiriwrite_presmodule->addhiddendata("confirm", "1");
2761                 $main::kiriwrite_presmodule->addhiddendata("count", $pageseek);
2763                 $pageseek = 1;
2765                 foreach $page (keys %delete_list){
2767                         $main::kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on");
2768                         $main::kiriwrite_presmodule->addhiddendata("id[" . $pageseek . "]", $delete_list{$page}{Filename});
2770                         $pageseek++;
2772                 }
2774                 $main::kiriwrite_presmodule->addlinebreak();
2775                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{deletemultiplemessage}, $database_name));
2776                 $main::kiriwrite_presmodule->addlinebreak();
2777                 $main::kiriwrite_presmodule->addlinebreak();
2778                 $main::kiriwrite_presmodule->startbox("datalist");
2780                 foreach $page (keys %delete_list){
2782                         if (!$delete_list{$page}{Name}){
2783                                 $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{noname});
2784                                 $main::kiriwrite_presmodule->addtext(" (" . $delete_list{$page}{Filename} . ")");
2785                         } else {
2786                                 $main::kiriwrite_presmodule->addtext($delete_list{$page}{Name} . " (" . $delete_list{$page}{Filename} . ")");
2787                         }
2788                         $main::kiriwrite_presmodule->addlinebreak();
2790                 }
2792                 $main::kiriwrite_presmodule->endbox();
2793                 $main::kiriwrite_presmodule->addlinebreak();
2794                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{pages}{deletepagesbutton});
2795                 $main::kiriwrite_presmodule->addtext(" | ");
2796                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{deletepagesreturnlink}, $database_name)});
2797                 $main::kiriwrite_presmodule->endbox();
2798                 $main::kiriwrite_presmodule->endform();
2800                 return $main::kiriwrite_presmodule->grab();
2802         } else {
2804                 # A confirm value other than 0 or 1 is given, so
2805                 # return an error.
2807                 kiriwrite_error("invaildvalue");
2809         }
2813 sub kiriwrite_page_multimove{
2814 #################################################################################
2815 # kiriwrite_page_multimove: Move several pages from one database to another     #
2816 # database.                                                                     #
2817 #                                                                               #
2818 # Usage:                                                                        #
2819 #                                                                               #
2820 # kiriwrite_page_multimove(database, newdatabase, confirm, filelist);           #
2821 #                                                                               #
2822 # database      Specifies the database to move the selected pages from.         #
2823 # newdatabase   Specifies the database to move the selected pages to.           #
2824 # confirm       Confirms the action to move the pages from one database to      #
2825 #               another.                                                        #
2826 # filelist      Specifies the list of pages to move.                            #
2827 #################################################################################
2829         # Get the values that were passed to the subroutine.
2831         my ($database, $newdatabase, $confirm, @filelist) = @_;
2833         # Check if the database filename is valid and return
2834         # an error if it isn't.
2836         my $newpagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1);
2838         if ($newpagedatabase_filename_check eq 1){
2840                 # The database filename is blank, so return an error.
2842                 kiriwrite_error("blankdatabasepageadd");
2844         } elsif ($newpagedatabase_filename_check eq 2){
2846                 # The database filename is invalid, so return an error.
2848                 kiriwrite_error("databasefilenameinvalid");
2850         }
2852         # Check if the file list is blank and return an error
2853         # if it is.
2855         if (!@filelist){
2857                 # The file list really is blank so return
2858                 # an error.
2860                 kiriwrite_error("nopagesselected");
2862         }
2864         # Check if the confirm value is blank and if it is then
2865         # set the confirm value to 0.
2867         if (!$confirm){
2869                 $confirm = 0;
2871         }
2873         if ($confirm eq 1){
2875                 # The action to move several pages from one database
2876                 # to another has been confirmed.
2878                 # Check if the database that the pages are moving from 
2879                 # is the same as the database the pages are moving to.
2880                 # Return an error if it is.
2882                 if ($database eq $newdatabase){
2884                         # The database that the pages are moving from
2885                         # and the database the pages are moving to
2886                         # is the same, so return an error.
2888                         kiriwrite_error("databasemovesame");
2890                 }
2892                 # Check if the new database filename is valid and return an error if
2893                 # it isn't.
2895                 my $newpagedatabase_filename_check = kiriwrite_variablecheck($newdatabase, "filename", 0, 1);
2897                 if ($newpagedatabase_filename_check eq 1){
2899                         # The database filename is blank, so return an error.
2901                         kiriwrite_error("blankdatabasepageadd");
2903                 } elsif ($newpagedatabase_filename_check eq 2){
2905                         # The database filename is invalid, so return an error.
2907                         kiriwrite_error("databasefilenameinvalid");
2909                 }
2911                 # Connect to the database server.
2913                 $main::kiriwrite_dbmodule->connect();
2915                 # Check if any errors occured while connecting to the database server.
2917                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
2919                         # A database connection error has occured so return
2920                         # an error.
2922                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
2924                 }
2926                 # Select the database the pages are going to be moved from.
2928                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
2930                 # Check if any errors had occured while selecting the database.
2932                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
2934                         # The database does not exist, so return an error.
2936                         kiriwrite_error("oldmovedatabasedoesnotexist");
2938                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
2940                         # The database has invalid permissions set, so return
2941                         # an error.
2943                         kiriwrite_error("oldmovedatabasefileinvalidpermissions");
2945                 }
2947                 # Check if the database has read and write permissions.
2949                 my $database_permissions = $main::kiriwrite_dbmodule->dbpermissions($database, 1, 1);
2951                 if ($database_permissions eq 1){
2953                         # The database permissions are invalid so return an error.
2955                         kiriwrite_error("oldmovedatabasefileinvalidpermissions");
2957                 }
2959                 # Select the database the pages are going to be moved to.
2961                 $main::kiriwrite_dbmodule->selectseconddb({ DatabaseName => $newdatabase });
2963                 # Check if any errors had occured while selecting the database.
2965                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
2967                         # The database does not exist, so return an error.
2969                         kiriwrite_error("newmovedatabasedoesnotexist");
2971                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
2973                         # The database has invalid permissions set, so return
2974                         # an error.
2976                         kiriwrite_error("newmovedatabasefileinvalidpermissions");
2978                 }
2980                 # Check if the database has read and write permissions.
2982                 $database_permissions = $main::kiriwrite_dbmodule->dbpermissions($newdatabase, 1, 1);
2984                 if ($database_permissions eq 1){
2986                         # The database permissions are invalid so return an error.
2988                         kiriwrite_error("newmovedatabasefileinvalidpermissions");
2990                 }
2992                 # Define some values for later.
2994                 my %moved_list;
2995                 my %warning_list;
2996                 my %page_info;
2998                 my $filename;
3000                 my $olddatabase_name;
3001                 my $newdatabase_name;
3003                 my $page;
3004                 my $warning;
3006                 my $page_found = 0;
3007                 my $move_count = 0;
3008                 my $warning_count = 0;
3010                 tie(%moved_list, 'Tie::IxHash');
3011                 tie(%warning_list, 'Tie::IxHash');
3013                 # Get information about the database that the selected pages are moving from.
3015                 my %olddatabase_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
3017                 # Check if any errors had occured while getting the database
3018                 # information.
3020                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
3022                         # A database error has occured so return an error and
3023                         # also the extended error information.
3025                         kiriwrite_error("oldmovedatabasedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
3027                 };
3029                 $olddatabase_name = $olddatabase_info{"DatabaseName"};
3031                 # Get information about the database that the selected pages are moving to.
3033                 my %newdatabase_info = $main::kiriwrite_dbmodule->getseconddatabaseinfo();
3035                 # Check if any errors had occured while getting the database
3036                 # information.
3038                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
3040                         # A database error has occured so return an error and
3041                         # also the extended error information.
3043                         kiriwrite_error("newmovedatabasedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
3045                 };
3047                 $newdatabase_name = $newdatabase_info{"DatabaseName"};
3049                 # Get each file in the old database, get the page values,
3050                 # put them into the new database and delete the pages
3051                 # from the old database.
3053                 foreach $filename (@filelist){
3055                         # Get the page information.
3057                         %page_info = $main::kiriwrite_dbmodule->getpageinfo({ PageFilename => $filename });
3059                         # Check if any errors occured.
3061                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
3063                                 # A database error has occured so write a warning message and
3064                                 # also the extended error information.
3066                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasepageerror}, $filename, $main::kiriwrite_dbmodule->geterror(1));
3067                                 $warning_count++;
3068                                 next;
3070                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
3072                                 # The page does not exist, so process the next page.
3074                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{pagedoesnotexist}, $filename);
3075                                 $warning_count++;
3076                                 next;
3078                         }
3080                         # Move the selected page.
3082                         $main::kiriwrite_dbmodule->movepage({ PageFilename => $filename });
3084                         # Check if any errors occured while moving the page.
3086                         if ($main::kiriwrite_dbmodule->geterror eq "OldDatabaseError"){
3088                                 # A database error has occured while moving the pages from
3089                                 # the old database, so write a warning message.
3091                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasemovefrompageerror}, $filename, $main::kiriwrite_dbmodule->geterror(1));
3092                                 $warning_count++;
3093                                 next;
3095                         } elsif ($main::kiriwrite_dbmodule->geterror eq "NewDatabaseError"){
3097                                 # A database error has occured while moving the pages to
3098                                 # the new database, so write a warning message.
3100                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasemovetopageerror}, $filename, $main::kiriwrite_dbmodule->geterror(1));
3101                                 $warning_count++;
3102                                 next;
3104                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
3106                                 # The page with the filename given in the database that
3107                                 # the page is to be moved from doesn't exist so write
3108                                 # a warning message.
3110                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasemovefrompagenotexist}, $filename);
3111                                 $warning_count++;
3112                                 next;
3114                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageAlreadyExists"){
3116                                 # The page with the filename given in the database that
3117                                 # the page is to be moved to already exists so write a
3118                                 # warning message.
3120                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasemovetopageexists}, $filename);
3121                                 $warning_count++;
3122                                 next;
3124                         }
3126                         $moved_list{$move_count}{Filename}      = $page_info{"PageFilename"};
3127                         $moved_list{$move_count}{Name}          = $page_info{"PageName"};
3129                         $move_count++;
3131                 }
3133                 # Disconnect from the database server.
3135                 $main::kiriwrite_dbmodule->disconnect();
3137                 # Write out a message saying that the pages were moved (if any)
3138                 # to the new database (and any warnings given).
3140                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{movepages}, { Style => "pageheader" });
3141                 $main::kiriwrite_presmodule->addlinebreak();
3142                 $main::kiriwrite_presmodule->addlinebreak();
3144                 if (%moved_list){
3146                         $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{movedpagesmessage}, $olddatabase_name, $newdatabase_name));
3147                         $main::kiriwrite_presmodule->addlinebreak();
3148                         $main::kiriwrite_presmodule->addlinebreak();
3150                         $main::kiriwrite_presmodule->startbox("datalist");
3151                         foreach $page (keys %moved_list){
3152                                 if (!$moved_list{$page}{Name}){
3153                                         $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{noname});
3154                                         $main::kiriwrite_presmodule->addtext(" (" . $moved_list{$page}{Filename} . ")");
3155                                 } else {
3156                                         $main::kiriwrite_presmodule->addtext($moved_list{$page}{Name} . " (" . $moved_list{$page}{Filename} . ")");
3157                                 }
3159                                 $main::kiriwrite_presmodule->addlinebreak();
3160                         }
3161                         $main::kiriwrite_presmodule->endbox();
3163                 } else {
3165                         $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{nopagesmoved}, $olddatabase_name, $newdatabase_name));
3166                         $main::kiriwrite_presmodule->addlinebreak();
3167                         $main::kiriwrite_presmodule->addlinebreak();
3169                 }
3171                 if (%warning_list){
3173                         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{errormessages});
3174                         $main::kiriwrite_presmodule->addlinebreak();
3175                         $main::kiriwrite_presmodule->addlinebreak();
3176                         $main::kiriwrite_presmodule->startbox("datalist");
3177                         foreach $warning (keys %warning_list){
3178                                 $main::kiriwrite_presmodule->addtext($warning_list{$warning}{Message});
3179                                 $main::kiriwrite_presmodule->addlinebreak();
3180                         }
3181                         $main::kiriwrite_presmodule->endbox();
3183                 }
3185                 $main::kiriwrite_presmodule->addlinebreak();
3186                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{returnpagelist}, $olddatabase_name)}); 
3187                 $main::kiriwrite_presmodule->addtext(" | ");
3188                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $newdatabase, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{viewpagelist}, $newdatabase_name)});
3190                 return $main::kiriwrite_presmodule->grab();
3192         } elsif ($confirm eq 0) {
3194                 # The action to move several pages from one database
3195                 # to another has not been confirmed so write a form.
3197                 # Connect to the database server.
3199                 $main::kiriwrite_dbmodule->connect();
3201                 # Check if any errors occured while connecting to the database server.
3203                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
3205                         # A database connection error has occured so return
3206                         # an error.
3208                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
3210                 }
3212                 # Select the database.
3214                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
3216                 # Check if any errors occured while selecting the database.
3218                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
3220                         # The database does not exist, so return an error.
3222                         kiriwrite_error("databasemissingfile");
3224                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
3226                         # The database has invalid permissions set, so return
3227                         # an error.
3229                         kiriwrite_error("databaseinvalidpermissions");
3231                 }
3233                 # Check if the database has read and write permissions.
3235                 my $database_permissions = $main::kiriwrite_dbmodule->dbpermissions($database, 1, 1);
3237                 if ($database_permissions eq 1){
3239                         # The database permissions are invalid so return an error.
3241                         kiriwrite_error("databaseinvalidpermissions");
3243                 }
3245                 # Get information about the database.
3247                 my %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
3249                 # Check if any errors had occured while getting the database
3250                 # information.
3252                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
3254                         # A database error has occured so return an error and
3255                         # also the extended error information.
3257                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
3259                 };
3261                 my $database_name       = $database_info{"DatabaseName"};
3263                 # Define some values for later.
3265                 my %db_list;
3266                 my %move_list;
3267                 my %page_info;
3268                 my $page;
3269                 my $data_file;
3270                 my $db_name;
3271                 my $filename;
3272                 my $filelist_filename;
3273                 my $pagename;
3274                 my $pageseek    = 0;
3275                 my $dbseek      = 0;
3277                 # Process each filename given.
3279                 tie (%move_list, 'Tie::IxHash');
3280                 tie (%db_list, 'Tie::IxHash');
3282                 foreach $filelist_filename (@filelist){
3284                         # Get the page information.
3286                         %page_info = $main::kiriwrite_dbmodule->getpageinfo({ PageFilename => $filelist_filename });
3288                         # Check if any errors occured.
3290                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
3292                                 # A database error has occured so return an error and
3293                                 # also the extended error information.
3295                                 kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
3297                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
3299                                 # The page does not exist, so process the next page.
3301                                 next;
3303                         }
3305                         # Add the page name and file name to the list of
3306                         # pages to move.
3308                         $move_list{$pageseek}{Filename} = $page_info{"PageFilename"};
3309                         $move_list{$pageseek}{Name}     = $page_info{"PageName"};
3311                         # Increment the page seek counter and reset the
3312                         # page found value.
3314                         $pageseek++;
3316                 }
3318                 # Check if any pages exust and return an error if
3319                 # there wasn't.
3321                 if ($pageseek eq 0){
3323                         # None of the selected pages exist, so return
3324                         # an error.
3326                         kiriwrite_error("nopagesselected");
3328                 }
3330                 # Get the list of databases.
3332                 my @database_list       = $main::kiriwrite_dbmodule->getdblist();
3334                 # Check if any errors occured while trying to get the list of databases.
3336                 if ($main::kiriwrite_dbmodule->geterror eq "DataDirMissing"){
3338                         # The database directory is missing so return an error.
3340                         kiriwrite_error("datadirectorymissing");
3342                 } elsif ($main::kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){
3344                         # The database directory has invalid permissions set so return
3345                         # an error.
3347                         kiriwrite_error("datadirectoryinvalidpermissions");
3349                 }
3351                 # Get the information about each database (the short name and friendly name).
3353                 foreach $data_file (@database_list){
3355                         $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $data_file });
3357                         # Check if any errors occured while selecting the database.
3359                         if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
3361                                 # The database does not exist, so process the next
3362                                 # database.
3364                                 next;
3366                         } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
3368                                 # The database has invalid permissions set, so process
3369                                 # the next database.
3371                                 next;
3373                         }
3375                         # Get the database information.
3377                         %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
3379                         # Check if any errors had occured while getting the database
3380                         # information.
3382                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
3384                                 # A database error has occured so process the next
3385                                 # database.
3387                                 next;
3389                         };
3391                         # Check if the database name is undefined and if it is
3392                         # then set it blank.
3394                         if (!$database_name){
3395                                 $database_name = "";
3396                         }
3398                         # Append the database to the list of databases available.
3400                         $db_list{$dbseek}{Filename}     = $data_file;
3401                         $db_list{$dbseek}{Name}         = $database_info{"DatabaseName"};
3403                         $dbseek++;
3405                 }
3407                 # Disconnect from the database server.
3409                 $main::kiriwrite_dbmodule->disconnect();
3411                 # Write out the form.
3413                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{movepages}, { Style => "pageheader" });
3414                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
3415                 $main::kiriwrite_presmodule->startbox();
3416                 $main::kiriwrite_presmodule->addhiddendata("mode", "page");
3417                 $main::kiriwrite_presmodule->addhiddendata("action", "multimove");
3418                 $main::kiriwrite_presmodule->addhiddendata("database", $database);
3419                 $main::kiriwrite_presmodule->addhiddendata("count", $pageseek);
3420                 $main::kiriwrite_presmodule->addhiddendata("confirm", "1");
3422                 # Write the page form data.
3424                 $pageseek = 1;
3426                 foreach $page (keys %move_list){
3427                         $main::kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on");
3428                         $main::kiriwrite_presmodule->addhiddendata("id[" . $pageseek . "]", $move_list{$page}{Filename});
3429                         $pageseek++;
3430                 }
3432                 $main::kiriwrite_presmodule->addlinebreak();
3433                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{movepagesmessage}, $database_name));
3434                 $main::kiriwrite_presmodule->addlinebreak();
3435                 $main::kiriwrite_presmodule->addlinebreak();
3436                 $main::kiriwrite_presmodule->startbox("datalist");
3438                 foreach $page (keys %move_list){
3439                         if (!$move_list{$page}{Name}){
3440                                 $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{noname});
3441                                 $main::kiriwrite_presmodule->addtext(" (" . $move_list{$page}{Filename} . ")");
3442                         } else {
3443                                 $main::kiriwrite_presmodule->addtext($move_list{$page}{Name} . " (" . $move_list{$page}{Filename} . ")");
3444                         }
3445                         $main::kiriwrite_presmodule->addlinebreak();
3446                 }
3448                 $main::kiriwrite_presmodule->endbox();
3449                 $main::kiriwrite_presmodule->addlinebreak();
3450                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{movepagesto});
3452                 $main::kiriwrite_presmodule->addselectbox("newdatabase");
3454                 foreach $db_name (keys %db_list){
3455                         $main::kiriwrite_presmodule->addoption($db_list{$db_name}{Name} . " (" . $db_list{$db_name}{Filename} . ")", { Value => $db_list{$db_name}{Filename}});
3456                 }
3458                 $main::kiriwrite_presmodule->endselectbox();
3459                 $main::kiriwrite_presmodule->addlinebreak();
3460                 $main::kiriwrite_presmodule->addlinebreak();
3461                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{pages}{movepagesbutton});
3462                 $main::kiriwrite_presmodule->addtext(" | ");
3463                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{returnpagelist}, $database_name)});
3464                 $main::kiriwrite_presmodule->endbox();
3465                 $main::kiriwrite_presmodule->endform();
3467                 return $main::kiriwrite_presmodule->grab();
3469         } else {
3471                 # The confirm value is other than 0 or 1, so return
3472                 # an error.
3474                 kiriwrite_error("invalidvariable");
3476         }
3482 sub kiriwrite_page_multicopy{
3483 #################################################################################
3484 # kiriwrite_page_multicopy: Copy several pages from one database to another     #
3485 # database.                                                                     #
3486 #                                                                               #
3487 # Usage:                                                                        #
3488 #                                                                               #
3489 # kiriwrite_page_multicopy(database, newdatabase, confirm, filelist);           #
3490 #                                                                               #
3491 # database      Specifies the database to copy the selected pages from.         #
3492 # newdatabase   Specifies the database to copy the selected page to.            #
3493 # confirm       Confirms the action to copy the pages.                          #
3494 # filelist      A list of filenames to copy in an array.                        #
3495 #################################################################################
3497         # Get the values that were passed to the subroutine.
3499         my ($database, $newdatabase, $confirm, @filelist) = @_;
3501         # Check if the file list is blank and return an error
3502         # if it is.
3504         if (!@filelist){
3506                 # The file list really is blank so return
3507                 # an error.
3509                 kiriwrite_error("nopagesselected");
3511         }
3513         # Check if the confirm value is blank and if it is then
3514         # set the confirm value to 0.
3516         if (!$confirm){
3518                 $confirm = 0;
3520         }
3522         # Check if the database filename is valid and return an error if
3523         # it isn't.
3525         my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1);
3527         if ($pagedatabase_filename_check eq 1){
3529                 # The database filename is blank, so return an error.
3531                 kiriwrite_error("blankdatabasepageadd");
3533         } elsif ($pagedatabase_filename_check eq 2){
3535                 # The database filename is invalid, so return an error.
3537                 kiriwrite_error("databasefilenameinvalid");
3539         }
3541         if ($confirm eq 1){
3543                 # The action to copy several pages from one database
3544                 # to another has been confirmed.
3546                 # Check if the database that the pages are copied from 
3547                 # is the same as the database the pages are copied to.
3548                 # Return an error if it is.
3550                 if ($database eq $newdatabase){
3552                         # The database that the pages are being copied from
3553                         # and the database that the pages are copied to
3554                         # is the same, so return an error.
3556                         kiriwrite_error("databasecopysame");
3558                 }
3560                 # Check if the new database filename is valid and return an error if
3561                 # it isn't.
3563                 my $pagedatabase_filename_check = kiriwrite_variablecheck($newdatabase, "filename", 0, 1);
3565                 if ($pagedatabase_filename_check eq 1){
3567                         # The database filename is blank, so return an error.
3569                         kiriwrite_error("blankdatabasepageadd");
3571                 } elsif ($pagedatabase_filename_check eq 2){
3573                         # The database filename is invalid, so return an error.
3575                         kiriwrite_error("databasefilenameinvalid");
3577                 }
3579                 # Connect to the database server.
3581                 $main::kiriwrite_dbmodule->connect();
3583                 # Check if any errors occured while connecting to the database server.
3585                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
3587                         # A database connection error has occured so return
3588                         # an error.
3590                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
3592                 }
3594                 # Select the database the pages are going to be copied from.
3596                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
3598                 # Check if any errors had occured while selecting the database.
3600                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
3602                         # The database does not exist, so return an error.
3604                         kiriwrite_error("oldcopydatabasedoesnotexist");
3606                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
3608                         # The database has invalid permissions set, so return
3609                         # an error.
3611                         kiriwrite_error("oldcopydatabasefileinvalidpermissions");
3613                 }
3615                 # Select the database the pages are going to be copied to.
3617                 $main::kiriwrite_dbmodule->selectseconddb({ DatabaseName => $newdatabase });
3619                 # Check if any errors had occured while selecting the database.
3621                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
3623                         # The database does not exist, so return an error.
3625                         kiriwrite_error("newcopydatabasedoesnotexist");
3627                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
3629                         # The database has invalid permissions set, so return
3630                         # an error.
3632                         kiriwrite_error("newcopydatabasefileinvalidpermissions");
3634                 }
3636                 # Check if the database has read and write permissions.
3638                 my $database_permissions = $main::kiriwrite_dbmodule->dbpermissions($newdatabase, 1, 1);
3640                 if ($database_permissions eq 1){
3642                         # The database permissions are invalid so return an error.
3644                         kiriwrite_error("newcopydatabasefileinvalidpermissions");
3646                 }
3648                 # Define some values for later.
3650                 my %copied_list;
3651                 my %warning_list;
3652                 my %page_info;
3654                 my @olddatabase_info;
3655                 my @olddatabase_page;
3656                 my @newdatabase_info;
3657                 my @newdatabase_page;
3659                 my $filename;
3661                 my $olddatabase_name;
3662                 my $newdatabase_name;
3664                 my $page;
3665                 my $warning;
3666                 my $page_filename;
3667                 my $page_name;
3668                 my $page_description;
3669                 my $page_section;
3670                 my $page_template;
3671                 my $page_data;
3672                 my $page_settings;
3673                 my $page_lastmodified;
3675                 my $page_seek = 0;
3676                 my $warning_count = 0;
3678                 my $page_found = 0;
3680                 tie(%copied_list, 'Tie::IxHash');
3681                 tie(%warning_list, 'Tie::IxHash');
3683                 # Get information about the database that the selected pages are moving from.
3685                 my %olddatabase_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
3687                 # Check if any errors had occured while getting the database
3688                 # information.
3690                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
3692                         # A database error has occured so return an error and
3693                         # also the extended error information.
3695                         kiriwrite_error("oldcopydatabasedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
3697                 };
3699                 $olddatabase_name = $olddatabase_info{"DatabaseName"};
3701                 # Get information about the database that the selected pages are moving to.
3703                 my %newdatabase_info = $main::kiriwrite_dbmodule->getseconddatabaseinfo();
3705                 # Check if any errors had occured while getting the database
3706                 # information.
3708                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
3710                         # A database error has occured so return an error and
3711                         # also the extended error information.
3713                         kiriwrite_error("newcopydatabasedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
3715                 };
3717                 $newdatabase_name = $newdatabase_info{"DatabaseName"};
3719                 # Check if the database filename is valid and return an error if
3720                 # it isn't.
3722                 my $newpagedatabase_filename_check = kiriwrite_variablecheck($newdatabase, "filename", 0, 1);
3724                 if ($newpagedatabase_filename_check eq 1){
3726                         # The database filename is blank, so return an error.
3728                         kiriwrite_error("blankdatabasepageadd");
3730                 } elsif ($newpagedatabase_filename_check eq 2){
3732                         # The database filename is invalid, so return an error.
3734                         kiriwrite_error("databasefilenameinvalid");
3736                 }
3738                 foreach $filename (@filelist){
3740                         # Get the page information.
3742                         %page_info = $main::kiriwrite_dbmodule->getpageinfo({ PageFilename => $filename });
3744                         # Check if any errors occured.
3746                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
3748                                 # A database error has occured so return an error and
3749                                 # also the extended error information.
3751                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasepageerror}, $filename, $main::kiriwrite_dbmodule->geterror(1));
3752                                 $warning_count++;
3753                                 next;
3755                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
3757                                 # The page does not exist, so process the next page.
3759                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasecopyfrompageerror}, $filename);
3760                                 $warning_count++;
3761                                 next;
3763                         }
3765                         $main::kiriwrite_dbmodule->copypage({ PageFilename => $filename });
3767                         # Check if any errors occured while copying the page.
3769                         if ($main::kiriwrite_dbmodule->geterror eq "OldDatabaseError"){
3771                                 # A database error has occured while copying the pages from
3772                                 # the old database, so write a warning message.
3774                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasecopyfromdatabaseerror}, $filename,  $main::kiriwrite_dbmodule->geterror(1));
3775                                 $warning_count++;
3776                                 next;
3778                         } elsif ($main::kiriwrite_dbmodule->geterror eq "NewDatabaseError"){
3780                                 # A database error has occured while copying the pages to
3781                                 # the new database, so write a warning message.
3783                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasecopytodatabaseerror}, $filename, $main::kiriwrite_dbmodule->geterror(1));
3784                                 $warning_count++;
3785                                 next;
3787                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
3789                                 # The page with the filename given in the database that
3790                                 # the page is to be copied from doesn't exist so write
3791                                 # a warning message.
3793                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasecopyfrompagenotexist}, $filename);
3794                                 $warning_count++;
3795                                 next;
3797                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageAlreadyExists"){
3799                                 # The page with the filename given in the database that
3800                                 # the page is to be copied to already exists so write a
3801                                 # warning message.
3803                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasecopytopageexists}, $filename);
3804                                 $warning_count++;
3805                                 next;
3807                         }
3809                         # Append the copied page (filename and name) to the list of
3810                         # copied pages.
3812                         $copied_list{$page_seek}{Filename}      = $filename;
3813                         $copied_list{$page_seek}{Name}          = $page_info{"PageName"};
3814                         $page_seek++;
3816                 }
3818                 # Disconnect from the database server.
3820                 $main::kiriwrite_dbmodule->disconnect();
3822                 # Write out a message saying that the pages were moved (if any)
3823                 # to the new database (and any warnings given).
3825                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{copypages}, { Style => "pageheader" });
3826                 $main::kiriwrite_presmodule->addlinebreak();
3827                 $main::kiriwrite_presmodule->addlinebreak();
3829                 if (%copied_list){
3831                         $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{copypagesresultmessage}, $olddatabase_name, $newdatabase_name));
3832                         $main::kiriwrite_presmodule->addlinebreak();
3833                         $main::kiriwrite_presmodule->addlinebreak();
3834                         $main::kiriwrite_presmodule->startbox("datalist");
3835                         foreach $page (keys %copied_list){
3836                                 if (!$copied_list{$page}{Name}){
3837                                         $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{noname});
3838                                         $main::kiriwrite_presmodule->addtext(" (" . $copied_list{$page}{Filename} . ")");
3839                                 } else {
3840                                         $main::kiriwrite_presmodule->addtext($copied_list{$page}{Name} . " (" . $copied_list{$page}{Filename} . ")");
3841                                 }
3842                                 $main::kiriwrite_presmodule->addlinebreak();
3843                         }
3844                         $main::kiriwrite_presmodule->endbox();
3846                 } else {
3848                         $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{nopagescopied}, $olddatabase_name, $newdatabase_name));
3850                 }
3852                 if (%warning_list){
3854                         $main::kiriwrite_presmodule->addlinebreak();
3855                         $main::kiriwrite_presmodule->addlinebreak();
3856                         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{copypageswarnings});
3857                         $main::kiriwrite_presmodule->addlinebreak();
3858                         $main::kiriwrite_presmodule->addlinebreak();
3859                         $main::kiriwrite_presmodule->startbox("datalist");
3860                         foreach $warning (keys %warning_list){
3861                                 $main::kiriwrite_presmodule->addtext($warning_list{$warning}{Message});
3862                                 $main::kiriwrite_presmodule->addlinebreak();
3863                         }
3864                         $main::kiriwrite_presmodule->endbox();
3866                 }
3868                 $main::kiriwrite_presmodule->addlinebreak();
3869                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{returnpagelist}, $olddatabase_name)});
3870                 $main::kiriwrite_presmodule->addtext(" | ");
3871                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $newdatabase, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{viewpagelist}, $newdatabase_name)});
3873                 return $main::kiriwrite_presmodule->grab();
3875         } elsif ($confirm eq 0) {
3877                 # The action to copy several pages from one database
3878                 # to another has not been confirmed so write a form.
3880                 # Connect to the database server.
3882                 $main::kiriwrite_dbmodule->connect();
3884                 # Check if any errors occured while connecting to the database server.
3886                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
3888                         # A database connection error has occured so return
3889                         # an error.
3891                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
3893                 }
3895                 # Select the database to copy the pages from.
3897                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
3899                 # Check if any errors occured while selecting the database.
3901                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
3903                         # The database does not exist, so return an error.
3905                         kiriwrite_error("databasemissingfile");
3907                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
3909                         # The database has invalid permissions set, so return
3910                         # an error.
3912                         kiriwrite_error("databaseinvalidpermissions");
3914                 }
3916                 # Get information about the database.
3918                 my %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
3920                 # Check if any errors had occured while getting the database
3921                 # information.
3923                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
3925                         # A database error has occured so return an error and
3926                         # also the extended error information.
3928                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
3930                 };
3932                 my $database_name       = $database_info{"DatabaseName"};
3934                 # Define some values for later.
3936                 my %page_info;
3937                 my %copy_list;
3938                 my %db_list;
3939                 my @page_info;
3940                 my $page;
3941                 my $data_file;
3942                 my $dbname;
3943                 my $filename;
3944                 my $pageseek    = 0;
3945                 my $dbseek      = 0;
3946                 my $pagefound   = 0;
3948                 tie(%copy_list, 'Tie::IxHash');
3949                 tie(%db_list, 'Tie::IxHash');
3951                 # Process each filename given.
3953                 foreach $filename (@filelist){
3955                         # Get the page information.
3957                         %page_info = $main::kiriwrite_dbmodule->getpageinfo({ PageFilename => $filename });
3959                         # Check if any errors occured.
3961                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
3963                                 # A database error has occured so return an error and
3964                                 # also the extended error information.
3966                                 kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
3968                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
3970                                 # The page does not exist, so process the next page.
3972                                 next;
3974                         }
3976                         # Add the page name and file name to the list of
3977                         # pages to move.
3979                         $copy_list{$pageseek}{Filename} = $page_info{"PageFilename"};
3980                         $copy_list{$pageseek}{Name}     = $page_info{"PageName"};
3982                         # Increment the page seek counter.
3984                         $pageseek++;
3986                 }
3988                 # Check if any pages exust and return an error if
3989                 # there wasn't.
3991                 if ($pageseek eq 0){
3993                         # None of the selected pages exist, so return
3994                         # an error.
3996                         kiriwrite_error("nopagesselected");
3998                 }
4000                 # Get the database filenames and names.
4002                 my @database_list       = $main::kiriwrite_dbmodule->getdblist();
4004                 # Check if any errors occured while trying to get the list of databases.
4006                 if ($main::kiriwrite_dbmodule->geterror eq "DataDirMissing"){
4008                         # The database directory is missing so return an error.
4010                         kiriwrite_error("datadirectorymissing");
4012                 } elsif ($main::kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){
4014                         # The database directory has invalid permissions set so return
4015                         # an error.
4017                         kiriwrite_error("datadirectoryinvalidpermissions");
4019                 }
4021                 # Process each database to get the database name.
4023                 foreach $data_file (@database_list){
4025                         $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $data_file });
4027                         # Check if any errors occured while selecting the database.
4029                         if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
4031                                 # The database does not exist, so process the next
4032                                 # database.
4034                                 next;
4036                         } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
4038                                 # The database has invalid permissions set, so process
4039                                 # the next database.
4041                                 next;
4043                         }
4045                         # Get the database information.
4047                         %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
4049                         # Check if any errors had occured while getting the database
4050                         # information.
4052                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
4054                                 # A database error has occured so process the next
4055                                 # database.
4057                                 next;
4059                         };
4061                         # Check if the database name is undefined and if it is
4062                         # then set it blank.
4064                         if (!$database_name){
4065                                 $database_name = "";
4066                         }
4068                         # Append the database filename and name to the list of databases
4069                         # to move the pages to.
4071                         $db_list{$dbseek}{Filename}     = $data_file;
4072                         $db_list{$dbseek}{Name}         = $database_info{"DatabaseName"};
4074                         $dbseek++;
4076                 }
4078                 # Disconnect from the database server.
4080                 $main::kiriwrite_dbmodule->disconnect();
4082                 # Write out the form.
4084                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{copypages}, { Style => "pageheader" });
4085                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
4086                 $main::kiriwrite_presmodule->startbox();
4087                 $main::kiriwrite_presmodule->addhiddendata("mode", "page");
4088                 $main::kiriwrite_presmodule->addhiddendata("action", "multicopy");
4089                 $main::kiriwrite_presmodule->addhiddendata("database", $database);
4090                 $main::kiriwrite_presmodule->addhiddendata("count", $pageseek);
4091                 $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
4093                 $pageseek = 1;
4095                 foreach $page (keys %copy_list){
4096                         $main::kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on");
4097                         $main::kiriwrite_presmodule->addhiddendata("id[" . $pageseek . "]", $copy_list{$page}{Filename});
4098                         $pageseek++;
4099                 }
4101                 $main::kiriwrite_presmodule->addlinebreak();
4102                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{copypagesmessage}, $database_name));
4104                 $main::kiriwrite_presmodule->addlinebreak();
4105                 $main::kiriwrite_presmodule->addlinebreak();
4107                 $main::kiriwrite_presmodule->startbox("datalist");
4109                 foreach $page (keys %copy_list){
4110                         if (!$copy_list{$page}{Name}){
4111                                 $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{noname});
4112                                 $main::kiriwrite_presmodule->addtext(" (" . $copy_list{$page}{Filename} . ")");
4113                         } else {
4114                                 $main::kiriwrite_presmodule->addtext($copy_list{$page}{Name} . " (" . $copy_list{$page}{Filename} . ")");
4115                         }
4116                         $main::kiriwrite_presmodule->addlinebreak();
4117                 }
4119                 $main::kiriwrite_presmodule->endbox();
4121                 $main::kiriwrite_presmodule->addlinebreak();
4123                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{copypagesto});
4124                 $main::kiriwrite_presmodule->addselectbox("newdatabase");
4126                 foreach $dbname (keys %db_list){
4127                         $main::kiriwrite_presmodule->addoption($db_list{$dbname}{Name} . " (" . $db_list{$dbname}{Filename} . ")", { Value => $db_list{$dbname}{Filename}});
4128                 }
4130                 $main::kiriwrite_presmodule->endselectbox();
4132                 $main::kiriwrite_presmodule->addlinebreak();
4133                 $main::kiriwrite_presmodule->addlinebreak();
4134                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{pages}{copypagesbutton});
4135                 $main::kiriwrite_presmodule->addtext(" | ");
4136                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{returnpagelist}, $database_name) });
4138                 $main::kiriwrite_presmodule->endbox();          
4139                 $main::kiriwrite_presmodule->endform();
4141                 return $main::kiriwrite_presmodule->grab();
4143         } else {
4145                 # The confirm value is other than 0 or 1, so return
4146                 # an error.
4148                 kiriwrite_error("invalidvariable");
4150         }
4154 sub kiriwrite_page_multiedit{
4155 #################################################################################
4156 # kiriwrite_page_multiedit: Edit several pages from a database.                 #
4157 #                                                                               #
4158 # Usage:                                                                        #
4159 #                                                                               #
4160 # kiriwrite_page_multiedit(database, newsection, altersection, newtemplate,     #
4161 #                               altertemplate, newsettings, altersettings       #
4162 #                               confirm, filelist);                             #
4163 #                                                                               #
4164 # database      Specifies the database to edit the pages from.                  #
4165 # newsection    Specifies the new section name to use on the selected pages.    #
4166 # altersection  Specifies if the section name should be altered.                #
4167 # newtemplate   Specifies the new template filename to use on the selected      #
4168 #               pages.                                                          #
4169 # altertemplate Specifies if the template filename should be altered.           #
4170 # newsettings   Specifies the new settings to use on the selected pages.        #
4171 # altersettings Specifies if the settings should be altered.                    #
4172 # confirm       Confirms the action to edit the selected pages.                 #
4173 # filelist      The list of file names to edit.                                 #
4174 #################################################################################
4176         # Get the values that were passed to the subroutine.
4178         my ($database, $newsection, $altersection, $newtemplate, $altertemplate, $newsettings, $altersettings, $confirm, @filelist) = @_;
4180         # Check if the file list is blank and return an error
4181         # if it is.
4183         if (!@filelist){
4185                 # The file list really is blank so return
4186                 # an error.
4188                 kiriwrite_error("nopagesselected");
4190         }
4192         # Check if certain values are undefined and define them if
4193         # they are.
4195         if (!$altersection){
4197                 # The alter section value is blank, so set it to
4198                 # off.
4200                 $altersection   = "off";
4202         }
4204         if (!$altertemplate){
4206                 # The alter template value is blank, so set it to
4207                 # off.
4209                 $altertemplate  = "off";
4211         }
4213         if (!$altersettings){
4215                 # The alter settings value is blank, so set it to
4216                 # off.
4218                 $altersettings  = "off";
4220         }
4222         # Check if the database filename is valid and return an error if
4223         # it isn't.
4225         my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1);
4227         if ($pagedatabase_filename_check eq 1){
4229                 # The database filename is blank, so return an error.
4231                 kiriwrite_error("blankdatabasepageadd");
4233         } elsif ($pagedatabase_filename_check eq 2){
4235                 # The database filename is invalid, so return an error.
4237                 kiriwrite_error("databasefilenameinvalid");
4239         }
4241         # Check if the confirm value is blank and if it is then
4242         # set the confirm value to 0.
4244         if (!$confirm){
4246                 $confirm = 0;
4248         }
4250         if ($confirm eq 1){
4252                 # The action to edit the template has been confirmed so
4253                 # edit the selected pages.
4255                 # Check the values recieved at UTF8 compliant before
4256                 # converting.
4258                 kiriwrite_variablecheck($newsection, "utf8", 0, 0);
4259                 kiriwrite_variablecheck($newtemplate, "utf8", 0, 0);
4260                 kiriwrite_variablecheck($newsettings, "utf8", 0, 0);
4262                 # Convert the values into proper UTF8 values.
4264                 $newsection     = kiriwrite_utf8convert($newsection);
4265                 $newtemplate    = kiriwrite_utf8convert($newtemplate);
4266                 $newsettings    = kiriwrite_utf8convert($newsettings);
4268                 # Check the length of the variables.
4270                 kiriwrite_variablecheck($altersection, "maxlength", 3, 0);
4271                 kiriwrite_variablecheck($altertemplate, "maxlength", 3, 0);
4272                 kiriwrite_variablecheck($altersettings, "maxlength", 3, 0);
4273                 my $newsection_maxlength_check  = kiriwrite_variablecheck($newsection, "maxlength", 256, 1);
4274                 my $newtemplate_maxlength_check = kiriwrite_variablecheck($newtemplate, "maxlength", 256, 1);
4275                 my $newtemplate_filename_check  = kiriwrite_variablecheck($newtemplate, "filename", 0, 1);
4276                 my $newsettings_maxlength_check = kiriwrite_variablecheck($newsettings, "maxlength", 1, 1);
4277                 my $newsettings_settings_check  = kiriwrite_variablecheck($newsettings, "pagesetting", 0, 1);
4279                 # Check the values and return an error if needed.
4281                 if ($newsection_maxlength_check eq 1 && $altersection eq "on"){
4283                         # The new section name is too long, so return an
4284                         # error.
4286                         kiriwrite_error("pagesectiontoolong");
4288                 }
4290                 if ($newtemplate_maxlength_check eq 1 && $altertemplate eq "on"){
4292                         # The new template name is too long, so return an
4293                         # error.
4295                         kiriwrite_error("templatefilenametoolong");
4297                 }
4299                 # Check if the template filename is set to !skip or !none
4300                 # and skip this check if it is.
4302                 if ($newtemplate eq "!skip" || $newtemplate eq "!none"){
4304                         # Skip this check as the template filename is 
4305                         # !skip or !none.
4307                 } else {
4308                         if ($newtemplate_filename_check eq 1 && $altertemplate eq "on" || $newtemplate_filename_check eq 2 && $altertemplate eq "on"){
4310                                 # The new template filename is invalid, so return
4311                                 # an error.
4313                                 kiriwrite_error("templatefilenameinvalid");
4315                         }
4316                 }
4318                 if ($newsettings_maxlength_check eq 1 && $altertemplate eq "on"){
4320                         # The new settings value is too long, so return
4321                         # an error.
4323                         kiriwrite_error("pagesettingstoolong");
4325                 }
4327                 if ($newsettings_settings_check eq 1 && $altersettings eq "on"){
4329                         # The new settings value is invalid, so return
4330                         # an error.
4332                         kiriwrite_error("pagesettingsinvalid");
4334                 }
4336                 # Define some values for later.
4338                 my %database_info;
4339                 my %edited_list;
4340                 my %warning_list;
4341                 my %page_info;
4342                 my $page;
4343                 my $warning;
4344                 my $filename;
4345                 my $page_name;
4346                 my $pagefound = 0;
4347                 my $pageedited = 0;
4348                 my $warning_count = 0;
4350                 tie(%edited_list, 'Tie::IxHash');
4351                 tie(%warning_list, 'Tie::IxHash');
4353                 # Check if the template filename is !skip and
4354                 # set the alter template value to off if it
4355                 # is.
4357                 if ($newtemplate eq "!skip"){
4359                         $altertemplate = "off";
4361                 }
4363                 # Check if all values are not selected and return
4364                 # an error if they are.
4366                 if ($altersection ne "on" && $altertemplate ne "on" && $altersettings ne "on"){
4368                         # All values are not selected so return 
4369                         # an error.
4371                         kiriwrite_error("noeditvaluesselected");
4373                 }
4375                 # Connect to the database server.
4377                 $main::kiriwrite_dbmodule->connect();
4379                 # Check if any errors occured while connecting to the database server.
4381                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
4383                         # A database connection error has occured so return
4384                         # an error.
4386                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
4388                 }
4390                 # Select the database.
4392                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
4394                 # Check if any errors occured while selecting the database.
4396                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
4398                         # The database does not exist, so return an error.
4400                         kiriwrite_error("databasemissingfile");
4402                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
4404                         # The database has invalid permissions set, so return
4405                         # an error.
4407                         kiriwrite_error("databaseinvalidpermissions");
4409                 }
4411                 # Check if the database has read and write permissions.
4413                 my $database_permissions = $main::kiriwrite_dbmodule->dbpermissions($database, 1, 1);
4415                 if ($database_permissions eq 1){
4417                         # The database permissions are invalid so return an error.
4419                         kiriwrite_error("databaseinvalidpermissions");
4421                 }
4423                 # Get information about the database.
4425                 %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
4427                 # Check if any errors had occured while getting the database
4428                 # information.
4430                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
4432                         # A database error has occured so return an error and
4433                         # also the extended error information.
4435                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
4437                 };
4439                 my $database_name = $database_info{"DatabaseName"};
4441                 # Edit the selected pages.
4443                 foreach $filename (@filelist){
4445                         # Get the page information.
4447                         %page_info = $main::kiriwrite_dbmodule->getpageinfo({ PageFilename => $filename });
4449                         # Check if any errors occured.
4451                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
4453                                 # A database error has occured so write a warning message.
4455                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasepageerror}, $filename, $main::kiriwrite_dbmodule->geterror(1));
4457                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
4459                                 # The page does not exist, so write a warning message.
4461                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasepagedoesnotexist}, $filename);
4462                                 $warning_count++;
4463                                 next;
4465                         }
4467                         # Check if the page section should be altered.
4469                         if ($altersection eq "on"){
4471                                 # Change the section name.
4473                                 $page_info{"PageSection"} = $newsection;
4475                         }
4477                         # Check if the page template should be altered.
4479                         if ($altertemplate eq "on"){
4481                                 # Change the page template filename.
4483                                 $page_info{"PageTemplate"} = $newtemplate;
4485                         }
4487                         # Check if the page settings should be altered.
4489                         if ($altersettings eq "on"){
4491                                 # Change the page settings value.
4493                                 $page_info{"PageSettings"} = $newsettings;
4495                         }
4497                         # Edit the selected page.
4499                         $main::kiriwrite_dbmodule->editpage({ PageFilename => $page_info{"PageFilename"}, PageNewFilename => $page_info{"PageFilename"}, PageNewName => $page_info{"PageName"}, PageNewDescription => $page_info{"PageDescription"}, PageNewSection => $page_info{"PageSection"}, PageNewTemplate => $page_info{"PageTemplate"}, PageNewContent => $page_info{"PageContent"}, PageNewSettings => $page_info{"PageSettings"} });
4501                         # Check if any errors occured while editing the page.
4503                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
4505                                 # A database error has occured so write a warning message
4506                                 # with the extended error information.
4508                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasepageerror}, $filename, $main::kiriwrite_dbmodule->geterror(1));
4509                                 $warning_count++;
4510                                 next;
4512                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
4514                                 # The pages does not exist in the database.
4516                                 $warning_list{$warning_count}{Message} = kiriwrite_language($main::kiriwrite_lang{pages}{databasepagedoesnotexist}, $filename);
4517                                 $warning_count++;
4518                                 next;
4520                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageExists"){
4522                                 # A page already exists with the new filename.
4524                                 kiriwrite_error("pagefilenameexists");
4526                         }
4528                         # The page has been edited so write a message saying that the page
4529                         # has been edited.
4531                         $edited_list{$pageedited}{Filename}     = $page_info{"PageFilename"};
4532                         $edited_list{$pageedited}{Name}         = $page_info{"PageName"};
4533  
4534                         # Increment the counter of edited pages.
4535  
4536                         $pageedited++;
4538                 }
4540                 # Disconnect from the database server.
4542                 $main::kiriwrite_dbmodule->disconnect();
4544                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{multiedit}, { Style => "pageheader" });
4545                 $main::kiriwrite_presmodule->addlinebreak();
4546                 $main::kiriwrite_presmodule->addlinebreak();
4548                 # Check if the counter of edited pages is 0 and if it is
4549                 # then write a message saying that no pages were edited
4550                 # else write a message listing all of the pages edited.
4552                 if ($pageedited eq 0){
4554                         $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{nopagesedited}, $database_name));
4556                 } else {
4558                         # Write out the message saying that the selected pages
4559                         # were edited.
4561                         $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{pagesedited}, $database_name));
4562                         $main::kiriwrite_presmodule->addlinebreak();
4563                         $main::kiriwrite_presmodule->addlinebreak();
4564                         $main::kiriwrite_presmodule->startbox("datalist");
4566                         foreach $page (keys %edited_list){
4568                                 # Check if the page name is not blank.
4570                                 if (!$edited_list{$page}{Name}){
4572                                         $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{noname});
4573                                         $main::kiriwrite_presmodule->addtext(" (" . $edited_list{$page}{Filename} . ")");
4575                                 } else {
4577                                         $main::kiriwrite_presmodule->addtext($edited_list{$page}{Name});
4578                                         $main::kiriwrite_presmodule->addtext(" (" . $edited_list{$page}{Filename} . ")");
4580                                 }
4582                                 $main::kiriwrite_presmodule->addlinebreak();
4583                         }
4585                         $main::kiriwrite_presmodule->endbox();
4587                 }
4589                 # Check if any warnings have occured and write a message
4590                 # if any warnings did occur.
4592                 if (%warning_list){
4594                         # One or several warnings have occured so 
4595                         # write a message.
4597                         $main::kiriwrite_presmodule->addlinebreak();
4598                         $main::kiriwrite_presmodule->addlinebreak();
4599                         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{editedpageswarnings});
4600                         $main::kiriwrite_presmodule->addlinebreak();
4601                         $main::kiriwrite_presmodule->addlinebreak();
4602                         $main::kiriwrite_presmodule->startbox("datalist");
4603                         foreach $warning (keys %warning_list) {
4604                                 $main::kiriwrite_presmodule->addtext($warning_list{$warning}{Message});
4605                                 $main::kiriwrite_presmodule->addlinebreak();
4606                         }
4607                         $main::kiriwrite_presmodule->endbox();
4609                 }
4611                 # Write a link going back to the page list for
4612                 # the selected database.
4614                 $main::kiriwrite_presmodule->addlinebreak();
4615                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{returnpagelist}, $database_name) });
4617                 return $main::kiriwrite_presmodule->grab();
4619         } elsif ($confirm eq 0){
4621                 # The action to edit the template has not been confirmed
4622                 # so write a form out instead.
4624                 # Connect to the database server.
4626                 $main::kiriwrite_dbmodule->connect();
4628                 # Check if any errors occured while connecting to the database server.
4630                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
4632                         # A database connection error has occured so return
4633                         # an error.
4635                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
4637                 }
4639                 # Select the database.
4641                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
4643                 # Check if any errors occured while selecting the database.
4645                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
4647                         # The database does not exist, so return an error.
4649                         kiriwrite_error("databasemissingfile");
4651                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
4653                         # The database has invalid permissions set, so return
4654                         # an error.
4656                         kiriwrite_error("databaseinvalidpermissions");
4658                 }
4660                 # Check if the database has read and write permissions.
4662                 my $database_permissions = $main::kiriwrite_dbmodule->dbpermissions($database, 1, 1);
4664                 if ($database_permissions eq 1){
4666                         # The database permissions are invalid so return an error.
4668                         kiriwrite_error("databaseinvalidpermissions");
4670                 }
4672                 # Get information about the database.
4674                 my %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
4676                 # Check if any errors had occured while getting the database
4677                 # information.
4679                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
4681                         # A database error has occured so return an error and
4682                         # also the extended error information.
4684                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
4686                 };
4688                 my $database_name       = $database_info{"DatabaseName"};
4690                 # Define some variables for later.
4692                 my %edit_list;
4693                 my %template_list;
4694                 my %template_info;
4695                 my %page_info;
4696                 my @templates_list;
4697                 my @filenames;
4698                 my $filelist_filename;
4699                 my $filename;
4700                 my $page;
4701                 my $pageseek = 0;
4702                 my $page_name;
4703                 my $page_filename;
4704                 my $template;
4705                 my $template_filename;
4706                 my $template_warning;
4707                 my $templateseek = 0;
4709                 tie(%edit_list, 'Tie::IxHash');
4710                 tie(%template_list, 'Tie::IxHash');
4712                 # Get the information about each page that is going
4713                 # to be edited.
4715                 foreach $filelist_filename (@filelist){
4717                         %page_info = $main::kiriwrite_dbmodule->getpageinfo({ PageFilename => $filelist_filename });
4719                         # Check if any errors occured.
4721                         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
4723                                 # A database error has occured so return an error and
4724                                 # also the extended error information.
4726                                 kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
4728                         } elsif ($main::kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
4730                                 # The page does not exist, so process the next page.
4732                                 next;
4734                         }
4736                         # Add the page name and file name to the list of
4737                         # pages to edit.
4739                         $edit_list{$pageseek}{Filename} = $page_info{"PageFilename"};
4740                         $edit_list{$pageseek}{Name}     = $page_info{"PageName"};
4742                         # Increment the page seek counter and reset the
4743                         # page found value.
4745                         $pageseek++;
4747                 }
4749                 # Check if any pages were found in the database and return
4750                 # an error if not.
4752                 if ($pageseek eq 0){
4754                         # No pages were found so return an error.
4756                         kiriwrite_error("nopagesselected");
4758                 }
4760                 # Connect to the template database.
4762                 $main::kiriwrite_dbmodule->connecttemplate();
4764                 # Check if any errors had occured.
4766                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
4768                         # The template database does not exist so write a warning
4769                         # message.
4771                         $template_warning = $main::kiriwrite_lang{pages}{templatedatabasenotexistmultieditkeep};
4773                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
4775                         # The template database has invalid permissions set so
4776                         # return an error.
4778                         $template_warning = $main::kiriwrite_lang{pages}{templatedatabasepermissionsinvalidmultieditkeep};
4780                 }
4782                 if (!$template_warning){
4784                         # Get the list of templates available.
4786                         @templates_list = $main::kiriwrite_dbmodule->gettemplatelist();
4788                         # Check if any errors had occured.
4790                         if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
4792                                 # A database error occured while getting the list
4793                                 # of templates so write a warning message with the 
4794                                 # extended error information.
4796                                 $template_warning = kiriwrite_language($main::kiriwrite_lang{pages}{templatedatabaseerrormultieditkeep}, $main::kiriwrite_dbmodule->geterror(1));
4798                         }
4800                         if (!$template_warning){
4802                                 foreach $template_filename (@templates_list){
4804                                         # Get the template data.
4806                                         %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_filename });
4808                                         # Check if any error occured while getting the template information.
4810                                         if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
4812                                                 # A database error has occured, so write a warning message with
4813                                                 # the extended error information.
4815                                                 $template_warning = kiriwrite_language($main::kiriwrite_lang{pages}{templatedatabaseerrormultieditkeep}, $main::kiriwrite_dbmodule->geterror(1));
4817                                         } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
4819                                                 # The template does not exist, so process the next page.
4821                                                 next;
4823                                         }
4825                                         # Add the template to the list of templates.
4827                                         $template_list{$templateseek}{Filename} = $template_info{"TemplateFilename"};
4828                                         $template_list{$templateseek}{Name}     = $template_info{"TemplateName"};
4830                                         $templateseek++;
4832                                 }
4834                         }
4836                 }
4838                 # Disconnect from the template database.
4840                 $main::kiriwrite_dbmodule->disconnecttemplate();
4842                 # Disconnect from the database server.
4844                 $main::kiriwrite_dbmodule->disconnect();
4846                 # Write a form for editing the selected pages.
4848                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{multiedit}, { Style => "pageheader" });
4849                 $main::kiriwrite_presmodule->addlinebreak();
4850                 $main::kiriwrite_presmodule->addlinebreak();
4851                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
4852                 $main::kiriwrite_presmodule->startbox();
4853                 $main::kiriwrite_presmodule->addhiddendata("mode", "page");
4854                 $main::kiriwrite_presmodule->addhiddendata("action", "multiedit");
4855                 $main::kiriwrite_presmodule->addhiddendata("database", $database);
4856                 $main::kiriwrite_presmodule->addhiddendata("count", $pageseek);
4857                 $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
4859                 $pageseek = 1;
4861                 foreach $page (keys %edit_list){
4862                         $main::kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on");
4863                         $main::kiriwrite_presmodule->addhiddendata("id[" . $pageseek  . "]", $edit_list{$page}{Filename});
4864                         $pageseek++;
4865                 }
4867                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{pages}{multieditmessage}, $database_name));
4868                 $main::kiriwrite_presmodule->addlinebreak();
4869                 $main::kiriwrite_presmodule->addlinebreak();
4870                 $main::kiriwrite_presmodule->startbox("datalist");
4872                 foreach $page (keys %edit_list){
4873                         if (!$edit_list{$page}{Name}){
4874                                 $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{noname});
4875                                 $main::kiriwrite_presmodule->addtext(" (" . $edit_list{$page}{Filename} . ")");
4876                         } else {
4877                                 $main::kiriwrite_presmodule->addtext($edit_list{$page}{Name} . " (" . $edit_list{$page}{Filename} . ")");
4878                         }
4880                         $main::kiriwrite_presmodule->addlinebreak();
4881                 }
4883                 $main::kiriwrite_presmodule->endbox();
4884                 $main::kiriwrite_presmodule->addlinebreak();
4885                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{multieditmessagevalues});
4886                 $main::kiriwrite_presmodule->addlinebreak();
4887                 $main::kiriwrite_presmodule->addlinebreak();
4888                 $main::kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
4890                 $main::kiriwrite_presmodule->startheader();
4891                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{alter}, { Style => "tablecellheader" });
4892                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{setting}, { Style => "tablecellheader" });
4893                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{value}, { Style => "tablecellheader" });
4894                 $main::kiriwrite_presmodule->endheader();
4896                 $main::kiriwrite_presmodule->startrow();
4897                 $main::kiriwrite_presmodule->addcell("tablecell1");
4898                 $main::kiriwrite_presmodule->addcheckbox("altersection");
4899                 $main::kiriwrite_presmodule->endcell();
4900                 $main::kiriwrite_presmodule->addcell("tablecell1");
4901                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagesection});
4902                 $main::kiriwrite_presmodule->endcell();
4903                 $main::kiriwrite_presmodule->addcell("tablecell1");
4904                 $main::kiriwrite_presmodule->addinputbox("newsection", { Size => 64, MaxLength => 256 });
4905                 $main::kiriwrite_presmodule->endcell();
4906                 $main::kiriwrite_presmodule->endrow();
4908                 $main::kiriwrite_presmodule->startrow();
4909                 $main::kiriwrite_presmodule->addcell("tablecell2");
4910                 $main::kiriwrite_presmodule->addcheckbox("altertemplate");
4911                 $main::kiriwrite_presmodule->endcell();
4912                 $main::kiriwrite_presmodule->addcell("tablecell2");
4913                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagetemplate});
4914                 $main::kiriwrite_presmodule->endcell();
4916                 $main::kiriwrite_presmodule->addcell("tablecell2");
4918                 if ($template_warning){
4920                         $main::kiriwrite_presmodule->addhiddendata("newtemplate", "!skip");
4921                         $main::kiriwrite_presmodule->addtext($template_warning);
4923                 } else {
4925                         $main::kiriwrite_presmodule->addselectbox("newtemplate");
4927                         foreach $template (keys %template_list){
4929                                 $main::kiriwrite_presmodule->addoption($template_list{$template}{Name} . " (" . $template_list{$template}{Filename} . ")", { Value => $template_list{$template}{Filename}});
4931                         }
4933                         $main::kiriwrite_presmodule->addoption($main::kiriwrite_lang{pages}{usenotemplate}, { Value => "!none", Selected => 1 });
4934                         $main::kiriwrite_presmodule->endselectbox();
4935                 }
4937                 $main::kiriwrite_presmodule->endcell();
4938                 $main::kiriwrite_presmodule->endrow();
4940                 $main::kiriwrite_presmodule->startrow();
4941                 $main::kiriwrite_presmodule->addcell("tablecell1");
4942                 $main::kiriwrite_presmodule->addcheckbox("altersettings");
4943                 $main::kiriwrite_presmodule->endcell();
4944                 $main::kiriwrite_presmodule->addcell("tablecell1");
4945                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{pages}{pagesettings});
4946                 $main::kiriwrite_presmodule->endcell();
4947                 $main::kiriwrite_presmodule->addcell("tablecell1");
4948                 $main::kiriwrite_presmodule->addradiobox("newsettings", { Description => $main::kiriwrite_lang{pages}{usepageandsection}, Value => 1 , Selected => 1});
4949                 $main::kiriwrite_presmodule->addlinebreak();
4950                 $main::kiriwrite_presmodule->addradiobox("newsettings", { Description => $main::kiriwrite_lang{pages}{usepagename}, Value => 2 });
4951                 $main::kiriwrite_presmodule->addlinebreak();
4952                 $main::kiriwrite_presmodule->addradiobox("newsettings", { Description => $main::kiriwrite_lang{pages}{usesectionname}, Value => 3 });
4953                 $main::kiriwrite_presmodule->addlinebreak();
4954                 $main::kiriwrite_presmodule->addradiobox("newsettings", { Description => $main::kiriwrite_lang{pages}{nopagesection}, Value => 0 });
4955                 $main::kiriwrite_presmodule->endcell();
4956                 $main::kiriwrite_presmodule->endrow();
4958                 $main::kiriwrite_presmodule->endtable();
4959                 $main::kiriwrite_presmodule->addlinebreak();
4960                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{pages}{editpagesbutton});
4961                 $main::kiriwrite_presmodule->addtext(" | ");
4962                 $main::kiriwrite_presmodule->addreset($main::kiriwrite_lang{common}{clearvalues});
4963                 $main::kiriwrite_presmodule->addtext(" | ");
4964                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($main::kiriwrite_lang{pages}{returnpagelist}, $database_name) });
4965                 $main::kiriwrite_presmodule->endbox();
4966                 $main::kiriwrite_presmodule->endform();
4968                 return $main::kiriwrite_presmodule->grab();
4970         } else {
4972                 # The confirm value is something else other than
4973                 # 1 or 0, so return an error.
4975                 kiriwrite_error("invalidvariable");
4977         }
4981 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