3 #################################################################################
4 # Kiriwrite (kiriwrite.pl/kiriwrite.cgi) #
5 # Main program script #
8 # mod_perl 2.x compatabile version #
10 # Copyright (C) 2005-2008 Steve Brokenshire <sbrokenshire@xestia.co.uk> #
12 # This program is free software; you can redistribute it and/or modify it under #
13 # the terms of the GNU General Public License as published by the Free #
14 # Software Foundation; as version 2 of the License. #
16 # This program is distributed in the hope that it will be useful, but WITHOUT #
17 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
18 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.#
20 # You should have received a copy of the GNU General Public License along with #
21 # this program; if not, write to the Free Software Foundation, Inc., 51 #
22 # Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #
23 #################################################################################
32 binmode STDOUT, ':utf8';
34 # This is commented out because it uses a fair bit of CPU usage.
36 #use CGI::Carp('fatalsToBrowser'); # Output errors to the browser.
38 # Declare global variables for Kiriwrite settings and languages.
40 our ($kiriwrite_config, %kiriwrite_config, %kiriwrite_lang, $kiriwrite_lang, $kiriwrite_version, %kiriwrite_version, $kiriwrite_env, %kiriwrite_env, $kiriwrite_presmodule, $kiriwrite_dbmodule, $kiriwrite_script_name, $kiriwrite_env_path);
41 our ($form_data, %form_data);
43 # If you are using mod_perl please change these settings to the correct
44 # directory where this script is being run from.
49 # Load the common functions module.
51 use Modules::System::Common;
53 # Setup the version information for Kiriwrite.
55 %kiriwrite_version = (
61 kiriwrite_initalise; # Initalise the Kiriwrite enviroment.
62 kiriwrite_settings_load; # Load the configuration options.
64 my $query_lite = new CGI::Lite;
66 # Check if a mode has been specified and if a mode has been specified, continue
67 # and work out what mode has been specified.
69 $form_data = $query_lite->parse_form_data();
71 if ($form_data->{'mode'}){
72 my $http_query_mode = $form_data->{'mode'};
74 if ($http_query_mode eq "db"){
76 use Modules::System::Database;
78 if ($form_data->{'action'}){
79 # An action has been specified, so find out what action has been specified.
81 my $http_query_action = $form_data->{'action'};
83 if ($http_query_action eq "edit"){
84 # The edit action (which mean edit the settings for the selected database) has been specified,
85 # get the database name and check if the action to edit an database has been confirmed.
87 if ($form_data->{'database'}){
88 # If there is a value in the database variable check if it is a valid database. Otherwise,
91 my $http_query_database = $form_data->{'database'};
93 # Check if a value for confirm has been specified, if there is, check if it is the correct
94 # value, otherwise return an error.
96 if ($form_data->{'confirm'}){
97 # A value for confirm has been specified, find out what value it is. If the value is correct
98 # then edit the database settings, otherwise return an error.
100 my $http_query_confirm = $form_data->{'confirm'};
102 if ($http_query_confirm eq 1){
103 # Value is correct, collect the variables to pass onto the database variable.
105 # Get the variables from the HTTP query.
107 my $newdatabasename = $form_data->{'databasename'};
108 my $newdatabasedescription = $form_data->{'databasedescription'};
109 my $newdatabasefilename = $form_data->{'databasefilename'};
110 my $databaseshortname = $form_data->{'database'};
111 my $databasenotes = $form_data->{'databasenotes'};
112 my $databasecategories = $form_data->{'databasecategories'};
114 # Pass the variables to the database editing subroutine.
116 my $pagedata = kiriwrite_database_edit($databaseshortname, $newdatabasefilename, $newdatabasename, $newdatabasedescription, $databasenotes, $databasecategories, 1);
118 kiriwrite_output_header;
119 kiriwrite_output_page($kiriwrite_lang{database}{editdatabasetitle}, $pagedata, "database");
123 # Value is incorrect, return and error.
124 kiriwrite_error("invalidvariable");
129 # Display the form for editing an database.
130 my $pagedata = kiriwrite_database_edit($http_query_database);
132 kiriwrite_output_header;
133 kiriwrite_output_page($kiriwrite_lang{database}{editdatabasetitle}, $pagedata, "database");
138 # If there is no value in the database variable, then return an error.
139 kiriwrite_error("invalidvariable");
143 } elsif ($http_query_action eq "delete"){
145 # Action equested is to delete a database, find out if the user has already confirmed deletion of the database
146 # and if the deletion of the database has been confirmed, delete the database.
148 if ($form_data->{'confirm'}){
150 # User has confirmed to delete a database, pass the parameters to the kiriwrite_database_delete
153 my $database_filename = $form_data->{'database'};
154 my $database_confirm = $form_data->{'confirm'};
155 my $pagedata = kiriwrite_database_delete($database_filename, $database_confirm);
157 kiriwrite_output_header;
158 kiriwrite_output_page($kiriwrite_lang->{database}->{deleteddatabase}, $pagedata, "database");
164 # User has clicked on the delete link (thus hasn't confirmed the action to delete a database).
166 my $database_filename = $form_data->{'database'};
167 my $pagedata = kiriwrite_database_delete($database_filename);
169 kiriwrite_output_header;
170 kiriwrite_output_page($kiriwrite_lang->{database}->{deletedatabase}, $pagedata, "database");
174 } elsif ($http_query_action eq "new"){
176 # Action requested is to create a new database, find out if the user has already entered the information needed
177 # to create a database and see if the user has confirmed the action, otherwise printout a form for adding a
180 my $http_query_confirm = $form_data->{'confirm'};
182 # Check if the confirm value is correct.
184 if ($http_query_confirm){
185 if ($http_query_confirm eq 1){
187 # User has confirmed to create a database, pass the parameters to the
188 # kiriwrite_database_add subroutine.
190 my $http_query_confirm = $form_data->{'confirm'};
192 my $database_name = $form_data->{'databasename'};
193 my $database_description = $form_data->{'databasedescription'};
194 my $database_filename = $form_data->{'databasefilename'};
195 my $database_notes = $form_data->{'databasenotes'};
196 my $database_categories = $form_data->{'databasecategories'};
198 my $pagedata = kiriwrite_database_add($database_filename, $database_name, $database_description, $database_notes, $database_categories, $http_query_confirm);
200 kiriwrite_output_header;
201 kiriwrite_output_page($kiriwrite_lang{database}{adddatabase}, $pagedata, "database");
206 # The confirm value is something else other than 1 (which it shouldn't be), so
212 # User has clicked on the 'Add Database' link.
214 my $pagedata = kiriwrite_database_add();
216 kiriwrite_output_header;
217 kiriwrite_output_page($main::kiriwrite_lang{database}{adddatabase}, $pagedata, "database");
221 # Another option has been specified, so return an error.
223 kiriwrite_error("invalidaction");
228 # No action has been specified, do the default action of displaying a list
231 my $pagedata = kiriwrite_database_list();
233 kiriwrite_output_header; # Output the header to browser/console/stdout.
234 kiriwrite_output_page("", $pagedata, "database"); # Output the page to browser/console/stdout.
235 exit; # End the script.
239 } elsif ($http_query_mode eq "page"){
241 use Modules::System::Page;
243 if ($form_data->{'action'}){
244 my $http_query_action = $form_data->{'action'};
246 # Check if the action requested matches with one of the options below. If it does,
247 # go to that section, otherwise return an error.
249 if ($http_query_action eq "view"){
251 # The action selected was to view pages from a database,
253 my $http_query_database = $form_data->{'database'};
254 my $http_query_browsenumber = $form_data->{'browsenumber'};
255 my $pagedata = kiriwrite_page_list($http_query_database, $http_query_browsenumber);
257 kiriwrite_output_header; # Output the header to browser/console/stdout.
258 kiriwrite_output_page($kiriwrite_lang->{pages}->{viewingdatabase}, $pagedata, "pages", $http_query_database); # Output the page to browser/console/stdout.
259 exit; # End the script.
261 } elsif ($http_query_action eq "add"){
263 # The action selected was to add a page to the selected database.
265 my $http_query_confirm = $form_data->{'confirm'};
267 if (!$http_query_confirm){
269 $http_query_confirm = 0;
273 if ($http_query_confirm eq 1){
275 my $http_query_database = $form_data->{'database'};
276 my $http_query_filename = $form_data->{'pagefilename'};
277 my $http_query_name = $form_data->{'pagename'};
278 my $http_query_description = $form_data->{'pagedescription'};
279 my $http_query_section = $form_data->{'pagesection'};
280 my $http_query_template = $form_data->{'pagetemplate'};
281 my $http_query_settings = $form_data->{'pagesettings'};
282 my $http_query_content = $form_data->{'pagecontent'};
284 my $pagedata = kiriwrite_page_add($http_query_database, $http_query_filename, $http_query_name, $http_query_description, $http_query_section, $http_query_template, $http_query_settings, $http_query_content, $http_query_confirm);
286 kiriwrite_output_header; # Output the header to browser/console/stdout.
287 kiriwrite_output_page($kiriwrite_lang{pages}{addpage}, $pagedata, "pages"); # Output the page to browser/console/stdout.
288 exit; # End the script.
292 my $http_query_database = $form_data->{'database'};
293 my $pagedata = kiriwrite_page_add($http_query_database);
295 kiriwrite_output_header; # Output the header to browser/console/stdout.
296 kiriwrite_output_page($kiriwrite_lang{pages}{addpage}, $pagedata, "pages"); # Output the page to browser/console/stdout.
297 exit; # End the script.
299 } elsif ($http_query_action eq "edit"){
301 # The action selected was to edit a page from a database.
303 my $http_query_confirm = $form_data->{'confirm'};
305 if (!$http_query_confirm){
307 $http_query_confirm = 0;
311 if ($http_query_confirm eq 1){
313 # Get the needed values from the HTTP query.
315 my $http_query_database = $form_data->{'database'};
316 my $http_query_filename = $form_data->{'page'};
317 my $http_query_newfilename = $form_data->{'pagefilename'};
318 my $http_query_name = $form_data->{'pagename'};
319 my $http_query_description = $form_data->{'pagedescription'};
320 my $http_query_section = $form_data->{'pagesection'};
321 my $http_query_template = $form_data->{'pagetemplate'};
322 my $http_query_settings = $form_data->{'pagesettings'};
323 my $http_query_content = $form_data->{'pagecontent'};
325 # Pass the values to the editing pages subroutine.
327 my $pagedata = kiriwrite_page_edit($http_query_database, $http_query_filename, $http_query_newfilename, $http_query_name, $http_query_description, $http_query_section, $http_query_template, $http_query_settings, $http_query_content, $http_query_confirm);
329 kiriwrite_output_header; # Output the header to browser/console/stdout.
330 kiriwrite_output_page($kiriwrite_lang{pages}{editpagetitle}, $pagedata, "pages"); # Output the page to browser/console/stdout.
331 exit; # End the script.
335 # Get the needed values from the HTTP query.
337 my $http_query_database = $form_data->{'database'};
338 my $http_query_filename = $form_data->{'page'};
340 # Pass the values to the editing pages subroutine.
342 my $pagedata = kiriwrite_page_edit($http_query_database, $http_query_filename);
344 kiriwrite_output_header; # Output the header to browser/console/stdout.
345 kiriwrite_output_page($kiriwrite_lang{pages}{editpagetitle}, $pagedata, "pages"); # Output the page to browser/console/stdout.
346 exit; # End the script.
348 } elsif ($http_query_action eq "delete"){
350 # The action selected was to delete a page from a database.
352 my $http_query_database = $form_data->{'database'};
353 my $http_query_page = $form_data->{'page'};
354 my $http_query_confirm = $form_data->{'confirm'};
357 my $selectionlist = "";
359 if ($http_query_confirm){
361 # The action has been confirmed, so try to delete the selected page
364 $pagedata = kiriwrite_page_delete($http_query_database, $http_query_page, $http_query_confirm);
366 kiriwrite_output_header; # Output the header to browser/console/stdout.
367 kiriwrite_output_page($kiriwrite_lang{pages}{deletepagetitle}, $pagedata, "pages"); # Output the page to browser/console/stdout.
368 exit; # End the script.
372 $pagedata = kiriwrite_page_delete($http_query_database, $http_query_page);
374 kiriwrite_output_header; # Output the header to browser/console/stdout.
375 kiriwrite_output_page($kiriwrite_lang{pages}{deletepagetitle}, $pagedata, "pages"); # Output the page to browser/console/stdout.
376 exit; # End the script.
378 } elsif ($http_query_action eq "multidelete"){
380 # The action selected was to delete multiple pages from a
383 my $http_query_database = $form_data->{'database'};
384 my $http_query_confirm = $form_data->{'confirm'};
389 if ($http_query_confirm eq 1){
391 # The action to delete multiple pages from the selected
392 # database has been confirmed.
394 @filelist = kiriwrite_selectedlist($form_data);
395 $pagedata = kiriwrite_page_multidelete($http_query_database, $http_query_confirm, @filelist);
397 kiriwrite_output_header; # Output the header to browser/console/stdout.
398 kiriwrite_output_page($kiriwrite_lang{pages}{deletemultiplepages}, $pagedata, "pages"); # Output the page to browser/console/stdout.
399 exit; # End the script.
403 # Get the list of selected pages and pass them to the
404 # multiple page delete subroutine.
406 @filelist = kiriwrite_selectedlist($form_data);
407 $pagedata = kiriwrite_page_multidelete($http_query_database, $http_query_confirm, @filelist);
409 kiriwrite_output_header; # Output the header to browser/console/stdout.
410 kiriwrite_output_page($kiriwrite_lang{pages}{deletemultiplepages}, $pagedata, "pages"); # Output the page to browser/console/stdout.
411 exit; # End the script.
413 } elsif ($http_query_action eq "multimove"){
415 # The action selected was to move multiple pages from a
418 my $http_query_database = $form_data->{'database'};
419 my $http_query_newdatabase = $form_data->{'newdatabase'};
420 my $http_query_confirm = $form_data->{'confirm'};
425 if ($http_query_confirm){
427 # The action to move multiple pages from the selected
428 # database has been confirmed.
430 @filelist = kiriwrite_selectedlist($form_data);
431 $pagedata = kiriwrite_page_multimove($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
433 kiriwrite_output_header; # Output the header to browser/console/stdout.
434 kiriwrite_output_page($kiriwrite_lang{pages}{movepages}, $pagedata, "pages"); # Output the page to browser/console/stdout.
435 exit; # End the script.
439 # Get the list of selected pages and pass them to the
440 # multiple page move subroutine.
442 @filelist = kiriwrite_selectedlist($form_data);
443 $pagedata = kiriwrite_page_multimove($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
445 kiriwrite_output_header; # Output the header to browser/console/stdout.
446 kiriwrite_output_page($kiriwrite_lang{pages}{movepages}, $pagedata, "pages"); # Output the page to browser/console/stdout.
447 exit; # End the script.
449 } elsif ($http_query_action eq "multicopy"){
451 # The action selected was to copy multiple pages from a
454 my $http_query_database = $form_data->{'database'};
455 my $http_query_newdatabase = $form_data->{'newdatabase'};
456 my $http_query_confirm = $form_data->{'confirm'};
461 if ($http_query_confirm){
463 # The action to copy multiple pages from the selected
464 # database has been confirmed.
466 @filelist = kiriwrite_selectedlist($form_data);
467 $pagedata = kiriwrite_page_multicopy($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
469 kiriwrite_output_header; # Output the header to browser/console/stdout.
470 kiriwrite_output_page($kiriwrite_lang{pages}{copypages}, $pagedata, "pages"); # Output the page to browser/console/stdout.
471 exit; # End the script.
475 # Get the list of selected pages and pass them to the
476 # multiple page copy subroutine.
478 @filelist = kiriwrite_selectedlist($form_data);
479 $pagedata = kiriwrite_page_multicopy($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
481 kiriwrite_output_header; # Output the header to browser/console/stdout.
482 kiriwrite_output_page($kiriwrite_lang{pages}{copypages}, $pagedata, "pages"); # Output the page to browser/console/stdout.
483 exit; # End the script.
485 } elsif ($http_query_action eq "multiedit"){
487 # The action selected was to edit multiple pages from a
490 my $http_query_database = $form_data->{'database'};
491 my $http_query_newsection = $form_data->{'newsection'};
492 my $http_query_altersection = $form_data->{'altersection'};
493 my $http_query_newtemplate = $form_data->{'newtemplate'};
494 my $http_query_altertemplate = $form_data->{'altertemplate'};
495 my $http_query_newsettings = $form_data->{'newsettings'};
496 my $http_query_altersettings = $form_data->{'altersettings'};
497 my $http_query_confirm = $form_data->{'confirm'};
502 if (!$http_query_confirm){
504 @filelist = kiriwrite_selectedlist($form_data);
505 $pagedata = kiriwrite_page_multiedit($http_query_database, $http_query_newsection, $http_query_altersection, $http_query_newtemplate, $http_query_altertemplate, $http_query_newsettings, $http_query_altersettings, $http_query_confirm, @filelist);
507 kiriwrite_output_header; # Output the header to browser/console/stdout.
508 kiriwrite_output_page($kiriwrite_lang{pages}{multiedit}, $pagedata, "pages"); # Output the page to browser/console/stdout.
513 # Get the list of selected pages and pass them to the
514 # multiple page edit subroutine.
516 @filelist = kiriwrite_selectedlist($form_data);
517 $pagedata = kiriwrite_page_multiedit($http_query_database, $http_query_newsection, $http_query_altersection, $http_query_newtemplate, $http_query_altertemplate, $http_query_newsettings, $http_query_altersettings, $http_query_confirm, @filelist);
519 kiriwrite_output_header; # Output the header to browser/console/stdout.
520 kiriwrite_output_page($kiriwrite_lang{pages}{multiedit}, $pagedata, "pages"); # Output the page to browser/console/stdout.
521 exit; # End the script.
524 kiriwrite_error("invalidaction");
529 # If there the action option is left blank, then print out a form where the database
530 # can be selected to view pages from.
532 my $pagedata = kiriwrite_page_list();
534 kiriwrite_output_header; # Output the header to browser/console/stdout.
535 kiriwrite_output_page($kiriwrite_lang{pages}{databaseselecttitle}, $pagedata, ""); # Output the page to browser/console/stdout.
536 exit; # End the script.
540 } elsif ($http_query_mode eq "template"){
542 use Modules::System::Template;
544 if ($form_data->{'action'}){
546 # An action has been specified in the HTTP query.
548 my $http_query_action = $form_data->{'action'};
550 if ($http_query_action eq "delete"){
551 # Get the required parameters from the HTTP query.
553 my $http_query_template = $form_data->{'template'};
554 my $http_query_confirm = $form_data->{'confirm'};
556 # Check if a value for confirm has been specified (it shouldn't)
559 if (!$http_query_confirm){
560 # The confirm parameter of the HTTP query is blank, so
561 # write out a form asking the user to confirm the deletion
562 # of the selected template.
564 my $pagedata = kiriwrite_template_delete($http_query_template);
566 kiriwrite_output_header; # Output the header to browser/console/stdout.
567 kiriwrite_output_page($kiriwrite_lang{template}{deletetemplate}, $pagedata, "template"); # Output the page to browser/console/stdout.
568 exit; # End the script.
572 my $pagedata = kiriwrite_template_delete($http_query_template, $http_query_confirm);
574 kiriwrite_output_header; # Output the header to browser/console/stdout.
575 kiriwrite_output_page($kiriwrite_lang{template}{deletetemplate}, $pagedata, "template"); # Output the page to browser/console/stdout.
576 exit; # End the script.
580 } elsif ($http_query_action eq "add") {
582 # Get the variables from the HTTP query in preperation for processing.
584 my $http_query_confirm = $form_data->{'confirm'};
585 my $http_query_templatelayout = $form_data->{'templatelayout'};
586 my $http_query_templatename = $form_data->{'templatename'};
587 my $http_query_templatedescription = $form_data->{'templatedescription'};
588 my $http_query_templatefilename = $form_data->{'templatefilename'};
590 # Check if there is a confirmed value in the http_query_confirm variable.
592 if (!$http_query_confirm){
594 # Since there is no confirm value, print out a form for creating a new
597 my $pagedata = kiriwrite_template_add();
599 kiriwrite_output_header; # Output the header to browser/console/stdout.
600 kiriwrite_output_page($kiriwrite_lang{template}{addtemplate}, $pagedata, "template"); # Output the page to browser/console/stdout.
601 exit; # End the script.
605 # A value in the http_query_confirm value is specified, so pass the
606 # variables onto the kiriwrite_template_add subroutine.
608 my $pagedata = kiriwrite_template_add($http_query_templatefilename, $http_query_templatename, $http_query_templatedescription, $http_query_templatelayout, $http_query_confirm);
610 kiriwrite_output_header; # Output the header to browser/console/stdout.
611 kiriwrite_output_page($kiriwrite_lang{template}{addtemplate}, $pagedata, "template"); # Output the page to browser/console/stdout.
612 exit; # End the script.
616 } elsif ($http_query_action eq "edit") {
618 # Get the required parameters from the HTTP query.
620 my $http_query_templatefile = $form_data->{'template'};
621 my $http_query_confirm = $form_data->{'confirm'};
623 # Check to see if http_query_confirm has a value of '1' in it and
624 # if it does, edit the template using the settings providied.
626 if (!$http_query_confirm){
628 # Since there is no confirm value, open the template configuration
629 # file and the template file itself then print out the data on to
632 my $pagedata = kiriwrite_template_edit($http_query_templatefile);
633 kiriwrite_output_header; # Output the header to browser/console/stdout.
634 kiriwrite_output_page($kiriwrite_lang{template}{edittemplate}, $pagedata, "template"); # Output the page to browser/console/stdout.
635 exit; # End the script.
637 } elsif ($http_query_confirm eq 1) {
639 # Since there is a confirm value of 1, the user has confirm the
640 # action of editing of a template so get the other variables
641 # that were also sent and pass the variables to the subroutine.
643 my $http_query_newfilename = $form_data->{'newfilename'};
644 my $http_query_newname = $form_data->{'newname'};
645 my $http_query_newdescription = $form_data->{'newdescription'};
646 my $http_query_newlayout = $form_data->{'newlayout'};
648 my $pagedata = kiriwrite_template_edit($http_query_templatefile, $http_query_newfilename, $http_query_newname, $http_query_newdescription, $http_query_newlayout, $http_query_confirm);
649 kiriwrite_output_header; # Output the header to browser/console/stdout.
650 kiriwrite_output_page($kiriwrite_lang{template}{edittemplate}, $pagedata, "template"); # Output the page to browser/console/stdout.
651 exit; # End the script.
655 # Another confirm value is there instead of '0' or '1'. Return
656 # an error saying it is invalid.
658 kiriwrite_error("invalidvariable");
662 } elsif ($http_query_action eq "view"){
664 # Get the required parameters from the HTTP query.
666 my $http_query_browsenumber = $form_data->{'browsenumber'};
668 my $pagedata = kiriwrite_template_list($http_query_browsenumber);
670 kiriwrite_output_header; # Output the header to browser/console/stdout.
671 kiriwrite_output_page($kiriwrite_lang{template}{viewtemplates}, $pagedata, "template"); # Output the page to browser/console/stdout.
672 exit; # End the script.
676 # Another action was specified and was not one of the ones above, so
679 kiriwrite_error("invalidaction");
685 # If the action option is left blank, then print out a form where the list
686 # of templates are available.
688 my $pagedata = kiriwrite_template_list();
690 kiriwrite_output_header; # Output the header to browser/console/stdout.
691 kiriwrite_output_page($kiriwrite_lang{template}{viewtemplates}, $pagedata, "template"); # Output the page to browser/console/stdout.
692 exit; # End the script.
696 } elsif ($http_query_mode eq "filter"){
698 use Modules::System::Filter;
700 if ($form_data->{'action'}){
702 # There is a value for action in the HTTP query,
703 # so get the value from it.
705 my $http_query_action = $form_data->{'action'};
707 if ($http_query_action eq "add"){
709 # The action the user requested is to add a filter to the
712 # Check if there is a value in confirm and if there is
713 # then pass it on to the new find and replace words
714 # to add to the filter database.
716 my $http_query_confirm = $form_data->{'confirm'};
718 if ($http_query_confirm){
720 # There is a value in http_query_confirm, so pass on the
721 # new find and replace words so that they can be added
722 # to the filter database.
724 my $http_query_findwords = $form_data->{'findword'};
725 my $http_query_replacewords = $form_data->{'replaceword'};
726 my $http_query_priority = $form_data->{'priority'};
727 my $http_query_enabled = $form_data->{'enabled'};
728 my $http_query_notes = $form_data->{'notes'};
730 my $pagedata = kiriwrite_filter_add({ FindFilter => $http_query_findwords, ReplaceFilter => $http_query_replacewords, Priority => $http_query_priority, Enabled => $http_query_enabled, Notes => $http_query_notes, Confirm => $http_query_confirm });
731 #my $pagedata = kiriwrite_filter_add($http_query_findwords, $http_query_replacewords, $http_query_priority, $http_query_notes, $http_query_confirm);
733 kiriwrite_output_header; # Output the header to browser/console/stdout.
734 kiriwrite_output_page($kiriwrite_lang{filter}{addfilter}, $pagedata, "filter"); # Output the page to browser/console/stdout.
735 exit; # End the script.
739 my $pagedata = kiriwrite_filter_add();
741 kiriwrite_output_header; # Output the header to browser/console/stdout.
742 kiriwrite_output_page($kiriwrite_lang{filter}{addfilter}, $pagedata, "filter"); # Output the page to browser/console/stdout.
743 exit; # End the script.
745 } elsif ($http_query_action eq "edit"){
747 # The action the user requested is to edit an filter from
748 # the filter database.
750 my $http_query_number = $form_data->{'filter'};
751 my $http_query_confirm = $form_data->{'confirm'};
753 if ($http_query_confirm){
755 # There is a value in http_query_confirm, so pass on the
756 # new find and replace words so that the filter database
759 my $http_query_findwords = $form_data->{'filterfind'};
760 my $http_query_replacewords = $form_data->{'filterreplace'};
761 my $http_query_priority = $form_data->{'priority'};
762 my $http_query_notes = $form_data->{'notes'};
763 my $http_query_enabled = $form_data->{'enabled'};
765 my $pagedata = kiriwrite_filter_edit({ FilterID => $http_query_number, NewFindFilter => $http_query_findwords, NewReplaceFilter => $http_query_replacewords, NewPriority => $http_query_priority, NewEnabled => $http_query_enabled, NewFilterNotes => $http_query_notes, Confirm => $http_query_confirm });
767 kiriwrite_output_header; # Output the header to browser/console/stdout.
768 kiriwrite_output_page($kiriwrite_lang{filter}{editfilter}, $pagedata, "filter"); # Output the page to browser/console/stdout.
769 exit; # End the script.
773 my $pagedata = kiriwrite_filter_edit({ FilterID => $http_query_number });
775 kiriwrite_output_header; # Output the header to browser/console/stdout.
776 kiriwrite_output_page($kiriwrite_lang{filter}{editfilter}, $pagedata, "filter"); # Output the page to browser/console/stdout.
777 exit; # End the script.
779 } elsif ($http_query_action eq "delete"){
781 # The action the user requested is to delete an filter
782 # from the filter database.
784 my $http_query_number = $form_data->{'filter'};
785 my $http_query_confirm = $form_data->{'confirm'};
787 if ($http_query_confirm){
789 my $pagedata = kiriwrite_filter_delete($http_query_number, $http_query_confirm);
791 kiriwrite_output_header; # Output the header to browser/console/stdout.
792 kiriwrite_output_page($kiriwrite_lang{filter}{deletefilter}, $pagedata, "filter"); # Output the page to browser/console/stdout.
793 exit; # End the script
797 my $pagedata = kiriwrite_filter_delete($http_query_number);
799 kiriwrite_output_header; # Output the header to browser/console/stdout.
800 kiriwrite_output_page($kiriwrite_lang{filter}{deletefilter}, $pagedata, "filter"); # Output the page to browser/console/stdout.
801 exit; # End the script.
803 } elsif ($http_query_action eq "view"){
805 # The action the user requested is to view the list
806 # filters on the filter database.
808 my $http_query_browsenumber = $form_data->{'browsenumber'};
810 my $pagedata = kiriwrite_filter_list($http_query_browsenumber);
812 kiriwrite_output_header; # Output the header to browser/console/stdout.
813 kiriwrite_output_page($kiriwrite_lang{filter}{viewfilters}, $pagedata, "filter"); # Output the page to browser/console/stdout.
814 exit; # End the script.
818 # Another action was requested that was not one of
819 # the ones prcedding this catch all, so return
820 # an error saying that an invalid option was
823 kiriwrite_error("invalidaction");
829 my $pagedata = kiriwrite_filter_list();
831 kiriwrite_output_header; # Output the header to browser/console/stdout.
832 kiriwrite_output_page($kiriwrite_lang{filter}{viewfilters}, $pagedata, "filter"); # Output the page to browser/console/stdout.
833 exit; # End the script.
837 } elsif ($http_query_mode eq "compile"){
839 use Modules::System::Compile;
841 if ($form_data->{'action'}){
843 my $http_query_action = $form_data->{'action'};
845 if ($http_query_action eq "compile"){
847 # The specified action is to compile the pages, check if the
848 # action to compile the page has been confirmed.
850 my $http_query_confirm = $form_data->{'confirm'};
851 my $http_query_type = $form_data->{'type'};
853 # If it is blank, set the confirm value to 0.
855 if (!$http_query_confirm){
857 # The http_query_confirm variable is uninitalised, so place a
858 # '0' (meaning an unconfirmed action).
860 $http_query_confirm = 0;
864 # If the compile type is blank then return an error.
866 if (!$http_query_type){
868 # Compile type is blank so return an error.
870 kiriwrite_error("blankcompiletype");
874 if ($http_query_type eq "multiple"){
876 if ($http_query_confirm eq 1){
878 # The action to compile the pages has been confirmed so
881 my $http_query_override = $form_data->{'enableoverride'};
882 my $http_query_overridetemplate = $form_data->{'overridetemplate'};
883 my $http_query_outputmodule = $form_data->{'outputmodule'};
885 my @selectedlist = kiriwrite_selectedlist($form_data);
886 my %form_data_hash = $query_lite->parse_form_data;
887 kiriwrite_compile_loadhash(%form_data_hash);
888 my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, $http_query_override, $http_query_overridetemplate, $http_query_outputmodule, @selectedlist);
890 kiriwrite_output_header; # Output the header to browser/console/stdout.
891 kiriwrite_output_page($kiriwrite_lang{compile}{compilepages}, $pagedata, "compile"); # Output the page to browser/console/stdout.
892 exit; # End the script.
896 # The action to compile the pages has not been confirmed
897 # so write a form asking the user to confirm the action
898 # of compiling the pages.
900 my $http_query_outputmodule = $form_data->{'outputmodule'};
902 my @selectedlist = kiriwrite_selectedlist($form_data);
903 my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, "", "", $http_query_outputmodule, @selectedlist);
905 kiriwrite_output_header; # Output the header to browser/console/stdout.
906 kiriwrite_output_page($kiriwrite_lang{compile}{compileselecteddatabases}, $pagedata, "compile"); # Output the page to browser/console/stdout.
907 exit; # End the script.
911 } elsif ($http_query_type eq "single"){
913 my $http_query_database = $form_data->{'database'};
914 my $http_query_outputmodule = $form_data->{'outputmodule'};
916 $selectedlist[0] = $http_query_database;
917 my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, "", "", $http_query_outputmodule, @selectedlist);
919 kiriwrite_output_header; # Output the header to browser/console/stdout.
920 kiriwrite_output_page($kiriwrite_lang{compile}{compiledatabase}, $pagedata, "compile");
921 exit; # End the script.
925 kiriwrite_error("invalidcompiletype");
929 } elsif ($http_query_action eq "all"){
931 # The selected action is to compile all of the databases
932 # in the database directory. Check if the action to
933 # compile all of the databases has been confirmed.
935 my $http_query_confirm = $form_data->{'confirm'};
936 my $http_query_outputmodule = $form_data->{'outputmodule'};
938 if (!$http_query_confirm){
940 # The http_query_confirm variable is uninitalised, so place a
941 # '0' (meaning an unconfirmed action).
943 $http_query_confirm = 0;
947 my $pagedata = kiriwrite_compile_all($http_query_outputmodule);
949 kiriwrite_output_header; # Output the header to browser/console/stdout.
950 kiriwrite_output_page($kiriwrite_lang{compile}{compilealldatabases}, $pagedata, "compile");
953 } elsif ($http_query_action eq "clean") {
955 # The selected action is to clean the output directory.
956 # Check if the action to clean the output directory
957 # has been confirmed.
959 my $http_query_confirm = $form_data->{'confirm'};
961 if (!$http_query_confirm){
963 # The http_query_confirm variable is uninitalised, so place a
964 # '0' (meaning an unconfirmed action).
966 $http_query_confirm = 0;
970 if ($http_query_confirm eq 1){
972 # The action to clean the output directory has been confirmed.
974 my $pagedata = kiriwrite_compile_clean($http_query_confirm);
976 kiriwrite_output_header; # Output the header to browser/console/stdout.
977 kiriwrite_output_page($kiriwrite_lang{compile}{cleanoutputdirectory}, $pagedata, "compile"); # Output the page to browser/console/stdout.
978 exit; # End the script.
982 # The action to clean the output directory is not
983 # confirmed, so write a page asking the user
984 # to confirm cleaning the output directory.
986 my $pagedata = kiriwrite_compile_clean();
988 kiriwrite_output_header; # Output the header to browser/console/stdout.
989 kiriwrite_output_page($kiriwrite_lang{compile}{cleanoutputdirectory}, $pagedata, "compile"); # Output the page to browser/console/stdout.
990 exit; # End the script.
994 # The action specified was something else other than those
995 # above, so return an error.
997 kiriwrite_error("invalidaction");
1002 my $pagedata = kiriwrite_compile_list();
1004 kiriwrite_output_header; # Output the header to browser/console/stdout.
1005 kiriwrite_output_page($kiriwrite_lang{compile}{compilepages}, $pagedata, "compile"); # Output the page to browser/console/stdout.
1006 exit; # End the script.
1008 } elsif ($http_query_mode eq "settings"){
1010 use Modules::System::Settings;
1012 if ($form_data->{'action'}){
1013 my $http_query_action = $form_data->{'action'};
1015 if ($http_query_action eq "edit"){
1017 # The action specified is to edit the settings. Check if the action
1018 # to edit the settings has been confirmed.
1020 my $http_query_confirm = $form_data->{'confirm'};
1022 if (!$http_query_confirm){
1024 # The confirm value is blank, so set it to 0.
1026 $http_query_confirm = 0;
1030 if ($http_query_confirm eq 1){
1032 # The action to edit the settings has been confirmed. Get the
1033 # required settings from the HTTP query.
1035 my $http_query_database = $form_data->{'databasedir'};
1036 my $http_query_output = $form_data->{'outputdir'};
1037 my $http_query_imagesuri = $form_data->{'imagesuripath'};
1038 my $http_query_datetimeformat = $form_data->{'datetime'};
1039 my $http_query_systemlanguage = $form_data->{'language'};
1040 my $http_query_presmodule = $form_data->{'presmodule'};
1041 my $http_query_dbmodule = $form_data->{'dbmodule'};
1042 my $http_query_outputmodule = $form_data->{'outputmodule'};
1043 my $http_query_textareacols = $form_data->{'textareacols'};
1044 my $http_query_textarearows = $form_data->{'textarearows'};
1045 my $http_query_pagecount = $form_data->{'pagecount'};
1046 my $http_query_filtercount = $form_data->{'filtercount'};
1047 my $http_query_templatecount = $form_data->{'templatecount'};
1049 my $http_query_database_server = $form_data->{'database_server'};
1050 my $http_query_database_port = $form_data->{'database_port'};
1051 my $http_query_database_protocol = $form_data->{'database_protocol'};
1052 my $http_query_database_sqldatabase = $form_data->{'database_sqldatabase'};
1053 my $http_query_database_username = $form_data->{'database_username'};
1054 my $http_query_database_passwordkeep = $form_data->{'database_password_keep'};
1055 my $http_query_database_password = $form_data->{'database_password'};
1056 my $http_query_database_tableprefix = $form_data->{'database_tableprefix'};
1058 my $pagedata = kiriwrite_settings_edit({ DatabaseDirectory => $http_query_database, OutputDirectory => $http_query_output, ImagesURIPath => $http_query_imagesuri, DateTimeFormat => $http_query_datetimeformat, SystemLanguage => $http_query_systemlanguage, PresentationModule => $http_query_presmodule, OutputModule => $http_query_outputmodule, TextAreaCols => $http_query_textareacols, TextAreaRows => $http_query_textarearows, PageCount => $http_query_pagecount, FilterCount => $http_query_filtercount, TemplateCount => $http_query_templatecount, DatabaseModule => $http_query_dbmodule, DatabaseServer => $http_query_database_server, DatabasePort => $http_query_database_port, DatabaseProtocol => $http_query_database_protocol, DatabaseSQLDatabase => $http_query_database_sqldatabase, DatabaseUsername => $http_query_database_username, DatabasePasswordKeep => $http_query_database_passwordkeep, DatabasePassword => $http_query_database_password, DatabaseTablePrefix => $http_query_database_tableprefix, Confirm => 1 });
1060 kiriwrite_output_header; # Output the header to browser/console/stdout.
1061 kiriwrite_output_page($kiriwrite_lang{setting}{editsettings}, $pagedata, "settings"); # Output the page to browser/console/stdout.
1062 exit; # End the script.
1066 # The action to edit the settings has not been confirmed.
1068 my $pagedata = kiriwrite_settings_edit();
1070 kiriwrite_output_header; # Output the header to browser/console/stdout.
1071 kiriwrite_output_page($kiriwrite_lang{setting}{editsettings}, $pagedata, "settings"); # Output the page to browser/console/stdout.
1072 exit; # End the script.
1076 # The action specified was something else other than those
1077 # above, so return an error.
1079 kiriwrite_error("invalidaction");
1085 # No action has been specified, so print out the list of settings currently being used.
1087 my $pagedata = kiriwrite_settings_view();
1089 kiriwrite_output_header; # Output the header to browser/console/stdout.
1090 kiriwrite_output_page($kiriwrite_lang{setting}{viewsettings}, $pagedata, "settings"); # Output the page to browser/console/stdout.
1091 exit; # End the script.
1095 # An invalid mode has been specified so return
1098 kiriwrite_error("invalidmode");
1104 # No mode has been specified, so print the default "first-run" view of the
1107 use Modules::System::Database;
1109 my $pagedata = kiriwrite_database_list();
1111 kiriwrite_output_header; # Output the header to browser/console/stdout.
1112 kiriwrite_output_page("", $pagedata, "database"); # Output the page to browser/console/stdout.
1113 exit; # End the script.