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, $form_data, $kiriwrite_script_name, $kiriwrite_env_path);
42 # If you are using mod_perl please change these settings to the correct
43 # directory where this script is being run from.
48 # Load the common functions module.
50 use Modules::System::Common;
52 # Setup the version information for Kiriwrite.
54 %kiriwrite_version = (
60 kiriwrite_initalise; # Initalise the Kiriwrite enviroment.
61 kiriwrite_settings_load; # Load the configuration options.
63 my $query_lite = new CGI::Lite;
65 # Check if a mode has been specified and if a mode has been specified, continue
66 # and work out what mode has been specified.
68 $form_data = $query_lite->parse_form_data;
70 if ($form_data->{'mode'}){
71 my $http_query_mode = $form_data->{'mode'};
73 if ($http_query_mode eq "db"){
75 use Modules::System::Database;
77 if ($form_data->{'action'}){
78 # An action has been specified, so find out what action has been specified.
80 my $http_query_action = $form_data->{'action'};
82 if ($http_query_action eq "edit"){
83 # The edit action (which mean edit the settings for the selected database) has been specified,
84 # get the database name and check if the action to edit an database has been confirmed.
86 if ($form_data->{'database'}){
87 # If there is a value in the database variable check if it is a valid database. Otherwise,
90 my $http_query_database = $form_data->{'database'};
92 # Check if a value for confirm has been specified, if there is, check if it is the correct
93 # value, otherwise return an error.
95 if ($form_data->{'confirm'}){
96 # A value for confirm has been specified, find out what value it is. If the value is correct
97 # then edit the database settings, otherwise return an error.
99 my $http_query_confirm = $form_data->{'confirm'};
101 if ($http_query_confirm eq 1){
102 # Value is correct, collect the variables to pass onto the database variable.
104 # Get the variables from the HTTP query.
106 my $newdatabasename = $form_data->{'databasename'};
107 my $newdatabasedescription = $form_data->{'databasedescription'};
108 my $newdatabasefilename = $form_data->{'databasefilename'};
109 my $databaseshortname = $form_data->{'database'};
110 my $databasenotes = $form_data->{'databasenotes'};
111 my $databasecategories = $form_data->{'databasecategories'};
113 # Pass the variables to the database editing subroutine.
115 my $pagedata = kiriwrite_database_edit($databaseshortname, $newdatabasefilename, $newdatabasename, $newdatabasedescription, $databasenotes, $databasecategories, 1);
117 kiriwrite_output_header;
118 kiriwrite_output_page($kiriwrite_lang{database}{editdatabasetitle}, $pagedata, "database");
122 # Value is incorrect, return and error.
123 kiriwrite_error("invalidvariable");
128 # Display the form for editing an database.
129 my $pagedata = kiriwrite_database_edit($http_query_database);
131 kiriwrite_output_header;
132 kiriwrite_output_page($kiriwrite_lang{database}{editdatabasetitle}, $pagedata, "database");
137 # If there is no value in the database variable, then return an error.
138 kiriwrite_error("invalidvariable");
142 } elsif ($http_query_action eq "delete"){
144 # Action equested is to delete a database, find out if the user has already confirmed deletion of the database
145 # and if the deletion of the database has been confirmed, delete the database.
147 if ($form_data->{'confirm'}){
149 # User has confirmed to delete a database, pass the parameters to the kiriwrite_database_delete
152 my $database_filename = $form_data->{'database'};
153 my $database_confirm = $form_data->{'confirm'};
154 my $pagedata = kiriwrite_database_delete($database_filename, $database_confirm);
156 kiriwrite_output_header;
157 kiriwrite_output_page($kiriwrite_lang->{database}->{deleteddatabase}, $pagedata, "database");
163 # User has clicked on the delete link (thus hasn't confirmed the action to delete a database).
165 my $database_filename = $form_data->{'database'};
166 my $pagedata = kiriwrite_database_delete($database_filename);
168 kiriwrite_output_header;
169 kiriwrite_output_page($kiriwrite_lang->{database}->{deletedatabase}, $pagedata, "database");
173 } elsif ($http_query_action eq "new"){
175 # Action requested is to create a new database, find out if the user has already entered the information needed
176 # to create a database and see if the user has confirmed the action, otherwise printout a form for adding a
179 my $http_query_confirm = $form_data->{'confirm'};
181 # Check if the confirm value is correct.
183 if ($http_query_confirm){
184 if ($http_query_confirm eq 1){
186 # User has confirmed to create a database, pass the parameters to the
187 # kiriwrite_database_add subroutine.
189 my $http_query_confirm = $form_data->{'confirm'};
191 my $database_name = $form_data->{'databasename'};
192 my $database_description = $form_data->{'databasedescription'};
193 my $database_filename = $form_data->{'databasefilename'};
194 my $database_notes = $form_data->{'databasenotes'};
195 my $database_categories = $form_data->{'databasecategories'};
197 my $pagedata = kiriwrite_database_add($database_filename, $database_name, $database_description, $database_notes, $database_categories, $http_query_confirm);
199 kiriwrite_output_header;
200 kiriwrite_output_page($kiriwrite_lang{database}{adddatabase}, $pagedata, "database");
205 # The confirm value is something else other than 1 (which it shouldn't be), so
211 # User has clicked on the 'Add Database' link.
213 my $pagedata = kiriwrite_database_add();
215 kiriwrite_output_header;
216 kiriwrite_output_page($main::kiriwrite_lang{database}{adddatabase}, $pagedata, "database");
220 # Another option has been specified, so return an error.
222 kiriwrite_error("invalidaction");
227 # No action has been specified, do the default action of displaying a list
230 my $pagedata = kiriwrite_database_list();
232 kiriwrite_output_header; # Output the header to browser/console/stdout.
233 kiriwrite_output_page("", $pagedata, "database"); # Output the page to browser/console/stdout.
234 exit; # End the script.
238 } elsif ($http_query_mode eq "page"){
240 use Modules::System::Page;
242 if ($form_data->{'action'}){
243 my $http_query_action = $form_data->{'action'};
245 # Check if the action requested matches with one of the options below. If it does,
246 # go to that section, otherwise return an error.
248 if ($http_query_action eq "view"){
250 # The action selected was to view pages from a database,
252 my $http_query_database = $form_data->{'database'};
253 my $http_query_browsenumber = $form_data->{'browsenumber'};
254 my $pagedata = kiriwrite_page_list($http_query_database, $http_query_browsenumber);
256 kiriwrite_output_header; # Output the header to browser/console/stdout.
257 kiriwrite_output_page($kiriwrite_lang->{pages}->{viewingdatabase}, $pagedata, "pages", $http_query_database); # Output the page to browser/console/stdout.
258 exit; # End the script.
260 } elsif ($http_query_action eq "add"){
262 # The action selected was to add a page to the selected database.
264 my $http_query_confirm = $form_data->{'confirm'};
266 if (!$http_query_confirm){
268 $http_query_confirm = 0;
272 if ($http_query_confirm eq 1){
274 my $http_query_database = $form_data->{'database'};
275 my $http_query_filename = $form_data->{'pagefilename'};
276 my $http_query_name = $form_data->{'pagename'};
277 my $http_query_description = $form_data->{'pagedescription'};
278 my $http_query_section = $form_data->{'pagesection'};
279 my $http_query_template = $form_data->{'pagetemplate'};
280 my $http_query_settings = $form_data->{'pagesettings'};
281 my $http_query_content = $form_data->{'pagecontent'};
283 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);
285 kiriwrite_output_header; # Output the header to browser/console/stdout.
286 kiriwrite_output_page($kiriwrite_lang{pages}{addpage}, $pagedata, "pages"); # Output the page to browser/console/stdout.
287 exit; # End the script.
291 my $http_query_database = $form_data->{'database'};
292 my $pagedata = kiriwrite_page_add($http_query_database);
294 kiriwrite_output_header; # Output the header to browser/console/stdout.
295 kiriwrite_output_page($kiriwrite_lang{pages}{addpage}, $pagedata, "pages"); # Output the page to browser/console/stdout.
296 exit; # End the script.
298 } elsif ($http_query_action eq "edit"){
300 # The action selected was to edit a page from a database.
302 my $http_query_confirm = $form_data->{'confirm'};
304 if (!$http_query_confirm){
306 $http_query_confirm = 0;
310 if ($http_query_confirm eq 1){
312 # Get the needed values from the HTTP query.
314 my $http_query_database = $form_data->{'database'};
315 my $http_query_filename = $form_data->{'page'};
316 my $http_query_newfilename = $form_data->{'pagefilename'};
317 my $http_query_name = $form_data->{'pagename'};
318 my $http_query_description = $form_data->{'pagedescription'};
319 my $http_query_section = $form_data->{'pagesection'};
320 my $http_query_template = $form_data->{'pagetemplate'};
321 my $http_query_settings = $form_data->{'pagesettings'};
322 my $http_query_content = $form_data->{'pagecontent'};
324 # Pass the values to the editing pages subroutine.
326 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);
328 kiriwrite_output_header; # Output the header to browser/console/stdout.
329 kiriwrite_output_page($kiriwrite_lang{pages}{editpagetitle}, $pagedata, "pages"); # Output the page to browser/console/stdout.
330 exit; # End the script.
334 # Get the needed values from the HTTP query.
336 my $http_query_database = $form_data->{'database'};
337 my $http_query_filename = $form_data->{'page'};
339 # Pass the values to the editing pages subroutine.
341 my $pagedata = kiriwrite_page_edit($http_query_database, $http_query_filename);
343 kiriwrite_output_header; # Output the header to browser/console/stdout.
344 kiriwrite_output_page($kiriwrite_lang{pages}{editpagetitle}, $pagedata, "pages"); # Output the page to browser/console/stdout.
345 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'};
884 my @selectedlist = kiriwrite_selectedlist($form_data);
885 my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, $http_query_override, $http_query_overridetemplate, @selectedlist);
887 kiriwrite_output_header; # Output the header to browser/console/stdout.
888 kiriwrite_output_page($kiriwrite_lang{compile}{compilepages}, $pagedata, "compile"); # Output the page to browser/console/stdout.
889 exit; # End the script.
893 # The action to compile the pages has not been confirmed
894 # so write a form asking the user to confirm the action
895 # of compiling the pages.
897 my @selectedlist = kiriwrite_selectedlist($form_data);
898 my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, "", "", @selectedlist);
900 kiriwrite_output_header; # Output the header to browser/console/stdout.
901 kiriwrite_output_page($kiriwrite_lang{compile}{compileselecteddatabases}, $pagedata, "compile"); # Output the page to browser/console/stdout.
902 exit; # End the script.
906 } elsif ($http_query_type eq "single"){
908 my $http_query_database = $form_data->{'database'};
910 $selectedlist[0] = $http_query_database;
911 my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, "", "", @selectedlist);
913 kiriwrite_output_header; # Output the header to browser/console/stdout.
914 kiriwrite_output_page($kiriwrite_lang{compile}{compiledatabase}, $pagedata, "compile");
915 exit; # End the script.
919 kiriwrite_error("invalidcompiletype");
923 } elsif ($http_query_action eq "all"){
925 # The selected action is to compile all of the databases
926 # in the database directory. Check if the action to
927 # compile all of the databases has been confirmed.
929 my $http_query_confirm = $form_data->{'confirm'};
931 if (!$http_query_confirm){
933 # The http_query_confirm variable is uninitalised, so place a
934 # '0' (meaning an unconfirmed action).
936 $http_query_confirm = 0;
940 if ($http_query_confirm eq 1){
942 # The action to compile all the databases has been confirmed.
946 my $pagedata = kiriwrite_compile_all();
948 kiriwrite_output_header; # Output the header to browser/console/stdout.
949 kiriwrite_output_page($kiriwrite_lang{compile}{compilealldatabases}, $pagedata, "compile");
952 } elsif ($http_query_action eq "clean") {
954 # The selected action is to clean the output directory.
955 # Check if the action to clean the output directory
956 # has been confirmed.
958 my $http_query_confirm = $form_data->{'confirm'};
960 if (!$http_query_confirm){
962 # The http_query_confirm variable is uninitalised, so place a
963 # '0' (meaning an unconfirmed action).
965 $http_query_confirm = 0;
969 if ($http_query_confirm eq 1){
971 # The action to clean the output directory has been confirmed.
973 my $pagedata = kiriwrite_compile_clean($http_query_confirm);
975 kiriwrite_output_header; # Output the header to browser/console/stdout.
976 kiriwrite_output_page($kiriwrite_lang{compile}{cleanoutputdirectory}, $pagedata, "compile"); # Output the page to browser/console/stdout.
977 exit; # End the script.
981 # The action to clean the output directory is not
982 # confirmed, so write a page asking the user
983 # to confirm cleaning the output directory.
985 my $pagedata = kiriwrite_compile_clean();
987 kiriwrite_output_header; # Output the header to browser/console/stdout.
988 kiriwrite_output_page($kiriwrite_lang{compile}{cleanoutputdirectory}, $pagedata, "compile"); # Output the page to browser/console/stdout.
989 exit; # End the script.
993 # The action specified was something else other than those
994 # above, so return an error.
996 kiriwrite_error("invalidaction");
1001 my $pagedata = kiriwrite_compile_list();
1003 kiriwrite_output_header; # Output the header to browser/console/stdout.
1004 kiriwrite_output_page($kiriwrite_lang{compile}{compilepages}, $pagedata, "compile"); # Output the page to browser/console/stdout.
1005 exit; # End the script.
1007 } elsif ($http_query_mode eq "settings"){
1009 use Modules::System::Settings;
1011 if ($form_data->{'action'}){
1012 my $http_query_action = $form_data->{'action'};
1014 if ($http_query_action eq "edit"){
1016 # The action specified is to edit the settings. Check if the action
1017 # to edit the settings has been confirmed.
1019 my $http_query_confirm = $form_data->{'confirm'};
1021 if (!$http_query_confirm){
1023 # The confirm value is blank, so set it to 0.
1025 $http_query_confirm = 0;
1029 if ($http_query_confirm eq 1){
1031 # The action to edit the settings has been confirmed. Get the
1032 # required settings from the HTTP query.
1034 my $http_query_database = $form_data->{'databasedir'};
1035 my $http_query_output = $form_data->{'outputdir'};
1036 my $http_query_imagesuri = $form_data->{'imagesuripath'};
1037 my $http_query_datetimeformat = $form_data->{'datetime'};
1038 my $http_query_systemlanguage = $form_data->{'language'};
1039 my $http_query_presmodule = $form_data->{'presmodule'};
1040 my $http_query_dbmodule = $form_data->{'dbmodule'};
1041 my $http_query_textareacols = $form_data->{'textareacols'};
1042 my $http_query_textarearows = $form_data->{'textarearows'};
1043 my $http_query_pagecount = $form_data->{'pagecount'};
1044 my $http_query_filtercount = $form_data->{'filtercount'};
1045 my $http_query_templatecount = $form_data->{'templatecount'};
1047 my $http_query_database_server = $form_data->{'database_server'};
1048 my $http_query_database_port = $form_data->{'database_port'};
1049 my $http_query_database_protocol = $form_data->{'database_protocol'};
1050 my $http_query_database_sqldatabase = $form_data->{'database_sqldatabase'};
1051 my $http_query_database_username = $form_data->{'database_username'};
1052 my $http_query_database_passwordkeep = $form_data->{'database_password_keep'};
1053 my $http_query_database_password = $form_data->{'database_password'};
1054 my $http_query_database_tableprefix = $form_data->{'database_tableprefix'};
1056 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, 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 });
1058 kiriwrite_output_header; # Output the header to browser/console/stdout.
1059 kiriwrite_output_page($kiriwrite_lang{setting}{editsettings}, $pagedata, "settings"); # Output the page to browser/console/stdout.
1060 exit; # End the script.
1064 # The action to edit the settings has not been confirmed.
1066 my $pagedata = kiriwrite_settings_edit();
1068 kiriwrite_output_header; # Output the header to browser/console/stdout.
1069 kiriwrite_output_page($kiriwrite_lang{setting}{editsettings}, $pagedata, "settings"); # Output the page to browser/console/stdout.
1070 exit; # End the script.
1074 # The action specified was something else other than those
1075 # above, so return an error.
1077 kiriwrite_error("invalidaction");
1083 # No action has been specified, so print out the list of settings currently being used.
1085 my $pagedata = kiriwrite_settings_view();
1087 kiriwrite_output_header; # Output the header to browser/console/stdout.
1088 kiriwrite_output_page($kiriwrite_lang{setting}{viewsettings}, $pagedata, "settings"); # Output the page to browser/console/stdout.
1089 exit; # End the script.
1093 # An invalid mode has been specified so return
1096 kiriwrite_error("invalidmode");
1102 # No mode has been specified, so print the default "first-run" view of the
1105 use Modules::System::Database;
1107 my $pagedata = kiriwrite_database_list();
1109 kiriwrite_output_header; # Output the header to browser/console/stdout.
1110 kiriwrite_output_page("", $pagedata, "database"); # Output the page to browser/console/stdout.
1111 exit; # End the script.