Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Changes made in preperation for Kiriwrite 0.4.0
[kiriwrite/.git] / cgi-files / Modules / System / Template.pm
1 package Modules::System::Template;
3 use Modules::System::Common;
4 use strict;
5 use warnings;
6 use Exporter;
8 our @ISA = qw(Exporter);
9 our @EXPORT = qw(kiriwrite_template_list kiriwrite_template_add kiriwrite_template_edit kiriwrite_template_delete);
11 sub kiriwrite_template_add{
12 #################################################################################
13 # kiriwrite_template_add: Add a template to the template folder                 #
14 #                                                                               #
15 # Usage:                                                                        #
16 #                                                                               #
17 # kiriwrite_template_add(filename, name, description, layout, confirm);         #
18 #                                                                               #
19 # filename      The filename of the new template.                               #
20 # name          The name of the template.                                       #
21 # description   The description of the template.                                #
22 # layout        The layout of the new template.                                 #
23 # confirm       Confirm the action of creating a new template.                  #
24 #################################################################################
26         # Get the variables that were passed to the subroutine.
28         my ($templatefilename, $templatename, $templatedescription, $templatelayout, $confirm) = @_;
30         # Check if the confirm value is blank and if it is then set confirm to 0.
32         if (!$confirm){
34                 # The confirm value is blank, so set the value of confirm to 0.
36                 $confirm = 0;
38         }
40         if ($confirm eq 1){
42                 # Check (validate) each of the values.
44                 kiriwrite_variablecheck($templatename, "utf8", 0, 0);
45                 kiriwrite_variablecheck($templatedescription, "utf8", 0, 0);
46                 kiriwrite_variablecheck($templatelayout, "utf8", 0, 0);
48                 # Convert the values into proper UTF8 strings that can be used.
50                 $templatename           = kiriwrite_utf8convert($templatename);
51                 $templatedescription    = kiriwrite_utf8convert($templatedescription);
52                 $templatelayout         = kiriwrite_utf8convert($templatelayout);
54                 # Check the length of the converted UTF8 strings.
56                 my $templatefilename_length_check       = kiriwrite_variablecheck($templatefilename, "maxlength", 64, 1);
57                 my $templatename_length_check           = kiriwrite_variablecheck($templatename, "maxlength", 512, 1);
58                 my $templatedescription_length_check    = kiriwrite_variablecheck($templatedescription, "maxlength", 512, 1);
59                 kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
61                 if ($templatefilename_length_check eq 1){
63                         # The template filename length is too long, so return an error.
65                         kiriwrite_error("templatefilenametoolong");
67                 }
69                 if ($templatename_length_check eq 1){
71                         # The template name length is too long, so return an error.
73                         kiriwrite_error("templatenametoolong");
75                 }
78                 if ($templatedescription_length_check eq 1){
80                         # The template description length is too long, so return an error.
82                         kiriwrite_error("templatedescriptiontoolong");
84                 }
86                 # Check if the filename specified is a valid filename.
88                 kiriwrite_variablecheck($templatefilename, "filename", "", 0);
90                 # Connect to the template server.
92                 $main::kiriwrite_dbmodule->connect();
94                 # Connect to the template database.
96                 $main::kiriwrite_dbmodule->connecttemplate(1);
98                 # Check if any errors had occured.
100                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
102                         # The template database has invalid permissions set so
103                         # return an error.
105                         kiriwrite_error("templatedatabaseinvalidpermissions");
107                 }
109                 $main::kiriwrite_dbmodule->addtemplate({ TemplateFilename => $templatefilename, TemplateName => $templatename, TemplateDescription => $templatedescription, TemplateLayout => $templatelayout });
111                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
113                         # A database error has occured so return an error along
114                         # with the extended error information.
116                         kiriwrite_error("templatedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
118                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
120                         # The template database has invalid permissions set so return
121                         # an error.
123                         kiriwrite_error("templatedatabaseinvalidpermissions");
125                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplatePageExists"){
127                         # The template page already exists so return an error.
129                         kiriwrite_error("templatefilenameexists");
131                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseUncreateable"){
133                         # The template databases is uncreatable so return an error.
135                         kiriwrite_error("templatedatabasenotcreated");
137                 }
139                 $main::kiriwrite_dbmodule->disconnecttemplate();
141                 # Disconnect from the template server.
143                 $main::kiriwrite_dbmodule->disconnect();
145                 # Print out the confirmation message.
147                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{addedtemplate}, { Style => "pageheader" });
148                 $main::kiriwrite_presmodule->addlinebreak();
149                 $main::kiriwrite_presmodule->addlinebreak();
150                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{template}{addedtemplatemessage}, $templatename));
151                 $main::kiriwrite_presmodule->addlinebreak();
152                 $main::kiriwrite_presmodule->addlinebreak();
153                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=template", { Text => $main::kiriwrite_lang{template}{returntemplatelist} });
154                 return $main::kiriwrite_presmodule->grab();
156         } else {
157                 # No confirmation was made, so print out a form for adding a template.
159                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{addtemplate}, { Style => "pageheader" });
160                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
161                 $main::kiriwrite_presmodule->startbox();
162                 $main::kiriwrite_presmodule->addhiddendata("mode", "template");
163                 $main::kiriwrite_presmodule->addhiddendata("action", "add");
164                 $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
165                 $main::kiriwrite_presmodule->addlinebreak();
166                 $main::kiriwrite_presmodule->starttable("", { CellSpacing => 0, CellPadding => 5 });
168                 $main::kiriwrite_presmodule->startheader();
169                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{setting}, { Style => "tablecellheader" });
170                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{value}, { Style => "tablecellheader" });
171                 $main::kiriwrite_presmodule->endheader();
173                 $main::kiriwrite_presmodule->startrow();
174                 $main::kiriwrite_presmodule->addcell("tablecell1");
175                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{templatename});
176                 $main::kiriwrite_presmodule->endcell();
177                 $main::kiriwrite_presmodule->addcell("tablecell2");
178                 $main::kiriwrite_presmodule->addinputbox("templatename", { Size => 64, MaxLength => 512 });
179                 $main::kiriwrite_presmodule->endcell();
180                 $main::kiriwrite_presmodule->endrow();
182                 $main::kiriwrite_presmodule->startrow();
183                 $main::kiriwrite_presmodule->addcell("tablecell1");
184                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{templatedescription});
185                 $main::kiriwrite_presmodule->endcell();
186                 $main::kiriwrite_presmodule->addcell("tablecell2");
187                 $main::kiriwrite_presmodule->addinputbox("templatedescription", { Size => 64, MaxLength => 512 });
188                 $main::kiriwrite_presmodule->endcell();
189                 $main::kiriwrite_presmodule->endrow();
191                 $main::kiriwrite_presmodule->startrow();
192                 $main::kiriwrite_presmodule->addcell("tablecell1");
193                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{templatefilename});
194                 $main::kiriwrite_presmodule->endcell();
195                 $main::kiriwrite_presmodule->addcell("tablecell2");
196                 $main::kiriwrite_presmodule->addinputbox("templatefilename", { Size => 32, MaxLength => 64 });
197                 $main::kiriwrite_presmodule->endcell();
198                 $main::kiriwrite_presmodule->endrow();
200                 $main::kiriwrite_presmodule->startrow();
201                 $main::kiriwrite_presmodule->addcell("tablecell1");
202                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{templatelayout});
203                 $main::kiriwrite_presmodule->endcell();
204                 $main::kiriwrite_presmodule->addcell("tablecell2");
205                 $main::kiriwrite_presmodule->addtextbox("templatelayout", { Columns => $main::kiriwrite_config{"display_textareacols"}, Rows => $main::kiriwrite_config{"display_textarearows"} });
206                 $main::kiriwrite_presmodule->addlinebreak();
207                 $main::kiriwrite_presmodule->addlinebreak();
208                 $main::kiriwrite_presmodule->startbox("datalist");
209                 $main::kiriwrite_presmodule->addboldtext($main::kiriwrite_lang{common}{tags});
210                 $main::kiriwrite_presmodule->addlinebreak();
211                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagecontent});
212                 $main::kiriwrite_presmodule->addlinebreak();
213                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagetitle});
214                 $main::kiriwrite_presmodule->addlinebreak();
215                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagename});
216                 $main::kiriwrite_presmodule->addlinebreak();
217                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagedescription});
218                 $main::kiriwrite_presmodule->addlinebreak();
219                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagesection});
220                 $main::kiriwrite_presmodule->addlinebreak();
221                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pageautosection});
222                 $main::kiriwrite_presmodule->addlinebreak();
223                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pageautotitle});
224                 $main::kiriwrite_presmodule->addlinebreak();
225                 $main::kiriwrite_presmodule->endbox();
226                 $main::kiriwrite_presmodule->endcell();
227                 $main::kiriwrite_presmodule->endrow();
228                 $main::kiriwrite_presmodule->endtable();
230                 $main::kiriwrite_presmodule->addlinebreak();
231                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{template}{addtemplatebutton});
232                 $main::kiriwrite_presmodule->addtext(" | ");
233                 $main::kiriwrite_presmodule->addreset($main::kiriwrite_lang{common}{clearvalues});
234                 $main::kiriwrite_presmodule->addtext(" | ");
235                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=template" , { Text => $main::kiriwrite_lang{template}{returntemplatelist} });
237                 $main::kiriwrite_presmodule->endbox();
238                 $main::kiriwrite_presmodule->endform();
240                 return $main::kiriwrite_presmodule->grab();
242         }
247 sub kiriwrite_template_edit{
248 #################################################################################
249 # kiriwrite_template_edit: Edit a template from the template folder.            #
250 #                                                                               #
251 # Usage:                                                                        #
252 #                                                                               #
253 # kiriwrite_template_edit(filename, [newfilename], [newname], [newdescription], #
254 #                               [templatelayout], [confirm]);                   #
255 #                                                                               #
256 # filename              The current filename of the template to edit.           #
257 # newfilename           The new filename of the template to edit.               #
258 # newname               The new name of the template being edited.              #
259 # newdescription        The new description of the template being edited.       #
260 # templatelayout        The modified/altered template layout.                   #
261 # confirm               Confirms the action to edit a template and its          #
262 #                       settings.                                               #
263 #################################################################################
265         # Get all the variables that have been passed to the subroutine.
267         my ($templatefilename, $templatenewfilename, $templatenewname, $templatenewdescription, $templatelayout, $confirm) = @_;
269         # Check if the confirm variable is blank, if it is then
270         # set confirm to '0'
272         if (!$confirm){
274                 # confirm is uninitalised/blank, so set the value of confirm
275                 # to '0'
277                 $confirm = 0;
279         }
281         # Check if the template filename is blank and if it is, then return
282         # an error.
284         if (!$templatefilename){
286                 kiriwrite_error("templatefilenameblank");
288         }
290         # Connect to the database server.
292         $main::kiriwrite_dbmodule->connect();
294         # Check if any errors occured while connecting to the database server.
296         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
298                 # A database connection error has occured so return
299                 # an error.
301                 kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
303         }
305         if ($confirm eq 1){
307                 # Check certain strings to see if they UTF8 compiliant.
309                 kiriwrite_variablecheck($templatenewname, "utf8", 0, 0);
310                 kiriwrite_variablecheck($templatenewdescription, "utf8", 0, 0);
311                 kiriwrite_variablecheck($templatelayout, "utf8", 0, 0);
313                 # Convert the values into proper UTF8 strings.
315                 $templatenewname        = kiriwrite_utf8convert($templatenewname);
316                 $templatenewdescription = kiriwrite_utf8convert($templatenewdescription);
317                 $templatelayout         = kiriwrite_utf8convert($templatelayout);
319                 # Check if the filenames recieved are valid filenames.
321                 kiriwrite_variablecheck($templatenewfilename, "maxlength", 64, 0);
322                 kiriwrite_variablecheck($templatenewdescription, "maxlength", 512, 0);
323                 kiriwrite_variablecheck($templatenewname, "maxlength", 512, 0);
324                 kiriwrite_variablecheck($templatefilename, "maxlength", 64, 0);
325                 kiriwrite_variablecheck($confirm, "maxlength", 1, 0);
327                 kiriwrite_variablecheck($templatefilename, "filename", "", 0);
328                 kiriwrite_variablecheck($templatenewfilename, "filename", "", 0);
330                 # Connect to the template database.
332                 $main::kiriwrite_dbmodule->connecttemplate();
334                 # Check if any errors had occured.
336                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
338                         # The template database has invalid permissions set so
339                         # return an error.
341                         kiriwrite_error("templatedatabaseinvalidpermissions");
343                 }
345                 # Edit the template.
347                 $main::kiriwrite_dbmodule->edittemplate({ TemplateFilename => $templatefilename, NewTemplateFilename => $templatenewfilename, NewTemplateName => $templatenewname, NewTemplateDescription => $templatenewdescription, NewTemplateLayout => $templatelayout });
349                 # Check if any error occured while editing the template.
351                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
353                         # A database error has occured, so return an error.
355                         kiriwrite_error("templatedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
357                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
359                         # The template database has invalid permissions set so return
360                         # an error.
362                         kiriwrite_error("templatedatabaseinvalidpermissions");
364                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
366                         # The template does not exist, so process the next template.
368                         kiriwrite_error("templatedoesnotexist");
370                 }
372                 # Disconnect from the database server.
374                 $main::kiriwrite_dbmodule->disconnect();
376                 # Disconnect from the template database.
378                 $main::kiriwrite_dbmodule->disconnecttemplate();
380                 # Append a link so that the user can return to the templates list.
382                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{editedtemplate}, { Style => "pageheader" });
383                 $main::kiriwrite_presmodule->addlinebreak();
384                 $main::kiriwrite_presmodule->addlinebreak();
385                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{template}{editedtemplatemessage}, $templatenewname));
386                 $main::kiriwrite_presmodule->addlinebreak();
387                 $main::kiriwrite_presmodule->addlinebreak();
388                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=template", { Text => $main::kiriwrite_lang{template}{returntemplatelist} });
390         } else {
392                 # Connect to the template database.
394                 $main::kiriwrite_dbmodule->connecttemplate();
396                 # Check if any errors had occured.
398                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
400                         # The template database has invalid permissions set so
401                         # return an error.
403                         kiriwrite_error("templatedatabaseinvalidpermissions");
405                 }
407                 # Get the template information.
409                 my %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $templatefilename });
411                 # Check if any error occured while getting the template information.
413                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
415                         # A database error has occured, so return an error.
417                         kiriwrite_error("templatedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
419                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
421                         # The template does not exist, so return an error.
423                         kiriwrite_error("templatedoesnotexist");
425                 }
427                 # Disconnect from the template database.
429                 $main::kiriwrite_dbmodule->disconnecttemplate();
431                 # Get the values from the query results.
433                 my $template_filename           = $template_info{"TemplateFilename"};
434                 my $template_name               = $template_info{"TemplateName"};
435                 my $template_description        = $template_info{"TemplateDescription"};
436                 my $template_layout             = $template_info{"TemplateLayout"};
437                 my $template_modified           = $template_info{"TemplateLastModified"};
439                 # Check if the values are undefined and set them blank
440                 # if they are.
442                 if (!$template_name){
443                         $template_name = "";
444                 }
446                 if (!$template_description){
447                         $template_description = "";
448                 }
450                 if (!$template_layout){
451                         $template_layout = "";
452                 }
454                 # Write out the form for editing an template with the current template 
455                 # settings put into the correct place.
457                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{edittemplate}, { Style => "pageheader" });
458                 $main::kiriwrite_presmodule->addlinebreak();
459                 $main::kiriwrite_presmodule->addlinebreak();
460                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
461                 $main::kiriwrite_presmodule->startbox();
462                 $main::kiriwrite_presmodule->addhiddendata("mode", "template");
463                 $main::kiriwrite_presmodule->addhiddendata("action", "edit");
464                 $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
465                 $main::kiriwrite_presmodule->addhiddendata("template", $template_filename);
466                 $main::kiriwrite_presmodule->starttable("", { CellSpacing => 0, CellPadding => 5});
468                 $main::kiriwrite_presmodule->startheader();
469                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{setting}, { Style => "tablecellheader" });
470                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{value}, { Style => "tablecellheader" });
471                 $main::kiriwrite_presmodule->endheader();
473                 $main::kiriwrite_presmodule->startrow();
474                 $main::kiriwrite_presmodule->addcell("tablecell1");
475                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{templatename});
476                 $main::kiriwrite_presmodule->endcell();
477                 $main::kiriwrite_presmodule->addcell("tablecell2");
478                 $main::kiriwrite_presmodule->addinputbox("newname", { Size => 64, MaxLength => 512, Value => $template_name });
479                 $main::kiriwrite_presmodule->endcell();
480                 $main::kiriwrite_presmodule->endrow();
482                 $main::kiriwrite_presmodule->startrow();
483                 $main::kiriwrite_presmodule->addcell("tablecell1");
484                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{templatedescription});
485                 $main::kiriwrite_presmodule->endcell();
486                 $main::kiriwrite_presmodule->addcell("tablecell2");
487                 $main::kiriwrite_presmodule->addinputbox("newdescription", { Size => 64, MaxLength => 512, Value => $template_description });
488                 $main::kiriwrite_presmodule->endcell();
489                 $main::kiriwrite_presmodule->endrow();
491                 $main::kiriwrite_presmodule->startrow();
492                 $main::kiriwrite_presmodule->addcell("tablecell1");
493                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{templatefilename});
494                 $main::kiriwrite_presmodule->endcell();
495                 $main::kiriwrite_presmodule->addcell("tablecell2");
496                 $main::kiriwrite_presmodule->addinputbox("newfilename", { Size => 32, MaxLength => 64, Value => $template_filename });
497                 $main::kiriwrite_presmodule->endcell();
498                 $main::kiriwrite_presmodule->endrow();
500                 $main::kiriwrite_presmodule->startrow();
501                 $main::kiriwrite_presmodule->addcell("tablecell1");
502                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{templatelayout});
503                 $main::kiriwrite_presmodule->endcell();
504                 $main::kiriwrite_presmodule->addcell("tablecell2");
505                 $main::kiriwrite_presmodule->addtextbox("newlayout", { Columns => $main::kiriwrite_config{"display_textareacols"}, Rows => $main::kiriwrite_config{"display_textarearows"}, Value => $template_layout});
506                 $main::kiriwrite_presmodule->addlinebreak();
507                 $main::kiriwrite_presmodule->addlinebreak();
508                 $main::kiriwrite_presmodule->startbox("datalist");
509                 $main::kiriwrite_presmodule->addboldtext($main::kiriwrite_lang{common}{tags});
510                 $main::kiriwrite_presmodule->addlinebreak();
511                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagecontent});
512                 $main::kiriwrite_presmodule->addlinebreak();
513                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagetitle});
514                 $main::kiriwrite_presmodule->addlinebreak();
515                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagename});
516                 $main::kiriwrite_presmodule->addlinebreak();
517                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagedescription});
518                 $main::kiriwrite_presmodule->addlinebreak();
519                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pagesection});
520                 $main::kiriwrite_presmodule->addlinebreak();
521                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pageautosection});
522                 $main::kiriwrite_presmodule->addlinebreak();
523                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{common}{pageautotitle});
524                 $main::kiriwrite_presmodule->addlinebreak();
525                 $main::kiriwrite_presmodule->endbox();
526                 $main::kiriwrite_presmodule->endcell();
527                 $main::kiriwrite_presmodule->endrow();
529                 $main::kiriwrite_presmodule->endtable();
531                 $main::kiriwrite_presmodule->addlinebreak();
533                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{template}{edittemplatebutton});
534                 $main::kiriwrite_presmodule->addtext(" | ");
535                 $main::kiriwrite_presmodule->addreset($main::kiriwrite_lang{common}{restorecurrent});
536                 $main::kiriwrite_presmodule->addtext(" | ");
537                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=template", { Text => $main::kiriwrite_lang{template}{returntemplatelist} });
539                 $main::kiriwrite_presmodule->endbox();
540                 $main::kiriwrite_presmodule->endform();
542         }
544         # Disconnect from the database server.
546         $main::kiriwrite_dbmodule->disconnect();
548         return $main::kiriwrite_presmodule->grab();
552 sub kiriwrite_template_delete{
553 #################################################################################
554 # kiriwrite_template_delete: Delete a template from the template folder.        #
555 #                                                                               #
556 # Usage:                                                                        #
557 #                                                                               #
558 # kiriwrite_template_delete(filename, confirm);                                 #
559 #                                                                               #
560 # filename      Specifies the filename of the database to delete.               #
561 # confirm       Confirms the action to delete a template.                       #
562 #################################################################################
564         # Get the parameters that were passed to the subroutine.
566         my ($template_filename, $template_confirm) = @_;
568         if (!$template_confirm){
569                 $template_confirm = 0;
570         }
572         # Check the length of the variables.
573         kiriwrite_variablecheck($template_filename, "maxlength", 64, 0);
574         kiriwrite_variablecheck($template_confirm, "maxlength", 1, 0);
576         # Check if the template_name string is blank and if it is then
577         # return an error (as the template_name string should not be
578         # blank.
580         if (!$template_filename){
582                 # The template_filename string really is blank, 
583                 # so return an error saying that an empty
584                 # filename was passed (to the subroutine).
586                 kiriwrite_error("templatefilenameblank");
588         }
590         # Check if the template_confirm string is blank and if it is, write
591         # out a form asking the user to confirm the deletion.
593         if ($template_confirm eq 1){
595                 # The action to delete the template from the template database has
596                 # been confirmed so delete the template.
598                 # Connect to the database server.
600                 $main::kiriwrite_dbmodule->connect();
602                 # Check if any errors occured while connecting to the database server.
604                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
606                         # A database connection error has occured so return
607                         # an error.
609                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
611                 }
613                 # Check if the template database exists and the file permissions
614                 # are valid and return an error if they aren't.
616                 $main::kiriwrite_dbmodule->connecttemplate();
618                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
620                         # The template database does not exist so write a warning
621                         # message.
623                         kiriwrite_error("templatedatabasemissing");
625                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
627                         # The template database has invalid permissions set so
628                         # return an error.
630                         kiriwrite_error("templatedatabaseinvalidpermissions");
632                 }
634                 my %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_filename });
636                 # Check if any error occured while getting the template information.
638                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
640                         # A database error has occured, so return an error.
642                         kiriwrite_error("templatedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
644                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
646                         # The template does not exist, so return an error.
648                         kiriwrite_error("templatedoesnotexist");
650                 }
652                 # Delete the selected template.
654                 $main::kiriwrite_dbmodule->deletetemplate({ TemplateFilename => $template_filename });
656                 # Check if any error occured while deleting the template.
658                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
660                         # A database error has occured, so return an error.
662                         kiriwrite_error("templatedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
664                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
666                         # The template does not exist, so process the next template.
668                         kiriwrite_error("templatedoesnotexist");
670                 }
672                 $main::kiriwrite_dbmodule->disconnecttemplate();
674                 # Get the deleted database name.
676                 my $database_template_name = $template_info{"TemplateName"};
678                 # Disconnect from the database server.
680                 $main::kiriwrite_dbmodule->disconnect();
682                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{deletedtemplate}, { Style => "pageheader" });
683                 $main::kiriwrite_presmodule->addlinebreak();
684                 $main::kiriwrite_presmodule->addlinebreak();
685                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{template}{deletedtemplatemessage}, $database_template_name) );
686                 $main::kiriwrite_presmodule->addlinebreak();
687                 $main::kiriwrite_presmodule->addlinebreak();
688                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=template", { Text => $main::kiriwrite_lang{template}{returntemplatelist} });
690                 return $main::kiriwrite_presmodule->grab();
692         } elsif ($template_confirm eq 0) {
694                 # The template confirm value is 0 (previously blank and then set to 0), so
695                 # write out a form asking the user to confirm the deletion of the template.
697                 # Connect to the database server.
699                 $main::kiriwrite_dbmodule->connect();
701                 # Check if any errors occured while connecting to the database server.
703                 if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
705                         # A database connection error has occured so return
706                         # an error.
708                         kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
710                 }
712                 # Connect to the template database.
714                 $main::kiriwrite_dbmodule->connecttemplate();
716                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
718                         # The template database does not exist so write a warning
719                         # message.
721                         kiriwrite_error("templatedatabasemissing");
723                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
725                         # The template database has invalid permissions set so
726                         # return an error.
728                         kiriwrite_error("templatedatabaseinvalidpermissions");
730                 }
732                 my %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template_filename });
734                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
736                         # A database error has occured, so return an error.
738                         kiriwrite_error("templatedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
740                 } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
742                         # The template does not exist, so return an error.
744                         kiriwrite_error("templatedoesnotexist");
746                 }
748                 my $template_data_filename      = $template_info{"TemplateFilename"};
749                 my $template_data_name          = $template_info{"TemplateName"};
751                 $main::kiriwrite_dbmodule->disconnecttemplate();
753                 # Disconnect from the database server.
755                 $main::kiriwrite_dbmodule->disconnect();
757                 # Write out the confirmation form.
759                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{deletetemplate}, { Style => "pageheader" });
760                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "POST");
761                 $main::kiriwrite_presmodule->startbox();
762                 $main::kiriwrite_presmodule->addhiddendata("mode", "template");
763                 $main::kiriwrite_presmodule->addhiddendata("template", $template_filename);
764                 $main::kiriwrite_presmodule->addhiddendata("action", "delete");
765                 $main::kiriwrite_presmodule->addhiddendata("confirm", 1);
766                 $main::kiriwrite_presmodule->addlinebreak();
767                 $main::kiriwrite_presmodule->addtext(kiriwrite_language($main::kiriwrite_lang{template}{deletetemplatemessage}, $template_data_name, $template_data_filename));
768                 $main::kiriwrite_presmodule->addlinebreak();
769                 $main::kiriwrite_presmodule->addlinebreak();
770                 $main::kiriwrite_presmodule->addsubmit($main::kiriwrite_lang{template}{deletetemplatebutton});
771                 $main::kiriwrite_presmodule->addtext(" | ");
772                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=template", { Text => $main::kiriwrite_lang{template}{deletetemplatereturntolist} });
773                 $main::kiriwrite_presmodule->endbox();
774                 $main::kiriwrite_presmodule->endform();
776                 return $main::kiriwrite_presmodule->grab();
778         } else {
780                         kiriwrite_error("invalidvariable");
782         }
786 sub kiriwrite_template_list{
787 #################################################################################
788 # kiriwrite_template_list: List the templates in the template folder.           #
789 #                                                                               #
790 # Usage:                                                                        #
791 #                                                                               #
792 # kiriwrite_template_list([browsenumber]);                                      #
793 #                                                                               #
794 # browsenumber  Specifies the page browse number to use.                        #
795 #################################################################################
797         # Define certain values for later.
799         my $template_browsenumber       = shift;
801         my %template_info;
803         my @templates_list;
805         my $template;
806         my $template_filename           = "";
807         my $template_filename_list      = "";
808         my $template_name               = "";
809         my $template_description        = "";
810         my $template_data               = "";
812         my $template_split      = $main::kiriwrite_config{"display_templatecount"};
813         my $template_list       = 0;
815         my $template_count = 0;
817         my $template_style = 0;
818         my $template_stylename = "";
820         my $templatewarning = "";
822         # Connect to the database server.
824         $main::kiriwrite_dbmodule->connect();
826         # Check if any errors occured while connecting to the database server.
828         if ($main::kiriwrite_dbmodule->geterror eq "DatabaseConnectionError"){
830                 # A database connection error has occured so return
831                 # an error.
833                 kiriwrite_error("databaseconnectionerror", $main::kiriwrite_dbmodule->geterror(1));
835         }
837         # Connect to the template database.
839         $main::kiriwrite_dbmodule->connecttemplate();
841         # Check if any errors had occured.
843         if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseDoesNotExist"){
845                 # The template database does not exist so write a warning
846                 # message.
848                 $templatewarning = $main::kiriwrite_lang{template}{templatedatabasedoesnotexist};
850         } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseInvalidPermissionsSet"){
852                 # The template database has invalid permissions set so
853                 # return an error.
855                 kiriwrite_error("templatedatabaseinvalidpermissions");
857         } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
859                 # A database error occured while getting the list of
860                 # templates so return an error with the extended
861                 # error information.
863                 kiriwrite_error("templatedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
865         }
867         # Get the list of template databases.
869         if (!$templatewarning){
871                 # Get the total count of filters in the filter database.
873                 my $template_total_count        = $main::kiriwrite_dbmodule->gettemplatecount;
875                 # Check if any errors occured while getting the count of filters.
877                 if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
879                         # A database error has occured with the filter database.
881                         kiriwrite_error("templatedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
883                 }
885                 if (!$template_browsenumber || $template_browsenumber eq 0){
887                         $template_browsenumber = 1;
889                 }
891                 # Check if the template browse number is valid and if it isn't
892                 # then return an error.
894                 my $kiriwrite_browsenumber_length_check         = kiriwrite_variablecheck($template_browsenumber, "maxlength", 7, 1);
895                 my $kiriwrite_browsenumber_number_check         = kiriwrite_variablecheck($template_browsenumber, "numbers", 0, 1);
897                 if ($kiriwrite_browsenumber_length_check eq 1){
899                         # The browse number was too long so return
900                         # an error.
902                         kiriwrite_error("browsenumbertoolong");
904                 }
906                 if ($kiriwrite_browsenumber_number_check eq 1){
908                         # The browse number wasn't a number so
909                         # return an error.
911                         kiriwrite_error("browsenumberinvalid");
913                 }
915                 if ($template_total_count ne 0){
917                         if ($template_total_count eq $template_split){
919                                 $template_list = int(($template_total_count / $template_split));
921                         } else {
923                                 $template_list = int(($template_total_count / $template_split) + 1);
925                         }
927                 }
929                 my $start_from = ($template_browsenumber - 1) * $template_split;
931                 @templates_list = $main::kiriwrite_dbmodule->gettemplatelist({ StartFrom => $start_from, Limit => $template_split });
933         }
935         # Check if any errors had occured.
937         if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
939                 # A database error occured while getting the list
940                 # of templates so return an error with the 
941                 # extended error information.
943                 kiriwrite_error("templatedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
945         }
947         my $template_list_count;
949         # Check if any templates are in the database and if there isn't
950         # then write a message saying that there are no templates in the
951         # database.
953         if (!@templates_list && $template_browsenumber > 1){
955                 # There were no values given for the page browse
956                 # number given so write a message saying that
957                 # there were no pages for the page browse number
958                 # given.
960                 $main::kiriwrite_presmodule->clear();
961                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{viewtemplates}, { Style => "pageheader" });
962                 $main::kiriwrite_presmodule->addlinebreak();
963                 $main::kiriwrite_presmodule->addlinebreak();
964                 $main::kiriwrite_presmodule->startbox("errorbox");
965                 $main::kiriwrite_presmodule->enterdata($main::kiriwrite_lang{template}{notemplatesinpagebrowse});
966                 $main::kiriwrite_presmodule->addlinebreak();
967                 $main::kiriwrite_presmodule->addlinebreak();
968                 $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=template", { Text => $main::kiriwrite_lang{template}{returntofirstpagebrowse} });
969                 $main::kiriwrite_presmodule->endbox();
971                 # Disconnect from the database server.
973                 $main::kiriwrite_dbmodule->disconnect();
974                 $main::kiriwrite_dbmodule->disconnecttemplate();
976                 return $main::kiriwrite_presmodule->grab();
978         } elsif (!@templates_list && !$templatewarning){
979                 $templatewarning = $main::kiriwrite_lang{template}{notemplatesavailable};
980         }
982         # Process the templates into a template list.
984         $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{viewtemplates}, { Style => "pageheader" });
985         $main::kiriwrite_presmodule->addlinebreak();
986         $main::kiriwrite_presmodule->addlinebreak();
988         if ($templatewarning){
990                 $main::kiriwrite_presmodule->startbox("errorbox");
991                 $main::kiriwrite_presmodule->addtext($templatewarning);
992                 $main::kiriwrite_presmodule->endbox();
994         } else {
996                 if (!$template_browsenumber || $template_browsenumber eq 0){
998                         $template_browsenumber = 1;
1000                 }
1002                 # Check if the template browse number is valid and if it isn't
1003                 # then return an error.
1005                 my $kiriwrite_browsenumber_length_check         = kiriwrite_variablecheck($template_browsenumber, "maxlength", 7, 1);
1006                 my $kiriwrite_browsenumber_number_check         = kiriwrite_variablecheck($template_browsenumber, "numbers", 0, 1);
1008                 if ($kiriwrite_browsenumber_length_check eq 1){
1010                         # The browse number was too long so return
1011                         # an error.
1013                         kiriwrite_error("browsenumbertoolong");
1015                 }
1017                 if ($kiriwrite_browsenumber_number_check eq 1){
1019                         # The browse number wasn't a number so
1020                         # return an error.
1022                         kiriwrite_error("browsenumberinvalid");
1024                 }
1026                 # Start a form for using the template browsing list with.
1028                 $main::kiriwrite_presmodule->startform($main::kiriwrite_env{"script_filename"}, "GET");
1029                 $main::kiriwrite_presmodule->addhiddendata("mode", "template");
1031                 # Write out the template browsing list.
1033                 $main::kiriwrite_presmodule->addtext($main::kiriwrite_lang{template}{showlistpage});
1034                 $main::kiriwrite_presmodule->addselectbox("browsenumber");
1036                 # Write out the list of available pages to browse.
1038                 if (!$template_list_count){
1040                         $template_list_count = 0;
1042                 }
1044                 while ($template_list_count ne $template_list){
1046                         $template_list_count++;
1048                         if ($template_list_count eq 1 && !$template_browsenumber){
1050                                 $main::kiriwrite_presmodule->addoption($template_list_count, { Value => $template_list_count, Selected => 1 });
1052                         } else {
1054                                 if ($template_browsenumber eq $template_list_count){
1056                                         $main::kiriwrite_presmodule->addoption($template_list_count, { Value => $template_list_count, Selected => 1 });
1058                                 } else {
1060                                         $main::kiriwrite_presmodule->addoption($template_list_count, { Value => $template_list_count });
1062                                 }
1064                         }
1066                 }
1068                 $main::kiriwrite_presmodule->endselectbox();
1069                 $main::kiriwrite_presmodule->addbutton("action", { Value => "view", Description => $main::kiriwrite_lang{template}{show} });            
1071                 if ($template_list ne $template_browsenumber){
1073                         $main::kiriwrite_presmodule->addtext(" | ");
1074                         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=template&action=view&browsenumber=" . ($template_browsenumber + 1), { Text => $main::kiriwrite_lang{template}{nextpage} });
1076                 }
1078                 # Check if the filter browse number is not blank and
1079                 # not set as 0 and hide the Previous page link if
1080                 # it is.
1082                 if ($template_browsenumber > 1){
1084                         $main::kiriwrite_presmodule->addtext(" | ");
1085                         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=template&action=view&browsenumber=" . ($template_browsenumber - 1), { Text => $main::kiriwrite_lang{template}{previouspage} });
1087                 }
1089                 $main::kiriwrite_presmodule->addlinebreak();
1090                 $main::kiriwrite_presmodule->addlinebreak();
1092                 $main::kiriwrite_presmodule->starttable("", { CellPadding => 5, CellSpacing => 0 });
1093                 $main::kiriwrite_presmodule->startheader();
1094                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{template}{templatefilename}, { Style => "tablecellheader" });
1095                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{template}{templatename}, { Style => "tablecellheader" });
1096                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{template}{templatedescription}, { Style => "tablecellheader" });
1097                 $main::kiriwrite_presmodule->addheader($main::kiriwrite_lang{common}{options}, { Style => "tablecellheader" });
1098                 $main::kiriwrite_presmodule->endheader();
1100                 foreach $template (@templates_list){
1102                         # Get the template data.
1104                         %template_info = $main::kiriwrite_dbmodule->gettemplateinfo({ TemplateFilename => $template, Reduced => 1 });
1106                         # Check if any errors occured while trying to get the template
1107                         # data.
1109                         if ($main::kiriwrite_dbmodule->geterror eq "TemplateDatabaseError"){
1111                                 # A database error has occured, so return an error.
1113                                 kiriwrite_error("templatedatabaseerror", $main::kiriwrite_dbmodule->geterror(1));
1115                         } elsif ($main::kiriwrite_dbmodule->geterror eq "TemplateDoesNotExist"){
1117                                 # The template does not exist, so process the next template.
1119                                 next;
1121                         }
1123                         $template_filename      = $template_info{"TemplateFileName"};
1124                         $template_name          = $template_info{"TemplateName"};
1125                         $template_description   = $template_info{"TemplateDescription"};
1127                         # Check what style the row of table cells should be.
1128  
1129                         if ($template_style eq 0){
1130  
1131                                 $template_stylename = "tablecell1";
1132                                 $template_style = 1;
1133  
1134                         } else {
1135  
1136                                 $template_stylename = "tablecell2";
1137                                 $template_style = 0;
1138  
1139                         }
1141                         $main::kiriwrite_presmodule->startrow();
1142                         $main::kiriwrite_presmodule->addcell($template_stylename);
1143                         $main::kiriwrite_presmodule->addtext($template_info{"TemplateFilename"});
1144                         $main::kiriwrite_presmodule->endcell();
1145                         $main::kiriwrite_presmodule->addcell($template_stylename);
1147                         # Check if the template name is blank and if it is
1148                         # write a message to say there's no name for the
1149                         # template.
1151                         if (!$template_info{"TemplateName"}){
1152                                 $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{noname});
1153                         } else {
1154                                 $main::kiriwrite_presmodule->addtext($template_info{"TemplateName"});
1155                         }
1157                         $main::kiriwrite_presmodule->endcell();
1158                         $main::kiriwrite_presmodule->addcell($template_stylename);
1160                         # Check if the template description is blank and if
1161                         # it is then write a message to say there's no
1162                         # description for the template.
1164                         if (!$template_info{"TemplateDescription"}){
1165                                 $main::kiriwrite_presmodule->additalictext($main::kiriwrite_lang{blank}{nodescription});
1166                         } else {
1167                                 $main::kiriwrite_presmodule->addtext($template_info{"TemplateDescription"});
1168                         }
1170                         $main::kiriwrite_presmodule->endcell();
1171                         $main::kiriwrite_presmodule->addcell($template_stylename);
1172                         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=template&action=edit&template=" . $template_info{"TemplateFilename"}, { Text => $main::kiriwrite_lang{options}{edit} });
1173                         $main::kiriwrite_presmodule->addlink($main::kiriwrite_env{"script_filename"} . "?mode=template&action=delete&template=" . $template_info{"TemplateFilename"}, { Text => $main::kiriwrite_lang{options}{delete} });
1174                         $main::kiriwrite_presmodule->endcell();
1175                         $main::kiriwrite_presmodule->endrow();
1177                 }
1179                 $main::kiriwrite_presmodule->endtable();
1180                 $main::kiriwrite_presmodule->endform();
1182         }
1184         # Disconnect from the database server.
1186         $main::kiriwrite_dbmodule->disconnect();
1188         $main::kiriwrite_dbmodule->disconnecttemplate();
1189         return $main::kiriwrite_presmodule->grab();
1194 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