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