]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/helper/web/forms/class_WebFormHelper.php
Payment introduced, minor rewrites
[shipsimu.git] / inc / classes / main / helper / web / forms / class_WebFormHelper.php
index d167768878bed59912c5e98324eb994ace2167f8..a188251b5cd84215b1e2c94e55a4ef4beb77a3c1 100644 (file)
@@ -132,6 +132,9 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
 
                        // Open the form and remeber the form name
                        $this->formOpened = true;
+
+                       // Add it to the content
+                       $this->addHeaderContent($formContent);
                } else {
                        // Add the hidden field required to identify safely this form
                        $this->addInputHiddenField('form', $this->getFormName());
@@ -144,10 +147,10 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
 
                        // Simply close it
                        $this->formOpened = false;
-               }
 
-               // Add it to the content
-               $this->addContent($formContent);
+                       // Add it to the content
+                       $this->addFooterContent($formContent);
+               }
        }
 
        /**
@@ -174,7 +177,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                );
 
                // And add it maybe with a "li" tag
-               $this->addContent($inputContent);
+               $this->addContentToPreviousGroup($inputContent);
        }
 
        /**
@@ -216,7 +219,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                );
 
                // And add it
-               $this->addContent($inputContent);
+               $this->addContentToPreviousGroup($inputContent);
        }
 
        /**
@@ -242,7 +245,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                );
 
                // And add it
-               $this->addContent($inputContent);
+               $this->addContentToPreviousGroup($inputContent);
        }
 
        /**
@@ -304,7 +307,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                );
 
                // And add it
-               $this->addContent($inputContent);
+               $this->addContentToPreviousGroup($inputContent);
        }
 
        /**
@@ -329,7 +332,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                );
 
                // And add it
-               $this->addContent($inputContent);
+               $this->addContentToPreviousGroup($inputContent);
        }
 
        /**
@@ -355,7 +358,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                );
 
                // And add it
-               $this->addContent($inputContent);
+               $this->addContentToPreviousGroup($inputContent);
        }
 
        /**
@@ -417,11 +420,15 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                                $this->addFormSubGroup();
                        } // END - if
 
+                       // Get previous group id
+                       $prevGroupId = $this->getPreviousGroupId();
+
                        // Switch the state
                        $this->closePreviousGroupByContent($content);
 
                        // All call it again if the group name is not empty
-                       if (!empty($groupId)) {
+                       if ((!empty($groupId)) && ($groupId != $prevGroupId)) {
+                               //* DEBUG: */ echo $groupId."/".$prevGroupId."<br />\n";
                                $this->addFormGroup($groupId, $groupText);
                        } // END - if
                }
@@ -451,11 +458,11 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                        throw new EmptyVariableException(array($this, 'subGroupId'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
                } elseif (empty($subGroupId)) {
                        // Close the last opened
-                       $subGroupId = $this->getSubGroupId();
+                       $subGroupId = $this->getPreviousSubGroupId();
                }
 
                // Same sub group to open?
-               if ((!$this->ifSubGroupOpenedPreviously()) && ($subGroupId == $this->getSubGroupId())) {
+               if ((!$this->ifSubGroupOpenedPreviously()) && ($subGroupId == $this->getPreviousSubGroupId())) {
                        // Abort here silently
                        return false;
                } // END - if
@@ -482,11 +489,14 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                        // Switch the state and remeber the name
                        $this->openSubGroupByIdContent($subGroupId, $content);
                } else {
+                       // Get previous sub group id
+                       $prevSubGroupId = $this->getPreviousSubGroupId();
+
                        // Switch the state
                        $this->closePreviousSubGroupByContent($content);
 
                        // All call it again if sub group name is not empty
-                       if (!empty($subGroupId)) {
+                       if ((!empty($subGroupId)) && ($subGroupId != $prevSubGroupId)) {
                                $this->addFormSubGroup($subGroupId, $subGroupText);
                        } // END - if
                }
@@ -523,7 +533,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                );
 
                // And add it
-               $this->addContent($inputContent);
+               $this->addContentToPreviousGroup($inputContent);
        }
 
        /**
@@ -557,27 +567,109 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                );
 
                // And add it
-               $this->addContent($inputContent);
+               $this->addContentToPreviousGroup($inputContent);
        }
 
        /**
-        * Checks wether the registration requires a valid email address
+        * Adds a selection box as a sub group to the form. Do not box this into
+        * another sub group. Sub-sub groups are not (yet) supported.
         *
-        * @return      $required       Wether the email address is required
+        * @param       $selectId               Id of the selection box
+        * @param       $firstEntry             Content to be added as first non-selectable entry
+        * @return      void
+        * @throws      FormClosedException             If the form is not yet opened
         */
-       public function ifRegisterRequiresEmailVerification () {
-               $required = ($this->getConfigInstance()->readConfig('register_requires_email') === "Y");
-               return $required;
+       public function addInputSelectField ($selectId, $firstEntry) {
+               // Is the form group opened?
+               if (($this->formOpened === false) && ($this->formEnabled === true)) {
+                       // Throw an exception
+                       throw new FormClosedException (array($this, "form_notes"), self::EXCEPTION_CLOSED_FORM);
+               } // END - if
+
+               // Shall we close or open the sub group?
+               if ((!$this->ifSubGroupOpenedPreviously()) && ($this->getPreviousSubGroupId() !== $selectId)) {
+                       // Initialize first entry (which might be non-selectable if content is provided
+                       if (!empty($firstEntry)) {
+                               // Add selection around it
+                               $firstEntry = sprintf("<option value=\"invalid\" disabled=\"disabled\">%s</option>\n",
+                                       $firstEntry
+                               );
+                       } // END - if
+
+                       // Construct the opening select tag
+                       $content = sprintf("<select class=\"select_box\" id=\"%s_%s\" name=\"%s\">\n%s",
+                               $this->getFormName(),
+                               $selectId,
+                               $selectId,
+                               $firstEntry
+                       );
+
+                       // Open the sub group
+                       $this->openSubGroupByIdContent($selectId, $content);
+               } elseif ($this->getPreviousSubGroupId() != $selectId) {
+                       // Something went wrong!
+                       $this->debugInstance();
+               } else {
+                       // Close the sub group
+                       $this->closePreviousSubGroupByContent("</select>");
+               }
        }
 
        /**
-        * Checks wether profile data shall be asked
+        * Adds a non-selectable sub option to a previously added selection box.
+        * This method does *not* validate if there is already a sub option added
+        * with the same name. We need to finish this here!
         *
-        * @return      $required       Wether profile shall be asked
+        * @param       $subName        Name of the sub action
+        * @param       $subValue       Value of the sub action
+        * @return      void
+        * @throws      HelperNoPreviousOpenedSubGroupException If no previously opened sub group was found
+        * @todo        Add checking if sub option is already added
         */
-       public function ifRegisterIncludesProfile () {
-               $required = ($this->getConfigInstance()->readConfig('register_includes_profile') === "Y");
-               return $required;
+       public function addSelectSubOption ($subName, $subValue) {
+               // Is there a sub group (shall be a selection box!)
+               if (!$this->ifSubGroupOpenedPreviously()) {
+                       // Then throw an exception here
+                       throw new HelperNoPreviousOpenedSubGroupException(array($this, $content), self::EXCEPTION_NO_PREVIOUS_SUB_GROUP_OPENED);
+               } // END - if
+
+               // Render the content
+               $content = sprintf("<option value=\"invalid\" class=\"suboption suboption_%s\" disabled=\"disabled\">%s</option>\n",
+                       $subName,
+                       $subValue
+               );
+
+               // Add the content to the previously opened sub group
+               $this->addContentToPreviousGroup($content);
+       }
+
+       /**
+        * Adds a selectable option to a previously added selection box. This method
+        * does *not* validate if there is already a sub option added with the same
+        * name. We need to finish this here!
+        *
+        * @param       $optionName     Name of the sub action
+        * @param       $optionValue    Value of the sub action
+        * @return      void
+        * @throws      HelperNoPreviousOpenedSubGroupException If no previously opened sub group was found
+        * @todo        Add checking if sub option is already added
+        */
+       public function addSelectOption ($optionName, $optionValue) {
+               // Is there a sub group (shall be a selection box!)
+               if (!$this->ifSubGroupOpenedPreviously()) {
+                       // Then throw an exception here
+                       throw new HelperNoPreviousOpenedSubGroupException(array($this, $content), self::EXCEPTION_NO_PREVIOUS_SUB_GROUP_OPENED);
+               } // END - if
+
+               // Render the content
+               $content = sprintf("<option value=\"%s\" class=\"option option_%s\">%s</option>\n",
+                       $optionName,
+                       $optionName,
+                       $optionValue
+               );
+
+               // Add the content to the previously opened sub group
+               $this->addContentToPreviousGroup($content);
        }
 
        /**
@@ -599,7 +691,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                $captchaInstance->renderCode();
 
                // Get the content and add it to the helper
-               $this->addContent($captchaInstance->getContent());
+               $this->addContentToPreviousGroup($captchaInstance->renderContent());
        }
 
        /**
@@ -631,6 +723,26 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                return $this->formName;
        }
 
+       /**
+        * Checks wether the registration requires a valid email address
+        *
+        * @return      $required       Wether the email address is required
+        */
+       public function ifRegisterRequiresEmailVerification () {
+               $required = ($this->getConfigInstance()->readConfig('register_requires_email') === "Y");
+               return $required;
+       }
+
+       /**
+        * Checks wether profile data shall be asked
+        *
+        * @return      $required       Wether profile data shall be asked
+        */
+       public function ifRegisterIncludesProfile () {
+               $required = ($this->getConfigInstance()->readConfig('register_includes_profile') === "Y");
+               return $required;
+       }
+
        /**
         * Checks wether this form is secured by a CAPTCHA
         *
@@ -664,8 +776,8 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                }
 
                // Send content to template engine
-               //* DEBUG: */ echo __METHOD__.": form=".$this->getFormName().", size=".strlen($this->getContent())."<br />\n";
-               $this->getTemplateInstance()->assignVariable($this->getFormName(), $this->getContent());
+               //* DEBUG: */ echo __METHOD__.": form=".$this->getFormName().", size=".strlen($this->renderContent())."<br />\n";
+               $this->getTemplateInstance()->assignVariable($this->getFormName(), $this->renderContent());
        }
 }