]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/helper/web/class_WebFormHelper.php
Final fixes for variable inserting
[shipsimu.git] / inc / classes / main / helper / web / class_WebFormHelper.php
index 43ea97822218276adde87a38717d69b8046a878f..1ec70bca8d5e36c56b75e3030bb2153f6997a80b 100644 (file)
@@ -48,6 +48,11 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate {
         */
        private $subGroupOpened = false;
 
         */
        private $subGroupOpened = false;
 
+       /**
+        * Name of the group
+        */
+       private $groupName = "";
+
        /**
         * Name of the sub group
         */
        /**
         * Name of the sub group
         */
@@ -182,7 +187,7 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate {
                        // Is a group open?
                        if ($this->groupOpened === true) {
                                // Then automatically close it here
                        // Is a group open?
                        if ($this->groupOpened === true) {
                                // Then automatically close it here
-                               $this->addFormGroup("", "");
+                               $this->addFormGroup();
                        } // END - if
 
                        // Simply close it
                        } // END - if
 
                        // Simply close it
@@ -404,13 +409,13 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate {
        /**
         * Add a form group or close an already opened and open a new one
         *
        /**
         * Add a form group or close an already opened and open a new one
         *
-        * @param       $groupName      Name of the group
+        * @param       $groupName      Name of the group or last opened if empty
         * @param       $groupText      Text including HTML to show above this group
         * @return      void
         * @throws      FormClosedException             If no form has been opened before
         * @throws      EmptyVariableException  If $groupName is not set
         */
         * @param       $groupText      Text including HTML to show above this group
         * @return      void
         * @throws      FormClosedException             If no form has been opened before
         * @throws      EmptyVariableException  If $groupName is not set
         */
-       public function addFormGroup ($groupName, $groupText) {
+       public function addFormGroup ($groupName = "", $groupText = "") {
                // Is a form opened?
                if (($this->formOpened === false) && ($this->formEnabled === true)) {
                        // Throw exception here
                // Is a form opened?
                if (($this->formOpened === false) && ($this->formEnabled === true)) {
                        // Throw exception here
@@ -421,6 +426,15 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate {
                if ((empty($groupName)) && ($this->groupOpened === false)) {
                        // Throw exception here
                        throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
                if ((empty($groupName)) && ($this->groupOpened === false)) {
                        // Throw exception here
                        throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+               } elseif (empty($groupName)) {
+                       // Close the last opened
+                       $groupName = $this->groupName;
+               }
+
+               // Same group to open?
+               if (($this->groupOpened === false) && ($groupName == $this->groupName)) {
+                       // Abort here silently
+                       return false;
                } // END - if
 
                // Initialize content with closing div by default
                } // END - if
 
                // Initialize content with closing div by default
@@ -446,12 +460,13 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate {
                        $this->addContent($content);
 
                        // Switch the state
                        $this->addContent($content);
 
                        // Switch the state
+                       $this->groupName = $groupName;
                        $this->groupOpened = true;
                } else {
                        // Is a sub group opened?
                        if ($this->subGroupOpened === true) {
                                // Close it here
                        $this->groupOpened = true;
                } else {
                        // Is a sub group opened?
                        if ($this->subGroupOpened === true) {
                                // Close it here
-                               $this->addFormSubGroup("", "");
+                               $this->addFormSubGroup();
                        } // END - if
 
                        // Add the content
                        } // END - if
 
                        // Add the content
@@ -472,13 +487,13 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate {
         * throws an exception if no group has been opened before or if the sub
         * group name is empty.
         *
         * throws an exception if no group has been opened before or if the sub
         * group name is empty.
         *
-        * @param       $subGroupName   Name of the group
+        * @param       $subGroupName   Name of the group or last opened if empty
         * @param       $subGroupText   Text including HTML to show above this group
         * @return      void
         * @throws      FormGroupClosedException        If no group has been opened before
         * @throws      EmptyVariableException          If $subGroupName is not set
         */
         * @param       $subGroupText   Text including HTML to show above this group
         * @return      void
         * @throws      FormGroupClosedException        If no group has been opened before
         * @throws      EmptyVariableException          If $subGroupName is not set
         */
-       public function addFormSubGroup ($subGroupName, $subGroupText) {
+       public function addFormSubGroup ($subGroupName = "", $subGroupText = "") {
                // Is a group opened?
                if ($this->groupOpened === false) {
                        // Throw exception here
                // Is a group opened?
                if ($this->groupOpened === false) {
                        // Throw exception here
@@ -489,7 +504,10 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate {
                if ((empty($subGroupName)) && ($this->subGroupOpened === false)) {
                        // Throw exception here
                        throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
                if ((empty($subGroupName)) && ($this->subGroupOpened === false)) {
                        // Throw exception here
                        throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
-               } // END - if
+               } elseif (empty($subGroupName)) {
+                       // Close the last opened
+                       $subGroupName = $this->subGroupName;
+               }
 
                // Initialize content with closing div by default
                $content = "    </div>\n</div><!-- Sub group- CLOSE //-->";
 
                // Initialize content with closing div by default
                $content = "    </div>\n</div><!-- Sub group- CLOSE //-->";
@@ -582,7 +600,7 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate {
                // Is a group open?
                if ($this->groupOpened === true) {
                        // Then automatically close it here
                // Is a group open?
                if ($this->groupOpened === true) {
                        // Then automatically close it here
-                       $this->addFormGroup("", "");
+                       $this->addFormGroup();
                } // END - if
 
                // Generate the content
                } // END - if
 
                // Generate the content
@@ -768,9 +786,18 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate {
                if (($this->formOpened === true) && ($this->formEnabled === true)) {
                        // Close the form automatically
                        $this->addFormTag();
                if (($this->formOpened === true) && ($this->formEnabled === true)) {
                        // Close the form automatically
                        $this->addFormTag();
-               } // END - if
+               } elseif ($this->formEnabled === false) {
+                       if ($this->subGroupOpened === true) {
+                               // Close sub group
+                               $this->addFormSubGroup();
+                       } elseif ($this->groupOpened === true) {
+                               // Close group
+                               $this->addFormGroup();
+                       }
+               }
 
                // Send content to template engine
 
                // Send content to template engine
+               //* DEBUG: */ echo __METHOD__.": form=".$this->getFormName().", size=".strlen($this->getContent())."<br />\n";
                $this->getTemplateInstance()->assignVariable($this->getFormName(), $this->getContent());
        }
 
                $this->getTemplateInstance()->assignVariable($this->getFormName(), $this->getContent());
        }
 
@@ -798,7 +825,7 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate {
                $extraInstance = Registry::getRegistry()->getInstance('extra');
 
                // Get a configured instance
                $extraInstance = Registry::getRegistry()->getInstance('extra');
 
                // Get a configured instance
-               $captchaInstance = ObjectFactory::createObjectByConfiguredName($this->getFormName()."_captcha", array($this->getTemplateInstance(), $extraInstance));
+               $captchaInstance = ObjectFactory::createObjectByConfiguredName($this->getFormName()."_captcha", array($this, $extraInstance));
 
                // Initiate the CAPTCHA
                $captchaInstance->initiateCaptcha();
 
                // Initiate the CAPTCHA
                $captchaInstance->initiateCaptcha();