Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Changes made in preperation for Kiriwrite 0.4.0
[kiriwrite/.git] / cgi-files / Modules / System / Database.pm
1 package Modules::System::Database;
3 use Modules::System::Common;
4 use strict;
5 use warnings;
6 use Exporter;
8 our @ISA = qw(Exporter);
9 our @EXPORT = qw(kiriwrite_database_list kiriwrite_database_add kiriwrite_database_edit kiriwrite_database_delete);
11 sub kiriwrite_database_list{
12 #################################################################################
13 # kiriwrite_database_list: Lists the databases available.                       #
14 #                                                                               #
15 # Usage:                                                                        #
16 #                                                                               #
17 # kiriwrite_database_list();                                                    #
18 #################################################################################
20         # Connect to the database server.
22         $main::kiriwrite_dbmodule->connect();
24         # Check if any errors occured while connecting to the database server.
26         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
28                 # A database connection error has occured so return
29                 # an error.
31                 kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
33         }
35         # Get the list of available databases and process any errors that
36         # might have occured.
38         my @database_list = $main::kiriwrite_dbmodule->getdblist();
40         if ($main::kiriwrite_dbmodule->geterror eq "DataDirMissing"){
42                 # The database directory is missing so return an error.
44                 kiriwrite_error("datadirectorymissing");
46         } elsif ($main::kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){
48                 # The database directory has invalid permissions set so return
49                 # an error.
51                 kiriwrite_error("datadirectoryinvalidpermissions");
53         }
55         # Declare the following variables that are going to be used before using 
56         # the foreach function.
58         my ($database_info, %database_info);
59         my @error_list;
60         my @permissions_list;
61         my $database_count = 0;
62         my $database_filename = "";
63         my $database_filename_friendly = "";
64         my $database_filename_length = 0;
65         my $database_name = "";
66         my $database_description = "";
67         my $database_permissions = "";
68         my $nodescription = 0;
69         my $noname = 0;
70         my $data_file = "";
71         my $table_style = 0;
72         my $table_style_name = "";
74         # Begin creating the table for the list of databases.
76         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databaselist}, { Style => "pageheader" });
77         $main::kiriwrite_presmodule->addlinebreak();
78         $main::kiriwrite_presmodule->addlinebreak();
79         $main::kiriwrite_presmodule->starttable("", { CellPadding => "5", CellSpacing => "0" });
80         $main::kiriwrite_presmodule->startheader();
81         $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{database}{databasename}, { Style => "tablecellheader" });
82         $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{database}{databasedescription}, { Style => "tablecellheader" });
83         $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{database}{databaseoptions}, { Style => "tablecellheader" });
84         $main::kiriwrite_presmodule->endheader();
86         foreach $data_file (@database_list){
88                 # Select the database.
90                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $data_file });
92                 # Check if any error occured while selecting the database.
94                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
96                         # The database does not exist, so process the next
97                         # database.
99                         next;
101                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet") {
103                         # The database has invalid permissions settings, so
104                         # add the database to the list of databases with
105                         # invalid permissions set and process the next
106                         # database.
108                         push(@permissions_list, $data_file);
109                         next;
111                 }
113                 # Get information about the database.
115                 %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
117                 # Check if any error occured while getting information from the
118                 # database.
120                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
122                         # A database error has occured, add the database and specific
123                         # error message to the list of databases with errors and
124                         # process the next database.
126                         push(@error_list, $data_file . ": " . $main::kiriwrite_dbmodule->geterror(1));
127                         next;
129                 }
131                 $database_name          = $database_info{"DatabaseName"};
132                 $database_description   = $database_info{"Description"};
134                 # Check the style to be used with.
136                 if ($table_style eq 0){
138                         # Use the first style and set the style value
139                         # to use the next style, the next time the
140                         # if statement is checked.
142                         $table_style_name = "tablecell1";
143                         $table_style = 1;
144                 } else {
146                         # Use the second style and set the style
147                         # value to use the first style, the next
148                         # time if statement is checked.
150                         $table_style_name = "tablecell2";
151                         $table_style = 0;
152                 }
154                 # Create a friendly name for the database.
156                 $database_filename_friendly = $data_file;
158                 # Append the database information to the table.
160                 $main::kiriwrite_presmodule->startrow();
161                 $main::kiriwrite_presmodule->addcell($table_style_name);
163                 if (!$database_name){
164                         $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang->{blank}->{noname});
165                 } else {
166                         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=page&action=view&database=" . $database_filename_friendly, { Text => $database_name });
167                 }
169                 $main::kiriwrite_presmodule->endcell();
170                 $main::kiriwrite_presmodule->addcell($table_style_name);
172                 if (!$database_description){
173                         $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{nodescription});
174                 } else {
175                         $main::kiriwrite_presmodule->addtext($database_description);
176                 }
178                 $main::kiriwrite_presmodule->endcell();
179                 $main::kiriwrite_presmodule->addcell($table_style_name);
180                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=db&action=edit&database=" . $database_filename_friendly, { Text => $main::kiriwrite_lang{options}{edit} });
181                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=compile&action=compile&type=single&database=" . $database_filename_friendly, { Text => $main::kiriwrite_lang{options}{compile} });
182                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{'script_filename'} . "?mode=db&action=delete&database=" . $database_filename_friendly, { Text => $main::kiriwrite_lang{options}{delete} });
183                 $main::kiriwrite_presmodule->endrow();
185                 $database_count++;
186                 $nodescription = 0;
187                 $noname = 0;
189         }
191         $main::kiriwrite_presmodule->endtable();
193         # Disconnect from the database server.
195         $main::kiriwrite_dbmodule->disconnect();
197         # Check if there are no valid databases are if there is no
198         # valid databases then write a message saying that no
199         # valid databases are available.
201         if ($database_count eq 0){
203                 $main::kiriwrite_presmodule->clear();
204                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databaselist}, { Style => "pageheader" });
205                 $main::kiriwrite_presmodule->addlinebreak();
206                 $main::kiriwrite_presmodule->addlinebreak();
207                 $main::kiriwrite_presmodule->startbox("errorbox");
208                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{nodatabasesavailable});
209                 $main::kiriwrite_presmodule->endbox();
211         }
213         # Check if any databases with problems have appeared and if they
214         # have, print out a message saying which databases have problems.
216         if (@permissions_list){
218                 $main::kiriwrite_presmodule->addlinebreak();
219                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databaseinvalidpermissions}, { Style => "smallpageheader" });
220                 $main::kiriwrite_presmodule->addlinebreak();
221                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databaseinvalidpermissionstext});
222                 $main::kiriwrite_presmodule->addlinebreak();
224                 foreach $data_file (@permissions_list){
225                         $main::kiriwrite_presmodule->addlinebreak();
226                         $main::kiriwrite_presmodule->addtext($data_file);
227                 }
229                 $main::kiriwrite_presmodule->addlinebreak();
231         }
233         if (@error_list){
235                 $main::kiriwrite_presmodule->addlinebreak();
236                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databaseerrors}, { Style => "smallpageheader" });
237                 $main::kiriwrite_presmodule->addlinebreak();
238                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databaseerrorstext});
239                 $main::kiriwrite_presmodule->addlinebreak();
241                 foreach $data_file (@error_list){
242                         $main::kiriwrite_presmodule->addlinebreak();
243                         $main::kiriwrite_presmodule->addtext($data_file);
244                 }
246                 $main::kiriwrite_presmodule->addlinebreak();
248         }
250         return $main::kiriwrite_presmodule->grab();     # Return to the main part of the script with the processed information.
252
254 sub kiriwrite_database_add{
255 #################################################################################
256 # kiriwrite_database_add: Creates a new database.                               #
257 #                                                                               #
258 # Usage:                                                                        #
259 #                                                                               #
260 # kiriwrite_database_add(filename, name, description, notes, categories,        #
261 #                               [confirm]);                                     #
262 #                                                                               #
263 # filename      Specifies the filename for the database.                        #
264 # name          Specifies a (friendly) name for the database.                   #
265 # description   Specifies a description for the database.                       #
266 # notes         Specifies the notes for the database.                           #
267 # categories    Specifies the categories for the database.                      #
268 # confirm       Confirms the action to create a database.                       #
269 #################################################################################
271         # Get the variables passed from the subroutine.
273         my ($database_filename, $database_name, $database_description, $database_notes, $database_categories, $database_confirm) = @_;
275         # Check if the confirm value is blank and if it is then
276         # set the confirm value to 0.
278         if (!$database_confirm){
280                 # The confirm value was blank so set the value to 0.
282                 $database_confirm = 0;
284         }
286         if ($database_confirm eq 1){
288                 # The action to create a new database is confirmed.
290                 # Validate the database name and database descriptions.
292                 my $database_name_check_utf8            = kiriwrite_variablecheck($database_name, "utf8", 0, 0);
293                 my $database_description_check_utf8     = kiriwrite_variablecheck($database_description, "utf8", 0, 0);
294                 my $database_notes_check_utf8           = kiriwrite_variablecheck($database_notes, "utf8", 0, 0);
295                 my $database_categories_check_utf8      = kiriwrite_variablecheck($database_categories, "utf8", 0, 0);
297                 # Convert the UTF8 strings before checking the length of the strings.
299                 $database_name                  = kiriwrite_utf8convert($database_name);
300                 $database_description           = kiriwrite_utf8convert($database_description);
301                 $database_notes                 = kiriwrite_utf8convert($database_notes);
302                 $database_categories            = kiriwrite_utf8convert($database_categories);
304                 my $database_name_check_blank           = kiriwrite_variablecheck($database_name, "blank", 0, 1);
305                 my $database_name_check_length          = kiriwrite_variablecheck($database_name, "maxlength", 256, 1);
306                 my $database_description_check_length   = kiriwrite_variablecheck($database_description, "maxlength", 512, 1);
307                 my $database_filename_check_length      = kiriwrite_variablecheck($database_filename, "maxlength", 32, 1);
308                 my $database_categories_check_length    = kiriwrite_variablecheck($database_categories, "maxlength", 512, 1);
310                 # Check if values returned contains any values that would
311                 # result in a specific error message being returned.
313                 if ($database_name_check_length eq 1){
315                         # The length of the database name is too long, so return an error.
316                         kiriwrite_error("databasenametoolong");
318                 }
320                 if ($database_description_check_length eq 1){
322                         # The database description length is too long, so return an error.
323                         kiriwrite_error("databasedescriptiontoolong");
325                 }
327                 if ($database_name_check_blank eq 1){
329                         # The database name is blank, so return an error.
330                         kiriwrite_error("databasenameblank");
332                 }
334                 if ($database_filename_check_length eq 1){
336                         # The database filename is to long, so return an error.
337                         kiriwrite_error("databasefilenametoolong");
339                 }
341                 if ($database_categories_check_length eq 1){
343                         # The database categories is too long, so return an error.
344                         kiriwrite_error("databasecategoriestoolong");
346                 }
348                 # Check if the database filename is blank and if it is then
349                 # generate a filename.
351                 if ($database_filename eq ""){
353                         # Filename is blank so generate a file name from
354                         # the database name.
356                         $database_filename = kiriwrite_processfilename($database_name);
358                 } else {
360                         # Filename is not blank so don't generate a filename.
362                 }
364                 kiriwrite_variablecheck($database_filename, "filename", "", 0);
365                 kiriwrite_variablecheck($database_filename, "maxlength", 32, 0);
367                 # Connect to the database server.
369                 $main::kiriwrite_dbmodule->connect();
371                 # Check if any errors occured while connecting to the database server.
373                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
375                         # A database connection error has occured so return
376                         # an error.
378                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
380                 }
382                 my $database_name_final = $database_name;
384                 # Create the database.
386                 $main::kiriwrite_dbmodule->adddatabase({ DatabaseFilename => $database_filename, DatabaseName => $database_name, DatabaseDescription => $database_description, DatabaseNotes => $database_notes, DatabaseCategories => $database_categories, VersionMajor => $main::kiriwrite_version{"major"}, VersionMinor => $main::kiriwrite_version{"minor"}, VersionRevision => $main::kiriwrite_version{"revision"} });
388                 # Check if any errors have occured.
390                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseExists"){
392                         # A database with the filename given already exists, so
393                         # return an error.
395                         kiriwrite_error("fileexists");
397                 } elsif ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
399                         # A database error has occured so return an error with
400                         # the extended error information.
402                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
404                 }
406                 # Disconnect from the database server.
408                 $main::kiriwrite_dbmodule->disconnect();
410                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{adddatabase}, { Style => "pageheader" });
411                 $main::kiriwrite_presmodule->addlinebreak();
412                 $main::kiriwrite_presmodule->addlinebreak();
413                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{database}{databaseadded} , $database_name_final));
414                 $main::kiriwrite_presmodule->addlinebreak();
415                 $main::kiriwrite_presmodule->addlinebreak();
416                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=db", { Text => $main::kiriwrite_lang{database}{databaselistreturnlink} });
418                 return $main::kiriwrite_presmodule->grab();
420         }
422         # There is confirm value is not 1, so write a form for creating a database to
423         # store pages in.
425         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{adddatabase}, { Style => "pageheader" });
426         $main::kiriwrite_presmodule->addlinebreak();
427         $main::kiriwrite_presmodule->addlinebreak();
428         $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
429         $main::kiriwrite_presmodule->startbox();        
430         $main::kiriwrite_presmodule->addhiddendata("mode", "db");
431         $main::kiriwrite_presmodule->addhiddendata("action", "new");
432         $main::kiriwrite_presmodule->addhiddendata("confirm", "1");
433         $main::kiriwrite_presmodule->endbox();
434         $main::kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
436         $main::kiriwrite_presmodule->startheader();
437         $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{setting}, { Style => "tablecellheader"});
438         $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{value}, { Style => "tablecellheader"});
439         $main::kiriwrite_presmodule->endheader();
441         $main::kiriwrite_presmodule->startrow();
442         $main::kiriwrite_presmodule->addcell("tablecell1");
443         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databasename});
444         $main::kiriwrite_presmodule->endcell();
445         $main::kiriwrite_presmodule->addcell("tablecell2");
446         $main::kiriwrite_presmodule->addinputbox("databasename", { Size => 64, MaxLength => 256 });
447         $main::kiriwrite_presmodule->endcell();
448         $main::kiriwrite_presmodule->endrow();
450         $main::kiriwrite_presmodule->startrow();
451         $main::kiriwrite_presmodule->addcell("tablecell1");
452         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databasedescription});
453         $main::kiriwrite_presmodule->endcell();
454         $main::kiriwrite_presmodule->addcell("tablecell2");
455         $main::kiriwrite_presmodule->addinputbox("databasedescription", { Size => 64, MaxLength => 512 });
456         $main::kiriwrite_presmodule->endcell();
457         $main::kiriwrite_presmodule->endrow();
459         $main::kiriwrite_presmodule->startrow();
460         $main::kiriwrite_presmodule->addcell("tablecell1");
461         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databasecategories});
462         $main::kiriwrite_presmodule->endcell();
463         $main::kiriwrite_presmodule->addcell("tablecell2");
464         $main::kiriwrite_presmodule->addinputbox("databasecategories", { Size => 64, MaxLength => 512 });
465         $main::kiriwrite_presmodule->endcell();
466         $main::kiriwrite_presmodule->endrow();
468         $main::kiriwrite_presmodule->startrow();
469         $main::kiriwrite_presmodule->addcell("tablecell1");
470         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databasenotes});
471         $main::kiriwrite_presmodule->endcell();
472         $main::kiriwrite_presmodule->addcell("tablecell2");
473         $main::kiriwrite_presmodule->addtextbox("databasenotes", { Columns => $main::kiriwrite_config{"display_textareacols"}, Rows => $main::kiriwrite_config{"display_textarearows"}, WordWrap => 0 });
474         $main::kiriwrite_presmodule->endcell();
475         $main::kiriwrite_presmodule->endrow();
477         $main::kiriwrite_presmodule->startrow();
478         $main::kiriwrite_presmodule->addcell("tablecell1");
479         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databasefilename});
480         $main::kiriwrite_presmodule->endcell();
481         $main::kiriwrite_presmodule->addcell("tablecell2");
482         $main::kiriwrite_presmodule->addinputbox("databasefilename", { Size => 32, MaxLength => 32 });
483         $main::kiriwrite_presmodule->startlist();
484         $main::kiriwrite_presmodule->additem($main::kiriwrite_lang{database}{adddatabaseautogenerate});
485         $main::kiriwrite_presmodule->additem($main::kiriwrite_lang{database}{adddatabasenoextensions});
486         $main::kiriwrite_presmodule->additem($main::kiriwrite_lang{database}{adddatabasecharacterlength});
487         $main::kiriwrite_presmodule->additem($main::kiriwrite_lang{database}{adddatabasecharacters});
488         $main::kiriwrite_presmodule->endlist();
489         $main::kiriwrite_presmodule->endcell();
490         $main::kiriwrite_presmodule->endrow();
492         $main::kiriwrite_presmodule->endtable();
493         $main::kiriwrite_presmodule->startbox();
494         $main::kiriwrite_presmodule->addlinebreak();
495         $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{database}{adddatabasebutton});
496         $main::kiriwrite_presmodule->addtext("|");
497         $main::kiriwrite_presmodule->addreset($main::kiriwrite_lang{database}{clearvaluesbutton});
498         $main::kiriwrite_presmodule->addtext("| ");
499         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=db", { Text => $main::kiriwrite_lang{database}{databaselistreturnlink} });
500         $main::kiriwrite_presmodule->endbox();
501         $main::kiriwrite_presmodule->endform();
503         # Exit the subroutine taking the data in the pagadata variable with it.
505         return $main::kiriwrite_presmodule->grab();
509 sub kiriwrite_database_edit{
510 #################################################################################
511 # kiriwrite_database_edit: Edits an database.                                   #
512 #                                                                               #
513 # Usage:                                                                        #
514 #                                                                               #
515 # kiriwrite_database_edit(filename, newfilename, newname, newdescription,       #
516 #                               notes, categories, [confirm]);                  #
517 #                                                                               #
518 # filename              Specifies the filename of the database.                 #
519 # newfilename           Specifies the new filename of the database.             #
520 # newname               Specifies the new name of the database.                 #
521 # newdescription        Specifies the new description of the database.          #
522 # notes                 Specifies the new notes of the database.                #
523 # categories            Specifies the new categories of the database.           #
524 # confirm               Confirms the action to edit a database.                 #
525 #################################################################################
527         # First, get all the variables passed to the subroutine.
529         my ($database_shortname, $database_newfilename, $database_newname, $database_newdescription, $database_notes, $database_categories, $database_confirm) = @_;
531         # Check if the database confirm value is blank and if it is
532         # set the confirm value to 0.
534         if (!$database_confirm){
536                 $database_confirm = 0;
538         }
540         # Check if the database filename given is valid and return an error
541         # if it isn't.
543         kiriwrite_variablecheck($database_shortname, "filename", "", 0);
545         # Check if the confirm variable has a value in it, if it has, check again to make sure it really is the correct value (Perl moans
546         # if $database_confirm was used directly).
548         if ($database_confirm eq 1){
550                 # Check if the new data passes the validation tests below. First, check the length of the variables.
552                 my $database_name_check_utf8            = kiriwrite_variablecheck($database_newname, "utf8", 0, 0);
553                 my $database_description_check_utf8     = kiriwrite_variablecheck($database_newdescription, "utf8", 0, 0);
554                 my $database_notes_check_utf8           = kiriwrite_variablecheck($database_notes, "utf8", 0, 0);
555                 my $database_categories_check_utf8      = kiriwrite_variablecheck($database_categories, "utf8", 0, 0);
557                 # Convert the UTF8 strings to make sure their length is accurate.
559                 $database_newname               = kiriwrite_utf8convert($database_newname);
560                 $database_newdescription        = kiriwrite_utf8convert($database_newdescription);
561                 $database_notes                 = kiriwrite_utf8convert($database_notes);
562                 $database_categories            = kiriwrite_utf8convert($database_categories);
564                 # Preform the following tests.
566                 my $database_filename_check_length      = kiriwrite_variablecheck($database_newfilename, "maxlength", 32, 1);
567                 my $database_filename_letnum            = kiriwrite_variablecheck($database_newfilename, "filename", 0, 0);
568                 my $database_name_check_length          = kiriwrite_variablecheck($database_newname, "maxlength", 256, 1);
569                 my $database_description_check_length   = kiriwrite_variablecheck($database_newdescription, "maxlength", 512, 1);
570                 my $database_categories_check_length    = kiriwrite_variablecheck($database_categories, "maxlength", 512, 1);
571                 my $database_name_check_blank           = kiriwrite_variablecheck($database_newname, "blank", 0, 1);
573                 # Check if the data is valid and return a specific error if it doesn't.
575                 if ($database_name_check_length eq 1){
577                         # The length of the database name is too long, so return an error.
578                         kiriwrite_error("databasenametoolong");
580                 }
582                 if ($database_description_check_length eq 1){
584                         # The database description length is too long, so return an error.
585                         kiriwrite_error("databasedescriptiontoolong");
587                 }
589                 if ($database_name_check_blank eq 1){
591                         # The database name is blank, so return an error.
592                         kiriwrite_error("databasenameblank");
594                 }
596                 if ($database_filename_check_length eq 1){
598                         # The database filename is too long, so return an error.
599                         kiriwrite_error("databasefilenametoolong");
601                 }
603                 if ($database_categories_check_length eq 1){
605                         # The database categories is too long, so return an error.
606                         kiriwrite_error("databasecategoriestoolong");
608                 }
610                 # Connect to the database server.
612                 $main::kiriwrite_dbmodule->connect();
614                 # Check if any errors occured while connecting to the database server.
616                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
618                         # A database connection error has occured so return
619                         # an error.
621                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
623                 }
625                 # Get the database.
627                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database_shortname });
629                 # Check if any errors had occured while selecting the database.
631                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
633                         # The database does not exist, so return an error.
635                         kiriwrite_error("databasemissingfile");
637                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
639                         # The database has invalid permissions set, so return
640                         # an error.
642                         kiriwrite_error("databaseinvalidpermissions");
644                 }
646                 # FIX THIS!! >O
648                 $main::kiriwrite_dbmodule->editdatabase({ DatabaseNewFilename => $database_newfilename, DatabaseName => $database_newname , DatabaseDescription => $database_newdescription , DatabaseNotes => $database_notes, DatabaseCategories => $database_categories });
650                 # Check if any errors had occured while using the database.
652                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
654                         # The database does not exist, so return an error.
656                         kiriwrite_error("databasemissingfile");
658                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
660                         # The database has invalid permissions set, so return
661                         # an error.
663                         kiriwrite_error("databaseinvalidpermissions");
665                 } elsif ($main::kiriwrite_dbmodule->geterror eq "DataDirInvalidPermissions"){
667                         # The database directory has invalid permissions set, so
668                         # return an error.
670                         kiriwrite_error("datadirectoryinvalidpermissions");
672                 } elsif ($main::kiriwrite_dbmodule->geterror eq "DatabaseExists"){
674                         # A database already exists with the new filename, so
675                         # return an error.
677                         kiriwrite_error("databasealreadyexists");
679                 } elsif ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
681                         # A database error has occured so return an error with
682                         # the extended error information.
684                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
686                 }
688                 # Disconnect from the server.
690                 $main::kiriwrite_dbmodule->disconnect();
692                 # Write out a message saying that the database has been updated.
694                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{editeddatabase}, { Style => "pageheader" } );
695                 $main::kiriwrite_presmodule->addlinebreak();
696                 $main::kiriwrite_presmodule->addlinebreak();
697                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{database}{databaseupdated}, $database_newname));
698                 $main::kiriwrite_presmodule->addlinebreak();
699                 $main::kiriwrite_presmodule->addlinebreak();
700                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=db", { Text => $main::kiriwrite_lang{database}{databaselistreturnlink} });
702                 return $main::kiriwrite_presmodule->grab();
704         } else {
706                 my (%database_info);
708                 # Check if the database filename given is valid and return an error
709                 # if it isn't.
711                 # Connect to the database server.
713                 $main::kiriwrite_dbmodule->connect();
715                 # Check if any errors occured while connecting to the database server.
717                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
719                         # A database connection error has occured so return
720                         # an error.
722                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
724                 }
726                 # Select the database.
728                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database_shortname });
730                 # Check if any errors had occured while setting the database.
732                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
734                         # The database does not exist, so return an error.
736                         kiriwrite_error("databasemissingfile");
738                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet"){
740                         # The database has invalid permissions set, so return
741                         # an error.
743                         kiriwrite_error("databaseinvalidpermissions");
745                 }
747                 # Get the database information.
749                 %database_info = $main::kiriwrite_dbmodule->getdatabaseinfo();
751                 # Check if any errors had occured while getting the database
752                 # information.
754                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
756                         # A database error has occured so return an error and
757                         # also the extended error information.
759                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
761                 }
763                 # Get the values needed from the kiriwrite_database_info table.
765                 my $database_oldname            = $database_info{"DatabaseName"};
766                 my $database_olddescription     = $database_info{"Description"};
767                 my $database_notes              = $database_info{"Notes"};
768                 my $database_categories         = $database_info{"Categories"};
770                 # Disconnect from the database server.
772                 $main::kiriwrite_dbmodule->disconnect();
774                 # Print out the form for editing a database's settings.
776                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{database}{editdatabase}, $database_oldname), { Style => "pageheader" });
777                 $main::kiriwrite_presmodule->addlinebreak();
778                 $main::kiriwrite_presmodule->addlinebreak();
779                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
780                 $main::kiriwrite_presmodule->startbox();
781                 $main::kiriwrite_presmodule->addhiddendata("mode", "db");
782                 $main::kiriwrite_presmodule->addhiddendata("action", "edit");
783                 $main::kiriwrite_presmodule->addhiddendata("database", $database_shortname);
784                 $main::kiriwrite_presmodule->addhiddendata("confirm", "1");
785                 $main::kiriwrite_presmodule->endbox();
787                 $main::kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
788                 $main::kiriwrite_presmodule->startheader();
789                 $main::kiriwrite_presmodule->addheader("Setting", { Style => "tablecellheader" });
790                 $main::kiriwrite_presmodule->addheader("Value", { Style => "tablecellheader" });
791                 $main::kiriwrite_presmodule->endheader();
793                 $main::kiriwrite_presmodule->startrow();
794                 $main::kiriwrite_presmodule->addcell("tablecell1");
795                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databasename});
796                 $main::kiriwrite_presmodule->endcell();
797                 $main::kiriwrite_presmodule->addcell("tablecell2");
798                 $main::kiriwrite_presmodule->addinputbox("databasename", { Size => 64, MaxLength => 256, Value => $database_oldname } );
799                 $main::kiriwrite_presmodule->endcell();
800                 $main::kiriwrite_presmodule->endrow();
802                 $main::kiriwrite_presmodule->startrow();
803                 $main::kiriwrite_presmodule->addcell("tablecell1");
804                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databasedescription});
805                 $main::kiriwrite_presmodule->endcell();
806                 $main::kiriwrite_presmodule->addcell("tablecell2");
807                 $main::kiriwrite_presmodule->addinputbox("databasedescription", { Size => 64, MaxLength => 512, Value => $database_olddescription } );
808                 $main::kiriwrite_presmodule->endcell();
809                 $main::kiriwrite_presmodule->endrow();
811                 $main::kiriwrite_presmodule->startrow();
812                 $main::kiriwrite_presmodule->addcell("tablecell1");
813                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databasecategories});
814                 $main::kiriwrite_presmodule->endcell();
815                 $main::kiriwrite_presmodule->addcell("tablecell2");
816                 $main::kiriwrite_presmodule->addinputbox("databasecategories", { Size => 64, MaxLength => 512, Value => $database_categories } );
817                 $main::kiriwrite_presmodule->endcell();
818                 $main::kiriwrite_presmodule->endrow();
820                 $main::kiriwrite_presmodule->startrow();
821                 $main::kiriwrite_presmodule->addcell("tablecell1");
822                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databasenotes});
823                 $main::kiriwrite_presmodule->endcell();
824                 $main::kiriwrite_presmodule->addcell("tablecell2");
825                 $main::kiriwrite_presmodule->addtextbox("databasenotes", { Columns => $main::kiriwrite_config{"display_textareacols"}, Rows => $main::kiriwrite_config{"display_textarearows"}, Value => $database_notes } );
826                 $main::kiriwrite_presmodule->endcell();
827                 $main::kiriwrite_presmodule->endrow();
829                 $main::kiriwrite_presmodule->startrow();
830                 $main::kiriwrite_presmodule->addcell("tablecell1");
831                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{databasefilename});
832                 $main::kiriwrite_presmodule->endcell();
833                 $main::kiriwrite_presmodule->addcell("tablecell2");
834                 $main::kiriwrite_presmodule->addinputbox("databasefilename", { Size => 32, MaxLength => 32, Value => $database_shortname } );
835                 $main::kiriwrite_presmodule->endcell();
836                 $main::kiriwrite_presmodule->endrow();
838                 $main::kiriwrite_presmodule->endtable();
840                 $main::kiriwrite_presmodule->startbox();
841                 $main::kiriwrite_presmodule->addlinebreak();
842                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{database}{editdatabasebutton});
843                 $main::kiriwrite_presmodule->addtext(" | ");
844                 $main::kiriwrite_presmodule->addreset($main::kiriwrite_lang{common}{restorecurrent});
845                 $main::kiriwrite_presmodule->addtext(" | ");
846                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=db", { Text => $main::kiriwrite_lang{database}{databaselistreturnlink} });
847                 $main::kiriwrite_presmodule->endbox();
848                 $main::kiriwrite_presmodule->endform();
850                 return $main::kiriwrite_presmodule->grab();
852         }
854         # The interpreter should not be here. So return an error saying invalid variable.
856         kiriwrite_error("invalidvariable");
860 sub kiriwrite_database_delete{
861 #################################################################################
862 # kiriwrite_database_delete: Deletes an database.                               #
863 #                                                                               #
864 # Usage:                                                                        #
865 #                                                                               #
866 # kiriwrite_database_delete(filename, [confirm]);                               #
867 #                                                                               #
868 # filename      Specifies the filename for the database to be deleted.          #
869 # confirm       Confirms the action to delete a database.                       #
870 #################################################################################
872         my ($database_filename, $database_confirm) = @_;
874         # Check if the confirm value is blank and if it is then set the
875         # confirm value to 0.
877         if (!$database_confirm){
879                 $database_confirm = 0;
881         }
883         # Connect to the database server.
885         $main::kiriwrite_dbmodule->connect();
887         # Check if any errors occured while connecting to the database server.
889         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
891                 # A database connection error has occured so return
892                 # an error.
894                 kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
896         }
898         # Check if the database filename given is valid and return an error
899         # if it isn't.
901         kiriwrite_variablecheck($database_filename, "filename", "", 0);
903         # Check if the request to delete a database has been confirmed. If it has, 
904         # then delete the database itself.
906         if ($database_confirm eq 1){
907                 # There is a value in the confirm variable of the HTTP query.
909                 # Select the database to delete and get the database name.
911                 $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database_filename });
913                 # Check if any error occured while selecting the database.
915                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
917                         # The database does not exist so return an error.
919                         kiriwrite_error("databasemissingfile");
921                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet") {
923                         # The database has invalid permissions set so return
924                         # an error.
926                         kiriwrite_error("databaseinvalidpermissions");
928                 }
930                 my %database_info       = $main::kiriwrite_dbmodule->getdatabaseinfo();
932                 # Check if any errors have occured while getting the database
933                 # name.
935                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
937                         # A database error has occured so return an error with
938                         # the extended error information.
940                         kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
942                 }
944                 my $database_name = $database_info{"DatabaseName"};
946                 # Delete the selected database.
948                 $main::kiriwrite_dbmodule->deletedatabase({ DatabaseName => $database_filename });
950                 # Check if any error occured while deleting the database.
952                 if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
954                         # The database does not exist so return an error.
956                         kiriwrite_error("databasemissingfile");
958                 } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet") {
960                         # The database has invalid permissions set so return
961                         # an error.
963                         kiriwrite_error("databaseinvalidpermissions");
965                 }
967                 # Disconnect from the database server.
969                 $main::kiriwrite_dbmodule->disconnect();
971                 # Write a message saying that the database has been deleted.
973                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{deleteddatabase}, { Style => "pageheader" });
974                 $main::kiriwrite_presmodule->addlinebreak();
975                 $main::kiriwrite_presmodule->addlinebreak();
976                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{database}{deleteddatabasemessage}, $database_name));
977                 $main::kiriwrite_presmodule->addlinebreak();
978                 $main::kiriwrite_presmodule->addlinebreak();
979                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=db", { Text => $main::kiriwrite_lang{database}{databaselistreturnlink} }); 
981                 return $main::kiriwrite_presmodule->grab();
983         }
985         # The action has not been confirmed, so write out a form asking the 
986         # user to confirm.
988         # Get the database name.
990         $main::kiriwrite_dbmodule->selectdb({ DatabaseName => $database_filename });
992         # Check if any error occured while selecting the database.
994         if ($main::kiriwrite_dbmodule->geterror eq "DoesNotExist"){
996                 # The database does not exist so return an error.
998                 kiriwrite_error("databasemissingfile");
1000         } elsif ($main::kiriwrite_dbmodule->geterror eq "InvalidPermissionsSet") {
1002                 # The database has invalid permissions set so return
1003                 # an error.
1005                 kiriwrite_error("databaseinvalidpermissions");
1008         }
1010         # Check if any errors have occured.
1012         my %database_info       = $main::kiriwrite_dbmodule->getdatabaseinfo();
1014         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseError"){
1016                 # A database error has occured so return an error with
1017                 # the extended error information.
1019                 kiriwrite_error("databaseerror", $main::kiriwrite_dbmodule->geterror(1));
1021         }
1023         my $database_name = $database_info{"DatabaseName"};
1025         # Disconnect from the database server.
1027         $main::kiriwrite_dbmodule->disconnect();
1029         # Write out the form to ask the user to confirm the deletion of the 
1030         # selected database.
1032         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{database}{deletedatabase}, { Style => "pageheader" });
1033         $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
1034         $main::kiriwrite_presmodule->startbox();
1035         $main::kiriwrite_presmodule->addhiddendata("mode", "db");
1036         $main::kiriwrite_presmodule->addhiddendata("action", "delete");
1037         $main::kiriwrite_presmodule->addhiddendata("database", $database_filename);
1038         $main::kiriwrite_presmodule->addhiddendata("confirm", "1");
1039         $main::kiriwrite_presmodule->addlinebreak();
1040         $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{database}{deletedatabasemessage}, $database_name));
1041         $main::kiriwrite_presmodule->addlinebreak();
1042         $main::kiriwrite_presmodule->addlinebreak();
1043         $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{database}{deletedatabasebutton});
1044         $main::kiriwrite_presmodule->addtext(" | ");
1045         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=db", { Text => $main::kiriwrite_lang{database}{deletedatabasereturn} });
1046         $main::kiriwrite_presmodule->endbox();
1047         $main::kiriwrite_presmodule->endform();
1049         return $main::kiriwrite_presmodule->grab();
1053 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