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