Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Extra alterations.
[kiriwrite/.git] / cgi-files / lib / page.lib
1 #################################################################################
2 # page.lib: Kiriwrite Page Library                                              #
3 #                                                                               #
4 # This library is under the same license as the main Kiriwrite script.          #
5 #################################################################################
7 # This section of the file is for when the library is called from the main
8 # Kiriwrite script.
10 if ($form_data->{'action'}){
11         my $http_query_action = $form_data->{'action'};
13         # Check if the action requested matches with one of the options below. If it does,
14         # go to that section, otherwise return an error.
16         if ($http_query_action eq "view"){
18                 # The action selected was to view pages from a database, 
20                 my $http_query_database         = $form_data->{'database'};
21                 my $http_query_browsenumber     = $form_data->{'browsenumber'};
22                 my $pagedata            = kiriwrite_page_list($http_query_database, $http_query_browsenumber);
24                 kiriwrite_output_header;        # Output the header to browser/console/stdout.
25                 kiriwrite_output_page($kiriwrite_lang->{pages}->{viewingdatabase}, $pagedata, "pages"); # Output the page to browser/console/stdout.
26                 exit;                   # End the script.
28         } elsif ($http_query_action eq "add"){
30                 # The action selected was to add a page to the selected database.
32                 my $http_query_confirm  = $form_data->{'confirm'};
34                 if (!$http_query_confirm){
36                         $http_query_confirm = 0;
38                 }
40                 if ($http_query_confirm eq 1){
42                         my $http_query_database         = $form_data->{'database'};
43                         my $http_query_filename         = $form_data->{'pagefilename'};
44                         my $http_query_name             = $form_data->{'pagename'};
45                         my $http_query_description      = $form_data->{'pagedescription'};
46                         my $http_query_section          = $form_data->{'pagesection'};
47                         my $http_query_template         = $form_data->{'pagetemplate'};
48                         my $http_query_settings         = $form_data->{'pagesettings'};
49                         my $http_query_content          = $form_data->{'pagecontent'};
50         
51                         my $pagedata                    = kiriwrite_page_add($http_query_database, $http_query_filename, $http_query_name, $http_query_description, $http_query_section, $http_query_template, $http_query_settings, $http_query_content, $http_query_confirm);
53                         kiriwrite_output_header;        # Output the header to browser/console/stdout.
54                         kiriwrite_output_page($kiriwrite_lang->{pages}->{addpage}, $pagedata, "pages"); # Output the page to browser/console/stdout.
55                         exit;                           # End the script.
57                 }
59                 my $http_query_database = $form_data->{'database'};
60                 my $pagedata            = kiriwrite_page_add($http_query_database);
62                 kiriwrite_output_header;        # Output the header to browser/console/stdout.
63                 kiriwrite_output_page($kiriwrite_lang->{pages}->{addpage}, $pagedata, "pages"); # Output the page to browser/console/stdout.
64                 exit;                           # End the script.
66         } elsif ($http_query_action eq "edit"){
67                 
68                 # The action selected was to edit a page from a database.
70                 my $http_query_confirm = $form_data->{'confirm'};
72                 if (!$http_query_confirm){
74                         $http_query_confirm = 0;
76                 }
78                 if ($http_query_confirm eq 1){
80                         # Get the needed values from the HTTP query.
82                         my $http_query_database         = $form_data->{'database'};
83                         my $http_query_filename         = $form_data->{'page'};
84                         my $http_query_newfilename      = $form_data->{'pagefilename'};
85                         my $http_query_name             = $form_data->{'pagename'};
86                         my $http_query_description      = $form_data->{'pagedescription'};
87                         my $http_query_section          = $form_data->{'pagesection'};
88                         my $http_query_template         = $form_data->{'pagetemplate'};
89                         my $http_query_settings         = $form_data->{'pagesettings'};
90                         my $http_query_content          = $form_data->{'pagecontent'};
92                         # Pass the values to the editing pages subroutine.
94                         my $pagedata = kiriwrite_page_edit($http_query_database, $http_query_filename, $http_query_newfilename, $http_query_name, $http_query_description, $http_query_section, $http_query_template, $http_query_settings, $http_query_content, $http_query_confirm);
96                         kiriwrite_output_header;        # Output the header to browser/console/stdout.
97                         kiriwrite_output_page($kiriwrite_lang->{pages}->{editpagetitle}, $pagedata, "pages");   # Output the page to browser/console/stdout.
98                         exit;                           # End the script.
100                 }
102                 # Get the needed values from the HTTP query.
104                 my $http_query_database = $form_data->{'database'};
105                 my $http_query_filename = $form_data->{'page'};
107                 # Pass the values to the editing pages subroutine.
109                 my $pagedata = kiriwrite_page_edit($http_query_database, $http_query_filename);
111                 kiriwrite_output_header;        # Output the header to browser/console/stdout.
112                 kiriwrite_output_page($kiriwrite_lang->{pages}->{editpagetitle}, $pagedata, "pages");   # Output the page to browser/console/stdout.
113                 exit;                           # End the script.
116         } elsif ($http_query_action eq "delete"){
118                 # The action selected was to delete a page from a database.
120                 my $http_query_database = $form_data->{'database'};
121                 my $http_query_page     = $form_data->{'page'};
122                 my $http_query_confirm  = $form_data->{'confirm'};
124                 my $pagedata = "";
125                 my $selectionlist = "";
127                 if ($http_query_confirm){
129                         # The action has been confirmed, so try to delete the selected page
130                         # from the database.
132                         $pagedata = kiriwrite_page_delete($http_query_database, $http_query_page, $http_query_confirm);
134                         kiriwrite_output_header;        # Output the header to browser/console/stdout.
135                         kiriwrite_output_page($kiriwrite_lang->{pages}->{deletepagetitle}, $pagedata, "pages"); # Output the page to browser/console/stdout.
136                         exit;                           # End the script.
138                 }
140                 $pagedata = kiriwrite_page_delete($http_query_database, $http_query_page);
142                 kiriwrite_output_header;        # Output the header to browser/console/stdout.
143                 kiriwrite_output_page($kiriwrite_lang->{pages}->{deletepagetitle}, $pagedata, "pages"); # Output the page to browser/console/stdout.
144                 exit;                           # End the script.
147         } elsif ($http_query_action eq "multidelete"){
149                 # The action selected was to delete multiple pages from a
150                 # database.
152                 my $http_query_database = $form_data->{'database'};
153                 my $http_query_confirm  = $form_data->{'confirm'};
155                 my @filelist;
156                 my $pagedata;
158                 if ($http_query_confirm){
160                         # The action to delete multiple pages from the selected
161                         # database has been confirmed.
163                         @filelist       = kiriwrite_selectedlist();
164                         $pagedata       = kiriwrite_page_multidelete($http_query_database, $http_query_confirm, @filelist);
166                         kiriwrite_output_header;        # Output the header to browser/console/stdout.
167                         kiriwrite_output_page($kiriwrite_lang->{pages}->{deletemultiplepages}, $pagedata, "pages"); # Output the page to browser/console/stdout.
168                         exit;                           # End the script.
170                 }
172                 # Get the list of selected pages and pass them to the
173                 # multiple page delete subroutine.
175                 @filelist       = kiriwrite_selectedlist();
176                 $pagedata       = kiriwrite_page_multidelete($http_query_database, $http_query_confirm, @filelist);
178                 kiriwrite_output_header;        # Output the header to browser/console/stdout.
179                 kiriwrite_output_page($kiriwrite_lang->{pages}->{deletemultiplepages}, $pagedata, "pages"); # Output the page to browser/console/stdout.
180                 exit;                           # End the script.
182         } elsif ($http_query_action eq "multimove"){
184                 # The action selected was to move multiple pages from a
185                 # database.
187                 my $http_query_database         = $form_data->{'database'};
188                 my $http_query_newdatabase      = $form_data->{'newdatabase'};
189                 my $http_query_confirm          = $form_data->{'confirm'};
191                 my @filelist;
192                 my $pagedata;
194                 if ($http_query_confirm){
196                         # The action to move multiple pages from the selected
197                         # database has been confirmed.
199                         @filelist       = kiriwrite_selectedlist();
200                         $pagedata       = kiriwrite_page_multimove($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
202                         kiriwrite_output_header;        # Output the header to browser/console/stdout.
203                         kiriwrite_output_page($kiriwrite_lang->{pages}->{movepages}, $pagedata, "pages"); # Output the page to browser/console/stdout.
204                         exit;                           # End the script.
206                 }
208                 # Get the list of selected pages and pass them to the
209                 # multiple page move subroutine.
211                 @filelist       = kiriwrite_selectedlist();
212                 $pagedata       = kiriwrite_page_multimove($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
214                 kiriwrite_output_header;        # Output the header to browser/console/stdout.
215                 kiriwrite_output_page($kiriwrite_lang->{pages}->{movepages}, $pagedata, "pages"); # Output the page to browser/console/stdout.
216                 exit;                           # End the script.
218         } elsif ($http_query_action eq "multicopy"){
220                 # The action selected was to copy multiple pages from a
221                 # database.
223                 my $http_query_database         = $form_data->{'database'};
224                 my $http_query_newdatabase      = $form_data->{'newdatabase'};
225                 my $http_query_confirm          = $form_data->{'confirm'};
227                 my @filelist;
228                 my $pagedata;
230                 if ($http_query_confirm){
232                         # The action to copy multiple pages from the selected
233                         # database has been confirmed.
235                         @filelist       = kiriwrite_selectedlist();
236                         $pagedata       = kiriwrite_page_multicopy($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
238                         kiriwrite_output_header;        # Output the header to browser/console/stdout.
239                         kiriwrite_output_page($kiriwrite_lang->{pages}->{copypages}, $pagedata, "pages"); # Output the page to browser/console/stdout.
240                         exit;                           # End the script.
242                 }
244                 # Get the list of selected pages and pass them to the
245                 # multiple page copy subroutine.
247                 @filelist       = kiriwrite_selectedlist();
248                 $pagedata       = kiriwrite_page_multicopy($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
250                 kiriwrite_output_header;        # Output the header to browser/console/stdout.
251                 kiriwrite_output_page($kiriwrite_lang->{pages}->{copypages}, $pagedata, "pages"); # Output the page to browser/console/stdout.
252                 exit;                           # End the script.
254         } elsif ($http_query_action eq "multiedit"){
256                 # The action selected was to edit multiple pages from a
257                 # database.
259                 my $http_query_database         = $form_data->{'database'};
260                 my $http_query_newsection       = $form_data->{'newsection'};
261                 my $http_query_altersection     = $form_data->{'altersection'};
262                 my $http_query_newtemplate      = $form_data->{'newtemplate'};
263                 my $http_query_altertemplate    = $form_data->{'altertemplate'};
264                 my $http_query_newsettings      = $form_data->{'newsettings'};
265                 my $http_query_altersettings    = $form_data->{'altersettings'};
266                 my $http_query_confirm          = $form_data->{'confirm'};
268                 my @filelist;
269                 my $pagedata;
271                 if (!$http_query_confirm){
273                         @filelist       = kiriwrite_selectedlist();
274                         $pagedata       = kiriwrite_page_multiedit($http_query_database, $http_query_newsection, $http_query_altersection, $http_query_newtemplate, $http_query_altertemplate, $http_query_newsettings, $http_query_altersettings, $http_query_confirm, @filelist);
276                         kiriwrite_output_header;        # Output the header to browser/console/stdout.
277                         kiriwrite_output_page($kiriwrite_lang->{pages}->{multiedit}, $pagedata, "pages"); # Output the page to browser/console/stdout.
278                         exit;
280                 }
282                 # Get the list of selected pages and pass them to the
283                 # multiple page edit subroutine.
285                 @filelist       = kiriwrite_selectedlist();
286                 $pagedata       = kiriwrite_page_multiedit($http_query_database, $http_query_newsection, $http_query_altersection, $http_query_newtemplate, $http_query_altertemplate, $http_query_newsettings, $http_query_altersettings, $http_query_confirm, @filelist);
288                 kiriwrite_output_header;        # Output the header to browser/console/stdout.
289                 kiriwrite_output_page($kiriwrite_lang->{pages}->{multiedit}, $pagedata, "pages"); # Output the page to browser/console/stdout.
290                 exit;                           # End the script.
292         } else {
293                 kiriwrite_error("invalidaction");
294         }
296 } else {
298         # If there the action option is left blank, then print out a form where the database
299         # can be selected to view pages from.
301         my $pagedata = kiriwrite_page_list();
303         kiriwrite_output_header;        # Output the header to browser/console/stdout.
304         kiriwrite_output_page($kiriwrite_lang->{pages}->{databaseselecttitle}, $pagedata, "pages");     # Output the page to browser/console/stdout.
305         exit;                           # End the script.
309 #################################################################################
310 # Begin list of relevant subroutines.                                           #
311 #################################################################################
313 sub kiriwrite_page_list{
314 #################################################################################
315 # kiriwrite_page_list: Lists pages from an database.                            #
316 #                                                                               #
317 # Usage:                                                                        #
318 #                                                                               #
319 # kiriwrite_page_list([database], [browsernumber]);                             #
320 #                                                                               #
321 # database      Specifies the database to retrieve the pages from.              #
322 # browsenumber  Specifies which list of pages to look at.                       #
323 #################################################################################
325         # Get the database file name from what was passed to the subroutine.
327         my ($database_file, $page_browsenumber) = @_;
329         # Check if the database_file variable is empty, if it is then print out a
330         # select box asking the user to select a database from the list.
332         if (!$database_file) {
334                 # Define the variables required for this section.
336                 my %database_info;
337                 my @database_list;
338                 my @databasefilenames;
339                 my @databasenames;
340                 my $dbseek              = 0;
341                 my $dbfilename          = "";
342                 my $dbname              = "";
343                 my $data_file           = "";
344                 my $data_file_length    = 0;
345                 my $data_file_friendly  = "";
346                 my $database_name       = "";
347                 my $file_permissions    = "";
349                 # Connect to the database server.
351                 $kiriwrite_dbmodule->connect();
353                 # Check if any errors occured while connecting to the database server.
355                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
357                         # A database connection error has occured so return
358                         # an error.
360                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
362                 }
364                 # Open the data directory and get all of the databases.
366                 @database_list  = $kiriwrite_dbmodule->getdblist();
368                 # Check if any errors occured while trying to get the list of databases.
370                 if ($kiriwrite_dbmodule->geterror eq "DataDirMissing"){
372                         # The database directory is missing so return an error.
374                         kiriwrite_error("datadirectorymissing");
376                 } elsif ($kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){
378                         # The database directory has invalid permissions set so return
379                         # an error.
381                         kiriwrite_error("datadirectoryinvalidpermissions");
383                 }
385                 # Get the information about each database (the short name and friendly name).
387                 foreach $data_file (@database_list){
389                         $kiriwrite_dbmodule->selectdb({ DatabaseName => $data_file });
391                         # Check if any errors occured while selecting the database.
393                         if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
395                                 # The database does not exist, so process the next
396                                 # database.
398                                 next;
400                         } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
402                                 # The database has invalid permissions set, so process
403                                 # the next database.
405                                 next;
407                         }
409                         # Get the database information.
411                         %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
413                         # Check if any errors had occured while getting the database
414                         # information.
416                         if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
418                                 # A database error has occured, so process the next 
419                                 # database.
421                                 next;
423                         };
425                         # Set the database name.
427                         $database_name          = $database_info{"DatabaseName"};
429                         # Check if the database name is undefined and if it is
430                         # then set it blank.
432                         if (!$database_name){
433                                 $database_name = "";
434                         }
436                         # Append the database to the list of databases available.
438                         push(@databasefilenames, $data_file);
439                         push(@databasenames, $database_name);
441                 }
443                 # Disconnect from the database server.
445                 $kiriwrite_dbmodule->disconnect();
447                 # Write the page data.
449                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{viewpages}, { Style => "pageheader" });
450                 $kiriwrite_presmodule->addlinebreak();
451                 $kiriwrite_presmodule->addlinebreak();
452                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{nodatabaseselected});
453                 $kiriwrite_presmodule->addlinebreak();
454                 $kiriwrite_presmodule->addlinebreak();
455                 $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"});
456                 $kiriwrite_presmodule->startbox();
457                 $kiriwrite_presmodule->addhiddendata("mode", "page");
458                 $kiriwrite_presmodule->addhiddendata("action", "view");
459                 $kiriwrite_presmodule->addselectbox("database");
460                 foreach $dbfilename (@databasefilenames){
461                         $dbname = $databasenames[$dbseek];
462                         $dbseek++;
463                         $kiriwrite_presmodule->addoption($dbname . " (" . $dbfilename . ")", { Value => $dbfilename });
464                 }
465                 $kiriwrite_presmodule->endselectbox();
466                 $kiriwrite_presmodule->addtext(" | ");
467                 $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{viewbutton});
468                 $kiriwrite_presmodule->endbox();
469                 $kiriwrite_presmodule->endform();
471                 return $kiriwrite_presmodule->grab();
473         } else {
475                 my %database_info;
476                 my %page_info;
477                 my @database_pages;
478                 my $pagemultioptions    = "";
479                 my $db_name             = "";
480                 my $tablestyle          = "";
482                 my $page_filename       = "";
483                 my $page_name           = "";
484                 my $page_description    = "";
485                 my $page_modified       = "";
487                 my $tablestyletype      = 0;
488                 my $page_count          = 0;
489                 my $db_file_notblank    = 0;
490                 my $page_split          = 50;
491                 my $page_list           = 0;
492                 my $page_list_count     = 0;
494                 tie(%database_info, 'Tie::IxHash');
495                 tie(%page_info, 'Tie::IxHash');
497                 # The database_file variable is not blank, so print out a list of pages from
498                 # the selected database.
500                 # Preform a variable check on the database filename to make sure that it is
501                 # valid before using it.
503                 kiriwrite_variablecheck($database_file, "filename", "", 0);
504                 kiriwrite_variablecheck($database_file, "maxlength", 32, 0);
506                 if (!$page_browsenumber || $page_browsenumber eq 0){
508                         $page_browsenumber = 1;
510                 }
512                 # Check if the page browse number is valid and if it isn't
513                 # then return an error.
515                 my $kiriwrite_browsenumber_length_check         = kiriwrite_variablecheck($page_browsenumber, "maxlength", 7, 1);
516                 my $kiriwrite_browsenumber_number_check         = kiriwrite_variablecheck($page_browsenumber, "numbers", 0, 1);
518                 if ($kiriwrite_browsenumber_length_check eq 1){
520                         # The browse number was too long so return
521                         # an error.
523                         kiriwrite_error("browsenumbertoolong");
525                 }
527                 if ($kiriwrite_browsenumber_number_check eq 1){
529                         # The browse number wasn't a number so
530                         # return an error.
532                         kiriwrite_error("browsenumberinvalid");
534                 }
536                 # Connect to the database server.
538                 $kiriwrite_dbmodule->connect();
540                 # Check if any errors occured while connecting to the database server.
542                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
544                         # A database connection error has occured so return
545                         # an error.
547                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
549                 }
551                 # Select the database.
553                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $database_file });
555                 # Check if any errors had occured while selecting the database.
557                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
559                         # The database does not exist, so return an error.
561                         kiriwrite_error("databasemissingfile");
563                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
565                         # The database has invalid permissions set, so return
566                         # an error.
568                         kiriwrite_error("databaseinvalidpermissions");
570                 }
572                 # Get information about the database.
574                 %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
576                 $db_name = $database_info{"DatabaseName"};
578                 # Check if any errors had occured while getting the database
579                 # information.
581                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
583                         # A database error has occured so return an error and
584                         # also the extended error information.
586                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
588                 }
590                 # Get the count of pages in the database.
592                 my $page_total_count = $kiriwrite_dbmodule->getpagecount();
594                 # Check if any errors had occured while getting the count of
595                 # pages in the database.
597                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
599                         # A database error has occured so return an error and
600                         # also the extended error information.
602                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
604                 }
606                 # Work out the total amount of page browse numbers.
608                 if ($page_total_count ne 0){
610                         if ($page_total_count eq $page_split){
612                                 $page_list = substr(($page_total_count / $page_split), 0, 1);
614                         } else {
616                                 $page_list = substr(($page_total_count / $page_split), 0, 1) + 1;
618                         }
620                 }
622                 my $start_from = ($page_browsenumber - 1) * $page_split;
624                 # Get the list of pages.
626                 @database_pages = $kiriwrite_dbmodule->getpagelist({ StartFrom => $start_from, Limit => $page_split });
628                 # Check if any errors had occured while getting the list of pages.
630                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
632                         # A database error has occured so return an error and
633                         # also the extended error information.
635                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
637                 }
639                 # Check if there are any page names in the database array.
641                 if (@database_pages){
643                         # Write the start of the page.
645                         $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{pagelist}, $db_name), { Style => "pageheader" });
646                         $kiriwrite_presmodule->addlinebreak();
647                         $kiriwrite_presmodule->addlinebreak();
648                         $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST");
649                         $kiriwrite_presmodule->startbox();
650                         $kiriwrite_presmodule->addhiddendata("mode", "page");
651                         $kiriwrite_presmodule->addhiddendata("database", $database_file);
652                         $kiriwrite_presmodule->addhiddendata("type", "multiple");
654                         # Write out the page browsing list.
656                         $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{showlistpage});
657                         $kiriwrite_presmodule->addselectbox("browsenumber");
659                         # Write out the list of available pages to browse.
660                         
661                         while ($page_list_count ne $page_list){
663                                 $page_list_count++;
665                                 if ($page_list_count eq 1 && !$page_browsenumber){
667                                         $kiriwrite_presmodule->addoption($page_list_count, { Value => $page_list_count, Selected => 1 });
669                                 } else {
671                                         if ($page_browsenumber eq $page_list_count){
673                                                 $kiriwrite_presmodule->addoption($page_list_count, { Value => $page_list_count, Selected => 1 });
675                                         } else {
677                                                 $kiriwrite_presmodule->addoption($page_list_count, { Value => $page_list_count });
679                                         }
681                                 }
683                         }
685                         $kiriwrite_presmodule->endselectbox();
686                         $kiriwrite_presmodule->addbutton("action", { Value => "view", Description => $kiriwrite_lang->{pages}->{show} });
689                         if ($page_list ne $page_browsenumber){
691                                 $kiriwrite_presmodule->addtext(" | ");
692                                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database_file . "&browsenumber=" . ($page_browsenumber + 1), { Text => $kiriwrite_lang->{pages}->{nextpage} });
694                         }
696                         # Check if the page browse number is not blank and
697                         # not set as 0 and hide the Previous page link if
698                         # it is.
700                         if ($page_browsenumber > 1){
702                                 $kiriwrite_presmodule->addtext(" | ");
703                                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database_file . "&browsenumber=" . ($page_browsenumber - 1), { Text => $kiriwrite_lang->{pages}->{previouspage} });
705                         }
707                         $kiriwrite_presmodule->addlinebreak();
709                         # Write the list of multiple selection options.
711                         $kiriwrite_presmodule->addreset($kiriwrite_lang->{common}->{selectnone});
712                         $kiriwrite_presmodule->addtext(" | ");
713                         $kiriwrite_presmodule->addbutton("action", { Value => "multidelete", Description => $kiriwrite_lang->{pages}->{deleteselectedbutton} });
714                         $kiriwrite_presmodule->addtext(" | ");
715                         $kiriwrite_presmodule->addbutton("action", { Value => "multimove", Description => $kiriwrite_lang->{pages}->{moveselectedbutton} });
716                         $kiriwrite_presmodule->addtext(" | ");
717                         $kiriwrite_presmodule->addbutton("action", { Value => "multicopy", Description => $kiriwrite_lang->{pages}->{copyselectedbutton} });
718                         $kiriwrite_presmodule->addtext(" | ");
719                         $kiriwrite_presmodule->addbutton("action", { Value => "multiedit", Description => $kiriwrite_lang->{pages}->{editselectedbutton} });
721                         $kiriwrite_presmodule->addlinebreak();
722                         $kiriwrite_presmodule->addlinebreak();
723                         $kiriwrite_presmodule->endbox();
725                         # Write the table header.
727                         $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
728                         $kiriwrite_presmodule->startheader();
729                         $kiriwrite_presmodule->addheader("", { Style => "tablecellheader" });
730                         $kiriwrite_presmodule->addheader($kiriwrite_lang->{pages}->{pagefilename}, { Style => "tablecellheader" });
731                         $kiriwrite_presmodule->addheader($kiriwrite_lang->{pages}->{pagename}, { Style => "tablecellheader" });
732                         $kiriwrite_presmodule->addheader($kiriwrite_lang->{pages}->{pagedescription}, { Style => "tablecellheader" });
733                         $kiriwrite_presmodule->addheader($kiriwrite_lang->{pages}->{lastmodified}, { Style => "tablecellheader" });
734                         $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{options}, { Style => "tablecellheader" });
735                         $kiriwrite_presmodule->endheader();
737                         # Process each page filename and get the page information.
739                         foreach $page_filename (@database_pages){
741                                 %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $page_filename, Reduced => 1 });
743                                 # Check if any errors have occured.
745                                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
747                                         # A database error has occured so return an error and
748                                         # also the extended error information.
750                                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
752                                 } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
754                                         # The page does not exist, so process the next page.
756                                         next;
758                                 }
760                                 $page_count++;
762                                 $page_filename          = $page_info{"PageFilename"};
763                                 $page_name              = $page_info{"PageName"};
764                                 $page_description       = $page_info{"PageDescription"};
765                                 $page_modified          = $page_info{"PageLastModified"};
767                                 # Set the table cell style.
769                                 if ($tablestyletype eq 0){
771                                         $tablestyle = "tablecell1";
772                                         $tablestyletype = 1;
774                                 } else {
776                                         $tablestyle = "tablecell2";
777                                         $tablestyletype = 0;
779                                 }
781                                 # Write out the row of data.
783                                 $kiriwrite_presmodule->startrow();
784                                 $kiriwrite_presmodule->addcell($tablestyle);
785                                 $kiriwrite_presmodule->addhiddendata("id[" . $page_count . "]", $page_filename);
786                                 $kiriwrite_presmodule->addcheckbox("name[" . $page_count . "]");
787                                 $kiriwrite_presmodule->endcell();
788                                 $kiriwrite_presmodule->addcell($tablestyle);
789                                 $kiriwrite_presmodule->addtext($page_filename);
790                                 $kiriwrite_presmodule->endcell();
791                                 $kiriwrite_presmodule->addcell($tablestyle);
793                                 if (!$page_name){
795                                         $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname});
797                                 } else {
799                                         $kiriwrite_presmodule->addtext($page_name);
801                                 }
803                                 $kiriwrite_presmodule->endcell();
804                                 $kiriwrite_presmodule->addcell($tablestyle);
806                                 if (!$page_description){
808                                         $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{nodescription});
810                                 } else {
812                                         $kiriwrite_presmodule->addtext($page_description);
814                                 }
816                                 $kiriwrite_presmodule->endcell();
817                                 $kiriwrite_presmodule->addcell($tablestyle);
819                                 if (!$page_modified){
821                                         $kiriwrite_presmodule->additalictext("No Date");
823                                 } else {
825                                         $kiriwrite_presmodule->addtext($page_modified);
827                                 }
829                                 $kiriwrite_presmodule->endcell();
830                                 $kiriwrite_presmodule->addcell($tablestyle);
831                                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"}  . "?mode=page&action=edit&database=" . $database_file . "&page=" . $page_filename, { Text => $kiriwrite_lang->{options}->{edit} });
832                                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"}  . "?mode=page&action=delete&database=" . $database_file . "&page=" . $page_filename, { Text => $kiriwrite_lang->{options}->{delete} });
833                                 $kiriwrite_presmodule->endcell();
834                                 $kiriwrite_presmodule->endrow();
836                                 # Increment the counter.
838                         }
840                 }
842                 # Disconnect from the database server.
844                 $kiriwrite_dbmodule->disconnect();
846                 $kiriwrite_presmodule->endtable();
847                 $kiriwrite_presmodule->startbox();
848                 $kiriwrite_presmodule->addhiddendata("count", $page_count);
849                 $kiriwrite_presmodule->endbox();
850                 $kiriwrite_presmodule->endform();
852                 if (!@database_pages && $page_browsenumber > 1){
854                         # There were no values given for the page browse
855                         # number given so write a message saying that
856                         # there were no pages for the page browse number
857                         # given.
859                         $kiriwrite_presmodule->clear();
860                         $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{pagelist}, $db_name), { Style => "pageheader" });
861                         $kiriwrite_presmodule->addlinebreak();
862                         $kiriwrite_presmodule->addlinebreak();
863                         $kiriwrite_presmodule->startbox("errorbox");
864                         $kiriwrite_presmodule->enterdata($kiriwrite_lang->{pages}->{nopagesinpagebrowse});
865                         $kiriwrite_presmodule->addlinebreak();
866                         $kiriwrite_presmodule->addlinebreak();
867                         $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database_file, { Text => $kiriwrite_lang->{pages}->{returntofirstpagebrowse} });
868                         $kiriwrite_presmodule->endbox();        
870                 } elsif (!@database_pages || !$page_count){
872                         # There were no values in the database pages array and 
873                         # the page count had not been incremented so write a
874                         # message saying that there were no pages in the
875                         # database.
877                         $kiriwrite_presmodule->clear();
878                         $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{pagelist}, $db_name), { Style => "pageheader" });
879                         $kiriwrite_presmodule->addlinebreak();
880                         $kiriwrite_presmodule->addlinebreak();
881                         $kiriwrite_presmodule->startbox("errorbox");
882                         $kiriwrite_presmodule->enterdata($kiriwrite_lang->{pages}->{nopagesindatabase});
883                         $kiriwrite_presmodule->endbox();
885                 }
887                 return $kiriwrite_presmodule->grab();
889         }
893 sub kiriwrite_page_add{
894 #################################################################################
895 # kiriwrite_page_add: Adds a page to a database                                 #
896 #                                                                               #
897 # Usage:                                                                        #
898 #                                                                               #
899 # kiriwrite_page_add(database, pagefilename, title, description, section,       #
900 #                       template, settings, info, confirm);                     #
901 #                                                                               #
902 # database      Specifies the database name.                                    #
903 # pagefilename  Specifies the page filename.                                    #
904 # title         Specifies the page title to be used.                            #
905 # description   Specifies the short description of the page.                    #
906 # section       Specifies the section assigned to the page.                     #
907 # template      Specifies the template to use.                                  #
908 # settings      Specifies the settings to be used on the page.                  #
909 # data          Specifies the data which consists the page.                     #
910 # confirm       Confirms action to add an page.                                 #
911 #################################################################################
913         # Fetch the required variables that have been passed to the subroutine.
915         my ($pagedatabase, $pagefilename, $pagetitle, $pagedescription, $pagesection, $pagetemplate, $pagesettings, $pagefiledata, $confirm) = @_;
917         # Check if the action to add a new page has been confirmed (or not).
919         if (!$confirm){
921                 $confirm = 0;
923         }
925         kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
927         # Check if the database filename is valid and return an error if
928         # it isn't.
930         my $pagedatabase_filename_check = kiriwrite_variablecheck($pagedatabase, "filename", 0, 1);
932         if ($pagedatabase_filename_check eq 1){
934                 # The database filename is blank, so return an error.
936                 kiriwrite_error("blankdatabasepageadd");
938         } elsif ($pagedatabase_filename_check eq 2){
940                 # The database filename is invalid, so return an error.
942                 kiriwrite_error("databasefilenameinvalid");
944         }
946         # Check the length the database name and return an error if it's
947         # too long.
949         my $pagedatabase_length_check   = kiriwrite_variablecheck($pagedatabase, "maxlength", 32, 1);
951         if ($pagedatabase_length_check eq 1){
953                 # The database name is too long, so return an error.
955                 kiriwrite_error("databasefilenametoolong");
957         }
959         if ($confirm eq "1"){
961                 # Check all the variables to see if they UTF8 valid.
963                 kiriwrite_variablecheck($pagefilename, "utf8", 0, 0);
964                 kiriwrite_variablecheck($pagetitle, "utf8", 0, 0);
965                 kiriwrite_variablecheck($pagedescription, "utf8", 0, 0);
966                 kiriwrite_variablecheck($pagesection, "utf8", 0, 0);
967                 kiriwrite_variablecheck($pagedatabase, "utf8", 0, 0);
968                 kiriwrite_variablecheck($pagesettings, "utf8", 0, 0);
969                 kiriwrite_variablecheck($pagetemplate, "utf8", 0, 0);
970                 kiriwrite_variablecheck($pagefiledata, "utf8", 0, 0);
972                 # Convert the values into proper UTF8 values.
974                 $pagefilename           = kiriwrite_utf8convert($pagefilename);
975                 $pagetitle              = kiriwrite_utf8convert($pagetitle);
976                 $pagedescription        = kiriwrite_utf8convert($pagedescription);
977                 $pagesection            = kiriwrite_utf8convert($pagesection);
978                 $pagedatabase           = kiriwrite_utf8convert($pagedatabase);
979                 $pagesettings           = kiriwrite_utf8convert($pagesettings);
980                 $pagetemplate           = kiriwrite_utf8convert($pagetemplate);
981                 $pagefiledata           = kiriwrite_utf8convert($pagefiledata);
983                 # Check all the variables (except for the page data, filename and settings 
984                 # will be checked more specifically later if needed) that were passed to 
985                 # the subroutine.
987                 my $pagefilename_maxlength_check                = kiriwrite_variablecheck($pagefilename, "maxlength", 256, 1);
988                 my $pagetitle_maxlength_check                   = kiriwrite_variablecheck($pagetitle, "maxlength", 512, 1);
989                 my $pagedescription_maxlength_check             = kiriwrite_variablecheck($pagedescription, "maxlength", 512, 1);
990                 my $pagesection_maxlength_check                 = kiriwrite_variablecheck($pagesection, "maxlength", 256, 1);
991                 my $pagedatabase_maxlength_check                = kiriwrite_variablecheck($pagedatabase, "maxlength", 32, 1);
992                 my $pagesettings_maxlength_check                = kiriwrite_variablecheck($pagesettings, "maxlength", 1, 1);
993                 my $pagetemplate_maxlength_check                = kiriwrite_variablecheck($pagetemplate, "maxlength", 64, 1);
995                 # Check if an value returned is something else other than 0.
997                 if ($pagefilename_maxlength_check eq 1){
999                         # The page filename given is too long, so return an error.
1001                         kiriwrite_error("pagefilenametoolong");
1003                 }
1005                 if ($pagetitle_maxlength_check eq 1){
1007                         # The page title given is too long, so return an error.
1009                         kiriwrite_error("pagetitletoolong");
1011                 }
1013                 if ($pagedescription_maxlength_check eq 1){
1015                         # The page description given is too long, so return an error.
1017                         kiriwrite_error("pagedescriptiontoolong");
1019                 }
1021                 if ($pagesection_maxlength_check eq 1){
1023                         # The page section given is too long, so return an error.
1025                         kiriwrite_error("pagesectiontoolong");
1027                 }
1029                 if ($pagedatabase_maxlength_check eq 1){
1031                         # The page database given is too long, so return an error.
1033                         kiriwrite_error("pagedatabasefilenametoolong");
1035                 }
1037                 if ($pagesettings_maxlength_check eq 1){
1039                         # The page settings given is too long, so return an error.
1041                         kiriwrite_error("pagesettingstoolong");
1043                 }
1045                 if ($pagetemplate_maxlength_check eq 1){
1047                         # The page template given is too long, so return an error.
1049                         kiriwrite_error("pagetemplatefilenametoolong");
1051                 }
1053                 # The action to create a new page has been confirmed, so add the page to the
1054                 # selected database.
1056                 if (!$pagefilename){
1057                         kiriwrite_error("pagefilenameblank");
1058                 }
1060                 # Check the page filename and page settings.
1062                 my $pagefilename_filename_check = kiriwrite_variablecheck($pagefilename, "page_filename", 0, 1);
1063                 my $pagesettings_setting_check  = kiriwrite_variablecheck($pagesettings, "pagesetting", 0, 1);
1064                 my $pagetemplate_filename_check = 0;
1066                 if ($pagetemplate ne "!none"){
1068                         # A template is being used so check the filename of the
1069                         # template.
1071                         $pagetemplate_filename_check    = kiriwrite_variablecheck($pagetemplate, "page_filename", 0, 1);
1073                 }
1075                 if ($pagefilename_filename_check ne 0){
1077                         # The page filename given is invalid, so return an error.
1079                         kiriwrite_error("pagefilenameinvalid");
1081                 }
1083                 if ($pagesettings_setting_check eq 1){
1085                         # The page settings given is invalid, so return an error.
1087                         kiriwrite_error("pagesettingsinvalid");
1089                 }
1091                 if ($pagetemplate_filename_check eq 1){
1093                         # The template filename given is invalid, so return an error
1095                         kiriwrite_error("templatefilenameinvalid");
1097                 }
1099                 # Check if the database has write permissions.
1101                 my $database_permissions = $kiriwrite_dbmodule->dbpermissions($pagedatabase, 1, 1);
1103                 if ($database_permissions eq 1){
1105                         # The database permissions are invalid so return an error.
1107                         kiriwrite_error("databaseinvalidpermissions");
1109                 }
1111                 # Connect to the database server.
1113                 $kiriwrite_dbmodule->connect();
1115                 # Check if any errors occured while connecting to the database server.
1117                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1119                         # A database connection error has occured so return
1120                         # an error.
1122                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
1124                 }
1126                 # Select the database to add the page to.
1128                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $pagedatabase });
1130                 # Check if any errors had occured while selecting the database.
1132                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
1134                         # The database does not exist, so return an error.
1136                         kiriwrite_error("databasemissingfile");
1138                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
1140                         # The database has invalid permissions set, so return
1141                         # an error.
1143                         kiriwrite_error("databaseinvalidpermissions");
1145                 }
1147                 # Get information about the database.
1149                 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
1151                 # Check if any error occured while getting the database information.
1153                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
1155                         # A database error has occured so return an error and
1156                         # also the extended error information.
1158                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
1160                 };
1162                 # Add the page to the selected database.
1164                 $kiriwrite_dbmodule->addpage({ PageFilename => $pagefilename, PageName => $pagetitle, PageDescription => $pagedescription, PageSection => $pagesection, PageTemplate => $pagetemplate, PageContent => $pagefiledata, PageSettings => $pagesettings });
1166                 # Check if any errors occured while adding the page.
1168                 if ($kiriwrite_dbmodule->geterror eq "PageExists"){
1170                         # A page with the filename given already exists so
1171                         # return an error.
1173                         kiriwrite_error("pagefilenameexists");
1175                 } elsif ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
1177                         # A database error has occured so return an error
1178                         # with extended error information.
1180                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
1182                 }
1184                 my $database_name = $database_info{"DatabaseName"};
1186                 # Disconnect from the database server.
1188                 $kiriwrite_dbmodule->disconnect();
1190                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{addpage}, { Style => "pageheader" });
1191                 $kiriwrite_presmodule->addlinebreak();
1192                 $kiriwrite_presmodule->addlinebreak();
1193                 $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{pageaddedmessage}, $pagetitle, $database_name));
1194                 $kiriwrite_presmodule->addlinebreak();
1195                 $kiriwrite_presmodule->addlinebreak();
1196                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $pagedatabase, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name) });
1198                 return $kiriwrite_presmodule->grab();
1200         } elsif ($confirm eq 0) {
1202                 # The action to create a new page has not been confirmed, so print out a form
1203                 # for adding a page to a database.
1205                 my %template_list;
1206                 my %template_info;
1207                 my @templates_list;
1208                 my %database_info;
1209                 my $template_filename;
1210                 my $template_name;
1211                 my $template_data = "";
1212                 my $template_warningmessage;
1213                 my $template_warning = 0;
1214                 my $template_count = 0;
1215                 my $template;
1217                 tie(%template_list, 'Tie::IxHash');
1219                 # Connect to the database server.
1221                 $kiriwrite_dbmodule->connect();
1223                 # Check if any errors occured while connecting to the database server.
1225                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1227                         # A database connection error has occured so return
1228                         # an error.
1230                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
1232                 }
1234                 # Select the database.
1236                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $pagedatabase });
1238                 # Check if any errors had occured while selecting the database.
1240                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
1242                         # The database does not exist, so return an error.
1244                         kiriwrite_error("databasemissingfile");
1246                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
1248                         # The database has invalid permissions set, so return
1249                         # an error.
1251                         kiriwrite_error("databaseinvalidpermissions");
1253                 }
1255                 # Check if the database has write permissions.
1257                 my $database_permissions = $kiriwrite_dbmodule->dbpermissions($pagedatabase, 1, 1);
1259                 if ($database_permissions eq 1){
1261                         # The database permissions are invalid so return an error.
1263                         kiriwrite_error("databaseinvalidpermissions");
1265                 }
1267                 # Get information about the database.
1269                 %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
1271                 # Check if any error occured while getting the database information.
1273                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
1275                         # A database error has occured so return an error and
1276                         # also the extended error information.
1278                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
1280                 };
1282                 # Connect to the template database.
1284                 $kiriwrite_dbmodule->connecttemplate();
1286                 # Check if any errors occured while connecting to the template database.
1288                 if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
1290                         # The template database does not exist so set the template
1291                         # warning message.
1293                         $template_warningmessage = $kiriwrite_lang->{pages}->{notemplatedatabase};
1294                         $template_warning = 1;
1296                 } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
1298                         # The template database has invalid permissions set so write
1299                         # the template warning message.
1301                         $template_warningmessage = $kiriwrite_lang->{pages}->{templatepermissionserror};
1302                         $template_warning = 1;
1304                 }
1306                 if ($template_warning eq 0){
1308                         # Get the list of templates available.
1310                         @templates_list = $kiriwrite_dbmodule->gettemplatelist();
1312                         # Check if any errors had occured.
1314                         if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1316                                 # A database error occured while getting the list
1317                                 # of templates so return a warning message with the 
1318                                 # extended error information.
1320                                 $template_warningmessage = kiriwrite_language($kiriwrite_lang->{pages}->{templatedatabaseerror}, $kiriwrite_dbmodule->geterror(1));
1321                                 $template_warning = 1;
1323                         }
1325                         if ($template_warning eq 0){
1327                                 # Check to see if there are any templates in the templates
1328                                 # list array.
1330                                 my $template_filename = "";
1331                                 my $template_name = "";
1333                                 foreach $template (@templates_list){
1335                                         # Get information about the template.
1337                                         %template_info = $kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template });
1339                                         # Check if any error occured while getting the template information.
1341                                         if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1343                                                 # A database error has occured, so return an error.
1345                                                 kiriwrite_error("templatedatabaseerror", $kiriwrite_dbmodule->geterror(1));
1347                                         } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
1349                                                 # The template does not exist, so process the next template.
1351                                                 next;
1353                                         }
1355                                         # Get the template filename and name.
1357                                         $template_filename = $template_info{"TemplateFilename"};
1358                                         $template_name = $template_info{"TemplateName"};
1360                                         $template_list{$template_count}{Filename} = $template_filename;
1361                                         $template_list{$template_count}{Name} = $template_name;
1363                                         $template_count++;
1365                                 }
1367                                 # Check if the final template list is blank.
1369                                 if (!%template_list){
1371                                         # The template list is blank so write the template
1372                                         # warning message.
1374                                         $template_warningmessage = $kiriwrite_lang->{pages}->{notemplatesavailable};
1376                                 }
1378                         }
1380                 }
1382                 my $database_name       = $database_info{"DatabaseName"};
1384                 # Disconnect from the template database.
1386                 $kiriwrite_dbmodule->disconnecttemplate();
1388                 # Disconnect from the database server.
1390                 $kiriwrite_dbmodule->disconnect();
1392                 # write out the form for adding a page.
1394                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{addpage}, { Style => "pageheader" });
1395                 $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST");#
1396                 $kiriwrite_presmodule->startbox();
1397                 $kiriwrite_presmodule->addhiddendata("mode", "page");
1398                 $kiriwrite_presmodule->addhiddendata("action", "add");
1399                 $kiriwrite_presmodule->addhiddendata("database", $pagedatabase);
1400                 $kiriwrite_presmodule->addhiddendata("confirm", "1");
1401                 $kiriwrite_presmodule->addlinebreak();
1402                 $kiriwrite_presmodule->endbox();
1403                 $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
1405                 $kiriwrite_presmodule->startheader();
1406                 $kiriwrite_presmodule->addcell("tablecellheader");
1407                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{setting});
1408                 $kiriwrite_presmodule->endcell();
1409                 $kiriwrite_presmodule->addcell("tablecellheader");
1410                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{value});
1411                 $kiriwrite_presmodule->endcell();
1412                 $kiriwrite_presmodule->endheader();
1414                 $kiriwrite_presmodule->startrow();
1415                 $kiriwrite_presmodule->addcell("tablecell1");
1416                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{database});
1417                 $kiriwrite_presmodule->endcell();
1418                 $kiriwrite_presmodule->addcell("tablecell2");
1419                 $kiriwrite_presmodule->addtext($database_name);
1420                 $kiriwrite_presmodule->endcell();
1421                 $kiriwrite_presmodule->endrow();
1423                 $kiriwrite_presmodule->startrow();
1424                 $kiriwrite_presmodule->addcell("tablecell1");
1425                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagename});
1426                 $kiriwrite_presmodule->endcell();
1427                 $kiriwrite_presmodule->addcell("tablecell2");
1428                 $kiriwrite_presmodule->addinputbox("pagename", { Size => 64, MaxLength => 512 });
1429                 $kiriwrite_presmodule->endcell();
1430                 $kiriwrite_presmodule->endrow();
1432                 $kiriwrite_presmodule->startrow();
1433                 $kiriwrite_presmodule->addcell("tablecell1");
1434                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagedescription});
1435                 $kiriwrite_presmodule->endcell();
1436                 $kiriwrite_presmodule->addcell("tablecell2");
1437                 $kiriwrite_presmodule->addinputbox("pagedescription", { Size => 64, MaxLength => 512 });
1438                 $kiriwrite_presmodule->endcell();
1439                 $kiriwrite_presmodule->endrow();
1441                 $kiriwrite_presmodule->startrow();
1442                 $kiriwrite_presmodule->addcell("tablecell1");
1443                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagesection});
1444                 $kiriwrite_presmodule->endcell();
1445                 $kiriwrite_presmodule->addcell("tablecell2");
1446                 $kiriwrite_presmodule->addinputbox("pagesection", { Size => 64, MaxLength => 256 });
1447                 $kiriwrite_presmodule->endcell();
1448                 $kiriwrite_presmodule->endrow();
1450                 $kiriwrite_presmodule->startrow();
1451                 $kiriwrite_presmodule->addcell("tablecell1");
1452                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagetemplate});
1453                 $kiriwrite_presmodule->endcell();
1454                 $kiriwrite_presmodule->addcell("tablecell2");
1456                 # Check if the template warning value has been set
1457                 # and write the error message in place of the templates
1458                 # list if it is.
1460                 if ($template_warning eq 1){
1462                         $kiriwrite_presmodule->addhiddendata("pagetemplate", "!none");
1463                         $kiriwrite_presmodule->addtext($template_warningmessage);
1465                 } else {
1467                         my $template_file;
1468                         my $page_filename;
1469                         my $page_name;
1471                         $kiriwrite_presmodule->addselectbox("pagetemplate");
1473                         foreach $template_file (keys %template_list){
1475                                 $page_filename  = $template_list{$template_file}{Filename};
1476                                 $page_name      = $template_list{$template_file}{Name};
1477                                 $kiriwrite_presmodule->addoption($page_name . " (" . $page_filename . ")", { Value => $page_filename });
1478                                 $template_count++;
1480                                 $template_count = 0;
1481                         }
1483                         $kiriwrite_presmodule->addoption($kiriwrite_lang->{pages}->{usenotemplate}, { Value => "!none", Selected => 1 });
1484                         $kiriwrite_presmodule->endselectbox();
1486                 }
1488                 $kiriwrite_presmodule->endcell();
1489                 $kiriwrite_presmodule->endrow();
1491                 $kiriwrite_presmodule->startrow();
1492                 $kiriwrite_presmodule->addcell("tablecell1");
1493                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagefilename});
1494                 $kiriwrite_presmodule->endcell();
1495                 $kiriwrite_presmodule->addcell("tablecell2");
1496                 $kiriwrite_presmodule->addinputbox("pagefilename", { Size => 64, MaxLength => 256 });
1497                 $kiriwrite_presmodule->endcell();
1498                 $kiriwrite_presmodule->endrow();
1500                 $kiriwrite_presmodule->startrow();
1501                 $kiriwrite_presmodule->addcell("tablecell1");
1502                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagecontent});
1503                 $kiriwrite_presmodule->endcell();
1504                 $kiriwrite_presmodule->addcell("tablecell2");
1505                 $kiriwrite_presmodule->addtextbox("pagecontent", { Columns => 50, Rows => 10 });
1506                 $kiriwrite_presmodule->addlinebreak();
1507                 $kiriwrite_presmodule->addlinebreak();
1508                 $kiriwrite_presmodule->startbox("datalist");
1509                 $kiriwrite_presmodule->addboldtext($kiriwrite_lang->{common}->{tags});
1510                 $kiriwrite_presmodule->addlinebreak();
1511                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagetitle});
1512                 $kiriwrite_presmodule->addlinebreak();
1513                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagename});
1514                 $kiriwrite_presmodule->addlinebreak();
1515                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagedescription});
1516                 $kiriwrite_presmodule->addlinebreak();
1517                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagesection});
1518                 $kiriwrite_presmodule->addlinebreak();
1519                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pageautosection});
1520                 $kiriwrite_presmodule->addlinebreak();
1521                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pageautotitle});
1522                 $kiriwrite_presmodule->addlinebreak();
1523                 $kiriwrite_presmodule->endbox();
1524                 $kiriwrite_presmodule->endcell();
1525                 $kiriwrite_presmodule->endrow();
1527                 $kiriwrite_presmodule->startrow();
1528                 $kiriwrite_presmodule->addcell("tablecell1");
1529                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagesettings});
1530                 $kiriwrite_presmodule->endcell();
1531                 $kiriwrite_presmodule->addcell("tablecell2");
1532                 $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepageandsection}, Value => "1", Selected => 1, LineBreak => 1});
1533                 $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepagename}, Value => "2", Selected => 0, LineBreak => 1});
1534                 $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usesectionname}, Value => "3", Selected => 0, LineBreak => 1});
1535                 $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{nopagesection}, Value => "0", Selected => 0, LineBreak => 1});
1536                 $kiriwrite_presmodule->endcell();
1537                 $kiriwrite_presmodule->endrow();
1539                 $kiriwrite_presmodule->endtable();
1541                 $kiriwrite_presmodule->startbox();
1542                 $kiriwrite_presmodule->addlinebreak();
1543                 $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{addpagebutton});
1544                 $kiriwrite_presmodule->addtext(" | ");
1545                 $kiriwrite_presmodule->addreset($kiriwrite_lang->{common}->{clearvalues});
1546                 $kiriwrite_presmodule->addtext(" | ");
1547                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $pagedatabase, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name) });
1548                 $kiriwrite_presmodule->endbox();
1549                 $kiriwrite_presmodule->endform();
1552                 return $kiriwrite_presmodule->grab();
1554         } else {
1556                 # The confirm value is something else than '1' or '0' so
1557                 # return an error.
1559                 kiriwrite_error("invalidvalue");
1561         }
1567 sub kiriwrite_page_delete{
1568 #################################################################################
1569 # kiriwrite_page_delete: Deletes a (single) page from a database.               #
1570 #                                                                               #
1571 # Usage:                                                                        #
1572 #                                                                               #
1573 # kiriwrite_page_delete(database, page, [confirm]);                             #
1574 #                                                                               #
1575 # database      Specifies the database to delete from.                          #
1576 # page          Specifies the page to delete.                                   #
1577 # confirm       Confirms the action to delete the page.                         #
1578 #################################################################################
1580         my ($database, $page, $confirm) = @_;
1582         # Check if the database filename is valid and return an error if
1583         # it isn't.
1585         my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1);
1587         if ($pagedatabase_filename_check eq 1){
1589                 # The database filename is blank, so return an error.
1591                 kiriwrite_error("blankdatabasepageadd");
1593         } elsif ($pagedatabase_filename_check eq 2){
1595                 # The database filename is invalid, so return an error.
1597                 kiriwrite_error("databasefilenameinvalid");
1599         }
1601         # Check the length the database name and return an error if it's
1602         # too long.
1604         my $pagedatabase_length_check   = kiriwrite_variablecheck($database, "maxlength", 32, 1);
1606         if ($pagedatabase_length_check eq 1){
1608                 # The database name is too long, so return an error.
1610                 kiriwrite_error("databasefilenametoolong");
1612         }
1614         # Check if the page name is specified is blank and return an error if
1615         # it is.
1617         if (!$page){
1619                 # The page name is blank, so return an error.
1621                 kiriwrite_error("blankfilename");
1623         }
1625         # If the confirm value is blank, then set the confirm value to 0.
1627         if (!$confirm){
1629                 $confirm = 0;
1631         }
1633         if ($confirm eq 1){
1635                 # The action to delete the selected page from the database
1636                 # has been confirmed.
1638                 # Connect to the database server.
1640                 $kiriwrite_dbmodule->connect();
1642                 # Check if any errors occured while connecting to the database server.
1644                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1646                         # A database connection error has occured so return
1647                         # an error.
1649                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
1651                 }
1653                 # Select the database to delete the page from.
1655                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
1657                 # Check if any errors had occured while selecting the database.
1659                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
1661                         # The database does not exist, so return an error.
1663                         kiriwrite_error("databasemissingfile");
1665                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
1667                         # The database has invalid permissions set, so return
1668                         # an error.
1670                         kiriwrite_error("databaseinvalidpermissions");
1672                 }
1674                 # Check if the database has write permissions.
1676                 my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1);
1678                 if ($database_permissions eq 1){
1680                         # The database permissions are invalid so return an error.
1682                         kiriwrite_error("databaseinvalidpermissions");
1684                 }
1686                 # Get the information about the database.
1688                 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
1690                 # Check if any error occured while getting the database information.
1692                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
1694                         # A database error has occured so return an error and
1695                         # also the extended error information.
1697                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
1699                 }
1701                 # Get the information about the page that is going to be deleted.
1703                 my %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $page });
1705                 # Check if any errors occured while getting the page information.
1707                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
1709                         # A database error has occured so return an error and
1710                         # also the extended error information.
1712                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
1714                 } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
1716                         # The page does not exist, so return an error.
1718                         kiriwrite_error("pagefilenamedoesnotexist");
1720                 }
1722                 # Delete the page from the database.
1724                 $kiriwrite_dbmodule->deletepage({ PageFilename => $page });
1726                 # Check if any errors occured while deleting the page from the database.
1728                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
1730                         # A database error has occured so return an error and
1731                         # also the extended error information.
1733                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
1735                 } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
1737                         # The page does not exist, so return an error.
1739                         kiriwrite_error("pagefilenamedoesnotexist");
1741                 }
1743                 # Get the database name and page name.
1745                 my $database_name       = $database_info{"DatabaseName"};
1746                 my $page_name           = $page_info{"PageName"};
1748                 # Disconnect from the database server.
1750                 $kiriwrite_dbmodule->disconnect();
1752                 # Write out a message saying that the selected page from
1753                 # the database has been deleted.
1755                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagedeleted}, { Style => "pageheader" });
1756                 $kiriwrite_presmodule->addlinebreak();
1757                 $kiriwrite_presmodule->addlinebreak();
1758                 $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{pagedeletedmessage}, $page_name, $database_name));
1759                 $kiriwrite_presmodule->addlinebreak();
1760                 $kiriwrite_presmodule->addlinebreak();
1761                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name)});
1763                 return $kiriwrite_presmodule->grab();
1765         } elsif ($confirm eq 0){
1767                 # Connect to the database server.
1769                 $kiriwrite_dbmodule->connect();
1771                 # Check if any errors occured while connecting to the database server.
1773                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1775                         # A database connection error has occured so return
1776                         # an error.
1778                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
1780                 }
1782                 # Select the database.
1784                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
1786                 # Check if any errors had occured while selecting the database.
1788                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
1790                         # The database does not exist, so return an error.
1792                         kiriwrite_error("databasemissingfile");
1794                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
1796                         # The database has invalid permissions set, so return
1797                         # an error.
1799                         kiriwrite_error("databaseinvalidpermissions");
1801                 }
1803                 # Get information about the database.
1805                 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
1807                 # Check if any errors occured while getting the database information.
1809                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
1811                         # A database error has occured so return an error and
1812                         # also the extended error information.
1814                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
1816                 }
1818                 # Get information about the page that is going to be deleted.
1820                 my %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $page });
1822                 # Check if any errors occured while getting the page information.
1824                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
1826                         # A database error has occured so return an error and
1827                         # also the extended error information.
1829                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
1831                 } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
1833                         # The page does not exist, so return an error.
1835                         kiriwrite_error("pagefilenamedoesnotexist");
1837                 }
1839                 my $database_name       = $database_info{"DatabaseName"};
1840                 my $page_name           = $page_info{"PageName"};
1842                 # Disconnect from the database server.
1844                 $kiriwrite_dbmodule->disconnect();
1846                 # Write a message asking the user to confirm the deletion of the
1847                 # page.
1849                 $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{deletepage}, $page_name), { Style => "pageheader" });
1850                 $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST");
1851                 $kiriwrite_presmodule->startbox();
1852                 $kiriwrite_presmodule->addhiddendata("mode", "page");
1853                 $kiriwrite_presmodule->addhiddendata("action", "delete");
1854                 $kiriwrite_presmodule->addhiddendata("database", $database);
1855                 $kiriwrite_presmodule->addhiddendata("page", $page);
1856                 $kiriwrite_presmodule->addhiddendata("confirm", "1");
1857                 $kiriwrite_presmodule->addlinebreak();
1858                 $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{deletepagemessage}, $page_name, $database_name));
1859                 $kiriwrite_presmodule->addlinebreak();
1860                 $kiriwrite_presmodule->addlinebreak();
1861                 $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{deletepagebutton});
1862                 $kiriwrite_presmodule->addtext(" | ");
1863                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{deletepagesreturnlink}, $database_name)});
1864                 $kiriwrite_presmodule->endbox();
1865                 $kiriwrite_presmodule->endform();
1867                 return $kiriwrite_presmodule->grab();
1869         } else {
1871                 # Another page deletion type was specified, so return an error.
1873                 kiriwrite_error("invalidoption");
1875         }
1879 sub kiriwrite_page_edit{
1880 #################################################################################
1881 # kiriwrite_page_edit: Edits a page from a database.                            #
1882 #                                                                               #
1883 # Usage:                                                                        #
1884 #                                                                               #
1885 # kiriwrite_page_edit(database, filename, newfilename, newname, newdescription, #
1886 #                       newsection, newtemplate,  newsettings, newpagecontent   #
1887 #                       confirm);                                               #
1888 #                                                                               #
1889 # database       Specifies the database to edit from.                           #
1890 # filename       Specifies the filename to use.                                 #
1891 # newfilename    Specifies the new page filename to use.                        #
1892 # newname        Specifies the new page name to use.                            #
1893 # newdescription Specifies the new description for the page.                    #
1894 # newsection     Specifies the new section name to use.                         #
1895 # newtemplate    Specifies the new template filename to use.                    #
1896 # newsettings    Specifies the new page settings to use.                        #
1897 # newpagecontent Specifies the new page content to use.                         #
1898 # confirm        Confirms the action to edit the page.                          #
1899 #################################################################################
1901         # Get the values that have been passed to the subroutine.
1903         my ($database, $pagefilename, $pagenewfilename, $pagenewtitle, $pagenewdescription, $pagenewsection, $pagenewtemplate, $pagenewsettings, $pagenewcontent, $confirm) = @_;
1905         # Check if the confirm value is blank and if it is, then set it to '0'.
1907         if (!$confirm){
1909                 $confirm = 0;
1911         }
1913         # Check if the confirm value is more than one character long and if it
1914         # is then return an error.
1916         kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
1918         # Check if the database filename is valid and return an error if
1919         # it isn't.
1921         my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1);
1923         if ($pagedatabase_filename_check eq 1){
1925                 # The database filename is blank, so return an error.
1927                 kiriwrite_error("blankdatabasepageadd");
1929         } elsif ($pagedatabase_filename_check eq 2){
1931                 # The database filename is invalid, so return an error.
1933                 kiriwrite_error("databasefilenameinvalid");
1935         }
1937         # Check the length the database name and return an error if it's
1938         # too long.
1940         my $pagedatabase_length_check   = kiriwrite_variablecheck($database, "maxlength", 32, 1);
1942         if ($pagedatabase_length_check eq 1){
1944                 # The database name is too long, so return an error.
1946                 kiriwrite_error("databasefilenametoolong");
1948         }
1950         # Check if the page identification number is blank (which it shouldn't
1951         # be) and if it is, then return an error.
1953         if (!$pagefilename){
1955                 kiriwrite_error("blankfilename");
1957         }
1959         # Check if the confirm value is '1' and if it is, edit the specified
1960         # page in the database.
1962         if ($confirm eq 1){
1964                 # Check if the new page filename is blank.
1966                 if (!$pagenewfilename){
1968                         # The page filename is blank so return an error.
1970                         kiriwrite_error("pagefilenameblank");
1972                 }
1974                 # The action to edit a page has been confirmed so check the
1975                 # variables recieved are UTF8 compiliant before converting.
1977                 kiriwrite_variablecheck($database, "utf8", 0, 0);
1978                 kiriwrite_variablecheck($pagefilename, "utf8", 0, 0);
1979                 kiriwrite_variablecheck($pagenewfilename, "utf8", 0, 0);
1980                 kiriwrite_variablecheck($pagenewtitle, "utf8", 0, 0);
1981                 kiriwrite_variablecheck($pagenewdescription, "utf8", 0, 0);
1982                 kiriwrite_variablecheck($pagenewsection, "utf8", 0, 0);
1983                 kiriwrite_variablecheck($pagenewsettings, "utf8", 0, 0);
1984                 kiriwrite_variablecheck($pagenewtemplate, "utf8", 0, 0);
1985                 kiriwrite_variablecheck($pagenewcontent, "utf8", 0, 0);
1987                 # Convert the variables into proper UTF8 variables.
1989                 $database               = kiriwrite_utf8convert($database);
1990                 $pagefilename           = kiriwrite_utf8convert($pagefilename);
1991                 $pagenewfilename        = kiriwrite_utf8convert($pagenewfilename);
1992                 $pagenewtitle           = kiriwrite_utf8convert($pagenewtitle);
1993                 $pagenewdescription     = kiriwrite_utf8convert($pagenewdescription);
1994                 $pagenewsection         = kiriwrite_utf8convert($pagenewsection);
1995                 $pagenewsettings        = kiriwrite_utf8convert($pagenewsettings);
1996                 $pagenewtemplate        = kiriwrite_utf8convert($pagenewtemplate);
1997                 $pagenewcontent         = kiriwrite_utf8convert($pagenewcontent);
1999                 # Check the lengths of the variables.
2001                 my $pagenewfilename_maxlength_check     = kiriwrite_variablecheck($pagenewfilename, "maxlength", 256, 1);
2002                 my $pagenewtitle_maxlength_check        = kiriwrite_variablecheck($pagenewtitle, "maxlength", 512, 1);
2003                 my $pagenewdescription_maxlength_check  = kiriwrite_variablecheck($pagenewdescription, "maxlength", 512, 1);
2004                 my $pagenewsection_maxlength_check      = kiriwrite_variablecheck($pagenewsection, "maxlength", 256, 1);
2005                 my $pagenewsettings_maxlength_check     = kiriwrite_variablecheck($pagenewsettings, "maxlength", 1, 1);
2006                 my $pagenewtemplate_maxlength_check     = kiriwrite_variablecheck($pagenewtemplate, "maxlength", 64, 1);
2008                 # Check each result to see if the length of the variable
2009                 # is valid and return an error if it isn't.
2011                 if ($pagenewfilename_maxlength_check eq 1){
2013                         # The new page filename given is too long, so return an error.
2015                         kiriwrite_error("pagefilenametoolong");
2017                 }
2019                 if ($pagenewtitle_maxlength_check eq 1){
2021                         # The new page title given is too long, so return an error.
2023                         kiriwrite_error("pagetitletoolong");
2025                 }
2027                 if ($pagenewdescription_maxlength_check eq 1){
2029                         # The new page description given is too long, so return an error.
2031                         kiriwrite_error("pagedescriptiontoolong");
2033                 }
2035                 if ($pagenewsection_maxlength_check eq 1){
2037                         # The new page section given is too long, so return an error.
2039                         kiriwrite_error("pagesectiontoolong");
2041                 }
2043                 if ($pagenewsettings_maxlength_check eq 1){
2045                         # The new page settings given is too long, so return an error.
2047                         kiriwrite_error("pagesettingstoolong");
2049                 }
2051                 if ($pagenewtemplate_maxlength_check eq 1){
2053                         # The new page template given is too long, so return an error.
2055                         kiriwrite_error("pagetemplatefilenametoolong");
2057                 }
2059                 # Check if the new page filename and new page settings
2060                 # are valid.
2062                 my $pagenewfilename_filename_check      = kiriwrite_variablecheck($pagenewfilename, "page_filename", 0, 1);
2063                 my $pagenewsettings_settings_check      = kiriwrite_variablecheck($pagenewsettings, "pagesetting", 0, 1);
2064                 my $pagetemplate_filename_check = 0;
2066                 if ($pagenewtemplate ne "!none"){
2068                         # A template is being used so check the filename of the
2069                         # template.
2071                         $pagetemplate_filename_check    = kiriwrite_variablecheck($pagenewtemplate, "page_filename", 0, 1);
2073                 }
2075                 # Check each result to see if the variables have passed
2076                 # their tests and return an error if they haven't.
2078                 if ($pagenewfilename_filename_check ne 0){
2080                         # The new page filename is invalid, so return an error.
2082                         kiriwrite_error("pagefilenameinvalid");
2084                 }
2086                 if ($pagenewsettings_settings_check eq 1){
2088                         # The new page settings is invalid, so return an error.
2090                         kiriwrite_error("pagesettingsinvalid");
2092                 }
2094                 if ($pagetemplate_filename_check eq 1){
2096                         # The template filename given is invalid, so return an error
2098                         kiriwrite_error("templatefilenameinvalid");
2100                 }
2102                 # Connect to the database server.
2104                 $kiriwrite_dbmodule->connect();
2106                 # Check if any errors occured while connecting to the database server.
2108                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
2110                         # A database connection error has occured so return
2111                         # an error.
2113                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
2115                 }
2117                 # Select the database.
2119                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
2121                 # Check if any errors had occured while selecting the database.
2123                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
2125                         # The database does not exist, so return an error.
2127                         kiriwrite_error("databasemissingfile");
2129                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
2131                         # The database has invalid permissions set, so return
2132                         # an error.
2134                         kiriwrite_error("databaseinvalidpermissions");
2136                 }
2138                 # Check if the database has write permissions.
2140                 my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1);
2142                 if ($database_permissions eq 1){
2144                         # The database permissions are invalid so return an error.
2146                         kiriwrite_error("databaseinvalidpermissions");
2148                 }
2150                 # Get the database information.
2152                 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
2154                 # Check if any errors had occured while getting the database information.
2156                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
2158                         # A database error has occured so return an error and
2159                         # also the extended error information.
2161                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
2163                 };
2165                 my $database_name = $database_info{"DatabaseName"};
2167                 # Edit the selected page.
2169                 $kiriwrite_dbmodule->editpage({ PageFilename => $pagefilename, PageNewFilename => $pagenewfilename, PageNewName => $pagenewtitle, PageNewDescription => $pagenewdescription, PageNewSection => $pagenewsection, PageNewTemplate => $pagenewtemplate, PageNewContent => $pagenewcontent, PageNewSettings => $pagenewsettings });
2171                 # Check if any errors occured while editing the page.
2173                 if ($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", $kiriwrite_dbmodule->geterror(1));
2180                 } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
2182                         # The pages does not exist in the database.
2184                         kiriwrite_error("pagefilenamedoesnotexist");
2186                 } elsif ($kiriwrite_dbmodule->geterror eq "PageExists"){
2188                         # A page already exists with the new filename.
2190                         kiriwrite_error("pagefilenameexists");
2192                 }
2194                 # Disconnect from the database server.
2196                 $kiriwrite_dbmodule->disconnect();
2198                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{editedpage}, { Style => "pageheader" });
2199                 $kiriwrite_presmodule->addlinebreak();
2200                 $kiriwrite_presmodule->addlinebreak();
2201                 $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{editedpagemessage}, $pagenewtitle));
2202                 $kiriwrite_presmodule->addlinebreak();
2203                 $kiriwrite_presmodule->addlinebreak();
2204                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name) });
2206                 return $kiriwrite_presmodule->grab();
2208         } elsif ($confirm eq 0) {
2210                 # Connect to the database server.
2212                 $kiriwrite_dbmodule->connect();
2214                 # Check if any errors occured while connecting to the database server.
2216                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
2218                         # A database connection error has occured so return
2219                         # an error.
2221                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
2223                 }
2225                 # Select the database.
2227                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
2229                 # Check if any errors had occured while selecting the database.
2231                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
2233                         # The database does not exist, so return an error.
2235                         kiriwrite_error("databasemissingfile");
2237                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
2239                         # The database has invalid permissions set, so return
2240                         # an error.
2242                         kiriwrite_error("databaseinvalidpermissions");
2244                 }
2246                 # Get the information about the database.
2248                 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
2250                 # Check if any errors had occured while getting the database information.
2252                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
2254                         # A database error has occured so return an error and
2255                         # also the extended error information.
2257                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
2259                 };
2261                 my $database_name = $database_info{"DatabaseName"};
2263                 # Get the page info.
2265                 my %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $pagefilename });
2267                 # Check if any errors occured while getting the page information.
2269                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
2271                         # A database error has occured so return an error and
2272                         # also the extended error information.
2274                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
2276                 } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
2278                         # The page does not exist, so return an error.
2280                         kiriwrite_error("pagefilenamedoesnotexist");
2282                 }
2284                 # Get the values from the hash.
2286                 my $data_filename               = $page_info{"PageFilename"};
2287                 my $data_name                   = $page_info{"PageName"};
2288                 my $data_description            = $page_info{"PageDescription"};
2289                 my $data_section                = $page_info{"PageSection"};
2290                 my $data_template               = $page_info{"PageTemplate"};
2291                 my $data_content                = $page_info{"PageContent"};
2292                 my $data_settings               = $page_info{"PageSettings"};
2293                 my $data_lastmodified           = $page_info{"PageLastModified"};
2295                 my $template_warning;
2296                 my $page_count = 0;
2297                 my %template_list;
2298                 my %template_info;
2299                 my @database_pages;
2300                 my @database_info;
2301                 my @database_templates;
2302                 my @template_filenames;
2303                 my $template_file;
2304                 my $template_filename;
2305                 my $template_name;
2306                 my $template_count = 0;
2307                 my $template_found = 0;
2309                 tie(%template_list, 'Tie::IxHash');
2311                 # Connect to the template database.
2313                 $kiriwrite_dbmodule->connecttemplate();
2315                 # Check if any errors occured while connecting to the template database.
2317                 if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
2319                         # The template database does not exist so set the template
2320                         # warning message.
2322                         $template_warning = $kiriwrite_lang->{pages}->{notemplatedatabasekeep};
2324                 } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
2326                         # The template database has invalid permissions set so write
2327                         # the template warning message.
2329                         $template_warning = $kiriwrite_lang->{pages}->{templatepermissionserrorkeep};
2331                 }
2333                 if (!$template_warning){
2335                         # Get the list of available templates.
2337                         @template_filenames = $kiriwrite_dbmodule->gettemplatelist();
2339                         # Check if any errors had occured.
2341                         if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
2343                                 # A database error occured while getting the list
2344                                 # of templates so return an error with the 
2345                                 # extended error information.
2347                                 $template_warning = kiriwrite_language($kiriwrite_lang->{pages}->{templatedatabaseerrorkeep} , $kiriwrite_dbmodule->geterror(1));
2349                         }
2351                         if (!$template_warning){
2353                                 foreach $template_filename (@template_filenames){
2355                                         # Get the information about each template.
2357                                         %template_info = $kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_filename });
2359                                         # Check if any errors occured while getting the template information.
2361                                         if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
2363                                                 # A template database error has occured so return a warning message
2364                                                 # with the extended error information.
2366                                                 $template_warning = kiriwrite_language($kiriwrite_lang->{pages}->{templatedatabaseerrorkeep} , $kiriwrite_dbmodule->geterror(1));
2367                                                 last;
2369                                         } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
2371                                                 # The template does not exist so process the next template.
2373                                                 next;
2375                                         }
2377                                         # Append the template name and filename to the list of available templates.
2379                                         $template_list{$template_count}{Filename} = $template_info{"TemplateFilename"};
2380                                         $template_list{$template_count}{Name}     = $template_info{"TemplateName"};
2382                                         # Append the template filename and name and make it the selected
2383                                         # template if that is the template the page is using.
2385                                         if ($data_template eq $template_filename && !$template_found){
2387                                                 $template_list{$template_count}{Selected}       = 1;
2388                                                 $template_found = 1;
2390                                         } else {
2392                                                 $template_list{$template_count}{Selected}       = 0;
2394                                         }
2396                                         $template_count++;
2398                                 }
2400                         }
2402                 }
2404                 # Check if certain values are undefined and if they
2405                 # are then set them blank (defined).
2407                 if (!$data_name){
2408                         $data_name = "";
2409                 }
2411                 if (!$data_description){
2412                         $data_description = "";
2413                 }
2415                 if (!$data_section){
2416                         $data_section = "";
2417                 }
2419                 if (!$data_template){
2420                         $data_template = "";
2422                 }
2424                 if (!$data_content){
2425                         $data_content = "";
2426                 }
2428                 if (!$data_settings){
2429                         $data_settings = "";
2430                 }
2432                 if (!$data_lastmodified){
2433                         $data_lastmodified = "";
2434                 }
2436                 # Begin writing out the form for editing the selected page.
2438                 $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{editpage}, $data_name), { Style => "pageheader" });
2439                 $kiriwrite_presmodule->addlinebreak();
2440                 $kiriwrite_presmodule->addlinebreak();
2442                 $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST");
2443                 $kiriwrite_presmodule->startbox();
2444                 $kiriwrite_presmodule->addhiddendata("mode", "page");
2445                 $kiriwrite_presmodule->addhiddendata("action", "edit");
2446                 $kiriwrite_presmodule->addhiddendata("database", $database);
2447                 $kiriwrite_presmodule->addhiddendata("page", $pagefilename);
2448                 $kiriwrite_presmodule->addhiddendata("confirm", 1);
2449                 $kiriwrite_presmodule->endbox();
2451                 $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
2453                 $kiriwrite_presmodule->startheader();
2454                 $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{setting}, { Style => "tablecellheader" });
2455                 $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{value}, { Style => "tablecellheader" });
2456                 $kiriwrite_presmodule->endheader();
2458                 $kiriwrite_presmodule->startrow();
2459                 $kiriwrite_presmodule->addcell("tablecell1");
2460                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{database});
2461                 $kiriwrite_presmodule->endcell();
2462                 $kiriwrite_presmodule->addcell("tablecell2");
2463                 $kiriwrite_presmodule->addtext($database_name);
2464                 $kiriwrite_presmodule->endcell();
2465                 $kiriwrite_presmodule->endrow();
2467                 $kiriwrite_presmodule->startrow();
2468                 $kiriwrite_presmodule->addcell("tablecell1");
2469                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagename});
2470                 $kiriwrite_presmodule->endcell();
2471                 $kiriwrite_presmodule->addcell("tablecell2");
2472                 $kiriwrite_presmodule->addinputbox("pagename", { Size => 64, MaxLength => 512, Value => $data_name });
2473                 $kiriwrite_presmodule->endcell();
2474                 $kiriwrite_presmodule->endrow();
2476                 $kiriwrite_presmodule->startrow();
2477                 $kiriwrite_presmodule->addcell("tablecell1");
2478                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagedescription});
2479                 $kiriwrite_presmodule->endcell();
2480                 $kiriwrite_presmodule->addcell("tablecell2");
2481                 $kiriwrite_presmodule->addinputbox("pagedescription", { Size => 64, MaxLength => 512, Value => $data_description });
2482                 $kiriwrite_presmodule->endcell();
2483                 $kiriwrite_presmodule->endrow();
2485                 $kiriwrite_presmodule->startrow();
2486                 $kiriwrite_presmodule->addcell("tablecell1");
2487                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagesection});
2488                 $kiriwrite_presmodule->endcell();
2489                 $kiriwrite_presmodule->addcell("tablecell2");
2490                 $kiriwrite_presmodule->addinputbox("pagesection", { Size => 64, MaxLength => 256, Value => $data_section });
2491                 $kiriwrite_presmodule->endcell();
2492                 $kiriwrite_presmodule->endrow();
2494                 $kiriwrite_presmodule->startrow();
2495                 $kiriwrite_presmodule->addcell("tablecell1");
2496                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagetemplate});
2497                 $kiriwrite_presmodule->endcell();
2498                 $kiriwrite_presmodule->addcell("tablecell2");
2500                 # Check if any template warnings have occured.
2502                 if ($template_warning){
2504                         $kiriwrite_presmodule->addtext($template_warning);
2505                         $kiriwrite_presmodule->addlinebreak();
2507                 }
2509                 $kiriwrite_presmodule->addselectbox("pagetemplate");
2511                 # Process the list of templates, select one if the
2512                 # template filename for the page matches, else give
2513                 # an option for the user to keep the current template
2514                 # filename.
2516                 $template_count = 0;
2518                 foreach $template_file (keys %template_list){
2520                         if ($template_list{$template_count}{Selected}){
2522                                 $kiriwrite_presmodule->addoption($template_list{$template_count}{Name} . " (" . $template_list{$template_count}{Filename} . ")", { Value => $template_list{$template_count}{Filename}, Selected => 1 });
2524                         } else {
2526                                 $kiriwrite_presmodule->addoption($template_list{$template_count}{Name} . " (" . $template_list{$template_count}{Filename} . ")", { Value => $template_list{$template_count}{Filename} });
2528                         }
2530                         $template_count++;
2532                 }
2534                 if ($data_template eq "!none"){
2536                         $kiriwrite_presmodule->addoption($kiriwrite_lang->{pages}->{usenotemplate}, { Value => "!none", Selected => 1 });
2537                         $template_found = 1;
2539                 } else {
2541                         $kiriwrite_presmodule->addoption($kiriwrite_lang->{pages}->{usenotemplate}, { Value => "!none" });
2543                 }
2545                 if ($template_found eq 0 && $data_template ne "!none"){
2547                         # The template with the filename given was not found.
2549                         $kiriwrite_presmodule->addoption(kiriwrite_language($kiriwrite_lang->{pages}->{keeptemplatefilename}, $data_template), { Value => $data_template, Selected => 1, Style => "warningoption" });
2551                 }
2553                 # Disconnect from the template database.
2555                 $kiriwrite_dbmodule->disconnecttemplate();
2557                 # Disconnect from the database server.
2559                 $kiriwrite_dbmodule->disconnect();
2561                 $kiriwrite_presmodule->endselectbox();
2563                 $kiriwrite_presmodule->endcell();
2564                 $kiriwrite_presmodule->endrow();
2566                 $kiriwrite_presmodule->startrow();
2567                 $kiriwrite_presmodule->addcell("tablecell1");
2568                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagefilename});
2569                 $kiriwrite_presmodule->endcell();
2570                 $kiriwrite_presmodule->addcell("tablecell2");
2571                 $kiriwrite_presmodule->addinputbox("pagefilename", { Size => 64, MaxLength => 256, Value => $data_filename });
2572                 $kiriwrite_presmodule->endcell();
2573                 $kiriwrite_presmodule->endrow();
2575                 $kiriwrite_presmodule->startrow();
2576                 $kiriwrite_presmodule->addcell("tablecell1");
2577                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagecontent});
2578                 $kiriwrite_presmodule->endcell();
2579                 $kiriwrite_presmodule->addcell("tablecell2");
2580                 $kiriwrite_presmodule->addtextbox("pagecontent", { Columns => 50, Rows => 10, Value => $data_content });
2581                 $kiriwrite_presmodule->addlinebreak();
2582                 $kiriwrite_presmodule->addlinebreak();
2583                 $kiriwrite_presmodule->startbox("datalist");
2584                 $kiriwrite_presmodule->addboldtext($kiriwrite_lang->{common}->{tags});
2585                 $kiriwrite_presmodule->addlinebreak();
2586                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagetitle});
2587                 $kiriwrite_presmodule->addlinebreak();
2588                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagename});
2589                 $kiriwrite_presmodule->addlinebreak();
2590                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagedescription});
2591                 $kiriwrite_presmodule->addlinebreak();
2592                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pagesection});
2593                 $kiriwrite_presmodule->addlinebreak();
2594                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pageautosection});
2595                 $kiriwrite_presmodule->addlinebreak();
2596                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{common}->{pageautotitle});
2597                 $kiriwrite_presmodule->addlinebreak();
2598                 $kiriwrite_presmodule->endbox();
2599                 $kiriwrite_presmodule->endcell();
2600                 $kiriwrite_presmodule->endrow();
2602                 $kiriwrite_presmodule->startrow();
2603                 $kiriwrite_presmodule->addcell("tablecell1");
2604                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagesettings});
2605                 $kiriwrite_presmodule->endcell();
2606                 $kiriwrite_presmodule->addcell("tablecell2");
2608                 # Check if the page settings value is set to a 
2609                 # certain number and select that option based
2610                 # on the number else set the value to 0.
2612                 if ($data_settings eq 1){
2613                         $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepageandsection}, Value => "1", Selected => 1, LineBreak => 1});
2614                 } else {
2615                         $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepageandsection}, Value => "1", LineBreak => 1});
2616                 }
2618                 if ($data_settings eq 2){
2619                         $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepagename}, Value => "2", Selected => 1, LineBreak => 1});
2620                 } else {
2621                         $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepagename}, Value => "2", LineBreak => 1});
2622                 }
2624                 if ($data_settings eq 3){
2625                         $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usesectionname}, Value => "3", Selected => 1, LineBreak => 1});
2626                 } else {
2627                         $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usesectionname}, Value => "3", LineBreak => 1});
2628                 }
2630                 if ($data_settings eq 0 || ($data_settings ne 1 && $data_settings ne 2 && $data_settings ne 3)){
2631                         $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{nopagesection}, Value => "0", Selected => 1, LineBreak => 1});
2632                 } else {
2633                         $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{nopagesection}, Value => "0", LineBreak => 1});
2634                 }
2636                 $kiriwrite_presmodule->endcell();
2637                 $kiriwrite_presmodule->endrow();
2638                 $kiriwrite_presmodule->endtable();
2640                 $kiriwrite_presmodule->startbox();
2641                 $kiriwrite_presmodule->addlinebreak();
2642                 $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{editpagebutton});
2643                 $kiriwrite_presmodule->addtext(" | ");
2644                 $kiriwrite_presmodule->addreset($kiriwrite_lang->{common}->{restorecurrent});
2645                 $kiriwrite_presmodule->addtext(" | ");
2646                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name) } );
2647                 $kiriwrite_presmodule->endbox();
2649                 $kiriwrite_presmodule->endform();
2651                 return $kiriwrite_presmodule->grab();
2653         } else {
2655                 # The confirm value is a value other than '0' and '1' so
2656                 # return an error.
2658                 kiriwrite_error("invalidvalue");
2660         }
2664 sub kiriwrite_page_multidelete{
2665 #################################################################################
2666 # kiriwrite_page_multidelete: Delete mulitple pages from the database.          #
2667 #                                                                               #
2668 # Usage:                                                                        #
2669 #                                                                               #
2670 # kiriwrite_page_multidelete(database, confirm, filelist);                      #
2671 #                                                                               #
2672 # database      Specifies the database to delete multiple pages from.           #
2673 # confirm       Confirms the action to delete the selected pages from the       #
2674 #               database.                                                       #
2675 # filelist      The list of files to delete from the selected database.         #
2676 #################################################################################
2678         # Get the information passed to the subroutine.
2680         my ($database, $confirm, @filelist) = @_;
2682         # Check if the database name is blank and return an error if
2683         # it is.
2685         if (!$database){
2687                 # The database name is blank so return an error.
2689                 kiriwrite_error("databasenameblank");
2691         }
2693         # Check if the file list array has any values and return
2694         # an error if it doesn't.
2696         if (!@filelist){
2698                 # The page list really is blank so return
2699                 # an error.
2701                 kiriwrite_error("nopagesselected");
2702         }
2704         # Check if the database filename is valid and return an error if
2705         # it isn't.
2707         my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1);
2709         if ($pagedatabase_filename_check eq 1){
2711                 # The database filename is blank, so return an error.
2713                 kiriwrite_error("blankdatabasepageadd");
2715         } elsif ($pagedatabase_filename_check eq 2){
2717                 # The database filename is invalid, so return an error.
2719                 kiriwrite_error("databasefilenameinvalid");
2721         }
2723         # Check the length the database name and return an error if it's
2724         # too long.
2726         my $pagedatabase_length_check   = kiriwrite_variablecheck($database, "maxlength", 32, 1);
2728         if ($pagedatabase_length_check eq 1){
2730                 # The database name is too long, so return an error.
2732                 kiriwrite_error("databasefilenametoolong");
2734         }
2736         # Check if the confirm value is blank and if it is, then
2737         # set it to 0.
2739         if (!$confirm){
2741                 # The confirm value is blank so set the confirm value
2742                 # to 0.
2744                 $confirm = 0;
2746         }
2748         if ($confirm eq 1){
2750                 # The action to delete multiple pages from the database has
2751                 # been confirmed.
2753                 # Connect to the database server.
2755                 $kiriwrite_dbmodule->connect();
2757                 # Check if any errors occured while connecting to the database server.
2759                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
2761                         # A database connection error has occured so return
2762                         # an error.
2764                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
2766                 }
2768                 # Select the database.
2770                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
2772                 # Check if any errors occured while selecting the database.
2774                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
2776                         # The database does not exist, so return an error.
2778                         kiriwrite_error("databasemissingfile");
2780                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
2782                         # The database has invalid permissions set, so return
2783                         # an error.
2785                         kiriwrite_error("databaseinvalidpermissions");
2787                 }
2789                 # Check if the database has read and write permissions.
2791                 my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1);
2793                 if ($database_permissions eq 1){
2795                         # The database permissions are invalid so return an error.
2797                         kiriwrite_error("databaseinvalidpermissions");
2799                 }
2801                 # Get information about the database.
2803                 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
2805                 # Check if any errors had occured while getting the database
2806                 # information.
2808                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
2810                         # A database error has occured so return an error and
2811                         # also the extended error information.
2813                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
2815                 };
2817                 my $database_name       = $database_info{"DatabaseName"};
2819                 # Define some variables for later.
2821                 my @database_page;
2822                 my %page_info;
2823                 my $filelist_filename;
2824                 my %deleted_list;
2825                 my $page;
2826                 my $page_name;
2827                 my $page_found = 0;
2828                 my $page_count = 0;
2830                 tie (%deleted_list, 'Tie::IxHash');
2832                 my $deleted_list = "";
2834                 foreach $filelist_filename (@filelist){
2836                         # Get the page information.
2838                         %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filelist_filename });
2840                         # Check if any errors occured.
2842                         if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
2844                                 # A database error has occured so return an error and
2845                                 # also the extended error information.
2847                                 kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
2849                         } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
2851                                 # The page does not exist, so process the next page.
2853                                 next;
2855                         }
2857                         # Add the page to the list of deleted pages.
2859                         $deleted_list{$page_count}{Filename}    = $page_info{"PageFilename"};
2860                         $deleted_list{$page_count}{Name}        = $page_info{"PageName"};
2862                         # Delete the page.
2864                         $kiriwrite_dbmodule->deletepage({ PageFilename => $filelist_filename });
2866                         # Check if any errors occured while deleting the page from the database.
2868                         if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
2870                                 # A database error has occured so return an error and
2871                                 # also the extended error information.
2873                                 kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
2875                         } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
2877                                 # The page does not exist, so process the next page.
2879                                 next;
2881                         }
2883                         $page_found = 0;
2884                         $page_count++;
2886                 }
2888                 # Disconnect from the database server.
2890                 $kiriwrite_dbmodule->disconnect();
2892                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{selectedpagesdeleted}, { Style => "pageheader" });
2893                 $kiriwrite_presmodule->addlinebreak();
2894                 $kiriwrite_presmodule->addlinebreak();
2895                 $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{selectedpagesdeletedmessage}, $database_name));
2896                 $kiriwrite_presmodule->addlinebreak();
2897                 $kiriwrite_presmodule->addlinebreak();
2898                 $kiriwrite_presmodule->startbox("datalist");
2900                 foreach $page (keys %deleted_list){
2902                         if (!$deleted_list{$page}{Name}){
2903                                 $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname});
2904                                 $kiriwrite_presmodule->addtext(" (" . $deleted_list{$page}{Filename} . ")");
2906                         } else {
2907                                 $kiriwrite_presmodule->addtext($deleted_list{$page}{Name} . " (" . $deleted_list{$page}{Filename} . ")");
2908                         }
2910                         $kiriwrite_presmodule->addlinebreak();
2911                 }
2913                 $kiriwrite_presmodule->endbox();
2914                 $kiriwrite_presmodule->addlinebreak();
2915                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name)});
2917                 return $kiriwrite_presmodule->grab();
2919         } elsif ($confirm eq 0){
2921                 # The action to delete multiple pages from the database has
2922                 # not been confirmed, so write a form asking the user to confirm
2923                 # the deletion of those pages.
2925                 # Connect to the database server.
2927                 $kiriwrite_dbmodule->connect();
2929                 # Check if any errors occured while connecting to the database server.
2931                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
2933                         # A database connection error has occured so return
2934                         # an error.
2936                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
2938                 }
2940                 # Select the database.
2942                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
2944                 # Check if any errors occured while selecting the database.
2946                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
2948                         # The database does not exist, so return an error.
2950                         kiriwrite_error("databasemissingfile");
2952                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
2954                         # The database has invalid permissions set, so return
2955                         # an error.
2957                         kiriwrite_error("databaseinvalidpermissions");
2959                 }
2961                 # Check if the database has read and write permissions.
2963                 my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1);
2965                 if ($database_permissions eq 1){
2967                         # The database permissions are invalid so return an error.
2969                         kiriwrite_error("databaseinvalidpermissions");
2971                 }
2973                 # Get information about the database.
2975                 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
2977                 # Check if any errors had occured while getting the database
2978                 # information.
2980                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
2982                         # A database error has occured so return an error and
2983                         # also the extended error information.
2985                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
2987                 };
2989                 my $database_name       = $database_info{"DatabaseName"};
2991                 # Define some variables for later.
2993                 my %page_info;
2994                 my %delete_list;
2995                 my $pagename;
2996                 my $page = "";
2997                 my $filelist_filename;
2998                 my $filelist_filename_sql;
2999                 my $pageseek = 0;
3001                 tie(%delete_list, 'Tie::IxHash');
3003                 # Process each filename given.
3005                 foreach $filelist_filename (@filelist){
3007                         # Get the page information.
3009                         %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filelist_filename });
3011                         # Check if any errors occured.
3013                         if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
3015                                 # A database error has occured so return an error and
3016                                 # also the extended error information.
3018                                 kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
3020                         } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
3022                                 # The page does not exist, so process the next page.
3024                                 next;
3026                         }
3028                         # Add the page file name and name to the list
3029                         # of pages to delete.
3031                         $delete_list{$pageseek}{Filename}       = $page_info{"PageFilename"};
3032                         $delete_list{$pageseek}{Name}           = $page_info{"PageName"};
3034                         # Increment the page seek counter and reset the
3035                         # page found value.
3037                         $pageseek++;
3039                 }
3041                 # Disconnect from the database server.
3043                 $kiriwrite_dbmodule->disconnect();
3045                 # Check if any files were selected and return
3046                 # an error if there wasn't.
3048                 if ($pageseek eq 0){
3050                         # No pages were selected so return an error.
3052                         kiriwrite_error("nopagesselected");
3054                 }
3056                 # Write the form for displaying pages.
3058                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{deletemultiplepages}, { Style => "pageheader" });
3059                 $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST");
3060                 $kiriwrite_presmodule->startbox();
3061                 $kiriwrite_presmodule->addhiddendata("mode", "page");
3062                 $kiriwrite_presmodule->addhiddendata("action", "multidelete");
3063                 $kiriwrite_presmodule->addhiddendata("database", $database);
3064                 $kiriwrite_presmodule->addhiddendata("confirm", "1");
3065                 $kiriwrite_presmodule->addhiddendata("count", $pageseek);
3067                 $pageseek = 1;
3069                 foreach $page (keys %delete_list){
3071                         $kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on");
3072                         $kiriwrite_presmodule->addhiddendata("id[" . $pageseek . "]", $delete_list{$page}{Filename});
3074                         $pageseek++;
3076                 }
3078                 $kiriwrite_presmodule->addlinebreak();
3079                 $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{deletemultiplemessage}, $database_name));
3080                 $kiriwrite_presmodule->addlinebreak();
3081                 $kiriwrite_presmodule->addlinebreak();
3082                 $kiriwrite_presmodule->startbox("datalist");
3084                 foreach $page (keys %delete_list){
3086                         if (!$delete_list{$page}{Name}){
3087                                 $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname});
3088                                 $kiriwrite_presmodule->addtext(" (" . $delete_list{$page}{Filename} . ")");
3089                         } else {
3090                                 $kiriwrite_presmodule->addtext($delete_list{$page}{Name} . " (" . $delete_list{$page}{Filename} . ")");
3091                         }
3092                         $kiriwrite_presmodule->addlinebreak();
3094                 }
3096                 $kiriwrite_presmodule->endbox();
3097                 $kiriwrite_presmodule->addlinebreak();
3098                 $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{deletepagesbutton});
3099                 $kiriwrite_presmodule->addtext(" | ");
3100                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{deletepagesreturnlink}, $database_name)});
3101                 $kiriwrite_presmodule->endbox();
3102                 $kiriwrite_presmodule->endform();
3104                 return $kiriwrite_presmodule->grab();
3106         } else {
3108                 # A confirm value other than 0 or 1 is given, so
3109                 # return an error.
3111                 kiriwrite_error("invaildvalue");
3113         }
3117 sub kiriwrite_page_multimove{
3118 #################################################################################
3119 # kiriwrite_page_multimove: Move several pages from one database to another     #
3120 # database.                                                                     #
3121 #                                                                               #
3122 # Usage:                                                                        #
3123 #                                                                               #
3124 # kiriwrite_page_multimove(database, newdatabase, confirm, filelist);           #
3125 #                                                                               #
3126 # database      Specifies the database to move the selected pages from.         #
3127 # newdatabase   Specifies the database to move the selected pages to.           #
3128 # confirm       Confirms the action to move the pages from one database to      #
3129 #               another.                                                        #
3130 # filelist      Specifies the list of pages to move.                            #
3131 #################################################################################
3133         # Get the values that were passed to the subroutine.
3135         my ($database, $newdatabase, $confirm, @filelist) = @_;
3137         # Check if the database filename is valid and return
3138         # an error if it isn't.
3140         my $newpagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1);
3142         if ($newpagedatabase_filename_check eq 1){
3144                 # The database filename is blank, so return an error.
3146                 kiriwrite_error("blankdatabasepageadd");
3148         } elsif ($newpagedatabase_filename_check eq 2){
3150                 # The database filename is invalid, so return an error.
3152                 kiriwrite_error("databasefilenameinvalid");
3154         }
3156         # Check if the file list is blank and return an error
3157         # if it is.
3159         if (!@filelist){
3161                 # The file list really is blank so return
3162                 # an error.
3164                 kiriwrite_error("nopagesselected");
3166         }
3168         # Check if the confirm value is blank and if it is then
3169         # set the confirm value to 0.
3171         if (!$confirm){
3173                 $confirm = 0;
3175         }
3177         if ($confirm eq 1){
3179                 # The action to move several pages from one database
3180                 # to another has been confirmed.
3182                 # Check if the database that the pages are moving from 
3183                 # is the same as the database the pages are moving to.
3184                 # Return an error if it is.
3186                 if ($database eq $newdatabase){
3188                         # The database that the pages are moving from
3189                         # and the database the pages are moving to
3190                         # is the same, so return an error.
3192                         kiriwrite_error("databasemovesame");
3194                 }
3196                 # Check if the new database filename is valid and return an error if
3197                 # it isn't.
3199                 my $newpagedatabase_filename_check = kiriwrite_variablecheck($newdatabase, "filename", 0, 1);
3201                 if ($newpagedatabase_filename_check eq 1){
3203                         # The database filename is blank, so return an error.
3205                         kiriwrite_error("blankdatabasepageadd");
3207                 } elsif ($newpagedatabase_filename_check eq 2){
3209                         # The database filename is invalid, so return an error.
3211                         kiriwrite_error("databasefilenameinvalid");
3213                 }
3215                 # Connect to the database server.
3217                 $kiriwrite_dbmodule->connect();
3219                 # Check if any errors occured while connecting to the database server.
3221                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
3223                         # A database connection error has occured so return
3224                         # an error.
3226                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
3228                 }
3230                 # Select the database the pages are going to be moved from.
3232                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
3234                 # Check if any errors had occured while selecting the database.
3236                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
3238                         # The database does not exist, so return an error.
3240                         kiriwrite_error("oldmovedatabasedoesnotexist");
3242                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
3244                         # The database has invalid permissions set, so return
3245                         # an error.
3247                         kiriwrite_error("oldmovedatabasefileinvalidpermissions");
3249                 }
3251                 # Check if the database has read and write permissions.
3253                 my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1);
3255                 if ($database_permissions eq 1){
3257                         # The database permissions are invalid so return an error.
3259                         kiriwrite_error("oldmovedatabasefileinvalidpermissions");
3261                 }
3263                 # Select the database the pages are going to be moved to.
3265                 $kiriwrite_dbmodule->selectseconddb({ DatabaseName => $newdatabase });
3267                 # Check if any errors had occured while selecting the database.
3269                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
3271                         # The database does not exist, so return an error.
3273                         kiriwrite_error("newmovedatabasedoesnotexist");
3275                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
3277                         # The database has invalid permissions set, so return
3278                         # an error.
3280                         kiriwrite_error("newmovedatabasefileinvalidpermissions");
3282                 }
3284                 # Check if the database has read and write permissions.
3286                 $database_permissions = $kiriwrite_dbmodule->dbpermissions($newdatabase, 1, 1);
3288                 if ($database_permissions eq 1){
3290                         # The database permissions are invalid so return an error.
3292                         kiriwrite_error("newmovedatabasefileinvalidpermissions");
3294                 }
3296                 # Define some values for later.
3298                 my %moved_list;
3299                 my %warning_list;
3300                 my %page_info;
3302                 my $filename;
3304                 my $olddatabase_name;
3305                 my $newdatabase_name;
3307                 my $page;
3308                 my $warning;
3310                 my $page_found = 0;
3311                 my $move_count = 0;
3312                 my $warning_count = 0;
3314                 tie(%moved_list, 'Tie::IxHash');
3315                 tie(%warning_list, 'Tie::IxHash');
3317                 # Get information about the database that the selected pages are moving from.
3319                 my %olddatabase_info = $kiriwrite_dbmodule->getdatabaseinfo();
3321                 # Check if any errors had occured while getting the database
3322                 # information.
3324                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
3326                         # A database error has occured so return an error and
3327                         # also the extended error information.
3329                         kiriwrite_error("oldmovedatabasedatabaseerror", $kiriwrite_dbmodule->geterror(1));
3331                 };
3333                 $olddatabase_name = $olddatabase_info{"DatabaseName"};
3335                 # Get information about the database that the selected pages are moving to.
3337                 my %newdatabase_info = $kiriwrite_dbmodule->getseconddatabaseinfo();
3339                 # Check if any errors had occured while getting the database
3340                 # information.
3342                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
3344                         # A database error has occured so return an error and
3345                         # also the extended error information.
3347                         kiriwrite_error("newmovedatabasedatabaseerror", $kiriwrite_dbmodule->geterror(1));
3349                 };
3351                 $newdatabase_name = $newdatabase_info{"DatabaseName"};
3353                 # Get each file in the old database, get the page values,
3354                 # put them into the new database and delete the pages
3355                 # from the old database.
3357                 foreach $filename (@filelist){
3359                         # Get the page information.
3361                         %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filename });
3363                         # Check if any errors occured.
3365                         if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
3367                                 # A database error has occured so write a warning message and
3368                                 # also the extended error information.
3370                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasepageerror}, $filename, $kiriwrite_dbmodule->geterror(1));
3371                                 $warning_count++;
3372                                 next;
3374                         } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
3376                                 # The page does not exist, so process the next page.
3378                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{pagedoesnotexist}, $filename);
3379                                 $warning_count++;
3380                                 next;
3382                         }
3384                         # Move the selected page.
3386                         $kiriwrite_dbmodule->movepage({ PageFilename => $filename });
3388                         # Check if any errors occured while moving the page.
3390                         if ($kiriwrite_dbmodule->geterror eq "OldDatabaseError"){
3392                                 # A database error has occured while moving the pages from
3393                                 # the old database, so write a warning message.
3395                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasemovefrompageerror}, $filename, $kiriwrite_dbmodule->geterror(1));
3396                                 $warning_count++;
3397                                 next;
3399                         } elsif ($kiriwrite_dbmodule->geterror eq "NewDatabaseError"){
3401                                 # A database error has occured while moving the pages to
3402                                 # the new database, so write a warning message.
3404                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasemovetopageerror}, $filename, $kiriwrite_dbmodule->geterror(1));
3405                                 $warning_count++;
3406                                 next;
3408                         } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
3410                                 # The page with the filename given in the database that
3411                                 # the page is to be moved from doesn't exist so write
3412                                 # a warning message.
3414                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasemovefrompagenotexist}, $filename);
3415                                 $warning_count++;
3416                                 next;
3418                         } elsif ($kiriwrite_dbmodule->geterror eq "PageAlreadyExists"){
3420                                 # The page with the filename given in the database that
3421                                 # the page is to be moved to already exists so write a
3422                                 # warning message.
3424                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasemovetopageexists}, $filename);
3425                                 $warning_count++;
3426                                 next;
3428                         }
3430                         $moved_list{$move_count}{Filename}      = $page_info{"PageFilename"};
3431                         $moved_list{$move_count}{Name}          = $page_info{"PageName"};
3433                         $move_count++;
3435                 }
3437                 # Disconnect from the database server.
3439                 $kiriwrite_dbmodule->disconnect();
3441                 # Write out a message saying that the pages were moved (if any)
3442                 # to the new database (and any warnings given).
3444                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{movepages}, { Style => "pageheader" });
3445                 $kiriwrite_presmodule->addlinebreak();
3446                 $kiriwrite_presmodule->addlinebreak();
3448                 if (%moved_list){
3450                         $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{movedpagesmessage}, $olddatabase_name, $newdatabase_name));
3451                         $kiriwrite_presmodule->addlinebreak();
3452                         $kiriwrite_presmodule->addlinebreak();
3454                         $kiriwrite_presmodule->startbox("datalist");
3455                         foreach $page (keys %moved_list){
3456                                 if (!$moved_list{$page}{Name}){
3457                                         $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname});
3458                                         $kiriwrite_presmodule->addtext(" (" . $moved_list{$page}{Filename} . ")");
3459                                 } else {
3460                                         $kiriwrite_presmodule->addtext($moved_list{$page}{Name} . " (" . $moved_list{$page}{Filename} . ")");
3461                                 }
3463                                 $kiriwrite_presmodule->addlinebreak();
3464                         }
3465                         $kiriwrite_presmodule->endbox();
3467                 } else {
3469                         $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{nopagesmoved}, $olddatabase_name, $newdatabase_name));
3470                         $kiriwrite_presmodule->addlinebreak();
3471                         $kiriwrite_presmodule->addlinebreak();
3473                 }
3475                 if (%warning_list){
3477                         $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{errormessages});
3478                         $kiriwrite_presmodule->addlinebreak();
3479                         $kiriwrite_presmodule->addlinebreak();
3480                         $kiriwrite_presmodule->startbox("datalist");
3481                         foreach $warning (keys %warning_list){
3482                                 $kiriwrite_presmodule->addtext($warning_list{$warning}{Message});
3483                                 $kiriwrite_presmodule->addlinebreak();
3484                         }
3485                         $kiriwrite_presmodule->endbox();
3487                 }
3489                 $kiriwrite_presmodule->addlinebreak();
3490                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $olddatabase_name)}); 
3491                 $kiriwrite_presmodule->addtext(" | ");
3492                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $newdatabase, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{viewpagelist}, $newdatabase_name)});
3494                 return $kiriwrite_presmodule->grab();
3496         } elsif ($confirm eq 0) {
3498                 # The action to move several pages from one database
3499                 # to another has not been confirmed so write a form.
3501                 # Connect to the database server.
3503                 $kiriwrite_dbmodule->connect();
3505                 # Check if any errors occured while connecting to the database server.
3507                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
3509                         # A database connection error has occured so return
3510                         # an error.
3512                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
3514                 }
3516                 # Select the database.
3518                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
3520                 # Check if any errors occured while selecting the database.
3522                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
3524                         # The database does not exist, so return an error.
3526                         kiriwrite_error("databasemissingfile");
3528                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
3530                         # The database has invalid permissions set, so return
3531                         # an error.
3533                         kiriwrite_error("databaseinvalidpermissions");
3535                 }
3537                 # Check if the database has read and write permissions.
3539                 my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1);
3541                 if ($database_permissions eq 1){
3543                         # The database permissions are invalid so return an error.
3545                         kiriwrite_error("databaseinvalidpermissions");
3547                 }
3549                 # Get information about the database.
3551                 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
3553                 # Check if any errors had occured while getting the database
3554                 # information.
3556                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
3558                         # A database error has occured so return an error and
3559                         # also the extended error information.
3561                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
3563                 };
3565                 my $database_name       = $database_info{"DatabaseName"};
3567                 # Define some values for later.
3569                 my %db_list;
3570                 my %move_list;
3571                 my %page_info;
3572                 my $page;
3573                 my $data_file;
3574                 my $db_name;
3575                 my $filename;
3576                 my $filelist_filename;
3577                 my $pagename;
3578                 my $pageseek    = 0;
3579                 my $dbseek      = 0;
3581                 # Process each filename given.
3583                 tie (%move_list, 'Tie::IxHash');
3584                 tie (%db_list, 'Tie::IxHash');
3586                 foreach $filelist_filename (@filelist){
3588                         # Get the page information.
3590                         %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filelist_filename });
3592                         # Check if any errors occured.
3594                         if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
3596                                 # A database error has occured so return an error and
3597                                 # also the extended error information.
3599                                 kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
3601                         } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
3603                                 # The page does not exist, so process the next page.
3605                                 next;
3607                         }
3609                         # Add the page name and file name to the list of
3610                         # pages to move.
3612                         $move_list{$pageseek}{Filename} = $page_info{"PageFilename"};
3613                         $move_list{$pageseek}{Name}     = $page_info{"PageName"};
3615                         # Increment the page seek counter and reset the
3616                         # page found value.
3618                         $pageseek++;
3620                 }
3622                 # Check if any pages exust and return an error if
3623                 # there wasn't.
3625                 if ($pageseek eq 0){
3627                         # None of the selected pages exist, so return
3628                         # an error.
3630                         kiriwrite_error("nopagesselected");
3632                 }
3634                 # Get the list of databases.
3636                 my @database_list       = $kiriwrite_dbmodule->getdblist();
3638                 # Check if any errors occured while trying to get the list of databases.
3640                 if ($kiriwrite_dbmodule->geterror eq "DataDirMissing"){
3642                         # The database directory is missing so return an error.
3644                         kiriwrite_error("datadirectorymissing");
3646                 } elsif ($kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){
3648                         # The database directory has invalid permissions set so return
3649                         # an error.
3651                         kiriwrite_error("datadirectoryinvalidpermissions");
3653                 }
3655                 # Get the information about each database (the short name and friendly name).
3657                 foreach $data_file (@database_list){
3659                         $kiriwrite_dbmodule->selectdb({ DatabaseName => $data_file });
3661                         # Check if any errors occured while selecting the database.
3663                         if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
3665                                 # The database does not exist, so process the next
3666                                 # database.
3668                                 next;
3670                         } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
3672                                 # The database has invalid permissions set, so process
3673                                 # the next database.
3675                                 next;
3677                         }
3679                         # Get the database information.
3681                         %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
3683                         # Check if any errors had occured while getting the database
3684                         # information.
3686                         if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
3688                                 # A database error has occured so process the next
3689                                 # database.
3691                                 next;
3693                         };
3695                         # Check if the database name is undefined and if it is
3696                         # then set it blank.
3698                         if (!$database_name){
3699                                 $database_name = "";
3700                         }
3702                         # Append the database to the list of databases available.
3704                         $db_list{$dbseek}{Filename}     = $data_file;
3705                         $db_list{$dbseek}{Name}         = $database_info{"DatabaseName"};
3707                         $dbseek++;
3709                 }
3711                 # Disconnect from the database server.
3713                 $kiriwrite_dbmodule->disconnect();
3715                 # Write out the form.
3717                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{movepages}, { Style => "pageheader" });
3718                 $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST");
3719                 $kiriwrite_presmodule->startbox();
3720                 $kiriwrite_presmodule->addhiddendata("mode", "page");
3721                 $kiriwrite_presmodule->addhiddendata("action", "multimove");
3722                 $kiriwrite_presmodule->addhiddendata("database", $database);
3723                 $kiriwrite_presmodule->addhiddendata("count", $pageseek);
3724                 $kiriwrite_presmodule->addhiddendata("confirm", "1");
3726                 # Write the page form data.
3728                 $pageseek = 1;
3730                 foreach $page (keys %move_list){
3731                         $kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on");
3732                         $kiriwrite_presmodule->addhiddendata("id[" . $pageseek . "]", $move_list{$page}{Filename});
3733                         $pageseek++;
3734                 }
3736                 $kiriwrite_presmodule->addlinebreak();
3737                 $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{movepagesmessage}, $database_name));
3738                 $kiriwrite_presmodule->addlinebreak();
3739                 $kiriwrite_presmodule->addlinebreak();
3740                 $kiriwrite_presmodule->startbox("datalist");
3742                 foreach $page (keys %move_list){
3743                         if (!$move_list{$page}{Name}){
3744                                 $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname});
3745                                 $kiriwrite_presmodule->addtext(" (" . $move_list{$page}{Filename} . ")");
3746                         } else {
3747                                 $kiriwrite_presmodule->addtext($move_list{$page}{Name} . " (" . $move_list{$page}{Filename} . ")");
3748                         }
3749                         $kiriwrite_presmodule->addlinebreak();
3750                 }
3752                 $kiriwrite_presmodule->endbox();
3753                 $kiriwrite_presmodule->addlinebreak();
3754                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{movepagesto});
3756                 $kiriwrite_presmodule->addselectbox("newdatabase");
3758                 foreach $db_name (keys %db_list){
3759                         $kiriwrite_presmodule->addoption($db_list{$db_name}{Name} . " (" . $db_list{$db_name}{Filename} . ")", { Value => $db_list{$db_name}{Filename}});
3760                 }
3762                 $kiriwrite_presmodule->endselectbox();
3763                 $kiriwrite_presmodule->addlinebreak();
3764                 $kiriwrite_presmodule->addlinebreak();
3765                 $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{movepagesbutton});
3766                 $kiriwrite_presmodule->addtext(" | ");
3767                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name)});
3768                 $kiriwrite_presmodule->endbox();
3769                 $kiriwrite_presmodule->endform();
3771                 return $kiriwrite_presmodule->grab();
3773         } else {
3775                 # The confirm value is other than 0 or 1, so return
3776                 # an error.
3778                 kiriwrite_error("invalidvariable");
3780         }
3786 sub kiriwrite_page_multicopy{
3787 #################################################################################
3788 # kiriwrite_page_multicopy: Copy several pages from one database to another     #
3789 # database.                                                                     #
3790 #                                                                               #
3791 # Usage:                                                                        #
3792 #                                                                               #
3793 # kiriwrite_page_multicopy(database, newdatabase, confirm, filelist);           #
3794 #                                                                               #
3795 # database      Specifies the database to copy the selected pages from.         #
3796 # newdatabase   Specifies the database to copy the selected page to.            #
3797 # confirm       Confirms the action to copy the pages.                          #
3798 # filelist      A list of filenames to copy in an array.                        #
3799 #################################################################################
3801         # Get the values that were passed to the subroutine.
3803         my ($database, $newdatabase, $confirm, @filelist) = @_;
3805         # Check if the file list is blank and return an error
3806         # if it is.
3808         if (!@filelist){
3810                 # The file list really is blank so return
3811                 # an error.
3813                 kiriwrite_error("nopagesselected");
3815         }
3817         # Check if the confirm value is blank and if it is then
3818         # set the confirm value to 0.
3820         if (!$confirm){
3822                 $confirm = 0;
3824         }
3826         # Check if the database filename is valid and return an error if
3827         # it isn't.
3829         my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1);
3831         if ($pagedatabase_filename_check eq 1){
3833                 # The database filename is blank, so return an error.
3835                 kiriwrite_error("blankdatabasepageadd");
3837         } elsif ($pagedatabase_filename_check eq 2){
3839                 # The database filename is invalid, so return an error.
3841                 kiriwrite_error("databasefilenameinvalid");
3843         }
3845         if ($confirm eq 1){
3847                 # The action to copy several pages from one database
3848                 # to another has been confirmed.
3850                 # Check if the database that the pages are copied from 
3851                 # is the same as the database the pages are copied to.
3852                 # Return an error if it is.
3854                 if ($database eq $newdatabase){
3856                         # The database that the pages are being copied from
3857                         # and the database that the pages are copied to
3858                         # is the same, so return an error.
3860                         kiriwrite_error("databasecopysame");
3862                 }
3864                 # Check if the new database filename is valid and return an error if
3865                 # it isn't.
3867                 my $pagedatabase_filename_check = kiriwrite_variablecheck($newdatabase, "filename", 0, 1);
3869                 if ($pagedatabase_filename_check eq 1){
3871                         # The database filename is blank, so return an error.
3873                         kiriwrite_error("blankdatabasepageadd");
3875                 } elsif ($pagedatabase_filename_check eq 2){
3877                         # The database filename is invalid, so return an error.
3879                         kiriwrite_error("databasefilenameinvalid");
3881                 }
3883                 # Connect to the database server.
3885                 $kiriwrite_dbmodule->connect();
3887                 # Check if any errors occured while connecting to the database server.
3889                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
3891                         # A database connection error has occured so return
3892                         # an error.
3894                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
3896                 }
3898                 # Select the database the pages are going to be copied from.
3900                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
3902                 # Check if any errors had occured while selecting the database.
3904                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
3906                         # The database does not exist, so return an error.
3908                         kiriwrite_error("oldcopydatabasedoesnotexist");
3910                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
3912                         # The database has invalid permissions set, so return
3913                         # an error.
3915                         kiriwrite_error("oldcopydatabasefileinvalidpermissions");
3917                 }
3919                 # Select the database the pages are going to be copied to.
3921                 $kiriwrite_dbmodule->selectseconddb({ DatabaseName => $newdatabase });
3923                 # Check if any errors had occured while selecting the database.
3925                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
3927                         # The database does not exist, so return an error.
3929                         kiriwrite_error("newcopydatabasedoesnotexist");
3931                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
3933                         # The database has invalid permissions set, so return
3934                         # an error.
3936                         kiriwrite_error("newcopydatabasefileinvalidpermissions");
3938                 }
3940                 # Check if the database has read and write permissions.
3942                 my $database_permissions = $kiriwrite_dbmodule->dbpermissions($newdatabase, 1, 1);
3944                 if ($database_permissions eq 1){
3946                         # The database permissions are invalid so return an error.
3948                         kiriwrite_error("newcopydatabasefileinvalidpermissions");
3950                 }
3952                 # Define some values for later.
3954                 my %copied_list;
3955                 my %warning_list;
3956                 my %page_info;
3958                 my @olddatabase_info;
3959                 my @olddatabase_page;
3960                 my @newdatabase_info;
3961                 my @newdatabase_page;
3963                 my $filename;
3965                 my $olddatabase_name;
3966                 my $newdatabase_name;
3968                 my $page;
3969                 my $warning;
3970                 my $page_filename;
3971                 my $page_name;
3972                 my $page_description;
3973                 my $page_section;
3974                 my $page_template;
3975                 my $page_data;
3976                 my $page_settings;
3977                 my $page_lastmodified;
3979                 my $page_seek = 0;
3980                 my $warning_count = 0;
3982                 my $page_found = 0;
3984                 tie(%copied_list, 'Tie::IxHash');
3985                 tie(%warning_list, 'Tie::IxHash');
3987                 # Get information about the database that the selected pages are moving from.
3989                 my %olddatabase_info = $kiriwrite_dbmodule->getdatabaseinfo();
3991                 # Check if any errors had occured while getting the database
3992                 # information.
3994                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
3996                         # A database error has occured so return an error and
3997                         # also the extended error information.
3999                         kiriwrite_error("oldcopydatabasedatabaseerror", $kiriwrite_dbmodule->geterror(1));
4001                 };
4003                 $olddatabase_name = $olddatabase_info{"DatabaseName"};
4005                 # Get information about the database that the selected pages are moving to.
4007                 my %newdatabase_info = $kiriwrite_dbmodule->getseconddatabaseinfo();
4009                 # Check if any errors had occured while getting the database
4010                 # information.
4012                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
4014                         # A database error has occured so return an error and
4015                         # also the extended error information.
4017                         kiriwrite_error("newcopydatabasedatabaseerror", $kiriwrite_dbmodule->geterror(1));
4019                 };
4021                 $newdatabase_name = $newdatabase_info{"DatabaseName"};
4023                 # Check if the database filename is valid and return an error if
4024                 # it isn't.
4026                 my $newpagedatabase_filename_check = kiriwrite_variablecheck($newdatabase, "filename", 0, 1);
4028                 if ($newpagedatabase_filename_check eq 1){
4030                         # The database filename is blank, so return an error.
4032                         kiriwrite_error("blankdatabasepageadd");
4034                 } elsif ($newpagedatabase_filename_check eq 2){
4036                         # The database filename is invalid, so return an error.
4038                         kiriwrite_error("databasefilenameinvalid");
4040                 }
4042                 foreach $filename (@filelist){
4044                         # Get the page information.
4046                         %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filename });
4048                         # Check if any errors occured.
4050                         if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
4052                                 # A database error has occured so return an error and
4053                                 # also the extended error information.
4055                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasepageerror}, $filename, $kiriwrite_dbmodule->geterror(1));
4056                                 $warning_count++;
4057                                 next;
4059                         } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
4061                                 # The page does not exist, so process the next page.
4063                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasecopyfrompageerror}, $filename);
4064                                 $warning_count++;
4065                                 next;
4067                         }
4069                         $kiriwrite_dbmodule->copypage({ PageFilename => $filename });
4071                         # Check if any errors occured while copying the page.
4073                         if ($kiriwrite_dbmodule->geterror eq "OldDatabaseError"){
4075                                 # A database error has occured while copying the pages from
4076                                 # the old database, so write a warning message.
4078                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasecopyfromdatabaseerror}, $filename,  $kiriwrite_dbmodule->geterror(1));
4079                                 $warning_count++;
4080                                 next;
4082                         } elsif ($kiriwrite_dbmodule->geterror eq "NewDatabaseError"){
4084                                 # A database error has occured while copying the pages to
4085                                 # the new database, so write a warning message.
4087                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasecopytodatabaseerror}, $filename, $kiriwrite_dbmodule->geterror(1));
4088                                 $warning_count++;
4089                                 next;
4091                         } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
4093                                 # The page with the filename given in the database that
4094                                 # the page is to be copied from doesn't exist so write
4095                                 # a warning message.
4097                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasecopyfrompagenotexist}, $filename);
4098                                 $warning_count++;
4099                                 next;
4101                         } elsif ($kiriwrite_dbmodule->geterror eq "PageAlreadyExists"){
4103                                 # The page with the filename given in the database that
4104                                 # the page is to be copied to already exists so write a
4105                                 # warning message.
4107                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasecopytopageexists}, $filename);
4108                                 $warning_count++;
4109                                 next;
4111                         }
4113                         # Append the copied page (filename and name) to the list of
4114                         # copied pages.
4116                         $copied_list{$page_seek}{Filename}      = $filename;
4117                         $copied_list{$page_seek}{Name}          = $page_info{"PageName"};
4118                         $page_seek++;
4120                 }
4122                 # Disconnect from the database server.
4124                 $kiriwrite_dbmodule->disconnect();
4126                 # Write out a message saying that the pages were moved (if any)
4127                 # to the new database (and any warnings given).
4129                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{copypages}, { Style => "pageheader" });
4130                 $kiriwrite_presmodule->addlinebreak();
4131                 $kiriwrite_presmodule->addlinebreak();
4133                 if (%copied_list){
4135                         $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{copypagesresultmessage}, $olddatabase_name, $newdatabase_name));
4136                         $kiriwrite_presmodule->addlinebreak();
4137                         $kiriwrite_presmodule->addlinebreak();
4138                         $kiriwrite_presmodule->startbox("datalist");
4139                         foreach $page (keys %copied_list){
4140                                 if (!$copied_list{$page}{Name}){
4141                                         $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname});
4142                                         $kiriwrite_presmodule->addtext(" (" . $copied_list{$page}{Filename} . ")");
4143                                 } else {
4144                                         $kiriwrite_presmodule->addtext($copied_list{$page}{Name} . " (" . $copied_list{$page}{Filename} . ")");
4145                                 }
4146                                 $kiriwrite_presmodule->addlinebreak();
4147                         }
4148                         $kiriwrite_presmodule->endbox();
4150                 } else {
4152                         $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{nopagescopied}, $olddatabase_name, $newdatabase_name));
4154                 }
4156                 if (%warning_list){
4158                         $kiriwrite_presmodule->addlinebreak();
4159                         $kiriwrite_presmodule->addlinebreak();
4160                         $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{copypageswarnings});
4161                         $kiriwrite_presmodule->addlinebreak();
4162                         $kiriwrite_presmodule->addlinebreak();
4163                         $kiriwrite_presmodule->startbox("datalist");
4164                         foreach $warning (keys %warning_list){
4165                                 $kiriwrite_presmodule->addtext($warning_list{$warning}{Message});
4166                                                         $kiriwrite_presmodule->addlinebreak();
4167                         }
4168                         $kiriwrite_presmodule->endbox();
4170                 }
4172                 $kiriwrite_presmodule->addlinebreak();
4173                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $olddatabase_name)});
4174                 $kiriwrite_presmodule->addtext(" | ");
4175                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $newdatabase, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{viewpagelist}, $newdatabase_name)});
4177                 return $kiriwrite_presmodule->grab();
4179         } elsif ($confirm eq 0) {
4181                 # The action to copy several pages from one database
4182                 # to another has not been confirmed so write a form.
4184                 # Connect to the database server.
4186                 $kiriwrite_dbmodule->connect();
4188                 # Check if any errors occured while connecting to the database server.
4190                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
4192                         # A database connection error has occured so return
4193                         # an error.
4195                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
4197                 }
4199                 # Select the database to copy the pages from.
4201                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
4203                 # Check if any errors occured while selecting the database.
4205                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
4207                         # The database does not exist, so return an error.
4209                         kiriwrite_error("databasemissingfile");
4211                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
4213                         # The database has invalid permissions set, so return
4214                         # an error.
4216                         kiriwrite_error("databaseinvalidpermissions");
4218                 }
4220                 # Get information about the database.
4222                 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
4224                 # Check if any errors had occured while getting the database
4225                 # information.
4227                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
4229                         # A database error has occured so return an error and
4230                         # also the extended error information.
4232                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
4234                 };
4236                 my $database_name       = $database_info{"DatabaseName"};
4238                 # Define some values for later.
4240                 my %page_info;
4241                 my %copy_list;
4242                 my %db_list;
4243                 my @page_info;
4244                 my $page;
4245                 my $data_file;
4246                 my $dbname;
4247                 my $filename;
4248                 my $pageseek    = 0;
4249                 my $dbseek      = 0;
4250                 my $pagefound   = 0;
4252                 tie(%copy_list, 'Tie::IxHash');
4253                 tie(%db_list, 'Tie::IxHash');
4255                 # Process each filename given.
4257                 foreach $filename (@filelist){
4259                         # Get the page information.
4261                         %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filename });
4263                         # Check if any errors occured.
4265                         if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
4267                                 # A database error has occured so return an error and
4268                                 # also the extended error information.
4270                                 kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
4272                         } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
4274                                 # The page does not exist, so process the next page.
4276                                 next;
4278                         }
4280                         # Add the page name and file name to the list of
4281                         # pages to move.
4283                         $copy_list{$pageseek}{Filename} = $page_info{"PageFilename"};
4284                         $copy_list{$pageseek}{Name}     = $page_info{"PageName"};
4286                         # Increment the page seek counter.
4288                         $pageseek++;
4290                 }
4292                 # Check if any pages exust and return an error if
4293                 # there wasn't.
4295                 if ($pageseek eq 0){
4297                         # None of the selected pages exist, so return
4298                         # an error.
4300                         kiriwrite_error("nopagesselected");
4302                 }
4304                 # Get the database filenames and names.
4306                 my @database_list       = $kiriwrite_dbmodule->getdblist();
4308                 # Check if any errors occured while trying to get the list of databases.
4310                 if ($kiriwrite_dbmodule->geterror eq "DataDirMissing"){
4312                         # The database directory is missing so return an error.
4314                         kiriwrite_error("datadirectorymissing");
4316                 } elsif ($kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){
4318                         # The database directory has invalid permissions set so return
4319                         # an error.
4321                         kiriwrite_error("datadirectoryinvalidpermissions");
4323                 }
4325                 # Process each database to get the database name.
4327                 foreach $data_file (@database_list){
4329                         $kiriwrite_dbmodule->selectdb({ DatabaseName => $data_file });
4331                         # Check if any errors occured while selecting the database.
4333                         if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
4335                                 # The database does not exist, so process the next
4336                                 # database.
4338                                 next;
4340                         } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
4342                                 # The database has invalid permissions set, so process
4343                                 # the next database.
4345                                 next;
4347                         }
4349                         # Get the database information.
4351                         %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
4353                         # Check if any errors had occured while getting the database
4354                         # information.
4356                         if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
4358                                 # A database error has occured so process the next
4359                                 # database.
4361                                 next;
4363                         };
4365                         # Check if the database name is undefined and if it is
4366                         # then set it blank.
4368                         if (!$database_name){
4369                                 $database_name = "";
4370                         }
4372                         # Append the database filename and name to the list of databases
4373                         # to move the pages to.
4375                         $db_list{$dbseek}{Filename}     = $data_file;
4376                         $db_list{$dbseek}{Name}         = $database_info{"DatabaseName"};
4378                         $dbseek++;
4380                 }
4382                 # Disconnect from the database server.
4384                 $kiriwrite_dbmodule->disconnect();
4386                 # Write out the form.
4388                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{copypages}, { Style => "pageheader" });
4389                 $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST");
4390                 $kiriwrite_presmodule->startbox();
4391                 $kiriwrite_presmodule->addhiddendata("mode", "page");
4392                 $kiriwrite_presmodule->addhiddendata("action", "multicopy");
4393                 $kiriwrite_presmodule->addhiddendata("database", $database);
4394                 $kiriwrite_presmodule->addhiddendata("count", $pageseek);
4395                 $kiriwrite_presmodule->addhiddendata("confirm", 1);
4397                 $pageseek = 1;
4399                 foreach $page (keys %copy_list){
4400                         $kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on");
4401                         $kiriwrite_presmodule->addhiddendata("id[" . $pageseek . "]", $copy_list{$page}{Filename});
4402                         $pageseek++;
4403                 }
4405                 $kiriwrite_presmodule->addlinebreak();
4406                 $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{copypagesmessage}, $database_name));
4408                 $kiriwrite_presmodule->addlinebreak();
4409                 $kiriwrite_presmodule->addlinebreak();
4411                 $kiriwrite_presmodule->startbox("datalist");
4413                 foreach $page (keys %copy_list){
4414                         if (!$copy_list{$page}{Name}){
4415                                 $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname});
4416                                 $kiriwrite_presmodule->addtext(" (" . $copy_list{$page}{Filename} . ")");
4417                         } else {
4418                                 $kiriwrite_presmodule->addtext($copy_list{$page}{Name} . " (" . $copy_list{$page}{Filename} . ")");
4419                         }
4420                         $kiriwrite_presmodule->addlinebreak();
4421                 }
4423                 $kiriwrite_presmodule->endbox();
4425                 $kiriwrite_presmodule->addlinebreak();
4427                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{copypagesto});
4428                 $kiriwrite_presmodule->addselectbox("newdatabase");
4430                 foreach $dbname (keys %db_list){
4431                         $kiriwrite_presmodule->addoption($db_list{$dbname}{Name} . " (" . $db_list{$dbname}{Filename} . ")", { Value => $db_list{$dbname}{Filename}});
4432                 }
4434                 $kiriwrite_presmodule->endselectbox();
4436                 $kiriwrite_presmodule->addlinebreak();
4437                 $kiriwrite_presmodule->addlinebreak();
4438                 $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{copypagesbutton});
4439                 $kiriwrite_presmodule->addtext(" | ");
4440                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name) });
4442                 $kiriwrite_presmodule->endbox();                
4443                 $kiriwrite_presmodule->endform();
4445                 return $kiriwrite_presmodule->grab();
4447         } else {
4449                 # The confirm value is other than 0 or 1, so return
4450                 # an error.
4452                 kiriwrite_error("invalidvariable");
4454         }
4458 sub kiriwrite_page_multiedit{
4459 #################################################################################
4460 # kiriwrite_page_multiedit: Edit several pages from a database.                 #
4461 #                                                                               #
4462 # Usage:                                                                        #
4463 #                                                                               #
4464 # kiriwrite_page_multiedit(database, newsection, altersection, newtemplate,     #
4465 #                               altertemplate, newsettings, altersettings       #
4466 #                               confirm, filelist);                             #
4467 #                                                                               #
4468 # database      Specifies the database to edit the pages from.                  #
4469 # newsection    Specifies the new section name to use on the selected pages.    #
4470 # altersection  Specifies if the section name should be altered.                #
4471 # newtemplate   Specifies the new template filename to use on the selected      #
4472 #               pages.                                                          #
4473 # altertemplate Specifies if the template filename should be altered.           #
4474 # newsettings   Specifies the new settings to use on the selected pages.        #
4475 # altersettings Specifies if the settings should be altered.                    #
4476 # confirm       Confirms the action to edit the selected pages.                 #
4477 # filelist      The list of file names to edit.                                 #
4478 #################################################################################
4480         # Get the values that were passed to the subroutine.
4482         my ($database, $newsection, $altersection, $newtemplate, $altertemplate, $newsettings, $altersettings, $confirm, @filelist) = @_;
4484         # Check if the file list is blank and return an error
4485         # if it is.
4487         if (!@filelist){
4489                 # The file list really is blank so return
4490                 # an error.
4492                 kiriwrite_error("nopagesselected");
4494         }
4496         # Check if certain values are undefined and define them if
4497         # they are.
4499         if (!$altersection){
4501                 # The alter section value is blank, so set it to
4502                 # off.
4504                 $altersection   = "off";
4506         }
4508         if (!$altertemplate){
4510                 # The alter template value is blank, so set it to
4511                 # off.
4513                 $altertemplate  = "off";
4515         }
4517         if (!$altersettings){
4519                 # The alter settings value is blank, so set it to
4520                 # off.
4522                 $altersettings  = "off";
4524         }
4526         # Check if the database filename is valid and return an error if
4527         # it isn't.
4529         my $pagedatabase_filename_check = kiriwrite_variablecheck($database, "filename", 0, 1);
4531         if ($pagedatabase_filename_check eq 1){
4533                 # The database filename is blank, so return an error.
4535                 kiriwrite_error("blankdatabasepageadd");
4537         } elsif ($pagedatabase_filename_check eq 2){
4539                 # The database filename is invalid, so return an error.
4541                 kiriwrite_error("databasefilenameinvalid");
4543         }
4545         # Check if the confirm value is blank and if it is then
4546         # set the confirm value to 0.
4548         if (!$confirm){
4550                 $confirm = 0;
4552         }
4554         if ($confirm eq 1){
4556                 # The action to edit the template has been confirmed so
4557                 # edit the selected pages.
4559                 # Check the values recieved at UTF8 compliant before
4560                 # converting.
4562                 kiriwrite_variablecheck($newsection, "utf8", 0, 0);
4563                 kiriwrite_variablecheck($newtemplate, "utf8", 0, 0);
4564                 kiriwrite_variablecheck($newsettings, "utf8", 0, 0);
4566                 # Convert the values into proper UTF8 values.
4568                 $newsection     = kiriwrite_utf8convert($newsection);
4569                 $newtemplate    = kiriwrite_utf8convert($newtemplate);
4570                 $newsettings    = kiriwrite_utf8convert($newsettings);
4572                 # Check the length of the variables.
4574                 kiriwrite_variablecheck($altersection, "maxlength", 3, 0);
4575                 kiriwrite_variablecheck($altertemplate, "maxlength", 3, 0);
4576                 kiriwrite_variablecheck($altersettings, "maxlength", 3, 0);
4577                 my $newsection_maxlength_check  = kiriwrite_variablecheck($newsection, "maxlength", 256, 1);
4578                 my $newtemplate_maxlength_check = kiriwrite_variablecheck($newtemplate, "maxlength", 256, 1);
4579                 my $newtemplate_filename_check  = kiriwrite_variablecheck($newtemplate, "filename", 0, 1);
4580                 my $newsettings_maxlength_check = kiriwrite_variablecheck($newsettings, "maxlength", 1, 1);
4581                 my $newsettings_settings_check  = kiriwrite_variablecheck($newsettings, "pagesetting", 0, 1);
4583                 # Check the values and return an error if needed.
4585                 if ($newsection_maxlength_check eq 1 && $altersection eq "on"){
4587                         # The new section name is too long, so return an
4588                         # error.
4590                         kiriwrite_error("pagesectiontoolong");
4592                 }
4594                 if ($newtemplate_maxlength_check eq 1 && $altertemplate eq "on"){
4596                         # The new template name is too long, so return an
4597                         # error.
4599                         kiriwrite_error("templatefilenametoolong");
4601                 }
4603                 # Check if the template filename is set to !skip or !none
4604                 # and skip this check if it is.
4606                 if ($newtemplate eq "!skip" || $newtemplate eq "!none"){
4608                         # Skip this check as the template filename is 
4609                         # !skip or !none.
4611                 } else {
4612                         if ($newtemplate_filename_check eq 1 && $altertemplate eq "on" || $newtemplate_filename_check eq 2 && $altertemplate eq "on"){
4614                                 # The new template filename is invalid, so return
4615                                 # an error.
4617                                 kiriwrite_error("templatefilenameinvalid");
4619                         }
4620                 }
4622                 if ($newsettings_maxlength_check eq 1 && $altertemplate eq "on"){
4624                         # The new settings value is too long, so return
4625                         # an error.
4627                         kiriwrite_error("pagesettingstoolong");
4629                 }
4631                 if ($newsettings_settings_check eq 1 && $altersettings eq "on"){
4633                         # The new settings value is invalid, so return
4634                         # an error.
4636                         kiriwrite_error("pagesettingsinvalid");
4638                 }
4640                 # Define some values for later.
4642                 my %database_info;
4643                 my %edited_list;
4644                 my %warning_list;
4645                 my %page_info;
4646                 my $page;
4647                 my $warning;
4648                 my $filename;
4649                 my $page_name;
4650                 my $pagefound = 0;
4651                 my $pageedited = 0;
4652                 my $warning_count = 0;
4654                 tie(%edited_list, 'Tie::IxHash');
4655                 tie(%warning_list, 'Tie::IxHash');
4657                 # Check if the template filename is !skip and
4658                 # set the alter template value to off if it
4659                 # is.
4661                 if ($newtemplate eq "!skip"){
4663                         $altertemplate = "off";
4665                 }
4667                 # Check if all values are not selected and return
4668                 # an error if they are.
4670                 if ($altersection ne "on" && $altertemplate ne "on" && $altersettings ne "on"){
4672                         # All values are not selected so return 
4673                         # an error.
4675                         kiriwrite_error("noeditvaluesselected");
4677                 }
4679                 # Connect to the database server.
4681                 $kiriwrite_dbmodule->connect();
4683                 # Check if any errors occured while connecting to the database server.
4685                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
4687                         # A database connection error has occured so return
4688                         # an error.
4690                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
4692                 }
4694                 # Select the database.
4696                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
4698                 # Check if any errors occured while selecting the database.
4700                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
4702                         # The database does not exist, so return an error.
4704                         kiriwrite_error("databasemissingfile");
4706                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
4708                         # The database has invalid permissions set, so return
4709                         # an error.
4711                         kiriwrite_error("databaseinvalidpermissions");
4713                 }
4715                 # Check if the database has read and write permissions.
4717                 my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1);
4719                 if ($database_permissions eq 1){
4721                         # The database permissions are invalid so return an error.
4723                         kiriwrite_error("databaseinvalidpermissions");
4725                 }
4727                 # Get information about the database.
4729                 %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
4731                 # Check if any errors had occured while getting the database
4732                 # information.
4734                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
4736                         # A database error has occured so return an error and
4737                         # also the extended error information.
4739                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
4741                 };
4743                 my $database_name = $database_info{"DatabaseName"};
4745                 # Edit the selected pages.
4747                 foreach $filename (@filelist){
4749                         # Get the page information.
4751                         %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filename });
4753                         # Check if any errors occured.
4755                         if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
4757                                 # A database error has occured so write a warning message.
4759                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasepageerror}, $filename, $kiriwrite_dbmodule->geterror(1));
4761                         } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
4763                                 # The page does not exist, so write a warning message.
4765                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasepagedoesnotexist}, $filename);
4766                                 $warning_count++;
4767                                 next;
4769                         }
4771                         # Check if the page section should be altered.
4773                         if ($altersection eq "on"){
4775                                 # Change the section name.
4777                                 $page_info{"PageSection"} = $newsection;
4779                         }
4781                         # Check if the page template should be altered.
4783                         if ($altertemplate eq "on"){
4785                                 # Change the page template filename.
4787                                 $page_info{"PageTemplate"} = $newtemplate;
4789                         }
4791                         # Check if the page settings should be altered.
4793                         if ($altersettings eq "on"){
4795                                 # Change the page settings value.
4797                                 $page_info{"PageSettings"} = $newsettings;
4799                         }
4801                         # Edit the selected page.
4803                         $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"} });
4805                         # Check if any errors occured while editing the page.
4807                         if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
4809                                 # A database error has occured so write a warning message
4810                                 # with the extended error information.
4812                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasepageerror}, $filename, $kiriwrite_dbmodule->geterror(1));
4813                                 $warning_count++;
4814                                 next;
4816                         } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
4818                                 # The pages does not exist in the database.
4820                                 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasepagedoesnotexist}, $filename);
4821                                 $warning_count++;
4822                                 next;
4824                         } elsif ($kiriwrite_dbmodule->geterror eq "PageExists"){
4826                                 # A page already exists with the new filename.
4828                                 kiriwrite_error("pagefilenameexists");
4830                         }
4832                         # The page has been edited so write a message saying that the page
4833                         # has been edited.
4835                         $edited_list{$pageedited}{Filename}     = $page_info{"PageFilename"};
4836                         $edited_list{$pageedited}{Name}         = $page_info{"PageName"};
4837  
4838                         # Increment the counter of edited pages.
4839  
4840                         $pageedited++;
4842                 }
4844                 # Disconnect from the database server.
4846                 $kiriwrite_dbmodule->disconnect();
4848                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{multiedit}, { Style => "pageheader" });
4849                 $kiriwrite_presmodule->addlinebreak();
4850                 $kiriwrite_presmodule->addlinebreak();
4852                 # Check if the counter of edited pages is 0 and if it is
4853                 # then write a message saying that no pages were edited
4854                 # else write a message listing all of the pages edited.
4856                 if ($pageedited eq 0){
4858                         $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{nopagesedited}, $database_name));
4860                 } else {
4862                         # Write out the message saying that the selected pages
4863                         # were edited.
4865                         $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{pagesedited}, $database_name));
4866                         $kiriwrite_presmodule->addlinebreak();
4867                         $kiriwrite_presmodule->addlinebreak();
4868                         $kiriwrite_presmodule->startbox("datalist");
4870                         foreach $page (keys %edited_list){
4872                                 # Check if the page name is not blank.
4874                                 if (!$edited_list{$page}{Name}){
4876                                         $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname});
4877                                         $kiriwrite_presmodule->addtext(" (" . $edited_list{$page}{Filename} . ")");
4879                                 } else {
4881                                         $kiriwrite_presmodule->addtext($edited_list{$page}{Name});
4882                                         $kiriwrite_presmodule->addtext(" (" . $edited_list{$page}{Filename} . ")");
4884                                 }
4886                                 $kiriwrite_presmodule->addlinebreak();
4887                         }
4889                         $kiriwrite_presmodule->endbox();
4891                 }
4893                 # Check if any warnings have occured and write a message
4894                 # if any warnings did occur.
4896                 if (%warning_list){
4898                         # One or several warnings have occured so 
4899                         # write a message.
4901                         $kiriwrite_presmodule->addlinebreak();
4902                         $kiriwrite_presmodule->addlinebreak();
4903                         $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{editedpageswarnings});
4904                         $kiriwrite_presmodule->addlinebreak();
4905                         $kiriwrite_presmodule->addlinebreak();
4906                         $kiriwrite_presmodule->startbox("datalist");
4907                         foreach $warning (keys %warning_list) {
4908                                 $kiriwrite_presmodule->addtext($warning_list{$warning}{Message});
4909                                 $kiriwrite_presmodule->addlinebreak();
4910                         }
4911                         $kiriwrite_presmodule->endbox();
4913                 }
4915                 # Write a link going back to the page list for
4916                 # the selected database.
4918                 $kiriwrite_presmodule->addlinebreak();
4919                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name) });
4921                 return $kiriwrite_presmodule->grab();
4923         } elsif ($confirm eq 0){
4925                 # The action to edit the template has not been confirmed
4926                 # so write a form out instead.
4928                 # Connect to the database server.
4930                 $kiriwrite_dbmodule->connect();
4932                 # Check if any errors occured while connecting to the database server.
4934                 if ($kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
4936                         # A database connection error has occured so return
4937                         # an error.
4939                         kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
4941                 }
4943                 # Select the database.
4945                 $kiriwrite_dbmodule->selectdb({ DatabaseName => $database });
4947                 # Check if any errors occured while selecting the database.
4949                 if ($kiriwrite_dbmodule->geterror eq "DoesNotExist"){
4951                         # The database does not exist, so return an error.
4953                         kiriwrite_error("databasemissingfile");
4955                 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
4957                         # The database has invalid permissions set, so return
4958                         # an error.
4960                         kiriwrite_error("databaseinvalidpermissions");
4962                 }
4964                 # Check if the database has read and write permissions.
4966                 my $database_permissions = $kiriwrite_dbmodule->dbpermissions($database, 1, 1);
4968                 if ($database_permissions eq 1){
4970                         # The database permissions are invalid so return an error.
4972                         kiriwrite_error("databaseinvalidpermissions");
4974                 }
4976                 # Get information about the database.
4978                 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
4980                 # Check if any errors had occured while getting the database
4981                 # information.
4983                 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
4985                         # A database error has occured so return an error and
4986                         # also the extended error information.
4988                         kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
4990                 };
4992                 my $database_name       = $database_info{"DatabaseName"};
4994                 # Define some variables for later.
4996                 my %edit_list;
4997                 my %template_list;
4998                 my %template_info;
4999                 my %page_info;
5000                 my @templates_list;
5001                 my @filenames;
5002                 my $filelist_filename;
5003                 my $filename;
5004                 my $page;
5005                 my $pageseek = 0;
5006                 my $page_name;
5007                 my $page_filename;
5008                 my $template;
5009                 my $template_filename;
5010                 my $template_warning;
5011                 my $templateseek = 0;
5013                 tie(%edit_list, 'Tie::IxHash');
5014                 tie(%template_list, 'Tie::IxHash');
5016                 # Get the information about each page that is going
5017                 # to be edited.
5019                 foreach $filelist_filename (@filelist){
5021                         %page_info = $kiriwrite_dbmodule->getpageinfo({ PageFilename => $filelist_filename });
5023                         # Check if any errors occured.
5025                         if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
5027                                 # A database error has occured so return an error and
5028                                 # also the extended error information.
5030                                 kiriwrite_error("databaseerror", $kiriwrite_dbmodule->geterror(1));
5032                         } elsif ($kiriwrite_dbmodule->geterror eq "PageDoesNotExist"){
5034                                 # The page does not exist, so process the next page.
5036                                 next;
5038                         }
5040                         # Add the page name and file name to the list of
5041                         # pages to edit.
5043                         $edit_list{$pageseek}{Filename} = $page_info{"PageFilename"};
5044                         $edit_list{$pageseek}{Name}     = $page_info{"PageName"};
5046                         # Increment the page seek counter and reset the
5047                         # page found value.
5049                         $pageseek++;
5051                 }
5053                 # Check if any pages were found in the database and return
5054                 # an error if not.
5056                 if ($pageseek eq 0){
5058                         # No pages were found so return an error.
5060                         kiriwrite_error("nopagesselected");
5062                 }
5064                 # Connect to the template database.
5066                 $kiriwrite_dbmodule->connecttemplate();
5068                 # Check if any errors had occured.
5070                 if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
5072                         # The template database does not exist so write a warning
5073                         # message.
5075                         $template_warning = $kiriwrite_lang->{pages}->{templatedatabasenotexistmultieditkeep};
5077                 } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
5079                         # The template database has invalid permissions set so
5080                         # return an error.
5082                         $template_warning = $kiriwrite_lang->{pages}->{templatedatabasepermissionsinvalidmultieditkeep};
5084                 }
5086                 if (!$template_warning){
5088                         # Get the list of templates available.
5090                         @templates_list = $kiriwrite_dbmodule->gettemplatelist();
5092                         # Check if any errors had occured.
5094                         if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
5096                                 # A database error occured while getting the list
5097                                 # of templates so write a warning message with the 
5098                                 # extended error information.
5100                                 $template_warning = kiriwrite_language($kiriwrite_lang->{pages}->{templatedatabaseerrormultieditkeep}, $kiriwrite_dbmodule->geterror(1));
5102                         }
5104                         if (!$template_warning){
5106                                 foreach $template_filename (@templates_list){
5108                                         # Get the template data.
5110                                         %template_info = $kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_filename });
5112                                         # Check if any error occured while getting the template information.
5114                                         if ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
5116                                                 # A database error has occured, so write a warning message with
5117                                                 # the extended error information.
5119                                                 $template_warning = kiriwrite_language($kiriwrite_lang->{pages}->{templatedatabaseerrormultieditkeep}, $kiriwrite_dbmodule->geterror(1));
5121                                         } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
5123                                                 # The template does not exist, so process the next page.
5125                                                 next;
5127                                         }
5129                                         # Add the template to the list of templates.
5131                                         $template_list{$templateseek}{Filename} = $template_info{"TemplateFilename"};
5132                                         $template_list{$templateseek}{Name}     = $template_info{"TemplateName"};
5134                                         $templateseek++;
5136                                 }
5138                         }
5140                 }
5142                 # Disconnect from the template database.
5144                 $kiriwrite_dbmodule->disconnecttemplate();
5146                 # Disconnect from the database server.
5148                 $kiriwrite_dbmodule->disconnect();
5150                 # Write a form for editing the selected pages.
5152                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{multiedit}, { Style => "pageheader" });
5153                 $kiriwrite_presmodule->addlinebreak();
5154                 $kiriwrite_presmodule->addlinebreak();
5155                 $kiriwrite_presmodule->startform($kiriwrite_env{"script_filename"}, "POST");
5156                 $kiriwrite_presmodule->startbox();
5157                 $kiriwrite_presmodule->addhiddendata("mode", "page");
5158                 $kiriwrite_presmodule->addhiddendata("action", "multiedit");
5159                 $kiriwrite_presmodule->addhiddendata("database", $database);
5160                 $kiriwrite_presmodule->addhiddendata("count", $pageseek);
5161                 $kiriwrite_presmodule->addhiddendata("confirm", 1);
5163                 $pageseek = 1;
5165                 foreach $page (keys %edit_list){
5166                         $kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on");
5167                         $kiriwrite_presmodule->addhiddendata("id[" . $pageseek  . "]", $edit_list{$page}{Filename});
5168                         $pageseek++;
5169                 }
5171                 $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{multieditmessage}, $database_name));
5172                 $kiriwrite_presmodule->addlinebreak();
5173                 $kiriwrite_presmodule->addlinebreak();
5174                 $kiriwrite_presmodule->startbox("datalist");
5176                 foreach $page (keys %edit_list){
5177                         if (!$edit_list{$page}{Name}){
5178                                 $kiriwrite_presmodule->additalictext("No Name");
5179                                 $kiriwrite_presmodule->addtext(" (" . $edit_list{$page}{Filename} . ")");
5180                         } else {
5181                                 $kiriwrite_presmodule->addtext($edit_list{$page}{Name} . " (" . $edit_list{$page}{Filename} . ")");
5182                         }
5184                         $kiriwrite_presmodule->addlinebreak();
5185                 }
5187                 $kiriwrite_presmodule->endbox();
5188                 $kiriwrite_presmodule->addlinebreak();
5189                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{multieditmessagevalues});
5190                 $kiriwrite_presmodule->addlinebreak();
5191                 $kiriwrite_presmodule->addlinebreak();
5192                 $kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
5194                 $kiriwrite_presmodule->startheader();
5195                 $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{alter}, { Style => "tablecellheader" });
5196                 $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{setting}, { Style => "tablecellheader" });
5197                 $kiriwrite_presmodule->addheader($kiriwrite_lang->{common}->{value}, { Style => "tablecellheader" });
5198                 $kiriwrite_presmodule->endheader();
5200                 $kiriwrite_presmodule->startrow();
5201                 $kiriwrite_presmodule->addcell("tablecell1");
5202                 $kiriwrite_presmodule->addcheckbox("altersection");
5203                 $kiriwrite_presmodule->endcell();
5204                 $kiriwrite_presmodule->addcell("tablecell1");
5205                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagesection});
5206                 $kiriwrite_presmodule->endcell();
5207                 $kiriwrite_presmodule->addcell("tablecell1");
5208                 $kiriwrite_presmodule->addinputbox("newsection", { Size => 64, MaxLength => 256 });
5209                 $kiriwrite_presmodule->endcell();
5210                 $kiriwrite_presmodule->endrow();
5212                 $kiriwrite_presmodule->startrow();
5213                 $kiriwrite_presmodule->addcell("tablecell2");
5214                 $kiriwrite_presmodule->addcheckbox("altertemplate");
5215                 $kiriwrite_presmodule->endcell();
5216                 $kiriwrite_presmodule->addcell("tablecell2");
5217                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagetemplate});
5218                 $kiriwrite_presmodule->endcell();
5220                 $kiriwrite_presmodule->addcell("tablecell2");
5222                 if ($template_warning){
5224                         $kiriwrite_presmodule->addhiddendata("newtemplate", "!skip");
5225                         $kiriwrite_presmodule->addtext($template_warning);
5227                 } else {
5229                         $kiriwrite_presmodule->addselectbox("newtemplate");
5231                         foreach $template (keys %template_list){
5233                                 $kiriwrite_presmodule->addoption($template_list{$template}{Name} . " (" . $template_list{$template}{Filename} . ")", { Value => $template_list{$template}{Filename}});
5235                         }
5237                         $kiriwrite_presmodule->addoption($kiriwrite_lang->{pages}->{usenotemplate}, { Value => "!none", Selected => 1 });
5238                         $kiriwrite_presmodule->endselectbox();
5239                 }
5241                 $kiriwrite_presmodule->endcell();
5242                 $kiriwrite_presmodule->endrow();
5244                 $kiriwrite_presmodule->startrow();
5245                 $kiriwrite_presmodule->addcell("tablecell1");
5246                 $kiriwrite_presmodule->addcheckbox("altersettings");
5247                 $kiriwrite_presmodule->endcell();
5248                 $kiriwrite_presmodule->addcell("tablecell1");
5249                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{pages}->{pagesettings});
5250                 $kiriwrite_presmodule->endcell();
5251                 $kiriwrite_presmodule->addcell("tablecell1");
5252                 $kiriwrite_presmodule->addradiobox("newsettings", { Description => $kiriwrite_lang->{pages}->{usepageandsection}, Value => 1 , Selected => 1});
5253                 $kiriwrite_presmodule->addlinebreak();
5254                 $kiriwrite_presmodule->addradiobox("newsettings", { Description => $kiriwrite_lang->{pages}->{usepagename}, Value => 2 });
5255                 $kiriwrite_presmodule->addlinebreak();
5256                 $kiriwrite_presmodule->addradiobox("newsettings", { Description => $kiriwrite_lang->{pages}->{usesectionname}, Value => 3 });
5257                 $kiriwrite_presmodule->addlinebreak();
5258                 $kiriwrite_presmodule->addradiobox("newsettings", { Description => $kiriwrite_lang->{pages}->{nopagesection}, Value => 0 });
5259                 $kiriwrite_presmodule->endcell();
5260                 $kiriwrite_presmodule->endrow();
5262                 $kiriwrite_presmodule->endtable();
5263                 $kiriwrite_presmodule->addlinebreak();
5264                 $kiriwrite_presmodule->addsubmit($kiriwrite_lang->{pages}->{editpagesbutton});
5265                 $kiriwrite_presmodule->addtext(" | ");
5266                 $kiriwrite_presmodule->addreset($kiriwrite_lang->{common}->{clearvalues});
5267                 $kiriwrite_presmodule->addtext(" | ");
5268                 $kiriwrite_presmodule->addlink($kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database, { Text => kiriwrite_language($kiriwrite_lang->{pages}->{returnpagelist}, $database_name) });
5269                 $kiriwrite_presmodule->endbox();
5270                 $kiriwrite_presmodule->endform();
5272                 return $kiriwrite_presmodule->grab();
5274         } else {
5276                 # The confirm value is something else other than
5277                 # 1 or 0, so return an error.
5279                 kiriwrite_error("invalidvariable");
5281         }
5285 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