X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fhelper%2Fweb%2Fforms%2Fclass_WebFormHelper.php;h=1fffb7af1d9c215d0de1850bce4190ee0bf92aa6;hb=5bf79580029c4f6ee71e6c9e7890169e4b344def;hp=d167768878bed59912c5e98324eb994ace2167f8;hpb=ec23e72b16433ac136817f3ea78697fb70236e4a;p=shipsimu.git diff --git a/inc/classes/main/helper/web/forms/class_WebFormHelper.php b/inc/classes/main/helper/web/forms/class_WebFormHelper.php index d167768..1fffb7a 100644 --- a/inc/classes/main/helper/web/forms/class_WebFormHelper.php +++ b/inc/classes/main/helper/web/forms/class_WebFormHelper.php @@ -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); } /** @@ -375,7 +378,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate { } // END - if // At least the group name should be set - if ((empty($groupId)) && (!$this->ifGroupOpenedPreviously())) { + if ((empty($groupId)) && ($this->ifGroupOpenedPreviously() === false)) { // Throw exception here throw new EmptyVariableException(array($this, 'groupId'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); } elseif (empty($groupId)) { @@ -384,7 +387,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate { } // Same group to open? - if ((!$this->ifGroupOpenedPreviously()) && ($groupId == $this->getPreviousGroupId())) { + if (($this->ifGroupOpenedPreviously() === false) && ($groupId === $this->getPreviousGroupId())) { // Abort here silently return false; } // END - if @@ -393,7 +396,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate { $content = " \n"; // Is this group opened? - if (!$this->ifGroupOpenedPreviously()) { + if ($this->ifGroupOpenedPreviously() === false) { // Begin the div/span blocks $content = sprintf("
@@ -409,7 +412,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate { ); // Switch the state - $this->openGroupByIdContent($groupId, $content); + $this->openGroupByIdContent($groupId, $content, "div"); } else { // Is a sub group opened? if ($this->ifSubGroupOpenedPreviously()) { @@ -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)) { + // All call it again if group name is not empty + if ((!empty($groupId)) && ($groupId != $prevGroupId)) { + //* DEBUG: */ echo $groupId."/".$prevGroupId."
\n"; $this->addFormGroup($groupId, $groupText); } // END - if } @@ -429,8 +436,8 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate { /** * Add a form sub group or close an already opened and open a new one or - * 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 sub group + * name is empty. * * @param $subGroupId Name of the group or last opened if empty * @param $subGroupText Text including HTML to show above this group @@ -440,22 +447,22 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate { */ public function addFormSubGroup ($subGroupId = "", $subGroupText = "") { // Is a group opened? - if (!$this->ifGroupOpenedPreviously()) { + if ($this->ifGroupOpenedPreviously() === false) { // Throw exception here throw new FormFormClosedException(array($this, $subGroupId), self::EXCEPTION_UNEXPECTED_CLOSED_GROUP); } // END - if // At least the sub group name should be set - if ((empty($subGroupId)) && (!$this->ifSubGroupOpenedPreviously())) { + if ((empty($subGroupId)) && ($this->ifSubGroupOpenedPreviously() === false)) { // Throw exception here 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() === false) && ($subGroupId == $this->getPreviousSubGroupId())) { // Abort here silently return false; } // END - if @@ -464,7 +471,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate { $content = "
\n"; // Is this group opened? - if (!$this->ifSubGroupOpenedPreviously()) { + if ($this->ifSubGroupOpenedPreviously() === false) { // Begin the span block $content = sprintf("
@@ -480,13 +487,16 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate { ); // Switch the state and remeber the name - $this->openSubGroupByIdContent($subGroupId, $content); + $this->openSubGroupByIdContent($subGroupId, $content, "div"); } 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); } /** @@ -542,12 +552,6 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate { throw new FormClosedException (array($this, "form_notes"), self::EXCEPTION_CLOSED_FORM); } // END - if - // Is a group open? - if ($this->ifGroupOpenedPreviously()) { - // Then automatically close it here - $this->addFormGroup(); - } // END - if - // Generate the content $inputContent = sprintf("
%s @@ -557,27 +561,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() === false) && ($this->getPreviousSubGroupId() !== $selectId)) { + // Initialize first entry (which might be non-selectable if content is provided + if (!empty($firstEntry)) { + // Add selection around it + $firstEntry = sprintf("\n", + $firstEntry + ); + } // END - if + + // Construct the opening select tag + $content = sprintf(""); + } } /** - * 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() === false) { + // 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("\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() === false) { + // 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("\n", + $optionName, + $optionName, + $optionValue + ); + + // Add the content to the previously opened sub group + $this->addContentToPreviousGroup($content); } /** @@ -599,7 +685,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 +717,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 +770,8 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate { } // Send content to template engine - //* DEBUG: */ echo __METHOD__.": form=".$this->getFormName().", size=".strlen($this->getContent())."
\n"; - $this->getTemplateInstance()->assignVariable($this->getFormName(), $this->getContent()); + //* DEBUG: */ echo __METHOD__.": form=".$this->getFormName().", size=".strlen($this->renderContent())."
\n"; + $this->getTemplateInstance()->assignVariable($this->getFormName(), $this->renderContent()); } }