8d20001046a071f98afbff5556decf17bb8b727c
[shipsimu.git] / inc / classes / main / helper / web / class_WebFormHelper.php
1 <?php
2 /**
3  * A helper for constructing web forms
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 class WebFormHelper extends BaseHelper implements HelpableTemplate {
25         /**
26          * Instance to the class which provides field values
27          */
28         private $valueInstance = null;
29
30         /**
31          * Wether the form tag is opened (keep at false or else your forms will
32          * never work!)
33          */
34         private $formOpened = false;
35
36         /**
37          * Name of the form
38          */
39         private $formName = "";
40
41         /**
42          * Wether the group is opened or not
43          */
44         private $groupOpened = false;
45
46         /**
47          * Wether the sub group is opened or not
48          */
49         private $subGroupOpened = false;
50
51         /**
52          * Name of the sub group
53          */
54         private $subGroupName = "";
55
56         /**
57          * Wether form tag is enabled (default: true)
58          */
59         private $formEnabled = true;
60
61         // Class Constants
62         const EXCEPTION_FORM_NAME_INVALID       = 0x030;
63         const EXCEPTION_CLOSED_FORM             = 0x031;
64         const EXCEPTION_OPENED_FORM             = 0x032;
65         const EXCEPTION_UNEXPECTED_CLOSED_GROUP = 0x033;
66
67         /**
68          * Protected constructor
69          *
70          * @return      void
71          */
72         protected function __construct () {
73                 // Call parent constructor
74                 parent::__construct(__CLASS__);
75
76                 // Set part description
77                 $this->setObjectDescription("Helper class for HTML forms");
78
79                 // Create unique ID number
80                 $this->generateUniqueId();
81         }
82
83         /**
84          * Creates the helper class with the given template engine instance and form name
85          *
86          * @param       $templateInstance       An instance of a valid template engine
87          * @param       $formName                       Name of the form
88          * @param       $formId                         Value for "id" attribute (default: $formName)
89          * @param       $withForm                       Wether include the form tag
90          * @return      $helperInstance         A preparedf instance of this class
91          */
92         public final static function createWebFormHelper (CompileableTemplate $templateInstance, $formName, $formId = false, $withForm = true) {
93                 // Get new instance
94                 $helperInstance = new WebFormHelper();
95
96                 // Set template instance
97                 $helperInstance->setTemplateInstance($templateInstance);
98
99                 // Is the form id not set?
100                 if ($formId === false) {
101                         // Use form id from form name
102                         $formId = $formName;
103                 } // END - if
104
105                 // Set form name
106                 $helperInstance->setFormName($formName);
107                 // A form-less field may say "false" here...
108                 if ($withForm === true) {
109                         // Create the form
110                         $helperInstance->addFormTag($formName, $formId);
111                 } else {
112                         // Disable form
113                         $helperInstance->enableForm(false);
114                 }
115
116                 // Return the prepared instance
117                 return $helperInstance;
118         }
119
120         /**
121          * Pre-fetches field default values from the given registry key instance into this class
122          *
123          * @param       $registryKey
124          * @return      void
125          * @throws      NullPointerException    If an instance from registry is null
126          */
127         public function prefetchFieldValues ($registryKey) {
128                 // Get the required instance
129                 $this->valueInstance = Registry::getRegistry()->getInstance($registryKey);
130
131                 // Is the instance valid?
132                 if (is_null($this->valueInstance)) {
133                         // Throw an exception
134                         throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
135                 } // END - if
136         }
137
138         /**
139          * Add the form tag or close it an already opened form tag
140          *
141          * @param       $formName       Name of the form (default: false)
142          * @param       $formId         Id of the form (attribute "id"; default: false)
143          * @return      void
144          * @throws      InvalidFormNameException        If the form name is invalid (=false)
145          * @todo        Add some unique PIN here to bypass problems with some browser and/or extensions
146          */
147         public function addFormTag ($formName = false, $formId = false) {
148                 // When the form is not yet opened at least form name must be valid
149                 if (($this->formOpened === false) && ($formName === false)) {
150                         // Thrown an exception
151                         throw new InvalidFormNameException ($this, self::EXCEPTION_FORM_NAME_INVALID);
152                 } // END - if
153
154                 // Close the form is default
155                 $formContent = "</form>";
156
157                 // Check wether we shall open or close the form
158                 if (($this->formOpened === false) && ($this->formEnabled === true)) {
159                         // Add HTML code
160                         $formContent = sprintf("<form name=\"%s\" class=\"forms\" action=\"%s/%s\" method=\"%s\" target=\"%s\"",
161                                 $formName,
162                                 $this->getConfigInstance()->readConfig('base_url'),
163                                 $this->getConfigInstance()->readConfig('form_action'),
164                                 $this->getConfigInstance()->readConfig('form_method'),
165                                 $this->getConfigInstance()->readConfig('form_target')
166                         );
167
168                         // Add form id as well
169                         $formContent .= sprintf(" id=\"%s_form\"",
170                                 $formId
171                         );
172
173                         // Add close bracket
174                         $formContent .= ">";
175
176                         // Open the form and remeber the form name
177                         $this->formOpened = true;
178                 } else {
179                         // Add the hidden field required to identify safely this form
180                         $this->addInputHiddenField('form', $this->getFormName());
181
182                         // Is a group open?
183                         if ($this->groupOpened === true) {
184                                 // Then automatically close it here
185                                 $this->addFormGroup("", "");
186                         } // END - if
187
188                         // Simply close it
189                         $this->formOpened = false;
190                 }
191
192                 // Add it to the content
193                 $this->addContent($formContent);
194         }
195
196         /**
197          * Add a text input tag to the form or throw an exception if it is not yet
198          * opened. The field's name will be set as id.
199          *
200          * @param       $fieldName              Input field name
201          * @param       $fieldValue             Input default value (default: empty)
202          * @return      void
203          * @throws      FormClosedException             If the form is not yet opened
204          */
205         public function addInputTextField ($fieldName, $fieldValue = "") {
206                 // Is the form opened?
207                 if (($this->formOpened === false) && ($this->formEnabled === true)) {
208                         // Throw an exception
209                         throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
210                 } // END - if
211
212                 // Generate the content
213                 $inputContent = sprintf("<input type=\"text\" class=\"textfield\" id=\"%s_field\" name=\"%s\" value=\"%s\" />",
214                         $fieldName,
215                         $fieldName,
216                         $fieldValue
217                 );
218
219                 // And add it maybe with a "li" tag
220                 $this->addContent($inputContent);
221         }
222
223         /**
224          * Add a text input tag to the form with pre-loaded default value
225          *
226          * @param       $fieldName      Input field name
227          * @return      void
228          */
229         public function addInputTextFieldWithDefault ($fieldName) {
230                 // Get the value from instance
231                 $fieldValue = $this->getField($fieldName);
232                 //* DEBUG: */ echo __METHOD__.":".$fieldName."=".$fieldValue."<br />\n";
233
234                 // Add the text field
235                 $this->addInputTextField($fieldName, $fieldValue);
236         }
237
238         /**
239          * Add a password input tag to the form or throw an exception if it is not
240          * yet opened. The field's name will be set as id.
241          *
242          * @param       $fieldName                      Input field name
243          * @param       $fieldValue                     Input default value (default: empty)
244          * @return      void
245          * @throws      FormClosedException             If the form is not yet opened
246          */
247         public function addInputPasswordField ($fieldName, $fieldValue = "") {
248                 // Is the form opened?
249                 if (($this->formOpened === false) && ($this->formEnabled === true)) {
250                         // Throw an exception
251                         throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
252                 } // END - if
253
254                 // Generate the content
255                 $inputContent = sprintf("<input type=\"password\" class=\"password\" id=\"%s_field\" name=\"%s\" value=\"%s\" />",
256                         $fieldName,
257                         $fieldName,
258                         $fieldValue
259                 );
260
261                 // And add it
262                 $this->addContent($inputContent);
263         }
264
265         /**
266          * Add a hidden input tag to the form or throw an exception if it is not
267          * yet opened. The field's name will be set as id.
268          *
269          * @param       $fieldName                      Input field name
270          * @param       $fieldValue                     Input default value (default: empty)
271          * @return      void
272          * @throws      FormClosedException             If the form is not yet opened
273          */
274         public function addInputHiddenField ($fieldName, $fieldValue = "") {
275                 // Is the form opened?
276                 if (($this->formOpened === false) && ($this->formEnabled === true)) {
277                         // Throw an exception
278                         throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
279                 } // END - if
280
281                 // Generate the content
282                 $inputContent = sprintf("<input type=\"hidden\" name=\"%s\" value=\"%s\" />",
283                         $fieldName,
284                         $fieldValue
285                 );
286
287                 // And add it
288                 $this->addContent($inputContent);
289         }
290
291         /**
292          * Add a hidden input tag to the form with pre-loaded default value
293          *
294          * @param       $fieldName      Input field name
295          * @return      void
296          */
297         public function addInputHiddenFieldWithDefault ($fieldName) {
298                 // Get the value from instance
299                 $fieldValue = $this->getField($fieldName);
300                 //* DEBUG: */ echo __METHOD__.":".$fieldName."=".$fieldValue."<br />\n";
301
302                 // Add the text field
303                 $this->addInputHiddenField($fieldName, $fieldValue);
304         }
305
306         /**
307          * Add a hidden input tag to the form with configuration value
308          *
309          * @param       $fieldName      Input field name
310          * @param       $prefix         Prefix for configuration without trailing _
311          * @return      void
312          */
313         public function addInputHiddenConfiguredField ($fieldName, $prefix) {
314                 // Get the value from instance
315                 $fieldValue = $this->getConfigInstance()->readConfig("{$prefix}_{$fieldName}");
316                 //* DEBUG: */ echo __METHOD__.":".$fieldName."=".$fieldValue."<br />\n";
317
318                 // Add the text field
319                 $this->addInputHiddenField($fieldName, $fieldValue);
320         }
321
322         /**
323          * Add a checkbox input tag to the form or throw an exception if it is not
324          * yet opened. The field's name will be set as id.
325          *
326          * @param       $fieldName                      Input field name
327          * @param       $fieldChecked           Wether the field is checked (defaut: checked)
328          * @return      void
329          * @throws      FormClosedException             If the form is not yet opened
330          */
331         public function addInputCheckboxField ($fieldName, $fieldChecked = true) {
332                 // Is the form opened?
333                 if (($this->formOpened === false) && ($this->formEnabled === true)) {
334                         // Throw an exception
335                         throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
336                 } // END - if
337
338                 // Set wether the check box is checked...
339                 $checked = " checked=\"checked\"";
340                 if ($fieldChecked === false) $checked = " ";
341
342                 // Generate the content
343                 $inputContent = sprintf("<input type=\"checkbox\" name=\"%s\" class=\"checkbox\" id=\"%s_field\" value=\"1\"%s/>",
344                         $fieldName,
345                         $fieldName,
346                         $checked
347                 );
348
349                 // And add it
350                 $this->addContent($inputContent);
351         }
352
353         /**
354          * Add a reset input tag to the form or throw an exception if it is not
355          * yet opened. The field's name will be set as id.
356          *
357          * @param       $buttonText             Text displayed on the button
358          * @return      void
359          * @throws      FormClosedException             If the form is not yet opened
360          */
361         public function addInputResetButton ($buttonText) {
362                 // Is the form opened?
363                 if (($this->formOpened === false) && ($this->formEnabled === true)) {
364                         // Throw an exception
365                         throw new FormClosedException (array($this, "reset"), self::EXCEPTION_CLOSED_FORM);
366                 } // END - if
367
368                 // Generate the content
369                 $inputContent = sprintf("<input type=\"reset\" class=\"reset_button\" id=\"%s_reset\" value=\"%s\" />",
370                         $this->getFormName(),
371                         $buttonText
372                 );
373
374                 // And add it
375                 $this->addContent($inputContent);
376         }
377
378         /**
379          * Add a reset input tag to the form or throw an exception if it is not
380          * yet opened. The field's name will be set as id.
381          *
382          * @param       $buttonText                     Text displayed on the button
383          * @return      void
384          * @throws      FormClosedException             If the form is not yet opened
385          */
386         public function addInputSubmitButton ($buttonText) {
387                 // Is the form opened?
388                 if (($this->formOpened === false) && ($this->formEnabled === true)) {
389                         // Throw an exception
390                         throw new FormClosedException (array($this, "submit"), self::EXCEPTION_CLOSED_FORM);
391                 } // END - if
392
393                 // Generate the content
394                 $inputContent = sprintf("<input type=\"submit\" class=\"submit_button\" id=\"%s_submit\" name=\"%s_button\" value=\"%s\" />",
395                         $this->getFormName(),
396                         $this->getFormName(),
397                         $buttonText
398                 );
399
400                 // And add it
401                 $this->addContent($inputContent);
402         }
403
404         /**
405          * Add a form group or close an already opened and open a new one
406          *
407          * @param       $groupName      Name of the group
408          * @param       $groupText      Text including HTML to show above this group
409          * @return      void
410          * @throws      FormClosedException             If no form has been opened before
411          * @throws      EmptyVariableException  If $groupName is not set
412          */
413         public function addFormGroup ($groupName, $groupText) {
414                 // Is a form opened?
415                 if (($this->formOpened === false) && ($this->formEnabled === true)) {
416                         // Throw exception here
417                         throw new FormClosedException(array($this, $groupName), self::EXCEPTION_CLOSED_FORM);
418                 } // END - if
419
420                 // At least the group name should be set
421                 if ((empty($groupName)) && ($this->groupOpened === false)) {
422                         // Throw exception here
423                         throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
424                 } // END - if
425
426                 // Initialize content with closing div by default
427                 $content = "    </div>\n</div><!-- Group - CLOSE //-->";
428
429                 // Is this group opened?
430                 if ($this->groupOpened === false) {
431                         // Begin the div/span blocks
432                         $content = sprintf("<!-- Group %s - OPEN //-->
433 <div class=\"group_box\" id=\"%s_group_box\">
434         <span class=\"group_text\" id=\"%s_group_text\">
435                 %s
436         </span>
437         <div class=\"group_field\" id=\"%s_group_field\">",
438                                 $groupName,
439                                 $groupName,
440                                 $groupName,
441                                 $groupText,
442                                 $groupName
443                         );
444
445                         // Add the content
446                         $this->addContent($content);
447
448                         // Switch the state
449                         $this->groupOpened = true;
450                 } else {
451                         // Is a sub group opened?
452                         if ($this->subGroupOpened === true) {
453                                 // Close it here
454                                 $this->addFormSubGroup("", "");
455                         } // END - if
456
457                         // Add the content
458                         $this->addContent($content);
459
460                         // Switch the state
461                         $this->groupOpened = false;
462
463                         // All call it again if the group name is not empty
464                         if (!empty($groupName)) {
465                                 $this->addFormGroup($groupName, $groupText);
466                         } // END - if
467                 }
468         }
469
470         /**
471          * Add a form sub group or close an already opened and open a new one or
472          * throws an exception if no group has been opened before or if the sub
473          * group name is empty.
474          *
475          * @param       $subGroupName   Name of the group
476          * @param       $subGroupText   Text including HTML to show above this group
477          * @return      void
478          * @throws      FormGroupClosedException        If no group has been opened before
479          * @throws      EmptyVariableException          If $subGroupName is not set
480          */
481         public function addFormSubGroup ($subGroupName, $subGroupText) {
482                 // Is a group opened?
483                 if ($this->groupOpened === false) {
484                         // Throw exception here
485                         throw new FormGroupClosedException(array($this, $subGroupName), self::EXCEPTION_UNEXPECTED_CLOSED_GROUP);
486                 } // END - if
487
488                 // At least the sub group name should be set
489                 if ((empty($subGroupName)) && ($this->subGroupOpened === false)) {
490                         // Throw exception here
491                         throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
492                 } // END - if
493
494                 // Initialize content with closing div by default
495                 $content = "    </div>\n</div><!-- Sub group- CLOSE //-->";
496
497                 // Is this group opened?
498                 if ($this->subGroupOpened === false) {
499                         // Begin the span block
500                         $content = sprintf("<!-- Sub group %s - OPEN //-->
501 <div class=\"subgroup_box\" id=\"%s_subgroup_box\">
502         <span class=\"subgroup_text\" id=\"%s_subgroup_text\">
503                 %s
504         </span>
505         <div class=\"subgroup_field\" id=\"%s_subgroup_field\">",
506                                 $subGroupName,
507                                 $subGroupName,
508                                 $subGroupName,
509                                 $subGroupText,
510                                 $subGroupName
511                         );
512
513                         // Add the content
514                         $this->addContent($content);
515
516                         // Switch the state and remeber the name
517                         $this->subGroupOpened = true;
518                         $this->subGroupName = $subGroupName;
519                 } else {
520                         // Add the content
521                         $this->addContent($content);
522
523                         // Switch the state
524                         $this->subGroupOpened = false;
525
526                         // All call it again if sub group name is not empty
527                         if (!empty($subGroupName)) {
528                                 $this->addFormSubGroup($subGroupName, $subGroupText);
529                         } // END - if
530                 }
531         }
532
533         /**
534          * Add text surrounded by a span block when there is a group opened before
535          * or else by a div block.
536          *
537          * @param       $fieldName                      Field name
538          * @param       $fieldText                      Text for the field
539          * @return      void
540          * @throws      FormClosedException             If the form is not yet opened
541          */
542         public function addFieldText ($fieldName, $fieldText) {
543                 // Is the form opened?
544                 if (($this->formOpened === false) && ($this->formEnabled === true)) {
545                         // Throw an exception
546                         throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
547                 } // END - if
548
549                 // Set the block type
550                 $block = "div";
551                 if ($this->groupOpened === true) $block = "span";
552
553                 // Generate the content
554                 $inputContent = sprintf("       <%s id=\"%s_text\">
555                 %s
556         </%s>",
557                         $block,
558                         $fieldName,
559                         $fieldText,
560                         $block
561                 );
562
563                 // And add it
564                 $this->addContent($inputContent);
565         }
566
567         /**
568          * Add text (notes) surrounded by a div block. Still opened groups or sub
569          * groups will be automatically closed.
570          *
571          * @param       $formNotes      The form notes we shell addd
572          * @return      void
573          * @throws      FormClosedException             If the form is not yet opened
574          */
575         public function addFormNote ($formNotes) {
576                 // Is the form opened?
577                 if (($this->formOpened === false) && ($this->formEnabled === true)) {
578                         // Throw an exception
579                         throw new FormClosedException (array($this, "form_notes"), self::EXCEPTION_CLOSED_FORM);
580                 } // END - if
581
582                 // Is a group open?
583                 if ($this->groupOpened === true) {
584                         // Then automatically close it here
585                         $this->addFormGroup("", "");
586                 } // END - if
587
588                 // Generate the content
589                 $inputContent = sprintf("       <div id=\"form_note\">
590                 %s
591         </div>",
592                         $formNotes
593                 );
594
595                 // And add it
596                 $this->addContent($inputContent);
597         }
598
599         /**
600          * Checks wether the registration requires a valid email address
601          *
602          * @return      $required       Wether the email address is required
603          */
604         public function ifRegisterRequiresEmailVerification () {
605                 $required = ($this->getConfigInstance()->readConfig('register_requires_email') == "Y");
606                 return $required;
607         }
608
609         /**
610          * Checks wether profile data shall be asked
611          *
612          * @return      $required       Wether profile shall be asked
613          */
614         public function ifRegisterIncludesProfile () {
615                 $required = ($this->getConfigInstance()->readConfig('register_includes_profile') == "Y");
616                 return $required;
617         }
618
619         /**
620          * Checks wether personal data shall be asked
621          *
622          * @return      $required       Wether personal data shall be asked
623          */
624         public function ifRegisterIncludesPersonaData () {
625                 $required = ($this->getConfigInstance()->readConfig('register_personal_data') == "Y");
626                 return $required;
627         }
628
629         /**
630          * Checks wether email addresses can only be once used
631          *
632          * @return      $isUnique
633          */
634         public function ifEmailMustBeUnique () {
635                 $isUnique = ($this->getConfigInstance()->readConfig('register_email_unique') == "Y");
636                 return $isUnique;
637         }
638
639         /**
640          * Checks wether the specified chat protocol is enabled in this form
641          *
642          * @return      $required       Wether the specified chat protocol is enabled
643          */
644         public function ifChatEnabled ($chatProtocol) {
645                 $required = ($this->getConfigInstance()->readConfig(sprintf("chat_enabled_%s", $chatProtocol)) == "Y");
646                 return $required;
647         }
648
649         /**
650          * Checks wether login is enabled or disabled
651          *
652          * @return      $isEnabled      Wether the login is enabled or disabled
653          */
654         public function ifLoginIsEnabled () {
655                 $isEnabled = ($this->getConfigInstance()->readConfig('login_enabled') == "Y");
656                 return $isEnabled;
657         }
658
659         /**
660          * Checks wether login shall be done by username
661          *
662          * @return      $isEnabled      Wether the login shall be done by username
663          */
664         public function ifLoginWithUsername () {
665                 $isEnabled = ($this->getConfigInstance()->readConfig('login_type') == "username");
666                 return $isEnabled;
667         }
668
669         /**
670          * Checks wether login shall be done by email
671          *
672          * @return      $isEnabled      Wether the login shall be done by email
673          */
674         public function ifLoginWithEmail () {
675                 $isEnabled = ($this->getConfigInstance()->readConfig('login_type') == "email");
676                 return $isEnabled;
677         }
678
679         /**
680          * Checks wether guest login is allowed
681          *
682          * @return      $isAllowed      Wether guest login is allowed
683          */
684         public function ifGuestLoginAllowed () {
685                 $isAllowed = ($this->getConfigInstance()->readConfig('guest_login_allowed') == "Y");
686                 return $isAllowed;
687         }
688
689         /**
690          * Checks wether the email address change must be confirmed
691          *
692          * @return      $requireConfirm         Wether email change must be confirmed
693          */
694         public function ifEmailChangeRequireConfirmation () {
695                 $requireConfirm = ($this->getConfigInstance()->readConfig('email_change_confirmation') == "Y");
696                 return $requireConfirm;
697         }
698
699         /**
700          * Checks wether the rules has been updated
701          *
702          * @return      $rulesUpdated   Wether rules has been updated
703          * @todo        Implement check if rules have been changed
704          */
705         public function ifRulesHaveChanged () {
706                 return false;
707         }
708
709         /**
710          * Checks wether email change is allowed
711          *
712          * @return      $emailChange    Wether changing email address is allowed
713          */
714         public function ifEmailChangeAllowed () {
715                 $emailChange = ($this->getConfigInstance()->readConfig('email_change_allowed') == "Y");
716                 return $emailChange;
717         }
718
719         /**
720          * Checks wether the user account is unconfirmed
721          *
722          * @return      $isUnconfirmed  Wether the user account is unconfirmed
723          */
724         public function ifUserAccountUnconfirmed () {
725                 $isUnconfirmed = ($this->getField('user_status') === $this->getConfigInstance()->readConfig('user_status_unconfirmed'));
726                 return $isUnconfirmed;
727         }
728
729         /**
730          * Checks wether the user account is locked
731          *
732          * @return      $isUnconfirmed  Wether the user account is locked
733          */
734         public function ifUserAccountLocked () {
735                 $isUnconfirmed = ($this->getField('user_status') === $this->getConfigInstance()->readConfig('user_status_locked'));
736                 return $isUnconfirmed;
737         }
738
739         /**
740          * Checks wether the user account is a guest
741          *
742          * @return      $isUnconfirmed  Wether the user account is a guest
743          */
744         public function ifUserAccountGuest () {
745                 $isUnconfirmed = ($this->getField('user_status') === $this->getConfigInstance()->readConfig('user_status_guest'));
746                 return $isUnconfirmed;
747         }
748
749         /**
750          * Checks wether this form is secured by a CAPTCHA
751          *
752          * @return      $isSecured      Wether this form is secured by a CAPTCHA
753          */
754         public function ifFormSecuredWithCaptcha () {
755                 $isSecured = ($this->getConfigInstance()->readConfig($this->getFormName()."_captcha_secured") == "Y");
756                 return $isSecured;
757         }
758
759         /**
760          * Flushs the content out (not yet secured against open forms, etc.!) or
761          * close the form automatically
762          *
763          * @return      void
764          * @throws      FormOpenedException             If the form is still open
765          */
766         public function flushContent () {
767                 // Is the form still open?
768                 if (($this->formOpened === true) && ($this->formEnabled === true)) {
769                         // Close the form automatically
770                         $this->addFormTag();
771                 } // END - if
772
773                 // Send content to template engine
774                 $this->getTemplateInstance()->assignVariable($this->getFormName(), $this->getContent());
775         }
776
777         /**
778          * Getter for direct field values
779          *
780          * @param       $fieldName              Name of the field we shall fetch
781          * @return      $fieldValue             Value from field
782          */
783         public function getField ($fieldName) {
784                 // Get the field value
785                 $fieldValue = call_user_func_array(array($this->valueInstance, 'getField'), array($fieldName));
786
787                 // Return it
788                 return $fieldValue;
789         }
790
791         /**
792          * Adds a pre-configured CAPTCHA
793          *
794          * @return      void
795          */
796         public function addCaptcha () {
797                 // Get last executed pre filter
798                 $extraInstance = Registry::getRegistry()->getInstance('extra');
799
800                 // Get a configured instance
801                 $captchaInstance = ObjectFactory::createObjectByConfiguredName($this->getFormName()."_captcha", array($this->getTemplateInstance(), $extraInstance));
802
803                 // Initiate the CAPTCHA
804                 $captchaInstance->initiateCaptcha();
805
806                 // Render the CAPTCHA code
807                 $captchaInstance->renderCode();
808
809                 // Get the content and add it to the helper
810                 $this->addContent($captchaInstance->getContent());
811         }
812
813         /**
814          * Enables/disables the form tag usage
815          *
816          * @param       $formEnabled    Wether form is enabled or disabled
817          * @return      void
818          */
819         public final function enableForm ($formEnabled = true) {
820                 $this->formEnabled = (bool) $formEnabled;
821         }
822
823         /**
824          * Setter for form name
825          *
826          * @param       $formName       Name of this form
827          * @return      void
828          */
829         public final function setFormName ($formName) {
830                 $this->formName = (string) $formName;
831         }
832
833         /**
834          * Getter for form name
835          *
836          * @return      $formName       Name of this form
837          */
838         public final function getFormName () {
839                 return $this->formName;
840         }
841 }
842
843 // [EOF]
844 ?>