Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Changes made in preperation for Kiriwrite 0.4.0
[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.4.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, $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.
45 use lib '.';
46 chdir('.');
48 # Load the common functions module.
50 use Modules::System::Common;
52 # Setup the version information for Kiriwrite.
54 %kiriwrite_version = (
55         "major"         => 0,
56         "minor"         => 4,
57         "revision"      => 0
58 );
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'};
81         
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.
85                 
86                                 if ($form_data->{'database'}){
87                                         # If there is a value in the database variable check if it is a valid database. Otherwise,
88                                         # return an error.
89                 
90                                         my $http_query_database = $form_data->{'database'};
91                                 
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.
94                 
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.
98                 
99                                                 my $http_query_confirm = $form_data->{'confirm'};
100                 
101                                                 if ($http_query_confirm eq 1){
102                                                         # Value is correct, collect the variables to pass onto the database variable.
103                 
104                                                         # Get the variables from the HTTP query.
105                 
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'};
112                 
113                                                         # Pass the variables to the database editing subroutine.
114                 
115                                                         my $pagedata = kiriwrite_database_edit($databaseshortname, $newdatabasefilename, $newdatabasename, $newdatabasedescription, $databasenotes, $databasecategories, 1);
116                 
117                                                         kiriwrite_output_header;
118                                                         kiriwrite_output_page($kiriwrite_lang{database}{editdatabasetitle}, $pagedata, "database");
119                                                         exit;
120                 
121                                                 } else {
122                                                         # Value is incorrect, return and error.
123                                                         kiriwrite_error("invalidvariable");
124                                                 } 
125                 
126                                         }
127                 
128                                         # Display the form for editing an database.
129                                         my $pagedata = kiriwrite_database_edit($http_query_database);
130                 
131                                         kiriwrite_output_header;
132                                         kiriwrite_output_page($kiriwrite_lang{database}{editdatabasetitle}, $pagedata, "database");
133                                         exit;
134                 
135                                 } else {
136                 
137                                         # If there is no value in the database variable, then return an error.
138                                         kiriwrite_error("invalidvariable");
139                 
140                                 }
141                 
142                         } elsif ($http_query_action eq "delete"){
143                 
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.
146                 
147                                 if ($form_data->{'confirm'}){
148                 
149                                         # User has confirmed to delete a database, pass the parameters to the kiriwrite_database_delete
150                                         # subroutine.
151                 
152                                         my $database_filename   = $form_data->{'database'};
153                                         my $database_confirm    = $form_data->{'confirm'};
154                                         my $pagedata = kiriwrite_database_delete($database_filename, $database_confirm);
155                 
156                                         kiriwrite_output_header;
157                                         kiriwrite_output_page($kiriwrite_lang->{database}->{deleteddatabase}, $pagedata, "database");
158                 
159                                         exit;
160                 
161                                 }
162                 
163                                 # User has clicked on the delete link (thus hasn't confirmed the action to delete a database).
164                 
165                                 my $database_filename = $form_data->{'database'};
166                                 my $pagedata = kiriwrite_database_delete($database_filename);
167                 
168                                 kiriwrite_output_header;
169                                 kiriwrite_output_page($kiriwrite_lang->{database}->{deletedatabase}, $pagedata, "database");
170                 
171                                 exit;
172                 
173                         } elsif ($http_query_action eq "new"){
174                 
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
177                                 # database.
178                 
179                                 my $http_query_confirm = $form_data->{'confirm'};
180                 
181                                 # Check if the confirm value is correct.
182                 
183                                 if ($http_query_confirm){
184                                         if ($http_query_confirm eq 1){
185                 
186                                                 # User has confirmed to create a database, pass the parameters to the 
187                                                 # kiriwrite_database_add subroutine.
188                 
189                                                 my $http_query_confirm = $form_data->{'confirm'};
190                 
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'};
196                 
197                                                 my $pagedata = kiriwrite_database_add($database_filename, $database_name, $database_description, $database_notes, $database_categories, $http_query_confirm);
198                 
199                                                 kiriwrite_output_header;
200                                                 kiriwrite_output_page($kiriwrite_lang{database}{adddatabase}, $pagedata, "database");
201                                                 exit;
202                 
203                                         } else {
204                 
205                                                 # The confirm value is something else other than 1 (which it shouldn't be), so
206                                                 # return an error.
207                 
208                                         }
209                                 }
210         
211                                 # User has clicked on the 'Add Database' link.
212         
213                                 my $pagedata = kiriwrite_database_add();
214         
215                                 kiriwrite_output_header;
216                                 kiriwrite_output_page($main::kiriwrite_lang{database}{adddatabase}, $pagedata, "database");
217                                 exit;
218         
219                         } else {
220                                 # Another option has been specified, so return an error.
221         
222                                 kiriwrite_error("invalidaction");
223                         }
225                 } else {
227                         # No action has been specified, do the default action of displaying a list
228                         # of databases.
229                 
230                         my $pagedata = kiriwrite_database_list();
231                 
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.
236                 }
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'};
244                 
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"){
249                 
250                                 # The action selected was to view pages from a database, 
251                 
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);
255                 
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.
259                 
260                         } elsif ($http_query_action eq "add"){
261                 
262                                 # The action selected was to add a page to the selected database.
263                 
264                                 my $http_query_confirm  = $form_data->{'confirm'};
265                 
266                                 if (!$http_query_confirm){
267                 
268                                         $http_query_confirm = 0;
269                 
270                                 }
271                 
272                                 if ($http_query_confirm eq 1){
273                 
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'};
282                         
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);
284                 
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.
288                 
289                                 }
290                 
291                                 my $http_query_database = $form_data->{'database'};
292                                 my $pagedata            = kiriwrite_page_add($http_query_database);
293                 
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.
297                 
298                         }  elsif ($http_query_action eq "edit"){
299                                 
300                                 # The action selected was to edit a page from a database.
301                 
302                                 my $http_query_confirm = $form_data->{'confirm'};
303                 
304                                 if (!$http_query_confirm){
305                 
306                                         $http_query_confirm = 0;
307                 
308                                 }
309                 
310                                 if ($http_query_confirm eq 1){
311                 
312                                         # Get the needed values from the HTTP query.
313                 
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'};
323                 
324                                         # Pass the values to the editing pages subroutine.
325                 
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);
327                 
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.
331                 
332                                 }
333                 
334                                 # Get the needed values from the HTTP query.
335                 
336                                 my $http_query_database = $form_data->{'database'};
337                                 my $http_query_filename = $form_data->{'page'};
338                 
339                                 # Pass the values to the editing pages subroutine.
340                 
341                                 my $pagedata = kiriwrite_page_edit($http_query_database, $http_query_filename);
342                 
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.
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                 
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);
886                 
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.
890                 
891                                         } else {
892                 
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.
896                 
897                                                 my @selectedlist = kiriwrite_selectedlist($form_data);
898                                                 my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, "", "", @selectedlist);
899                 
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.
903                 
904                                         }
905                 
906                                 } elsif ($http_query_type eq "single"){
907                 
908                                         my $http_query_database = $form_data->{'database'};
909                                         my @selectedlist;
910                                         $selectedlist[0] = $http_query_database;
911                                         my $pagedata = kiriwrite_compile_makepages($http_query_type, $http_query_confirm, "", "", @selectedlist);
912                 
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.
916                 
917                                 } else {
918                 
919                                         kiriwrite_error("invalidcompiletype");
920                 
921                                 }
922                 
923                         } elsif ($http_query_action eq "all"){
924                 
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.
928                 
929                                 my $http_query_confirm = $form_data->{'confirm'};
930                 
931                                 if (!$http_query_confirm){
932                 
933                                         # The http_query_confirm variable is uninitalised, so place a
934                                         # '0' (meaning an unconfirmed action).
935                 
936                                         $http_query_confirm = 0;
937                 
938                                 }
939                 
940                                 if ($http_query_confirm eq 1){
941                 
942                                         # The action to compile all the databases has been confirmed.
943                 
944                                 }
945                 
946                                 my $pagedata = kiriwrite_compile_all();
947                 
948                                 kiriwrite_output_header;                        # Output the header to browser/console/stdout.
949                                 kiriwrite_output_page($kiriwrite_lang{compile}{compilealldatabases}, $pagedata, "compile");
950                                 exit;
951                 
952                         } elsif ($http_query_action eq "clean") {
953                 
954                                 # The selected action is to clean the output directory.
955                                 # Check if the action to clean the output directory
956                                 # has been confirmed.
957                 
958                                 my $http_query_confirm = $form_data->{'confirm'};
959                 
960                                 if (!$http_query_confirm){
961                 
962                                         # The http_query_confirm variable is uninitalised, so place a
963                                         # '0' (meaning an unconfirmed action).
964                 
965                                         $http_query_confirm = 0;
966                 
967                                 }
968                 
969                                 if ($http_query_confirm eq 1){
970                 
971                                         # The action to clean the output directory has been confirmed.
972                 
973                                         my $pagedata = kiriwrite_compile_clean($http_query_confirm);
974                 
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.
978                         
979                                 }
980                 
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.
984                 
985                                 my $pagedata = kiriwrite_compile_clean();
986                 
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.
990                 
991                         } else {
992                 
993                                 # The action specified was something else other than those
994                                 # above, so return an error.
995                 
996                                 kiriwrite_error("invalidaction");
997                 
998                         }
999                 }
1000                 
1001                 my $pagedata = kiriwrite_compile_list();
1002                 
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.
1006                 
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'};
1013                 
1014                         if ($http_query_action eq "edit"){
1015                 
1016                                 # The action specified is to edit the settings. Check if the action
1017                                 # to edit the settings has been confirmed.
1018                 
1019                                 my $http_query_confirm = $form_data->{'confirm'};
1020                 
1021                                 if (!$http_query_confirm){
1022                 
1023                                         # The confirm value is blank, so set it to 0.
1024                 
1025                                         $http_query_confirm = 0;
1026                 
1027                                 }
1028                 
1029                                 if ($http_query_confirm eq 1){
1030                 
1031                                         # The action to edit the settings has been confirmed. Get the
1032                                         # required settings from the HTTP query.
1033                 
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'};
1046                 
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'};
1055                 
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 });
1057                 
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.
1061                 
1062                                 }
1063                 
1064                                 # The action to edit the settings has not been confirmed.
1065                 
1066                                 my $pagedata = kiriwrite_settings_edit();
1067                 
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.
1071                 
1072                         } else {
1073                 
1074                                 # The action specified was something else other than those
1075                                 # above, so return an error.
1076                 
1077                                 kiriwrite_error("invalidaction");
1078                 
1079                         }
1080                 
1081                 }
1082                 
1083                 # No action has been specified, so print out the list of settings currently being used.
1084                 
1085                 my $pagedata = kiriwrite_settings_view();
1086                 
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.
1091         } else {
1093                 # An invalid mode has been specified so return
1094                 # an error.
1096                 kiriwrite_error("invalidmode");
1098         }
1099         
1100 } else {
1102         # No mode has been specified, so print the default "first-run" view of the
1103         # database list.
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.               
1115 __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