1 #################################################################################
2 # page.lib: Kiriwrite Page Library #
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
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;
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'};
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.
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"){
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;
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.
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'};
125 my $selectionlist = "";
127 if ($http_query_confirm){
129 # The action has been confirmed, so try to delete the selected page
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.
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
152 my $http_query_database = $form_data->{'database'};
153 my $http_query_confirm = $form_data->{'confirm'};
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.
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
187 my $http_query_database = $form_data->{'database'};
188 my $http_query_newdatabase = $form_data->{'newdatabase'};
189 my $http_query_confirm = $form_data->{'confirm'};
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.
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
223 my $http_query_database = $form_data->{'database'};
224 my $http_query_newdatabase = $form_data->{'newdatabase'};
225 my $http_query_confirm = $form_data->{'confirm'};
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.
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
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'};
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.
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.
293 kiriwrite_error("invalidaction");
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. #
319 # kiriwrite_page_list([database], [browsernumber]); #
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.
338 my @databasefilenames;
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
360 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
381 kiriwrite_error("datadirectoryinvalidpermissions");
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
400 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
402 # The database has invalid permissions set, so process
409 # Get the database information.
411 %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
413 # Check if any errors had occured while getting the database
416 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
418 # A database error has occured, so process the next
425 # Set the database name.
427 $database_name = $database_info{"DatabaseName"};
429 # Check if the database name is undefined and if it is
432 if (!$database_name){
436 # Append the database to the list of databases available.
438 push(@databasefilenames, $data_file);
439 push(@databasenames, $database_name);
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];
463 $kiriwrite_presmodule->addoption($dbname . " (" . $dbfilename . ")", { Value => $dbfilename });
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();
478 my $pagemultioptions = "";
482 my $page_filename = "";
484 my $page_description = "";
485 my $page_modified = "";
487 my $tablestyletype = 0;
489 my $db_file_notblank = 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;
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
523 kiriwrite_error("browsenumbertoolong");
527 if ($kiriwrite_browsenumber_number_check eq 1){
529 # The browse number wasn't a number so
532 kiriwrite_error("browsenumberinvalid");
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
547 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
568 kiriwrite_error("databaseinvalidpermissions");
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
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));
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));
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);
616 $page_list = substr(($page_total_count / $page_split), 0, 1) + 1;
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));
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.
661 while ($page_list_count ne $page_list){
665 if ($page_list_count eq 1 && !$page_browsenumber){
667 $kiriwrite_presmodule->addoption($page_list_count, { Value => $page_list_count, Selected => 1 });
671 if ($page_browsenumber eq $page_list_count){
673 $kiriwrite_presmodule->addoption($page_list_count, { Value => $page_list_count, Selected => 1 });
677 $kiriwrite_presmodule->addoption($page_list_count, { Value => $page_list_count });
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} });
696 # Check if the page browse number is not blank and
697 # not set as 0 and hide the Previous page link if
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} });
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.
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";
776 $tablestyle = "tablecell2";
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);
795 $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{noname});
799 $kiriwrite_presmodule->addtext($page_name);
803 $kiriwrite_presmodule->endcell();
804 $kiriwrite_presmodule->addcell($tablestyle);
806 if (!$page_description){
808 $kiriwrite_presmodule->additalictext($kiriwrite_lang->{blank}->{nodescription});
812 $kiriwrite_presmodule->addtext($page_description);
816 $kiriwrite_presmodule->endcell();
817 $kiriwrite_presmodule->addcell($tablestyle);
819 if (!$page_modified){
821 $kiriwrite_presmodule->additalictext("No Date");
825 $kiriwrite_presmodule->addtext($page_modified);
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.
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
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
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();
887 return $kiriwrite_presmodule->grab();
893 sub kiriwrite_page_add{
894 #################################################################################
895 # kiriwrite_page_add: Adds a page to a database #
899 # kiriwrite_page_add(database, pagefilename, title, description, section, #
900 # template, settings, info, confirm); #
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).
925 kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
927 # Check if the database filename is valid and return an error if
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");
946 # Check the length the database name and return an error if it's
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");
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
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");
1005 if ($pagetitle_maxlength_check eq 1){
1007 # The page title given is too long, so return an error.
1009 kiriwrite_error("pagetitletoolong");
1013 if ($pagedescription_maxlength_check eq 1){
1015 # The page description given is too long, so return an error.
1017 kiriwrite_error("pagedescriptiontoolong");
1021 if ($pagesection_maxlength_check eq 1){
1023 # The page section given is too long, so return an error.
1025 kiriwrite_error("pagesectiontoolong");
1029 if ($pagedatabase_maxlength_check eq 1){
1031 # The page database given is too long, so return an error.
1033 kiriwrite_error("pagedatabasefilenametoolong");
1037 if ($pagesettings_maxlength_check eq 1){
1039 # The page settings given is too long, so return an error.
1041 kiriwrite_error("pagesettingstoolong");
1045 if ($pagetemplate_maxlength_check eq 1){
1047 # The page template given is too long, so return an error.
1049 kiriwrite_error("pagetemplatefilenametoolong");
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");
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
1071 $pagetemplate_filename_check = kiriwrite_variablecheck($pagetemplate, "page_filename", 0, 1);
1075 if ($pagefilename_filename_check ne 0){
1077 # The page filename given is invalid, so return an error.
1079 kiriwrite_error("pagefilenameinvalid");
1083 if ($pagesettings_setting_check eq 1){
1085 # The page settings given is invalid, so return an error.
1087 kiriwrite_error("pagesettingsinvalid");
1091 if ($pagetemplate_filename_check eq 1){
1093 # The template filename given is invalid, so return an error
1095 kiriwrite_error("templatefilenameinvalid");
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");
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
1122 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
1143 kiriwrite_error("databaseinvalidpermissions");
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));
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
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));
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.
1209 my $template_filename;
1211 my $template_data = "";
1212 my $template_warningmessage;
1213 my $template_warning = 0;
1214 my $template_count = 0;
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
1230 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
1251 kiriwrite_error("databaseinvalidpermissions");
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");
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));
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
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;
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;
1325 if ($template_warning eq 0){
1327 # Check to see if there are any templates in the templates
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.
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;
1367 # Check if the final template list is blank.
1369 if (!%template_list){
1371 # The template list is blank so write the template
1374 $template_warningmessage = $kiriwrite_lang->{pages}->{notemplatesavailable};
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
1460 if ($template_warning eq 1){
1462 $kiriwrite_presmodule->addhiddendata("pagetemplate", "!none");
1463 $kiriwrite_presmodule->addtext($template_warningmessage);
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 });
1480 $template_count = 0;
1483 $kiriwrite_presmodule->addoption($kiriwrite_lang->{pages}->{usenotemplate}, { Value => "!none", Selected => 1 });
1484 $kiriwrite_presmodule->endselectbox();
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();
1556 # The confirm value is something else than '1' or '0' so
1559 kiriwrite_error("invalidvalue");
1567 sub kiriwrite_page_delete{
1568 #################################################################################
1569 # kiriwrite_page_delete: Deletes a (single) page from a database. #
1573 # kiriwrite_page_delete(database, page, [confirm]); #
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
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");
1601 # Check the length the database name and return an error if it's
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");
1614 # Check if the page name is specified is blank and return an error if
1619 # The page name is blank, so return an error.
1621 kiriwrite_error("blankfilename");
1625 # If the confirm value is blank, then set the confirm value to 0.
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
1649 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
1670 kiriwrite_error("databaseinvalidpermissions");
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");
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));
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");
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");
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
1778 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
1799 kiriwrite_error("databaseinvalidpermissions");
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));
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");
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
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();
1871 # Another page deletion type was specified, so return an error.
1873 kiriwrite_error("invalidoption");
1879 sub kiriwrite_page_edit{
1880 #################################################################################
1881 # kiriwrite_page_edit: Edits a page from a database. #
1885 # kiriwrite_page_edit(database, filename, newfilename, newname, newdescription, #
1886 # newsection, newtemplate, newsettings, newpagecontent #
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'.
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
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");
1937 # Check the length the database name and return an error if it's
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");
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");
1959 # Check if the confirm value is '1' and if it is, edit the specified
1960 # page in the database.
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");
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");
2019 if ($pagenewtitle_maxlength_check eq 1){
2021 # The new page title given is too long, so return an error.
2023 kiriwrite_error("pagetitletoolong");
2027 if ($pagenewdescription_maxlength_check eq 1){
2029 # The new page description given is too long, so return an error.
2031 kiriwrite_error("pagedescriptiontoolong");
2035 if ($pagenewsection_maxlength_check eq 1){
2037 # The new page section given is too long, so return an error.
2039 kiriwrite_error("pagesectiontoolong");
2043 if ($pagenewsettings_maxlength_check eq 1){
2045 # The new page settings given is too long, so return an error.
2047 kiriwrite_error("pagesettingstoolong");
2051 if ($pagenewtemplate_maxlength_check eq 1){
2053 # The new page template given is too long, so return an error.
2055 kiriwrite_error("pagetemplatefilenametoolong");
2059 # Check if the new page filename and new page settings
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
2071 $pagetemplate_filename_check = kiriwrite_variablecheck($pagenewtemplate, "page_filename", 0, 1);
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");
2086 if ($pagenewsettings_settings_check eq 1){
2088 # The new page settings is invalid, so return an error.
2090 kiriwrite_error("pagesettingsinvalid");
2094 if ($pagetemplate_filename_check eq 1){
2096 # The template filename given is invalid, so return an error
2098 kiriwrite_error("templatefilenameinvalid");
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
2113 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
2134 kiriwrite_error("databaseinvalidpermissions");
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");
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));
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");
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
2221 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
2242 kiriwrite_error("databaseinvalidpermissions");
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));
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");
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;
2301 my @database_templates;
2302 my @template_filenames;
2304 my $template_filename;
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
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};
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));
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));
2369 } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
2371 # The template does not exist so process the next template.
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;
2392 $template_list{$template_count}{Selected} = 0;
2404 # Check if certain values are undefined and if they
2405 # are then set them blank (defined).
2411 if (!$data_description){
2412 $data_description = "";
2415 if (!$data_section){
2419 if (!$data_template){
2420 $data_template = "";
2424 if (!$data_content){
2428 if (!$data_settings){
2429 $data_settings = "";
2432 if (!$data_lastmodified){
2433 $data_lastmodified = "";
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();
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
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 });
2526 $kiriwrite_presmodule->addoption($template_list{$template_count}{Name} . " (" . $template_list{$template_count}{Filename} . ")", { Value => $template_list{$template_count}{Filename} });
2534 if ($data_template eq "!none"){
2536 $kiriwrite_presmodule->addoption($kiriwrite_lang->{pages}->{usenotemplate}, { Value => "!none", Selected => 1 });
2537 $template_found = 1;
2541 $kiriwrite_presmodule->addoption($kiriwrite_lang->{pages}->{usenotemplate}, { Value => "!none" });
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" });
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});
2615 $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepageandsection}, Value => "1", LineBreak => 1});
2618 if ($data_settings eq 2){
2619 $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepagename}, Value => "2", Selected => 1, LineBreak => 1});
2621 $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usepagename}, Value => "2", LineBreak => 1});
2624 if ($data_settings eq 3){
2625 $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usesectionname}, Value => "3", Selected => 1, LineBreak => 1});
2627 $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{usesectionname}, Value => "3", LineBreak => 1});
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});
2633 $kiriwrite_presmodule->addradiobox("pagesettings", { Description => $kiriwrite_lang->{pages}->{nopagesection}, Value => "0", LineBreak => 1});
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();
2655 # The confirm value is a value other than '0' and '1' so
2658 kiriwrite_error("invalidvalue");
2664 sub kiriwrite_page_multidelete{
2665 #################################################################################
2666 # kiriwrite_page_multidelete: Delete mulitple pages from the database. #
2670 # kiriwrite_page_multidelete(database, confirm, filelist); #
2672 # database Specifies the database to delete multiple pages from. #
2673 # confirm Confirms the action to delete the selected pages from the #
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
2687 # The database name is blank so return an error.
2689 kiriwrite_error("databasenameblank");
2693 # Check if the file list array has any values and return
2694 # an error if it doesn't.
2698 # The page list really is blank so return
2701 kiriwrite_error("nopagesselected");
2704 # Check if the database filename is valid and return an error if
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");
2723 # Check the length the database name and return an error if it's
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");
2736 # Check if the confirm value is blank and if it is, then
2741 # The confirm value is blank so set the confirm value
2750 # The action to delete multiple pages from the database has
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
2764 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
2785 kiriwrite_error("databaseinvalidpermissions");
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");
2801 # Get information about the database.
2803 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
2805 # Check if any errors had occured while getting the database
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));
2817 my $database_name = $database_info{"DatabaseName"};
2819 # Define some variables for later.
2823 my $filelist_filename;
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.
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"};
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.
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} . ")");
2907 $kiriwrite_presmodule->addtext($deleted_list{$page}{Name} . " (" . $deleted_list{$page}{Filename} . ")");
2910 $kiriwrite_presmodule->addlinebreak();
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
2936 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
2957 kiriwrite_error("databaseinvalidpermissions");
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");
2973 # Get information about the database.
2975 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
2977 # Check if any errors had occured while getting the database
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));
2989 my $database_name = $database_info{"DatabaseName"};
2991 # Define some variables for later.
2997 my $filelist_filename;
2998 my $filelist_filename_sql;
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.
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
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");
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);
3069 foreach $page (keys %delete_list){
3071 $kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on");
3072 $kiriwrite_presmodule->addhiddendata("id[" . $pageseek . "]", $delete_list{$page}{Filename});
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} . ")");
3090 $kiriwrite_presmodule->addtext($delete_list{$page}{Name} . " (" . $delete_list{$page}{Filename} . ")");
3092 $kiriwrite_presmodule->addlinebreak();
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();
3108 # A confirm value other than 0 or 1 is given, so
3111 kiriwrite_error("invaildvalue");
3117 sub kiriwrite_page_multimove{
3118 #################################################################################
3119 # kiriwrite_page_multimove: Move several pages from one database to another #
3124 # kiriwrite_page_multimove(database, newdatabase, confirm, filelist); #
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 #
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");
3156 # Check if the file list is blank and return an error
3161 # The file list really is blank so return
3164 kiriwrite_error("nopagesselected");
3168 # Check if the confirm value is blank and if it is then
3169 # set the confirm value to 0.
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");
3196 # Check if the new database filename is valid and return an error if
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");
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
3226 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
3247 kiriwrite_error("oldmovedatabasefileinvalidpermissions");
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");
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
3280 kiriwrite_error("newmovedatabasefileinvalidpermissions");
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");
3296 # Define some values for later.
3304 my $olddatabase_name;
3305 my $newdatabase_name;
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
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));
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
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));
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));
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);
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));
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));
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);
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
3424 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasemovetopageexists}, $filename);
3430 $moved_list{$move_count}{Filename} = $page_info{"PageFilename"};
3431 $moved_list{$move_count}{Name} = $page_info{"PageName"};
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();
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} . ")");
3460 $kiriwrite_presmodule->addtext($moved_list{$page}{Name} . " (" . $moved_list{$page}{Filename} . ")");
3463 $kiriwrite_presmodule->addlinebreak();
3465 $kiriwrite_presmodule->endbox();
3469 $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{nopagesmoved}, $olddatabase_name, $newdatabase_name));
3470 $kiriwrite_presmodule->addlinebreak();
3471 $kiriwrite_presmodule->addlinebreak();
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();
3485 $kiriwrite_presmodule->endbox();
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
3512 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
3533 kiriwrite_error("databaseinvalidpermissions");
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");
3549 # Get information about the database.
3551 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
3553 # Check if any errors had occured while getting the database
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));
3565 my $database_name = $database_info{"DatabaseName"};
3567 # Define some values for later.
3576 my $filelist_filename;
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.
3609 # Add the page name and file name to the list of
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
3622 # Check if any pages exust and return an error if
3625 if ($pageseek eq 0){
3627 # None of the selected pages exist, so return
3630 kiriwrite_error("nopagesselected");
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
3651 kiriwrite_error("datadirectoryinvalidpermissions");
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
3670 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
3672 # The database has invalid permissions set, so process
3673 # the next database.
3679 # Get the database information.
3681 %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
3683 # Check if any errors had occured while getting the database
3686 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
3688 # A database error has occured so process the next
3695 # Check if the database name is undefined and if it is
3696 # then set it blank.
3698 if (!$database_name){
3699 $database_name = "";
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"};
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.
3730 foreach $page (keys %move_list){
3731 $kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on");
3732 $kiriwrite_presmodule->addhiddendata("id[" . $pageseek . "]", $move_list{$page}{Filename});
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} . ")");
3747 $kiriwrite_presmodule->addtext($move_list{$page}{Name} . " (" . $move_list{$page}{Filename} . ")");
3749 $kiriwrite_presmodule->addlinebreak();
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}});
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();
3775 # The confirm value is other than 0 or 1, so return
3778 kiriwrite_error("invalidvariable");
3786 sub kiriwrite_page_multicopy{
3787 #################################################################################
3788 # kiriwrite_page_multicopy: Copy several pages from one database to another #
3793 # kiriwrite_page_multicopy(database, newdatabase, confirm, filelist); #
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
3810 # The file list really is blank so return
3813 kiriwrite_error("nopagesselected");
3817 # Check if the confirm value is blank and if it is then
3818 # set the confirm value to 0.
3826 # Check if the database filename is valid and return an error if
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");
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");
3864 # Check if the new database filename is valid and return an error if
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");
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
3894 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
3915 kiriwrite_error("oldcopydatabasefileinvalidpermissions");
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
3936 kiriwrite_error("newcopydatabasefileinvalidpermissions");
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");
3952 # Define some values for later.
3958 my @olddatabase_info;
3959 my @olddatabase_page;
3960 my @newdatabase_info;
3961 my @newdatabase_page;
3965 my $olddatabase_name;
3966 my $newdatabase_name;
3972 my $page_description;
3977 my $page_lastmodified;
3980 my $warning_count = 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
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));
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
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));
4021 $newdatabase_name = $newdatabase_info{"DatabaseName"};
4023 # Check if the database filename is valid and return an error if
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");
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));
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);
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));
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));
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);
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
4107 $warning_list{$warning_count}{Message} = kiriwrite_language($kiriwrite_lang->{pages}->{databasecopytopageexists}, $filename);
4113 # Append the copied page (filename and name) to the list of
4116 $copied_list{$page_seek}{Filename} = $filename;
4117 $copied_list{$page_seek}{Name} = $page_info{"PageName"};
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();
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} . ")");
4144 $kiriwrite_presmodule->addtext($copied_list{$page}{Name} . " (" . $copied_list{$page}{Filename} . ")");
4146 $kiriwrite_presmodule->addlinebreak();
4148 $kiriwrite_presmodule->endbox();
4152 $kiriwrite_presmodule->addtext(kiriwrite_language($kiriwrite_lang->{pages}->{nopagescopied}, $olddatabase_name, $newdatabase_name));
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();
4168 $kiriwrite_presmodule->endbox();
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
4195 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
4216 kiriwrite_error("databaseinvalidpermissions");
4220 # Get information about the database.
4222 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
4224 # Check if any errors had occured while getting the database
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));
4236 my $database_name = $database_info{"DatabaseName"};
4238 # Define some values for later.
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.
4280 # Add the page name and file name to the list of
4283 $copy_list{$pageseek}{Filename} = $page_info{"PageFilename"};
4284 $copy_list{$pageseek}{Name} = $page_info{"PageName"};
4286 # Increment the page seek counter.
4292 # Check if any pages exust and return an error if
4295 if ($pageseek eq 0){
4297 # None of the selected pages exist, so return
4300 kiriwrite_error("nopagesselected");
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
4321 kiriwrite_error("datadirectoryinvalidpermissions");
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
4340 } elsif ($kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
4342 # The database has invalid permissions set, so process
4343 # the next database.
4349 # Get the database information.
4351 %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
4353 # Check if any errors had occured while getting the database
4356 if ($kiriwrite_dbmodule->geterror eq "DatabaseError"){
4358 # A database error has occured so process the next
4365 # Check if the database name is undefined and if it is
4366 # then set it blank.
4368 if (!$database_name){
4369 $database_name = "";
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"};
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);
4399 foreach $page (keys %copy_list){
4400 $kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on");
4401 $kiriwrite_presmodule->addhiddendata("id[" . $pageseek . "]", $copy_list{$page}{Filename});
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} . ")");
4418 $kiriwrite_presmodule->addtext($copy_list{$page}{Name} . " (" . $copy_list{$page}{Filename} . ")");
4420 $kiriwrite_presmodule->addlinebreak();
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}});
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();
4449 # The confirm value is other than 0 or 1, so return
4452 kiriwrite_error("invalidvariable");
4458 sub kiriwrite_page_multiedit{
4459 #################################################################################
4460 # kiriwrite_page_multiedit: Edit several pages from a database. #
4464 # kiriwrite_page_multiedit(database, newsection, altersection, newtemplate, #
4465 # altertemplate, newsettings, altersettings #
4466 # confirm, filelist); #
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 #
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
4489 # The file list really is blank so return
4492 kiriwrite_error("nopagesselected");
4496 # Check if certain values are undefined and define them if
4499 if (!$altersection){
4501 # The alter section value is blank, so set it to
4504 $altersection = "off";
4508 if (!$altertemplate){
4510 # The alter template value is blank, so set it to
4513 $altertemplate = "off";
4517 if (!$altersettings){
4519 # The alter settings value is blank, so set it to
4522 $altersettings = "off";
4526 # Check if the database filename is valid and return an error if
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");
4545 # Check if the confirm value is blank and if it is then
4546 # set the confirm value to 0.
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
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
4590 kiriwrite_error("pagesectiontoolong");
4594 if ($newtemplate_maxlength_check eq 1 && $altertemplate eq "on"){
4596 # The new template name is too long, so return an
4599 kiriwrite_error("templatefilenametoolong");
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
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
4617 kiriwrite_error("templatefilenameinvalid");
4622 if ($newsettings_maxlength_check eq 1 && $altertemplate eq "on"){
4624 # The new settings value is too long, so return
4627 kiriwrite_error("pagesettingstoolong");
4631 if ($newsettings_settings_check eq 1 && $altersettings eq "on"){
4633 # The new settings value is invalid, so return
4636 kiriwrite_error("pagesettingsinvalid");
4640 # Define some values for later.
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
4661 if ($newtemplate eq "!skip"){
4663 $altertemplate = "off";
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
4675 kiriwrite_error("noeditvaluesselected");
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
4690 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
4711 kiriwrite_error("databaseinvalidpermissions");
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");
4727 # Get information about the database.
4729 %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
4731 # Check if any errors had occured while getting the database
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));
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);
4771 # Check if the page section should be altered.
4773 if ($altersection eq "on"){
4775 # Change the section name.
4777 $page_info{"PageSection"} = $newsection;
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;
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;
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));
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);
4824 } elsif ($kiriwrite_dbmodule->geterror eq "PageExists"){
4826 # A page already exists with the new filename.
4828 kiriwrite_error("pagefilenameexists");
4832 # The page has been edited so write a message saying that the page
4835 $edited_list{$pageedited}{Filename} = $page_info{"PageFilename"};
4836 $edited_list{$pageedited}{Name} = $page_info{"PageName"};
4838 # Increment the counter of edited pages.
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));
4862 # Write out the message saying that the selected pages
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} . ")");
4881 $kiriwrite_presmodule->addtext($edited_list{$page}{Name});
4882 $kiriwrite_presmodule->addtext(" (" . $edited_list{$page}{Filename} . ")");
4886 $kiriwrite_presmodule->addlinebreak();
4889 $kiriwrite_presmodule->endbox();
4893 # Check if any warnings have occured and write a message
4894 # if any warnings did occur.
4898 # One or several warnings have occured so
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();
4911 $kiriwrite_presmodule->endbox();
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
4939 kiriwrite_error("databaseconnectionerror", $kiriwrite_dbmodule->geterror(1));
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
4960 kiriwrite_error("databaseinvalidpermissions");
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");
4976 # Get information about the database.
4978 my %database_info = $kiriwrite_dbmodule->getdatabaseinfo();
4980 # Check if any errors had occured while getting the database
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));
4992 my $database_name = $database_info{"DatabaseName"};
4994 # Define some variables for later.
5002 my $filelist_filename;
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
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.
5040 # Add the page name and file name to the list of
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
5053 # Check if any pages were found in the database and return
5056 if ($pageseek eq 0){
5058 # No pages were found so return an error.
5060 kiriwrite_error("nopagesselected");
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
5075 $template_warning = $kiriwrite_lang->{pages}->{templatedatabasenotexistmultieditkeep};
5077 } elsif ($kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
5079 # The template database has invalid permissions set so
5082 $template_warning = $kiriwrite_lang->{pages}->{templatedatabasepermissionsinvalidmultieditkeep};
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));
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.
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"};
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);
5165 foreach $page (keys %edit_list){
5166 $kiriwrite_presmodule->addhiddendata("name[" . $pageseek . "]", "on");
5167 $kiriwrite_presmodule->addhiddendata("id[" . $pageseek . "]", $edit_list{$page}{Filename});
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} . ")");
5181 $kiriwrite_presmodule->addtext($edit_list{$page}{Name} . " (" . $edit_list{$page}{Filename} . ")");
5184 $kiriwrite_presmodule->addlinebreak();
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);
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}});
5237 $kiriwrite_presmodule->addoption($kiriwrite_lang->{pages}->{usenotemplate}, { Value => "!none", Selected => 1 });
5238 $kiriwrite_presmodule->endselectbox();
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();
5276 # The confirm value is something else other than
5277 # 1 or 0, so return an error.
5279 kiriwrite_error("invalidvariable");