Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Another commit to the trunk.
[kiriwrite/.git] / cgi-files / kiriwrite.cgi
1 #!/usr/bin/perl -Tw
3 #################################################################################
4 # Kiriwrite (kiriwrite.pl/kiriwrite.cgi)                                        #
5 # Main program script                                                           #
6 #                                                                               #
7 # Version: 0.5.0                                                                #
8 # mod_perl 2.x compatabile version                                              #
9 #                                                                               #
10 # Copyright (C) 2005-2008 Steve Brokenshire <sbrokenshire@xestia.co.uk>         #
11 #                                                                               #
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.                             #
15 #                                                                               #
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.#
19 #                                                                               #
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 #################################################################################
25 use strict;
26 use warnings;
28 use utf8;
29 use CGI::Lite;
30 use Tie::IxHash;
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.
46 use lib '.';
47 chdir('.');
49 # Load the common functions module.
51 use Modules::System::Common;
53 # Setup the version information for Kiriwrite.
55 %kiriwrite_version = (
56         "major"         => 0,
57         "minor"         => 5,
58         "revision"      => 0
59 );
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'};
82         
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.
86                 
87                                 if ($form_data->{'database'}){
88                                         # If there is a value in the database variable check if it is a valid database. Otherwise,
89                                         # return an error.
90                 
91                                         my $http_query_database = $form_data->{'database'};
92                                 
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.
95                 
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.
99                 
100                                                 my $http_query_confirm = $form_data->{'confirm'};
101                 
102                                                 if ($http_query_confirm eq 1){
103                                                         # Value is correct, collect the variables to pass onto the database variable.
104                 
105                                                         # Get the variables from the HTTP query.
106                 
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'};
113                 
114                                                         # Pass the variables to the database editing subroutine.
115                 
116                                                         my $pagedata = kiriwrite_database_edit($databaseshortname, $newdatabasefilename, $newdatabasename, $newdatabasedescription, $databasenotes, $databasecategories, 1);
117                 
118                                                         kiriwrite_output_header;
119                                                         kiriwrite_output_page($kiriwrite_lang{database}{editdatabasetitle}, $pagedata, "database");
120                                                         exit;
121                 
122                                                 } else {
123                                                         # Value is incorrect, return and error.
124                                                         kiriwrite_error("invalidvariable");
125                                                 } 
126                 
127                                         }
128                 
129                                         # Display the form for editing an database.
130                                         my $pagedata = kiriwrite_database_edit($http_query_database);
131                 
132                                         kiriwrite_output_header;
133                                         kiriwrite_output_page($kiriwrite_lang{database}{editdatabasetitle}, $pagedata, "database");
134                                         exit;
135                 
136                                 } else {
137                 
138                                         # If there is no value in the database variable, then return an error.
139                                         kiriwrite_error("invalidvariable");
140                 
141                                 }
142                 
143                         } elsif ($http_query_action eq "delete"){
144                 
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.
147                 
148                                 if ($form_data->{'confirm'}){
149                 
150                                         # User has confirmed to delete a database, pass the parameters to the kiriwrite_database_delete
151                                         # subroutine.
152                 
153                                         my $database_filename   = $form_data->{'database'};
154                                         my $database_confirm    = $form_data->{'confirm'};
155                                         my $pagedata = kiriwrite_database_delete($database_filename, $database_confirm);
156                 
157                                         kiriwrite_output_header;
158                                         kiriwrite_output_page($kiriwrite_lang->{database}->{deleteddatabase}, $pagedata, "database");
159                 
160                                         exit;
161                 
162                                 }
163                 
164                                 # User has clicked on the delete link (thus hasn't confirmed the action to delete a database).
165                 
166                                 my $database_filename = $form_data->{'database'};
167                                 my $pagedata = kiriwrite_database_delete($database_filename);
168                 
169                                 kiriwrite_output_header;
170                                 kiriwrite_output_page($kiriwrite_lang->{database}->{deletedatabase}, $pagedata, "database");
171                 
172                                 exit;
173                 
174                         } elsif ($http_query_action eq "new"){
175                 
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
178                                 # database.
179                 
180                                 my $http_query_confirm = $form_data->{'confirm'};
181                 
182                                 # Check if the confirm value is correct.
183                 
184                                 if ($http_query_confirm){
185                                         if ($http_query_confirm eq 1){
186                 
187                                                 # User has confirmed to create a database, pass the parameters to the 
188                                                 # kiriwrite_database_add subroutine.
189                 
190                                                 my $http_query_confirm = $form_data->{'confirm'};
191                 
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'};
197                 
198                                                 my $pagedata = kiriwrite_database_add($database_filename, $database_name, $database_description, $database_notes, $database_categories, $http_query_confirm);
199                 
200                                                 kiriwrite_output_header;
201                                                 kiriwrite_output_page($kiriwrite_lang{database}{adddatabase}, $pagedata, "database");
202                                                 exit;
203                 
204                                         } else {
205                 
206                                                 # The confirm value is something else other than 1 (which it shouldn't be), so
207                                                 # return an error.
208                 
209                                         }
210                                 }
211         
212                                 # User has clicked on the 'Add Database' link.
213         
214                                 my $pagedata = kiriwrite_database_add();
215         
216                                 kiriwrite_output_header;
217                                 kiriwrite_output_page($main::kiriwrite_lang{database}{adddatabase}, $pagedata, "database");
218                                 exit;
219         
220                         } else {
221                                 # Another option has been specified, so return an error.
222         
223                                 kiriwrite_error("invalidaction");
224                         }
226                 } else {
228                         # No action has been specified, do the default action of displaying a list
229                         # of databases.
230                 
231                         my $pagedata = kiriwrite_database_list();
232                 
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.
237                 }
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'};
245                 
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"){
250                 
251                                 # The action selected was to view pages from a database, 
252                 
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);
256                 
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.
260                 
261                         } elsif ($http_query_action eq "add"){
262                 
263                                 # The action selected was to add a page to the selected database.
264                 
265                                 my $http_query_confirm  = $form_data->{'confirm'};
266                 
267                                 if (!$http_query_confirm){
268                 
269                                         $http_query_confirm = 0;
270                 
271                                 }
272                 
273                                 if ($http_query_confirm eq 1){
274                 
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'};
283                         
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);
285                 
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.
289                 
290                                 }
291                 
292                                 my $http_query_database = $form_data->{'database'};
293                                 my $pagedata            = kiriwrite_page_add($http_query_database);
294                 
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.
298                 
299                         }  elsif ($http_query_action eq "edit"){
300                                 
301                                 # The action selected was to edit a page from a database.
302                 
303                                 my $http_query_confirm = $form_data->{'confirm'};
304                 
305                                 if (!$http_query_confirm){
306                 
307                                         $http_query_confirm = 0;
308                 
309                                 }
310                 
311                                 if ($http_query_confirm eq 1){
312                 
313                                         # Get the needed values from the HTTP query.
314                 
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'};
324                 
325                                         # Pass the values to the editing pages subroutine.
326                 
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);
328                 
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.
332                 
333                                 }
334                 
335                                 # Get the needed values from the HTTP query.
336                 
337                                 my $http_query_database = $form_data->{'database'};
338                                 my $http_query_filename = $form_data->{'page'};
339                 
340                                 # Pass the values to the editing pages subroutine.
341                 
342                                 my $pagedata = kiriwrite_page_edit($http_query_database, $http_query_filename);
343                 
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.
347                         
348                         } elsif ($http_query_action eq "delete"){
349                 
350                                 # The action selected was to delete a page from a database.
351                 
352                                 my $http_query_database = $form_data->{'database'};
353                                 my $http_query_page     = $form_data->{'page'};
354                                 my $http_query_confirm  = $form_data->{'confirm'};
355                 
356                                 my $pagedata = "";
357                                 my $selectionlist = "";
358                 
359                                 if ($http_query_confirm){
360                 
361                                         # The action has been confirmed, so try to delete the selected page
362                                         # from the database.
363                 
364                                         $pagedata = kiriwrite_page_delete($http_query_database, $http_query_page, $http_query_confirm);
365                 
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.
369                 
370                                 }
371                 
372                                 $pagedata = kiriwrite_page_delete($http_query_database, $http_query_page);
373                 
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
381                                 # database.
382                 
383                                 my $http_query_database = $form_data->{'database'};
384                                 my $http_query_confirm  = $form_data->{'confirm'};
385                 
386                                 my @filelist;
387                                 my $pagedata;
389                                 if ($http_query_confirm eq 1){
390                 
391                                         # The action to delete multiple pages from the selected
392                                         # database has been confirmed.
393                 
394                                         @filelist       = kiriwrite_selectedlist($form_data);
395                                         $pagedata       = kiriwrite_page_multidelete($http_query_database, $http_query_confirm, @filelist);
396                 
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.
400                 
401                                 }
402                 
403                                 # Get the list of selected pages and pass them to the
404                                 # multiple page delete subroutine.
405                 
406                                 @filelist       = kiriwrite_selectedlist($form_data);
407                                 $pagedata       = kiriwrite_page_multidelete($http_query_database, $http_query_confirm, @filelist);
408                 
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
416                                 # database.
417                 
418                                 my $http_query_database         = $form_data->{'database'};
419                                 my $http_query_newdatabase      = $form_data->{'newdatabase'};
420                                 my $http_query_confirm          = $form_data->{'confirm'};
421                 
422                                 my @filelist;
423                                 my $pagedata;
424                 
425                                 if ($http_query_confirm){
426                 
427                                         # The action to move multiple pages from the selected
428                                         # database has been confirmed.
429                 
430                                         @filelist       = kiriwrite_selectedlist($form_data);
431                                         $pagedata       = kiriwrite_page_multimove($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
432                 
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.
436                 
437                                 }
438                 
439                                 # Get the list of selected pages and pass them to the
440                                 # multiple page move subroutine.
441                 
442                                 @filelist       = kiriwrite_selectedlist($form_data);
443                                 $pagedata       = kiriwrite_page_multimove($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
444                 
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
452                                 # database.
453                 
454                                 my $http_query_database         = $form_data->{'database'};
455                                 my $http_query_newdatabase      = $form_data->{'newdatabase'};
456                                 my $http_query_confirm          = $form_data->{'confirm'};
457                 
458                                 my @filelist;
459                                 my $pagedata;
460                 
461                                 if ($http_query_confirm){
462                 
463                                         # The action to copy multiple pages from the selected
464                                         # database has been confirmed.
465                 
466                                         @filelist       = kiriwrite_selectedlist($form_data);
467                                         $pagedata       = kiriwrite_page_multicopy($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
468                 
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.
472                 
473                                 }
474                 
475                                 # Get the list of selected pages and pass them to the
476                                 # multiple page copy subroutine.
477                 
478                                 @filelist       = kiriwrite_selectedlist($form_data);
479                                 $pagedata       = kiriwrite_page_multicopy($http_query_database, $http_query_newdatabase, $http_query_confirm, @filelist);
480                 
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
488                                 # database.
489                 
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'};
498                 
499                                 my @filelist;
500                                 my $pagedata;
501                 
502                                 if (!$http_query_confirm){
503                 
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);
506                 
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.
509                                         exit;
510                 
511                                 }
512                 
513                                 # Get the list of selected pages and pass them to the
514                                 # multiple page edit subroutine.
515                 
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);
518                 
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.
523                         } else {
524                                 kiriwrite_error("invalidaction");
525                         }
527                 } else {
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.
531                 
532                         my $pagedata = kiriwrite_page_list();
533                 
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.
538                 }
540         } elsif ($http_query_mode eq "template"){
542                 use Modules::System::Template;
544                 if ($form_data->{'action'}){
545                 
546                         # An action has been specified in the HTTP query.
547                 
548                         my $http_query_action = $form_data->{'action'};
549                 
550                         if ($http_query_action eq "delete"){
551                                 # Get the required parameters from the HTTP query.
552                 
553                                 my $http_query_template = $form_data->{'template'};
554                                 my $http_query_confirm  = $form_data->{'confirm'};
555                 
556                                 # Check if a value for confirm has been specified (it shouldn't)
557                                 # be blank.
558                 
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.
563                 
564                                         my $pagedata = kiriwrite_template_delete($http_query_template);
565                 
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.
569                 
570                                 } else {
571                 
572                                         my $pagedata = kiriwrite_template_delete($http_query_template, $http_query_confirm);
573                 
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.
577                 
578                                 }
579                 
580                         } elsif ($http_query_action eq "add") {
581                 
582                                 # Get the variables from the HTTP query in preperation for processing.
583                 
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'};
589                 
590                                 # Check if there is a confirmed value in the http_query_confirm variable.
591                 
592                                 if (!$http_query_confirm){
593                 
594                                         # Since there is no confirm value, print out a form for creating a new
595                                         # template.
596                 
597                                         my $pagedata = kiriwrite_template_add();
598                 
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.
602                 
603                                 } else {
604                 
605                                         # A value in the http_query_confirm value is specified, so pass the
606                                         # variables onto the kiriwrite_template_add subroutine.
607                 
608                                         my $pagedata = kiriwrite_template_add($http_query_templatefilename, $http_query_templatename, $http_query_templatedescription, $http_query_templatelayout, $http_query_confirm);
609                 
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.
613                 
614                                 }
615                 
616                         } elsif ($http_query_action eq "edit") {
617                 
618                                 # Get the required parameters from the HTTP query.
619                 
620                                 my $http_query_templatefile     = $form_data->{'template'};
621                                 my $http_query_confirm          = $form_data->{'confirm'};
622                 
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.
625                 
626                                 if (!$http_query_confirm){
627                 
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
630                                         # the form.
631                 
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.
636                 
637                                 } elsif ($http_query_confirm eq 1) {
638                 
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.
642                 
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'};
647                 
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.
652                 
653                                 } else {
654                 
655                                         # Another confirm value is there instead of '0' or '1'. Return
656                                         # an error saying it is invalid.
657                 
658                                         kiriwrite_error("invalidvariable");
659                 
660                                 }
661                 
662                         } elsif ($http_query_action eq "view"){
663                 
664                                 # Get the required parameters from the HTTP query.
665                 
666                                 my $http_query_browsenumber     = $form_data->{'browsenumber'};
667                 
668                                 my $pagedata = kiriwrite_template_list($http_query_browsenumber);
669                 
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.
673                 
674                         } else {
675                 
676                                 # Another action was specified and was not one of the ones above, so
677                                 # return an error.
678                 
679                                 kiriwrite_error("invalidaction");
680                 
681                         }
682                 
683                 } else {
684                 
685                         # If the action option is left blank, then print out a form where the list
686                         # of templates are available.
687                 
688                         my $pagedata = kiriwrite_template_list();
689                 
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.
693                 
694                 }
696         } elsif ($http_query_mode eq "filter"){
698                 use Modules::System::Filter;
700                 if ($form_data->{'action'}){
701                 
702                         # There is a value for action in the HTTP query,
703                         # so get the value from it.
704                 
705                         my $http_query_action = $form_data->{'action'};
706                 
707                         if ($http_query_action eq "add"){
708                 
709                                 # The action the user requested is to add a filter to the
710                                 # filter database.
711                 
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.
715                 
716                                 my $http_query_confirm = $form_data->{'confirm'};
717                 
718                                 if ($http_query_confirm){
719                 
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.
723                 
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'};
729                                 
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);
732                 
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.
736                 
737                                 }
738                 
739                                 my $pagedata = kiriwrite_filter_add();
740                 
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.
744                 
745                         } elsif ($http_query_action eq "edit"){
746                 
747                                 # The action the user requested is to edit an filter from
748                                 # the filter database.
749                 
750                                 my $http_query_number   = $form_data->{'filter'};
751                                 my $http_query_confirm  = $form_data->{'confirm'};
752                 
753                                 if ($http_query_confirm){
754                 
755                                         # There is a value in http_query_confirm, so pass on the
756                                         # new find and replace words so that the filter database
757                                         # can be edited.
758                 
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'};
764                 
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 });
766                 
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.
770                 
771                                 }
772                 
773                                 my $pagedata = kiriwrite_filter_edit({ FilterID => $http_query_number });
774                 
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.
778                 
779                         } elsif ($http_query_action eq "delete"){
780                 
781                                 # The action the user requested is to delete an filter
782                                 # from the filter database.
783                 
784                                 my $http_query_number = $form_data->{'filter'};
785                                 my $http_query_confirm = $form_data->{'confirm'};
786                 
787                                 if ($http_query_confirm){
788                 
789                                         my $pagedata = kiriwrite_filter_delete($http_query_number, $http_query_confirm);
790                 
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
794                 
795                                 }
796                 
797                                 my $pagedata = kiriwrite_filter_delete($http_query_number);
798                 
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.
802                 
803                         } elsif ($http_query_action eq "view"){
804                 
805                                 # The action the user requested is to view the list
806                                 # filters on the filter database.
807                 
808                                 my $http_query_browsenumber = $form_data->{'browsenumber'};
809                 
810                                 my $pagedata = kiriwrite_filter_list($http_query_browsenumber);
811                 
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.
815                 
816                         } else {
817                 
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
821                                 # specified.
822                 
823                                 kiriwrite_error("invalidaction");
824                 
825                         }
826                 
827                 } else {
828                 
829                         my $pagedata = kiriwrite_filter_list();
830                 
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.
834                 
835                 }
837         } elsif ($http_query_mode eq "compile"){
839                 use Modules::System::Compile;
841                 if ($form_data->{'action'}){
842                 
843                         my $http_query_action = $form_data->{'action'};
844                 
845                         if ($http_query_action eq "compile"){
846                 
847                                 # The specified action is to compile the pages, check if the
848                                 # action to compile the page has been confirmed.
849                 
850                                 my $http_query_confirm  = $form_data->{'confirm'};
851                                 my $http_query_type     = $form_data->{'type'};
852                 
853                                 # If it is blank, set the confirm value to 0.
854                 
855                                 if (!$http_query_confirm){
856                 
857                                         # The http_query_confirm variable is uninitalised, so place a
858                                         # '0' (meaning an unconfirmed action).
859                 
860                                         $http_query_confirm = 0;
861                 
862                                 }
863                 
864                                 # If the compile type is blank then return an error.
865                 
866                                 if (!$http_query_type){
867                 
868                                         # Compile type is blank so return an error.
869                 
870                                         kiriwrite_error("blankcompiletype");
871                 
872                                 }
873                 
874                                 if ($http_query_type eq "multiple"){
875                 
876                                         if ($http_query_confirm eq 1){
877                 
878                                                 # The action to compile the pages has been confirmed so
879                                                 # compile the pages.
880                 
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.
893                 
894                                         } else {
895                 
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);
904                 
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.
908                 
909                                         }
910                 
911                                 } elsif ($http_query_type eq "single"){
912                 
913                                         my $http_query_database         = $form_data->{'database'};
914                                         my $http_query_outputmodule     = $form_data->{'outputmodule'};
915                                         my @selectedlist;
916                                         $selectedlist[0] = $http_query_database;
917                                         my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, "", "", $http_query_outputmodule, @selectedlist);
918                 
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.
922                 
923                                 } else {
924                 
925                                         kiriwrite_error("invalidcompiletype");
926                 
927                                 }
928                 
929                         } elsif ($http_query_action eq "all"){
930                 
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.
934                 
935                                 my $http_query_confirm          = $form_data->{'confirm'};
936                                 my $http_query_outputmodule     = $form_data->{'outputmodule'};
937                 
938                                 if (!$http_query_confirm){
939                 
940                                         # The http_query_confirm variable is uninitalised, so place a
941                                         # '0' (meaning an unconfirmed action).
942                 
943                                         $http_query_confirm = 0;
944                 
945                                 }
946                 
947                                 my $pagedata = kiriwrite_compile_all($http_query_outputmodule);
948                 
949                                 kiriwrite_output_header;                        # Output the header to browser/console/stdout.
950                                 kiriwrite_output_page($kiriwrite_lang{compile}{compilealldatabases}, $pagedata, "compile");
951                                 exit;
952                 
953                         } elsif ($http_query_action eq "clean") {
954                 
955                                 # The selected action is to clean the output directory.
956                                 # Check if the action to clean the output directory
957                                 # has been confirmed.
958                 
959                                 my $http_query_confirm = $form_data->{'confirm'};
960                 
961                                 if (!$http_query_confirm){
962                 
963                                         # The http_query_confirm variable is uninitalised, so place a
964                                         # '0' (meaning an unconfirmed action).
965                 
966                                         $http_query_confirm = 0;
967                 
968                                 }
969                 
970                                 if ($http_query_confirm eq 1){
971                 
972                                         # The action to clean the output directory has been confirmed.
973                 
974                                         my $pagedata = kiriwrite_compile_clean($http_query_confirm);
975                 
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.
979                         
980                                 }
981                 
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.
985                 
986                                 my $pagedata = kiriwrite_compile_clean();
987                 
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.
991                 
992                         } else {
993                 
994                                 # The action specified was something else other than those
995                                 # above, so return an error.
996                 
997                                 kiriwrite_error("invalidaction");
998                 
999                         }
1000                 }
1001                 
1002                 my $pagedata = kiriwrite_compile_list();
1003                 
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.
1007                 
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'};
1014                 
1015                         if ($http_query_action eq "edit"){
1016                 
1017                                 # The action specified is to edit the settings. Check if the action
1018                                 # to edit the settings has been confirmed.
1019                 
1020                                 my $http_query_confirm = $form_data->{'confirm'};
1021                 
1022                                 if (!$http_query_confirm){
1023                 
1024                                         # The confirm value is blank, so set it to 0.
1025                 
1026                                         $http_query_confirm = 0;
1027                 
1028                                 }
1029                 
1030                                 if ($http_query_confirm eq 1){
1031                 
1032                                         # The action to edit the settings has been confirmed. Get the
1033                                         # required settings from the HTTP query.
1034                 
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'};
1048                 
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'};
1057                 
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 });
1059                 
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.
1063                 
1064                                 }
1065                 
1066                                 # The action to edit the settings has not been confirmed.
1067                 
1068                                 my $pagedata = kiriwrite_settings_edit();
1069                 
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.
1073                 
1074                         } else {
1075                 
1076                                 # The action specified was something else other than those
1077                                 # above, so return an error.
1078                 
1079                                 kiriwrite_error("invalidaction");
1080                 
1081                         }
1082                 
1083                 }
1084                 
1085                 # No action has been specified, so print out the list of settings currently being used.
1086                 
1087                 my $pagedata = kiriwrite_settings_view();
1088                 
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.
1093         } else {
1095                 # An invalid mode has been specified so return
1096                 # an error.
1098                 kiriwrite_error("invalidmode");
1100         }
1101         
1102 } else {
1104         # No mode has been specified, so print the default "first-run" view of the
1105         # database list.
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.               
1117 __END__
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy