Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Changes made in preperation for Kiriwrite 0.4.0
[kiriwrite/.git] / cgi-files / Modules / System / Filter.pm
1 package Modules::System::Filter;
3 use Modules::System::Common;
4 use strict;
5 use warnings;
6 use Exporter;
8 our @ISA = qw(Exporter);
9 our @EXPORT = qw(kiriwrite_filter_list kiriwrite_filter_add kiriwrite_filter_edit kiriwrite_filter_delete);
11 sub kiriwrite_filter_list{
12 #################################################################################
13 # kiriwrite_filter_list: Lists the filters that will be used when compiling a   #
14 # webpage.                                                                      #
15 #                                                                               #
16 # Usage:                                                                        #
17 #                                                                               #
18 # kiriwrite_filter_list([browsenumber]);                                        #
19 #                                                                               #
20 # browsenumber  Specifies the page browse number to use.                        #
21 #################################################################################
23         my $filter_browsenumber = shift;
25         my $filtersdb_notexist = 0;
27         # Connect to the database server.
29         $main::kiriwrite_dbmodule->connect();
31         # Check if any errors occured while connecting to the database server.
33         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
35                 # A database connection error has occured so return
36                 # an error.
38                 kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
40         }
42         # Connect to the filter database.
44         $main::kiriwrite_dbmodule->connectfilter();
46         # Check if any error has occured while connecting to the filter
47         # database.
49         if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){
51                 # The filter database does not exist.
53                 $filtersdb_notexist = 1;
55         } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){
57                 # The filter database has invalid permissions set so return
58                 # an error.
60                 kiriwrite_error("filtersdbpermissions");
62         } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
64                 # A database error has occured with the filter database.
66                 kiriwrite_error("filtersdbdatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
68         }
70         # Define some variables required for processing the filters list.
72         my %filter_list;
73         my %filter_info;
74         my @database_filters;
75         my $blankfindfilter = 0;
76         my $filterswarning = "";
77         my $filter;
78         my $filter_split = $main::kiriwrite_config{"display_filtercount"};
79         my $filter_list = 0;
80         my $filter_count = 0;
81         my $filter_style = 0;
82         my $filter_list_count = 0;
83         my $filter_total_count;
84         my $filter_style_name = "";
86         tie(%filter_list, 'Tie::IxHash');
88         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{viewfilters}, { Style => "pageheader" });
89         $main::kiriwrite_presmodule->addlinebreak();
90         $main::kiriwrite_presmodule->addlinebreak();
92         # If the filter database exists then get the list of filters,
93         # otherwise write a message saying that the filter database
94         # does not exist and will be created when a filter is added.
96         if ($filtersdb_notexist eq 0){
98                 if (!$filter_browsenumber || $filter_browsenumber eq 0){
100                         $filter_browsenumber = 1;
102                 }
104                 # Check if the filter browse number is valid and if it isn't
105                 # then return an error.
107                 my $kiriwrite_browsenumber_length_check         = kiriwrite_variablecheck($filter_browsenumber, "maxlength", 7, 1);
108                 my $kiriwrite_browsenumber_number_check         = kiriwrite_variablecheck($filter_browsenumber, "numbers", 0, 1);
110                 if ($kiriwrite_browsenumber_length_check eq 1){
112                         # The browse number was too long so return
113                         # an error.
115                         kiriwrite_error("browsenumbertoolong");
117                 }
119                 if ($kiriwrite_browsenumber_number_check eq 1){
121                         # The browse number wasn't a number so
122                         # return an error.
124                         kiriwrite_error("browsenumberinvalid");
126                 }
128                 # Get the total count of filters in the filter database.
130                 my $filter_total_count  = $main::kiriwrite_dbmodule->getfiltercount();
132                 # Check if any errors occured while getting the count of filters.
134                 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
136                         # A database error has occured with the filter database.
138                         kiriwrite_error("filtersdbdatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
140                 }
142                 if ($filter_total_count ne 0){
144                         if ($filter_total_count eq $filter_split){
146                                 $filter_list = int(($filter_total_count / $filter_split));
148                         } else {
150                                 $filter_list = int(($filter_total_count / $filter_split) + 1);
152                         }
154                 }
156                 my $start_from = ($filter_browsenumber - 1) * $filter_split;
158                 # Get the list of available filters.
160                 @database_filters       = $main::kiriwrite_dbmodule->getfilterlist({ StartFrom => $start_from, Limit => $filter_split });
162                 # Check if any errors occured while getting the list of filters.
164                 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
166                         # A database error has occured with the filter database.
168                         kiriwrite_error("filtersdbdatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
170                 }
172                 # Process each filter getting the priority, find setting and
173                 # replace setting.
175                 foreach $filter (@database_filters){
177                         # Get the information about the filter.
179                         %filter_info = $main::kiriwrite_dbmodule->getfilterinfo({ FilterID => $filter });
181                         # Check if any errors occured while getting the filter information.
183                         if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
185                                 # A database error occured while using the filter database.
187                                 kiriwrite_error("filtersdbdatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
189                         } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDoesNotExist"){
191                                 # The filter does not exist so process the next filter.
193                                 next;
195                         }
197                         # Check if the find filter is blank.
199                         if (!$filter_info{"FilterFind"}){
201                                 # The find filter is blank, so set the value to write a warning
202                                 # message saying that a find filter given is blank.
204                                 $blankfindfilter = 1;
206                         }
208                         $filter_list{$filter_count}{ID}         = $filter_info{"FilterID"};
209                         $filter_list{$filter_count}{Priority}   = $filter_info{"FilterPriority"};
210                         $filter_list{$filter_count}{Find}       = $filter_info{"FilterFind"};
211                         $filter_list{$filter_count}{Replace}    = $filter_info{"FilterReplace"};
212                         $filter_list{$filter_count}{Enabled}    = $filter_info{"FilterEnabled"};
213                         $filter_list{$filter_count}{Notes}      = $filter_info{"FilterNotes"};
215                         $filter_count++;
217                 }
219                 # Check if there are filters in the filter database and
220                 # write a message if there isn't.
222         }
224         # Check if the database wasn't found and if it
225         # wasn't then write a message saying that the
226         # database will be created when a filter is
227         # added.
229         if ($filtersdb_notexist eq 1){
231                 # The filter database doesn't exist so write
232                 # a message.
234                 $main::kiriwrite_presmodule->clear();
235                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{viewfilters}, { Style => "pageheader" });
236                 $main::kiriwrite_presmodule->addlinebreak();
237                 $main::kiriwrite_presmodule->addlinebreak();
238                 $main::kiriwrite_presmodule->startbox("errorbox");
239                 $main::kiriwrite_presmodule->enterdata($main::kiriwrite_lang{filter}{filterdatabasedoesnotexist});
240                 $main::kiriwrite_presmodule->endbox();
242                 # Disconnect from the filter database.
244                 $main::kiriwrite_dbmodule->disconnectfilter();
246                 # Disconnect from the database server.
248                 $main::kiriwrite_dbmodule->disconnect();
249                 return $main::kiriwrite_presmodule->grab();
251         }
253         # Check if there is a warning message and if
254         # there is then write that warning message
255         # else write the list of filters.
257         if ($filterswarning){
259                 $main::kiriwrite_presmodule->startbox("errorbox");
260                 $main::kiriwrite_presmodule->addtext($filterswarning);
261                 $main::kiriwrite_presmodule->endbox();
263         } elsif ($filter_count) {
265                 # The filter database exists so write out the
266                 # list of filters.
268                 if ($blankfindfilter eq 1){
270                         $main::kiriwrite_presmodule->addboldtext($main::kiriwrite_lang{filter}{warningtitle});
271                         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{blankfindfilters});
272                         $main::kiriwrite_presmodule->addtext();
273                         $main::kiriwrite_presmodule->addlinebreak();
274                         $main::kiriwrite_presmodule->addlinebreak();
276                 }
278                 # Start a form for using the filter browsing list with.
280                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "GET");
281                 $main::kiriwrite_presmodule->addhiddendata("mode", "filter");
283                 # Write out the filter browsing list.
285                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{showlistpage});
286                 $main::kiriwrite_presmodule->addselectbox("browsenumber");
288                 # Write out the list of available pages to browse.
289                 
290                 while ($filter_list_count ne $filter_list){
292                         $filter_list_count++;
294                         if ($filter_list_count eq 1 && !$filter_browsenumber){
296                                 $main::kiriwrite_presmodule->addoption($filter_list_count, { Value => $filter_list_count, Selected => 1 });
298                         } else {
300                                 if ($filter_browsenumber eq $filter_list_count){
302                                         $main::kiriwrite_presmodule->addoption($filter_list_count, { Value => $filter_list_count, Selected => 1 });
304                                 } else {
306                                         $main::kiriwrite_presmodule->addoption($filter_list_count, { Value => $filter_list_count });
308                                 }
310                         }
312                 }
314                 $main::kiriwrite_presmodule->endselectbox();
315                 $main::kiriwrite_presmodule->addbutton("action", { Value => "view", Description => $main::kiriwrite_lang{filter}{show} });
317                 if ($filter_list ne $filter_browsenumber){
319                         $main::kiriwrite_presmodule->addtext(" | ");
320                         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=filter&action=view&browsenumber=" . ($filter_browsenumber + 1), { Text => $main::kiriwrite_lang{filter}{nextpage} });
322                 }
324                 # Check if the filter browse number is not blank and
325                 # not set as 0 and hide the Previous page link if
326                 # it is.
328                 if ($filter_browsenumber > 1){
330                         $main::kiriwrite_presmodule->addtext(" | ");
331                         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=filter&action=view&browsenumber=" . ($filter_browsenumber - 1), { Text => $main::kiriwrite_lang{filter}{previouspage} });
333                 }
335                 $main::kiriwrite_presmodule->addlinebreak();
336                 $main::kiriwrite_presmodule->addlinebreak();
338                 $main::kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
340                 $main::kiriwrite_presmodule->startheader();
341                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{filter}{priority}, { Style => "tablecellheader" });
342                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{filter}{findsetting}, { Style => "tablecellheader" });
343                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{filter}{replacesetting}, { Style => "tablecellheader" });
344                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{options}, { Style => "tablecellheader" });
345                 $main::kiriwrite_presmodule->endheader();
347                 foreach $filter (keys %filter_list){
349                         # Check which style should be used.
351                         if ($filter_style eq 0){
353                                 $filter_style_name = "tablecell1";
354                                 $filter_style = 1;
356                         } else {
358                                 $filter_style_name = "tablecell2";
359                                 $filter_style = 0;
361                         }
363                         # Check if the filter is disabled.
365                         if (!$filter_list{$filter}{Enabled}){
367                                 $filter_style_name = "tablecelldisabled";
369                         }
371                         $main::kiriwrite_presmodule->startrow();
372                         $main::kiriwrite_presmodule->addcell($filter_style_name);
373                         $main::kiriwrite_presmodule->addtext($filter_list{$filter}{Priority});
374                         $main::kiriwrite_presmodule->endcell();
375                         $main::kiriwrite_presmodule->addcell($filter_style_name);
377                         # Check if the find filter is blank.
379                         if (!$filter_list{$filter}{Find}){
381                                 # The find filter is blank.
383                                 $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{filter}{blankfindsetting});
385                         } else {
387                                 # The find filter is not blank.
389                                 $main::kiriwrite_presmodule->addtext($filter_list{$filter}{Find});
391                         }
393                         $main::kiriwrite_presmodule->endcell();
394                         $main::kiriwrite_presmodule->addcell($filter_style_name);
396                         # Check if the replace filter is blank.
398                         if (!$filter_list{$filter}{Replace}){
400                                 # The replace filter is blank.
402                                 $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{filter}{blankreplacesetting});
404                         } else {
406                                 # The replace filter is not blank.
408                                 $main::kiriwrite_presmodule->addtext($filter_list{$filter}{Replace});
410                         }
412                         $main::kiriwrite_presmodule->endcell();
413                         $main::kiriwrite_presmodule->addcell($filter_style_name);
414                         $main::kiriwrite_presmodule->addlink("?mode=filter&action=edit&filter=" . $filter_list{$filter}{ID}, { Text => $main::kiriwrite_lang{options}{edit} });
415                         $main::kiriwrite_presmodule->addlink("?mode=filter&action=delete&filter=" . $filter_list{$filter}{ID}, { Text => $main::kiriwrite_lang{options}{delete} });
416                         $main::kiriwrite_presmodule->endcell();
417                         $main::kiriwrite_presmodule->endrow();
419                 }
421                 $main::kiriwrite_presmodule->endtable();
422                 $main::kiriwrite_presmodule->endform();
424         }
426         if (!$filter_total_count){
428                 $filter_total_count = "";
430         }
432         if ($filter_browsenumber > 1 && !@database_filters){
434                 # There were no values given for the page browse
435                 # number given so write a message saying that
436                 # there were no pages for the page browse number
437                 # given.
439                 $main::kiriwrite_presmodule->clear();
440                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{viewfilters}, { Style => "pageheader" });
441                 $main::kiriwrite_presmodule->addlinebreak();
442                 $main::kiriwrite_presmodule->addlinebreak();
443                 $main::kiriwrite_presmodule->startbox("errorbox");
444                 $main::kiriwrite_presmodule->enterdata($main::kiriwrite_lang{filter}{nofiltersinpagebrowse});
445                 $main::kiriwrite_presmodule->addlinebreak();
446                 $main::kiriwrite_presmodule->addlinebreak();
447                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=filter", { Text => $main::kiriwrite_lang{filter}{returntofirstpagebrowse} });
448                 $main::kiriwrite_presmodule->endbox();
450         } elsif (!@database_filters || !$filter_count || $filter_total_count eq 0){
452                 # There are no filters in the filter database.
454                 $main::kiriwrite_presmodule->clear();
455                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{filter}{viewfilters}), { Style => "pageheader" });
456                 $main::kiriwrite_presmodule->addlinebreak();
457                 $main::kiriwrite_presmodule->addlinebreak();
458                 $main::kiriwrite_presmodule->startbox("errorbox");
459                 $main::kiriwrite_presmodule->enterdata($main::kiriwrite_lang{filter}{nofiltersavailable});
460                 $main::kiriwrite_presmodule->endbox();
462         }
464         # Disconnect from the filter database.
466         $main::kiriwrite_dbmodule->disconnectfilter();
468         # Disconnect from the database server.
470         $main::kiriwrite_dbmodule->disconnect();
472         return $main::kiriwrite_presmodule->grab();
476 sub kiriwrite_filter_add{
477 #################################################################################
478 # kiriwrite_filter_add: Adds a filter to the filter list.                       #
479 #                                                                               #
480 # Usage:                                                                        #
481 #                                                                               #
482 # kiriwrite_filter_add(options);                                                #
483 #                                                                               #
484 # options       Specifies the following options as a hash (in any order).       #
485 #                                                                               #
486 # FindFilter    Specifies the find filter setting.                              #
487 # ReplaceFilter Specifies the replace filter setting.                           #
488 # Priority      Specifies the priority of the filter.                           #
489 # Enabled       Specifies if the filter should be enabled.                      #
490 # Notes         Specifies some notes about the filter.                          #
491 # Confirm       Specifies if the filter should be added.                        #
492 #################################################################################
494         # Get the values that have been passed to the subroutine.
496         my ($options) = @_;
498         my $confirm     = $options->{"Confirm"};
500         # Check the confirm value to make sure it is no more than
501         # one character long.
503         kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
505         if (!$confirm){
507                 # The confirm value is undefined, so set the
508                 # value of the confirm integer to '0'.
510                 $confirm = 0;
512         }
514         if ($confirm eq 1){
516                 # The confirm integer is '1', so add the word
517                 # to the filter list.
519                 # Get the values from the hashref.
521                 my $filter_new_find     = $options->{"FindFilter"};
522                 my $filter_new_replace  = $options->{"ReplaceFilter"};
523                 my $filter_new_priority = $options->{"Priority"};
524                 my $filter_new_enabled  = $options->{"Enabled"};
525                 my $filter_new_notes    = $options->{"Notes"};
527                 # First, check the variables recieved are UTF8
528                 # copliant.
530                 kiriwrite_variablecheck($filter_new_find, "utf8", 0, 0);
531                 kiriwrite_variablecheck($filter_new_replace, "utf8", 0, 0);
532                 kiriwrite_variablecheck($filter_new_priority, "utf8", 0, 0);
533                 kiriwrite_variablecheck($filter_new_notes, "utf8", 0, 0);
535                 # Convert the UTF8 values so that the length can
536                 # checked properly.
538                 $filter_new_find        = kiriwrite_utf8convert($filter_new_find);
539                 $filter_new_replace     = kiriwrite_utf8convert($filter_new_replace);
540                 $filter_new_priority    = kiriwrite_utf8convert($filter_new_priority);
541                 $filter_new_notes       = kiriwrite_utf8convert($filter_new_notes);
543                 # Check if the find filter is blank and return an error
544                 # if it is.
546                 if (!$filter_new_find){
548                         # The find filter given is blank so return an
549                         # error.
551                         kiriwrite_error("blankfindfilter");
553                 }
555                 if (!$filter_new_priority){
557                         # The filter priority is blank so set it
558                         # to 1.
560                         $filter_new_priority = 1;
562                 }
564                 # Check if the enabled value is either "on" or
565                 # blank and return an error if it is something
566                 # else.
568                 if (!$filter_new_enabled || $filter_new_enabled ne "off"){
570                 } else {
572                         # FINISH THIS.
574                 }
576                 # Check if the new filter should be enabled.
578                 my $filter_enable = 0;
580                 if (!$filter_new_enabled){
582                         $filter_new_enabled = "off";
584                 }
586                 if ($filter_new_enabled eq "on"){
587                         
588                         # The filter is enabled.
590                         $filter_enable = 1;
592                 }
594                 # Check the length and contents of the values given
595                 # to make sure they are valid.
597                 my $filterfind_maxlength_check          = kiriwrite_variablecheck($filter_new_find, "maxlength", 1024, 1);
598                 my $filterreplace_maxlength_check       = kiriwrite_variablecheck($filter_new_replace, "maxlength", 1024, 1);
599                 my $filterpriority_maxlength_check      = kiriwrite_variablecheck($filter_new_priority, "maxlength", 5, 1);
600                 my $filterpriority_numbers_check        = kiriwrite_variablecheck($filter_new_priority, "numbers", 0, 1);
602                 # Check if the result of the tests to see if they
603                 # are valid.
605                 if ($filterfind_maxlength_check eq 1){
607                         # The find filter is too long, so return
608                         # an error.
610                         kiriwrite_error("findfiltertoolong");
612                 }
614                 if ($filterreplace_maxlength_check eq 1){
616                         # The replace filter is too long, so
617                         # return an error.
619                         kiriwrite_error("replacefiltertoolong");
621                 }
623                 if ($filterpriority_maxlength_check eq 1){
625                         # The length of the filter priority
626                         # given is too long, so return an
627                         # error.
629                         kiriwrite_error("filterprioritytoolong");
631                 }
633                 if ($filterpriority_numbers_check eq 1){
635                         # The priority of the filter given
636                         # contains characters other than
637                         # numbers.
639                         kiriwrite_error("filterpriorityinvalidchars");
641                 }
643                 # Check if the filter priority is less than 1
644                 # and more than 10000 and return an error
645                 # if it is.
647                 if ($filter_new_priority < 1 || $filter_new_priority > 50000){
649                         # The filter priority is less than 1 and
650                         # more than 10000, so return an error.
652                         kiriwrite_error("filterpriorityinvalid");
654                 }
656                 # Connect to the database server.
658                 $main::kiriwrite_dbmodule->connect();
660                 # Check if any errors occured while connecting to the database server.
662                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
664                         # A database connection error has occured so return
665                         # an error.
667                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
669                 }
671                 # Connect to the filter database.
673                 $main::kiriwrite_dbmodule->connectfilter(1);
675                 # Check if any error has occured while connecting to the filter
676                 # database.
678                 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){
680                         # The filter database does not exist.
682                         kiriwrite_error("filtersdbmissing");
684                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){
686                         # The filter database has invalid permissions set so return
687                         # an error.
689                         kiriwrite_error("filtersdbpermissions");
691                 }
693                 # Add the filter to the filter database.
695                 $main::kiriwrite_dbmodule->addfilter({ FindFilter => $filter_new_find, ReplaceFilter => $filter_new_replace, Priority => $filter_new_priority, Enabled => $filter_enable, Notes => $filter_new_notes});
697                 # Check if any errors have occured while adding the filter.
699                 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){
701                         # The filter database has invalid permissions set so return
702                         # an error.
704                         kiriwrite_error("filtersdbpermissions");
706                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseUncreatable"){
708                         # The filter database is uncreatable so return an error.
710                         kiriwrite_error("filterdatabase");
712                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
714                         # A database error with the filter database has occured so return
715                         # an error with the extended error information.
717                         kiriwrite_error("filtersdbdatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
719                 }
721                 # Disconnect from the filter database.
723                 $main::kiriwrite_dbmodule->disconnectfilter();
725                 # Disconnect from the database server.
727                 $main::kiriwrite_dbmodule->disconnect();
729                 # Write out a message saying that the filter was added to the
730                 # filter database.
732                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{filteradded}, { Style => "pageheader" });
733                 $main::kiriwrite_presmodule->addlinebreak();
734                 $main::kiriwrite_presmodule->addlinebreak();
735                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{filteraddedmessage});
736                 $main::kiriwrite_presmodule->addlinebreak();
737                 $main::kiriwrite_presmodule->addlinebreak();
738                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=filter", { Text => $main::kiriwrite_lang{filter}{returnfilterlist} });
740                 return $main::kiriwrite_presmodule->grab();
742         } elsif ($confirm ne 0) {
744                 # The confirm integer is another value (which
745                 # it shouldn't be) so return an error.
747                 kiriwrite_error("invalidvalue");
749         }
751         # The confirm integer was blank so print out a form
752         # for adding a new filter.
754         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{addfilter}, { Style => "pageheader" });
755         $main::kiriwrite_presmodule->addlinebreak();
756         $main::kiriwrite_presmodule->addlinebreak();
757         $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
758         $main::kiriwrite_presmodule->startbox();
759         $main::kiriwrite_presmodule->addhiddendata("mode", "filter");
760         $main::kiriwrite_presmodule->addhiddendata("action", "add");
761         $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
762         $main::kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
764         $main::kiriwrite_presmodule->startheader();
765         $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{setting}, { Style => "tablecellheader" });
766         $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{value}, { Style => "tablecellheader" });
767         $main::kiriwrite_presmodule->endheader();
769         $main::kiriwrite_presmodule->startrow();
770         $main::kiriwrite_presmodule->addcell("tablecell1");
771         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{findfilter});
772         $main::kiriwrite_presmodule->endcell();
773         $main::kiriwrite_presmodule->addcell("tablecell2");
774         $main::kiriwrite_presmodule->addinputbox("findword", { Size => 64, MaxLength => 1024 });
775         $main::kiriwrite_presmodule->endcell();
776         $main::kiriwrite_presmodule->endrow();
778         $main::kiriwrite_presmodule->startrow();
779         $main::kiriwrite_presmodule->addcell("tablecell1");
780         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{replacefilter});
781         $main::kiriwrite_presmodule->endcell();
782         $main::kiriwrite_presmodule->addcell("tablecell2");
783         $main::kiriwrite_presmodule->addinputbox("replaceword", { Size => 64, MaxLength => 1024 });
784         $main::kiriwrite_presmodule->endcell();
785         $main::kiriwrite_presmodule->endrow();
787         $main::kiriwrite_presmodule->startrow();
788         $main::kiriwrite_presmodule->addcell("tablecell1");
789         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{priority});
790         $main::kiriwrite_presmodule->endcell();
791         $main::kiriwrite_presmodule->addcell("tablecell2");
792         $main::kiriwrite_presmodule->addinputbox("priority", { Size => 5, MaxLength => 5 });
793         $main::kiriwrite_presmodule->startlist();
794         $main::kiriwrite_presmodule->additem($main::kiriwrite_lang{filter}{noprioritygiven});
795         $main::kiriwrite_presmodule->endlist();
796         $main::kiriwrite_presmodule->endcell();
797         $main::kiriwrite_presmodule->endrow();
799         $main::kiriwrite_presmodule->startrow();
800         $main::kiriwrite_presmodule->addcell("tablecell1");
801         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{notes});
802         $main::kiriwrite_presmodule->endcell();
803         $main::kiriwrite_presmodule->addcell("tablecell2");
804         $main::kiriwrite_presmodule->addtextbox("notes", { Columns => $main::kiriwrite_config{"display_textareacols"}, Rows => $main::kiriwrite_config{"display_textarearows"} });
805         $main::kiriwrite_presmodule->endcell();
806         $main::kiriwrite_presmodule->endrow();
808         $main::kiriwrite_presmodule->startrow();
809         $main::kiriwrite_presmodule->addcell("tablecell1");
810         $main::kiriwrite_presmodule->endcell();
811         $main::kiriwrite_presmodule->addcell("tablecell2");
812         $main::kiriwrite_presmodule->addcheckbox("enabled", { OptionDescription => $main::kiriwrite_lang{filter}{enabled}, Checked => 1 });
813         $main::kiriwrite_presmodule->endcell();
814         $main::kiriwrite_presmodule->endrow();
816         $main::kiriwrite_presmodule->endtable();
818         $main::kiriwrite_presmodule->addlinebreak();
819         $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{filter}{addfilterbutton});
820         $main::kiriwrite_presmodule->addtext(" | ");
821         $main::kiriwrite_presmodule->addreset($main::kiriwrite_lang{common}{clearvalues});
822         $main::kiriwrite_presmodule->addtext(" | ");
823         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=filter", { Text => $main::kiriwrite_lang{filter}{returnfilterlist} });
825         $main::kiriwrite_presmodule->endbox();
826         $main::kiriwrite_presmodule->endform();
828         return $main::kiriwrite_presmodule->grab();
832 sub kiriwrite_filter_edit{
833 #################################################################################
834 # kiriwrite_filter_edit: Edits a filter from the filter list.                   #
835 #                                                                               #
836 # Usage:                                                                        #
837 #                                                                               #
838 # kiriwrite_filter_edit(options);                                               #
839 #                                                                               #
840 # options               Specifies the following options as hash (in any order). #
841 #                                                                               #
842 # FilterID              Specifies the filter number in the filter database.     #
843 # NewFindFilter         Specifies the new find filter.                          #
844 # NewReplaceFilter      Specifies the new replace filter.                       #
845 # NewPriority           Specifies the new priority.                             #
846 # NewEnabled            Specifies the new enable setting.                       #
847 # NewFilterNotes        Specifies the new filter notes.                         #
848 # Confirm               Confirms the action to edit a filter.                   #
849 #################################################################################
851         # Get the values that have been passed to the subroutine.
853         my ($options) = @_;
854         #my ($filter_id, $filter_new_find, $filter_new_replace, $filter_new_priority, $filter_new_notes, $confirm) = @_;
856         my $filter_id           = $options->{"FilterID"};
857         my $confirm = $options->{"Confirm"};
859         # Check the confirm value to make sure it is no more than
860         # one character long.
862         kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
864         # Check if the confirm value is blank and if it is
865         # srt the confirm value to 0.
867         if (!$confirm){
869                 # The confirm value does not have any value
870                 # set so set it to 0.
872                 $confirm = 0;
874         }
876         # Check if the filter identification number is blank,
877         # contains characters other than numbers and is more
878         # than seven characters long.
880         if (!$filter_id){
882                 # The filter identification number is blank,
883                 # so return an error.
885                 kiriwrite_error("filteridblank");
887         }
889         my $filter_id_numbers_check     = kiriwrite_variablecheck($filter_id, "numbers", 0, 1);
891         if ($filter_id_numbers_check eq 1){
893                 # The filter identification number contains
894                 # characters other than numbers, so return
895                 # an error.
897                 kiriwrite_error("filteridinvalid");
899         }
901         my $filter_id_maxlength_check   = kiriwrite_variablecheck($filter_id, "maxlength", 7, 1);
903         if ($filter_id_maxlength_check eq 1){
905                 # The filter identification number given
906                 # is more than seven characters long, so
907                 # return an error.
909                 kiriwrite_error("filteridtoolong");
911         }
913         my $filter_priority;
914         my $filter_find;
915         my $filter_replace;
916         my $filter_enabled;
917         my $filter_notes;
918  
919         # Check if the action to edit a filter has been
920         # confirmed.
922         if ($confirm eq 1){
924                 # The action to edit a filter has been confirmed so
925                 # edit the selected filter.
927                 # Get the values from the hashref.
929                 my $filter_new_find     = $options->{"NewFindFilter"};
930                 my $filter_new_replace  = $options->{"NewReplaceFilter"};
931                 my $filter_new_priority = $options->{"NewPriority"};
932                 my $filter_new_notes    = $options->{"NewFilterNotes"};
933                 my $filter_new_enabled  = $options->{"NewEnabled"};
935                 # First, check the variables recieved are UTF8
936                 # copliant.
938                 kiriwrite_variablecheck($filter_new_find, "utf8", 0, 0);
939                 kiriwrite_variablecheck($filter_new_replace, "utf8", 0, 0);
940                 kiriwrite_variablecheck($filter_new_priority, "utf8", 0, 0);
941                 kiriwrite_variablecheck($filter_new_notes, "utf8", 0, 0);
943                 # Convert the UTF8 values so that the length can
944                 # checked properly.
946                 $filter_find            = kiriwrite_utf8convert($filter_new_find);
947                 $filter_replace         = kiriwrite_utf8convert($filter_new_replace);
948                 $filter_priority        = kiriwrite_utf8convert($filter_new_priority);
949                 $filter_notes           = kiriwrite_utf8convert($filter_new_notes);
951                 # Check if the find filter is blank and return an error
952                 # if it is.
954                 if (!$filter_new_find){
956                         # The find filter given is blank so return an
957                         # error.
959                         kiriwrite_error("blankfindfilter");
961                 }
963                 if (!$filter_new_priority){
965                         # The filter priority is blank so set it
966                         # to 1.
968                         $filter_new_priority = 1;
970                 }
972                 # Check the length and contents of the values given
973                 # to make sure they are valid.
975                 my $filterfind_maxlength_check          = kiriwrite_variablecheck($filter_new_find, "maxlength", 1024, 1);
976                 my $filterreplace_maxlength_check       = kiriwrite_variablecheck($filter_new_replace, "maxlength", 1024, 1);
977                 my $filterpriority_maxlength_check      = kiriwrite_variablecheck($filter_new_priority, "maxlength", 5, 1);
978                 my $filterpriority_numbers_check        = kiriwrite_variablecheck($filter_new_priority, "numbers", 0, 1);
980                 # Check if the result of the tests to see if they
981                 # are valid.
983                 if ($filterfind_maxlength_check eq 1){
985                         # The find filter is too long, so return
986                         # an error.
988                         kiriwrite_error("findfiltertoolong");
990                 }
992                 if ($filterreplace_maxlength_check eq 1){
994                         # The replace filter is too long, so
995                         # return an error.
997                         kiriwrite_error("replacefiltertoolong");
999                 }
1001                 if ($filterpriority_maxlength_check eq 1){
1003                         # The length of the filter priority
1004                         # given is too long, so return an
1005                         # error.
1007                         kiriwrite_error("filterprioritytoolong");
1009                 }
1011                 if ($filterpriority_numbers_check eq 1){
1013                         # The priority of the filter given
1014                         # contains characters other than
1015                         # numbers.
1017                         kiriwrite_error("filterpriorityinvalidchars");
1019                 }
1021                 # Check if the filter priority is less than 1
1022                 # and more than 10000 and return an error
1023                 # if it is.
1025                 if ($filter_new_priority < 1 || $filter_new_priority > 50000){
1027                         # The filter priority is less than 1 and
1028                         # more than 10000, so return an error.
1030                         kiriwrite_error("filterpriorityinvalid");
1032                 }
1034                 # Check to see if the filter should be enabled.
1036                 my $filter_enable = 0;
1038                 if (!$filter_new_enabled){
1040                         $filter_new_enabled = "off";
1042                 }
1044                 if ($filter_new_enabled eq "on"){
1045                         
1046                         # The filter is enabled.
1048                         $filter_enable = 1;
1050                 }
1052                 # Connect to the database server.
1054                 $main::kiriwrite_dbmodule->connect();
1056                 # Check if any errors occured while connecting to the database server.
1058                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1060                         # A database connection error has occured so return
1061                         # an error.
1063                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
1065                 }
1067                 # Connect to the filter database.
1069                 $main::kiriwrite_dbmodule->connectfilter();
1071                 # Check if any error has occured while connecting to the filter
1072                 # database.
1074                 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){
1076                         # The filter database does not exist.
1078                         kiriwrite_error("filtersdbmissing");
1080                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){
1082                         # The filter database has invalid permissions set so return
1083                         # an error.
1085                         kiriwrite_error("filtersdbpermissions");
1087                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
1089                         # A database error has occured with the filter database.
1091                         kiriwrite_error("filtersdbdatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
1093                 }
1095                 # Edit the selected filter in the filter database.
1097                 $main::kiriwrite_dbmodule->editfilter({ FilterID => $filter_id, NewFindFilter => $filter_new_find, NewReplaceFilter => $filter_new_replace, NewFilterPriority => $filter_new_priority, NewEnabled => $filter_enable, NewFilterNotes => $filter_new_notes });
1099                 # Check if any errors occured while editing the filter.
1101                 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){
1103                         # The filter database has invalid permissions set so return
1104                         # an error.
1106                         kiriwrite_error("filtersdbpermissions");
1108                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
1110                         # A database error has occured while using the filter database
1111                         # so return an error.
1113                         kiriwrite_error("filtersdbdatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
1115                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDoesNotExist"){
1117                         # The specified filter does not exist so return an error.
1119                         kiriwrite_error("filterdoesnotexist");
1121                 }
1123                 # Disconnect from the filter database.
1125                 $main::kiriwrite_dbmodule->disconnectfilter();
1127                 # Disconnect from the database server.
1129                 $main::kiriwrite_dbmodule->disconnect();
1131                 # Write a message saying that the filter was edited.
1133                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{editedfilter}, { Style => "pageheader" });
1134                 $main::kiriwrite_presmodule->addlinebreak();
1135                 $main::kiriwrite_presmodule->addlinebreak();
1136                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{editedfiltermessage});
1137                 $main::kiriwrite_presmodule->addlinebreak();
1138                 $main::kiriwrite_presmodule->addlinebreak();
1139                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=filter", { Text => $main::kiriwrite_lang{filter}{returnfilterlist}});
1141                 return $main::kiriwrite_presmodule->grab();
1143         } elsif ($confirm eq 0){
1145                 # The action to edit a filter has not been confirmed
1146                 # so write a form for editing the filter with.
1148                 # Connect to the database server.
1150                 $main::kiriwrite_dbmodule->connect();
1152                 # Check if any errors occured while connecting to the database server.
1154                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1156                         # A database connection error has occured so return
1157                         # an error.
1159                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
1161                 }
1163                 # Connect to the database server.
1165                 $main::kiriwrite_dbmodule->connect();
1167                 # Check if any errors occured while connecting to the database server.
1169                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1171                         # A database connection error has occured so return
1172                         # an error.
1174                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
1176                 }
1178                 # Connect to the filter database.
1180                 $main::kiriwrite_dbmodule->connectfilter();
1182                 # Check if any error has occured while connecting to the filter
1183                 # database.
1185                 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){
1187                         # The filter database does not exist.
1189                         kiriwrite_error("filtersdbmissing");
1191                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){
1193                         # The filter database has invalid permissions set so return
1194                         # an error.
1196                         kiriwrite_error("filtersdbpermissions");
1198                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
1200                         # A database error has occured with the filter database.
1202                         kiriwrite_error("filtersdbdatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
1204                 }
1206                 # Get information about the filter.
1208                 my %filter_info = $main::kiriwrite_dbmodule->getfilterinfo({ FilterID => $filter_id });
1210                 # Check if any errors occured while getting information about the filter.
1212                 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
1214                         # A database error occured while using the filter database so
1215                         # return an error.
1217                         kiriwrite_error("filtersdbdatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
1219                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDoesNotExist"){
1221                         # The filter does not exist so return an error.
1223                         kiriwrite_error("filterdoesnotexist");
1225                 }
1227                 # Get the required information.
1229                 $filter_priority        = $filter_info{"FilterPriority"};
1230                 $filter_find            = $filter_info{"FilterFind"};
1231                 $filter_replace         = $filter_info{"FilterReplace"};
1232                 $filter_enabled         = $filter_info{"FilterEnabled"};
1233                 $filter_notes           = $filter_info{"FilterNotes"};
1235                 # Disconnect from the filter database.
1237                 $main::kiriwrite_dbmodule->disconnectfilter();
1239                 # Disconnect from the database server.
1241                 $main::kiriwrite_dbmodule->disconnect();
1243                 # Write out the form.
1245                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{editfilter}, { Style => "pageheader" });
1246                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1247                 $main::kiriwrite_presmodule->startbox();
1248                 $main::kiriwrite_presmodule->addhiddendata("mode", "filter");
1249                 $main::kiriwrite_presmodule->addhiddendata("action", "edit");
1250                 $main::kiriwrite_presmodule->addhiddendata("filter", $filter_id);
1251                 $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
1253                 $main::kiriwrite_presmodule->addlinebreak();
1254                 $main::kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
1256                 $main::kiriwrite_presmodule->startheader();
1257                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{setting}, { Style => "tablecellheader" });
1258                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{value}, { Style => "tablecellheader" });
1259                 $main::kiriwrite_presmodule->endheader();
1261                 $main::kiriwrite_presmodule->startrow();
1262                 $main::kiriwrite_presmodule->addcell("tablecell1");
1263                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{findfilter});
1264                 $main::kiriwrite_presmodule->endcell();
1265                 $main::kiriwrite_presmodule->addcell("tablecell2");
1266                 $main::kiriwrite_presmodule->addinputbox("filterfind", { Size => 64, MaxLength => 1024, Value => $filter_find });
1267                 $main::kiriwrite_presmodule->endcell();
1268                 $main::kiriwrite_presmodule->endrow();
1270                 $main::kiriwrite_presmodule->startrow();
1271                 $main::kiriwrite_presmodule->addcell("tablecell1");
1272                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{replacefilter});
1273                 $main::kiriwrite_presmodule->endcell();
1274                 $main::kiriwrite_presmodule->addcell("tablecell2");
1275                 $main::kiriwrite_presmodule->addinputbox("filterreplace", { Size => 64, MaxLength => 1024, Value => $filter_replace });
1276                 $main::kiriwrite_presmodule->endcell();
1277                 $main::kiriwrite_presmodule->endrow();
1279                 $main::kiriwrite_presmodule->startrow();
1280                 $main::kiriwrite_presmodule->addcell("tablecell1");
1281                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{priority});
1282                 $main::kiriwrite_presmodule->endcell();
1283                 $main::kiriwrite_presmodule->addcell("tablecell2");
1284                 $main::kiriwrite_presmodule->addinputbox("priority", { Size => 5, MaxLength => 5, Value => $filter_priority });
1285                 $main::kiriwrite_presmodule->startlist();
1286                 $main::kiriwrite_presmodule->additem($main::kiriwrite_lang{filter}{noprioritygiven});
1287                 $main::kiriwrite_presmodule->endlist();
1288                 $main::kiriwrite_presmodule->endcell();
1289                 $main::kiriwrite_presmodule->endrow();
1291                 $main::kiriwrite_presmodule->startrow();
1292                 $main::kiriwrite_presmodule->addcell("tablecell1");
1293                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{notes});
1294                 $main::kiriwrite_presmodule->endcell();
1295                 $main::kiriwrite_presmodule->addcell("tablecell2");
1296                 $main::kiriwrite_presmodule->addtextbox("notes", { Columns => $main::kiriwrite_config{"display_textareacols"}, Rows => $main::kiriwrite_config{"display_textarearows"}, Value => $filter_notes});
1297                 $main::kiriwrite_presmodule->endcell();
1298                 $main::kiriwrite_presmodule->endrow();
1300                 $main::kiriwrite_presmodule->startrow();
1301                 $main::kiriwrite_presmodule->addcell("tablecell1");
1302                 $main::kiriwrite_presmodule->endcell();
1303                 $main::kiriwrite_presmodule->addcell("tablecell2");
1305                 if ($filter_enabled eq 1){
1307                         $main::kiriwrite_presmodule->addcheckbox("enabled", { OptionDescription => $main::kiriwrite_lang{filter}{enabled}, Checked => 1 });
1309                 } else {
1311                         $main::kiriwrite_presmodule->addcheckbox("enabled", { OptionDescription => $main::kiriwrite_lang{filter}{enabled} });
1313                 }
1314                 $main::kiriwrite_presmodule->endcell();
1315                 $main::kiriwrite_presmodule->endrow();
1317                 $main::kiriwrite_presmodule->endtable();
1319                 $main::kiriwrite_presmodule->addlinebreak();
1320                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{filter}{editfilterbutton});
1321                 $main::kiriwrite_presmodule->addtext(" | ");
1322                 $main::kiriwrite_presmodule->addreset($main::kiriwrite_lang{common}{restorecurrent});
1323                 $main::kiriwrite_presmodule->addtext(" | ");
1324                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=filter", { Text => $main::kiriwrite_lang{filter}{returnfilterlist} });
1325                 $main::kiriwrite_presmodule->endbox();
1326                 $main::kiriwrite_presmodule->endform();
1328                 return $main::kiriwrite_presmodule->grab(); 
1330         } else {
1332                 # A confirm value other than 0 or 1 has been
1333                 # specified, so return an error.
1335                 kiriwrite_error("invalidvalue");
1337         }
1341 sub kiriwrite_filter_delete{
1342 #################################################################################
1343 # kiriwrite_filter_delete: Deletes a filter from the filter list.               #
1344 #                                                                               #
1345 # Usage:                                                                        #
1346 #                                                                               #
1347 # kiriwrite_filter_delete(filterid, confirm);                                   #
1348 #                                                                               #
1349 # filterid      Specifies the filter line number to delete.                     #
1350 # confirm       Confirms the deletion of the selected filter.                   #
1351 #################################################################################
1353         # Get the values that were passed to this subroutine.
1355         my ($filter_id, $confirm) = @_;
1357         # Check the confirm value to make sure it is no more than
1358         # one character long.
1360         kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
1362         # Check if the confirm value is blank and if it is
1363         # srt the confirm value to 0.
1365         if (!$confirm){
1367                 # The confirm value does not have any value
1368                 # set so set it to 0.
1370                 $confirm = 0;
1372         }
1374         # Check if the filter identification number is blank,
1375         # contains characters other than numbers and is more
1376         # than seven characters long.
1378         if (!$filter_id){
1380                 # The filter identification number is blank,
1381                 # so return an error.
1383                 kiriwrite_error("filteridblank");
1385         }
1387         my $filter_id_numbers_check     = kiriwrite_variablecheck($filter_id, "numbers", 0, 1);
1389         if ($filter_id_numbers_check eq 1){
1391                 # The filter identification number contains
1392                 # characters other than numbers, so return
1393                 # an error.
1395                 kiriwrite_error("filteridinvalid");
1397         }
1399         my $filter_id_maxlength_check   = kiriwrite_variablecheck($filter_id, "maxlength", 7, 1);
1401         if ($filter_id_maxlength_check eq 1){
1403                 # The filter identification number given
1404                 # is more than seven characters long, so
1405                 # return an error.
1407                 kiriwrite_error("filteridtoolong");
1409         }
1411         # Define some values for later.
1413         my @database_filter;
1414         my $filter_exists = 0;
1416         # Check if the confirm integer has a value of '1'.
1418         if ($confirm eq 1){
1420                 # The action to delete a filter has been confirmed.
1422                 # Connect to the database server.
1424                 $main::kiriwrite_dbmodule->connect();
1426                 # Check if any errors occured while connecting to the database server.
1428                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1430                         # A database connection error has occured so return
1431                         # an error.
1433                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
1435                 }
1437                 # Connect to the filter database.
1439                 $main::kiriwrite_dbmodule->connectfilter();
1441                 # Check if any error has occured while connecting to the filter
1442                 # database.
1444                 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){
1446                         # The filter database does not exist.
1448                         kiriwrite_error("filtersdbmissing");
1450                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){
1452                         # The filter database has invalid permissions set so return
1453                         # an error.
1455                         kiriwrite_error("filtersdbpermissions");
1457                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
1459                         # A database error has occured with the filter database.
1461                         kiriwrite_error("filtersdbdatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
1463                 }
1465                 # Delete the filter from the filter database.
1467                 $main::kiriwrite_dbmodule->deletefilter({ FilterID => $filter_id });
1469                 # Check if any errors occured while deleting the filter.
1471                 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
1473                         # A database error has occured while trying to delete a filter so
1474                         # return an error.
1476                         kiriwrite_error("filtersdbdatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
1478                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDoesNotExist"){
1480                         # The filter does not exist so return an error.
1481  
1482                         kiriwrite_error("filterdoesnotexist");
1484                 }
1486                 # Disconnect from the filter database.
1488                 $main::kiriwrite_dbmodule->disconnectfilter();
1490                 # Disconnect from the database server.
1492                 $main::kiriwrite_dbmodule->disconnect();
1494                 # Write a message saying that the filter was deleted
1495                 # from the filter database.
1497                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{deletedfilter}, { Style => "pageheader" });
1498                 $main::kiriwrite_presmodule->addlinebreak();
1499                 $main::kiriwrite_presmodule->addlinebreak();
1500                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{deletedfiltermessage});
1501                 $main::kiriwrite_presmodule->addlinebreak();
1502                 $main::kiriwrite_presmodule->addlinebreak();
1503                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=filter", { Text => $main::kiriwrite_lang{filter}{returnfilterlist} });
1505         } elsif ($confirm eq 0) {
1507                 # Connect to the database server.
1509                 $main::kiriwrite_dbmodule->connect();
1511                 # Check if any errors occured while connecting to the database server.
1513                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
1515                         # A database connection error has occured so return
1516                         # an error.
1518                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
1520                 }
1522                 # Connect to the filter database.
1524                 $main::kiriwrite_dbmodule->connectfilter();
1526                 # Check if any error has occured while connecting to the filter
1527                 # database.
1529                 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseDoesNotExist"){
1531                         # The filter database does not exist.
1533                         kiriwrite_error("filtersdbmissing");
1535                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseInvalidPermissionsSet"){
1537                         # The filter database has invalid permissions set so return
1538                         # an error.
1540                         kiriwrite_error("filtersdbpermissions");
1542                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
1544                         # A database error has occured with the filter database.
1546                         kiriwrite_error("filtersdbdatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
1548                 }
1550                 # Get information about the filter (to check if it exists).
1552                 my %filter_info = $main::kiriwrite_dbmodule->getfilterinfo({ FilterID => $filter_id });
1554                 # Check if any errors occured while getting information about the filter.
1556                 if ($main::kiriwrite_dbmodule->geterror eq "FilterDatabaseError"){
1558                         # A database error occured while using the filter database so
1559                         # return an error.
1561                         kiriwrite_error("filtersdbdatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
1563                 } elsif ($main::kiriwrite_dbmodule->geterror eq "FilterDoesNotExist"){
1565                         # The filter does not exist so return an error.
1567                         kiriwrite_error("filterdoesnotexist");
1569                 }
1571                 # Disconnect from the filter database.
1573                 $main::kiriwrite_dbmodule->disconnectfilter();
1575                 # Disconnect from the database
1577                 # The confirm integer is '0', so continue write out
1578                 # a form asking the user to confirm the deletion
1579                 # pf the filter.
1581                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{deletefilter}, { Style => "pageheader" });
1582                 $main::kiriwrite_presmodule->addlinebreak();
1583                 $main::kiriwrite_presmodule->addlinebreak();
1584                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{filter}{deletefiltermessage});
1585                 $main::kiriwrite_presmodule->addlinebreak();
1586                 $main::kiriwrite_presmodule->addlinebreak();
1587                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1588                 $main::kiriwrite_presmodule->startbox();
1589                 $main::kiriwrite_presmodule->addhiddendata("mode", "filter");
1590                 $main::kiriwrite_presmodule->addhiddendata("action", "delete");
1591                 $main::kiriwrite_presmodule->addhiddendata("filter", $filter_id);
1592                 $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
1593                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{filter}{deletefilterbutton});
1594                 $main::kiriwrite_presmodule->addtext(" | ");
1595                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=filter", { Text => $main::kiriwrite_lang{filter}{deletefilterreturn} });
1596                 $main::kiriwrite_presmodule->endbox();
1597                 $main::kiriwrite_presmodule->endform();
1599         } else {
1601                 kiriwrite_error("invalidvalue");
1603         }
1605         return $main::kiriwrite_presmodule->grab();
1609 1; 
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