From cc6ac14e62a0ba455caffae6870f6264141b0819 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 27 May 2008 12:18:50 +0000 Subject: [PATCH] Registration form and form helper completed, XHTML markup errors fixed --- .gitattributes | 12 +- .../templates/de/code/selector_main.ctp | 12 +- application/ship-simu/config.php | 36 ++ .../ship-simu/templates/de/code/header.ctp | 2 +- .../ship-simu/templates/de/code/register.ctp | 32 +- inc/classes/exceptions/helper/.htaccess | 1 + .../class_FormClosedException.php | 0 .../helper/class_FormGroupClosedException.php | 46 ++ .../class_FormOpenedException.php | 0 .../class_InvalidFormNameException.php | 0 ...s_InvalidTemplateVariableNameException.php | 3 +- .../main/class_BaseFrameworkSystem.php | 14 +- inc/classes/main/helper/class_ | 2 +- ...emplateHelper.php => class_BaseHelper.php} | 10 +- .../main/helper/web/class_HtmlFormHelper.php | 224 ------- .../main/helper/web/class_WebFormHelper.php | 574 ++++++++++++++++++ .../main/template/class_TemplateEngine.php | 2 +- inc/config.php | 12 - templates/de/code/header.ctp | 2 +- 19 files changed, 711 insertions(+), 273 deletions(-) create mode 100644 inc/classes/exceptions/helper/.htaccess rename inc/classes/exceptions/{template => helper}/class_FormClosedException.php (100%) create mode 100644 inc/classes/exceptions/helper/class_FormGroupClosedException.php rename inc/classes/exceptions/{template => helper}/class_FormOpenedException.php (100%) rename inc/classes/exceptions/{template => helper}/class_InvalidFormNameException.php (100%) rename inc/classes/main/helper/{class_BaseTemplateHelper.php => class_BaseHelper.php} (88%) delete mode 100644 inc/classes/main/helper/web/class_HtmlFormHelper.php create mode 100644 inc/classes/main/helper/web/class_WebFormHelper.php diff --git a/.gitattributes b/.gitattributes index 7c2e327..afa5c07 100644 --- a/.gitattributes +++ b/.gitattributes @@ -153,6 +153,11 @@ inc/classes/exceptions/database/local_file/class_SavePathIsEmptyException.php -t inc/classes/exceptions/database/local_file/class_SavePathIsNoDirectoryException.php -text inc/classes/exceptions/database/local_file/class_SavePathReadProtectedException.php -text inc/classes/exceptions/database/local_file/class_SavePathWriteProtectedException.php -text +inc/classes/exceptions/helper/.htaccess -text +inc/classes/exceptions/helper/class_FormClosedException.php -text +inc/classes/exceptions/helper/class_FormGroupClosedException.php -text +inc/classes/exceptions/helper/class_FormOpenedException.php -text +inc/classes/exceptions/helper/class_InvalidFormNameException.php -text inc/classes/exceptions/io/.htaccess -text inc/classes/exceptions/io/class_DirPointerNotOpenedException.php -text inc/classes/exceptions/io/class_FilePointerNotOpenedException.php -text @@ -197,10 +202,7 @@ inc/classes/exceptions/template/.htaccess -text inc/classes/exceptions/template/class_BasePathIsEmptyException.php -text inc/classes/exceptions/template/class_BasePathIsNoDirectoryException.php -text inc/classes/exceptions/template/class_BasePathReadProtectedException.php -text -inc/classes/exceptions/template/class_FormClosedException.php -text -inc/classes/exceptions/template/class_FormOpenedException.php -text inc/classes/exceptions/template/class_InvalidBasePathStringException.php -text -inc/classes/exceptions/template/class_InvalidFormNameException.php -text inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php -text inc/classes/exceptions/template/class_UnexpectedTemplateTypeException.php -text inc/classes/exceptions/template/class_UnsupportedTemplateEngineException.php -text @@ -288,9 +290,9 @@ inc/classes/main/factories/web/.htaccess -text inc/classes/main/factories/web/class_NewsFactory.php -text inc/classes/main/helper/.htaccess -text inc/classes/main/helper/class_ -text -inc/classes/main/helper/class_BaseTemplateHelper.php -text +inc/classes/main/helper/class_BaseHelper.php -text inc/classes/main/helper/web/.htaccess -text -inc/classes/main/helper/web/class_HtmlFormHelper.php -text +inc/classes/main/helper/web/class_WebFormHelper.php -text inc/classes/main/io/.htaccess -text inc/classes/main/io/class_FileIoStream.php -text inc/classes/main/io/class_FrameworkDirectoryPointer.php -text diff --git a/application/selector/templates/de/code/selector_main.ctp b/application/selector/templates/de/code/selector_main.ctp index 4779a57..1bdaaee 100644 --- a/application/selector/templates/de/code/selector_main.ctp +++ b/application/selector/templates/de/code/selector_main.ctp @@ -1,15 +1,17 @@ - - {?header?} {?navigation?}
- [HEADER_APPLICATION_SELECTOR] +[HEADER_APPLICATION_SELECTOR]
- {?selector_apps?} +{?selector_apps?} +
+ + -{?footer_msg:footer_msg=[FOOTER_APPLICATION_SELECTOR]?} +{?footer?} diff --git a/application/ship-simu/config.php b/application/ship-simu/config.php index a1c85d6..7c924f2 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -31,5 +31,41 @@ $cfg->setConfigEntry("default_command", "home"); // CFG: HOME-WITH-NEWS $cfg->setConfigEntry("home_with_news", "Y"); +// CFG: FORM-ACTION +$cfg->setConfigEntry("form_action", "index.php?app={?app_short_name?}&page=do_form"); + +// CFG: FORM-METHOD +$cfg->setConfigEntry("form_method", "post"); + +// CFG: FORM-TARGET +$cfg->setConfigEntry("form_target", "_self"); + +// CFG: REGISTRATION-REQUIRES-EMAIL +$cfg->setConfigEntry("register_requires_email", "Y"); + +// CFG: REGISTRATION-INCLUDES-PROFILE +$cfg->setConfigEntry("register_includes_profile", "Y"); + +// CFG: REGISTRATION-PERSONAL-DATA +$cfg->setConfigEntry("register_personal_data", "Y"); + +// CFG: CHAT-ENABLED-ICQ +$cfg->setConfigEntry("chat_enabled_icq", "Y"); + +// CFG: CHAT-ENABLED-JABBER +$cfg->setConfigEntry("chat_enabled_jabber", "Y"); + +// CFG: CHAT-ENABLED-YAHOO +$cfg->setConfigEntry("chat_enabled_yahoo", "Y"); + +// CFG: CHAT-ENABLED-AOL +$cfg->setConfigEntry("chat_enabled_aol", "Y"); + +// CFG: CHAT-ENABLED-MSN +$cfg->setConfigEntry("chat_enabled_msn", "Y"); + +// CFG: COMMAND-PARAMETER +$cfg->setConfigEntry("command_parameter", "page"); + // [EOF] ?> diff --git a/application/ship-simu/templates/de/code/header.ctp b/application/ship-simu/templates/de/code/header.ctp index 2306a6b..2134e43 100644 --- a/application/ship-simu/templates/de/code/header.ctp +++ b/application/ship-simu/templates/de/code/header.ctp @@ -10,7 +10,7 @@ - + diff --git a/application/ship-simu/templates/de/code/register.ctp b/application/ship-simu/templates/de/code/register.ctp index cfdbf8c..adc4561 100644 --- a/application/ship-simu/templates/de/code/register.ctp +++ b/application/ship-simu/templates/de/code/register.ctp @@ -1,13 +1,13 @@ addFormGroup("login", "Bitte gebe hier gewünschten Nickname und dein Zugangspasswort ein."); -$helper->addFormSubGroup("username", "Dein Nickname wird nach Absenden des Formulares erst geprüft. Später bauen wir dann einen automatischen Test ein, der dir sofort zeigt, ob der Nickname bereits vergeben ist."); +$helper->addFormSubGroup("username", "Dein Nickname wird erst nach Absenden des Formulares geprüft. Später bauen wir dann einen automatischen Test ein, der dir sofort zeigt, ob der Nickname bereits vergeben ist."); $helper->addFieldText("username", "Nickname im Spiel:"); $helper->addInputTextField("username", 10, 255); $helper->addFormSubGroup("password", "Dein Passwort sollte nicht zu leicht erratbar sein. Später bauen wir hier noch einen automatischen Test ein, der dir sofort die Passwortstärke anzeigt."); @@ -16,7 +16,7 @@ $helper->addInputPasswordField("pass1", 5, 255); $helper->addFieldText("pass2", "Passwortwiederholung:"); $helper->addInputPasswordField("pass2", 5, 255); -if ($helper->ifRegistrationRequiresEmailVerification()) { +if ($helper->ifRegisterRequiresEmailVerification()) { $helper->addFormGroup("email", "Bitte gebe deine Email zweimal (ein zweites Mal zur Bestätigung) ein, damit wir dir deinen Freischaltlink zusenden können."); $helper->addFieldText("email1", "Email-Adresse:"); $helper->addInputTextField("email1", 15, 255); @@ -24,16 +24,16 @@ if ($helper->ifRegistrationRequiresEmailVerification()) { $helper->addInputTextField("email2", 15, 255); } // END - email verification -if ($helper->ifRegistrationIncludesProfile()) { +if ($helper->ifRegisterIncludesProfile()) { $helper->addFormGroup("profile", "Hier kannst du zusätzlich deine Profildaten vorweg eingeben, du kannst sie aber auch nach dem Login vervollständigen!"); - if (!$helper->ifRegistrationRequiresEmailVerification()) { + if (!$helper->ifRegisterRequiresEmailVerification()) { $helper->addFormSubGroup("email", "Die Angabe deiner Email-Adresse ist nur dann nötig, wenn du auch Email-Benachrichtigungen (*1) haben möchtest."); $helper->addFieldText("email1", "Email-Adresse:"); $helper->addInputTextField("email1", 15, 255); } // END - No email verification // Persoenliche Daten mit in der Anmeldung abfragen? - if ($helper->ifRegistrationIncludesPersonaData()) { + if ($helper->ifRegisterIncludesPersonaData()) { $helper->addFormSubGroup("persona", "Wenn du magst, dann vervollständige deine komplette Adresse mit deinem Namen."); $helper->addFieldText("surname", "Dein Vorname:"); $helper->addInputTextField("surname", 10, 255); @@ -56,31 +56,35 @@ if ($helper->ifRegistrationIncludesProfile()) { } if ($helper->ifChatEnabled("jabber")) { $helper->addFieldText("jabber", "Jabber:"); - $helper->addInputTextField("jabber", 10, 15); + $helper->addInputTextField("jabber", 15, 50); } if ($helper->ifChatEnabled("yahoo")) { $helper->addFieldText("yahoo", "Yahoo!:"); - $helper->addInputTextField("yahoo", 10, 15); + $helper->addInputTextField("yahoo", 15, 50); } if ($helper->ifChatEnabled("aol")) { $helper->addFieldText("aol", "AOL-Screenname:"); - $helper->addInputTextField("aol", 10, 15); + $helper->addInputTextField("aol", 15, 50); } if ($helper->ifChatEnabled("msn")) { $helper->addFieldText("msn", "MSN:"); - $helper->addInputTextField("msn", 10, 15); + $helper->addInputTextField("msn", 15, 50); } - if (!$helper->ifRegistrationRequiresEmailVerification()) { + if (!$helper->ifRegisterRequiresEmailVerification()) { $helper->addFormExtraNote(1, "Die Benachrichtigungen per sind im Loginbereich verfeinerbar, welche du genau haben willst."); } // END - Extra note } // END - ask profile data // Spielregeln abfragen $helper->addFormGroup("rules", "Bitte lese dir die Spieleregeln gut durch und kreuze dann "Ja, ich akzeptiere die aktuellen Spielregeln" an."); +$helper->addFieldText("rules", "Ja, ich akzeptiere die aktuellen Spielregeln:"); $helper->addInputCheckboxField("rules", false); // Abschliessender Hinweis und Abschluss des Formulars +$helper->addFormGroup("buttons", "Wenn du alle benötigten Felder korrekt ausgefüt hast, kannst du die Anmeldung abschliessen."); +$helper->addInputResetButton("Alles nochmal eingeben"); +$helper->addInputSubmitButton("Anmeldung zum Spiel abschliessen"); $helper->addFormNote("Deine Daten werden nach den gültigen Datenschutzgesetzten gespeichert und werden nicht an Dritte weitergegeben. Weiteres dazu siehe Link "Datenschutz"."); $helper->addFormTag(); $helper->flushContent(); @@ -90,5 +94,5 @@ $helper->flushContent();
- {?register_form?} + {?shipsimu_register?}
diff --git a/inc/classes/exceptions/helper/.htaccess b/inc/classes/exceptions/helper/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/exceptions/helper/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/exceptions/template/class_FormClosedException.php b/inc/classes/exceptions/helper/class_FormClosedException.php similarity index 100% rename from inc/classes/exceptions/template/class_FormClosedException.php rename to inc/classes/exceptions/helper/class_FormClosedException.php diff --git a/inc/classes/exceptions/helper/class_FormGroupClosedException.php b/inc/classes/exceptions/helper/class_FormGroupClosedException.php new file mode 100644 index 0000000..608228d --- /dev/null +++ b/inc/classes/exceptions/helper/class_FormGroupClosedException.php @@ -0,0 +1,46 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class FormGroupClosedException extends FrameworkException { + /** + * The constructor + * + * @param $classArray Class throwing the exception + * @param $code Code number for the exception + * @return void + */ + public function __construct (array $classArray, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Could not add sub group %s because no form group has been opened before.", + $classArray[0]->__toString(), + $this->getLine(), + $classArray[1] + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/template/class_FormOpenedException.php b/inc/classes/exceptions/helper/class_FormOpenedException.php similarity index 100% rename from inc/classes/exceptions/template/class_FormOpenedException.php rename to inc/classes/exceptions/helper/class_FormOpenedException.php diff --git a/inc/classes/exceptions/template/class_InvalidFormNameException.php b/inc/classes/exceptions/helper/class_InvalidFormNameException.php similarity index 100% rename from inc/classes/exceptions/template/class_InvalidFormNameException.php rename to inc/classes/exceptions/helper/class_InvalidFormNameException.php diff --git a/inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php b/inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php index 3f92b37..43a5ec6 100644 --- a/inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php +++ b/inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php @@ -7,6 +7,7 @@ * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org + * @deprecated * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,7 +27,7 @@ class InvalidTemplateVariableNameException extends FrameworkException { * The constructor * * @param $classArray An array holding our informations - * @param $code Code number for the exception + * @param $code Code number for the exception * @return void */ public function __construct (array $classArray, $code) { diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 5e923ad..f460986 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -903,12 +903,20 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } /** - * Output a partial stub message for the given method name + * Output a partial stub message for the caller method * - * @param $methodName Name of the partially finished method * @return void */ - protected function partialStub ($methodName) { + protected function partialStub () { + // Get the backtrace + $backtrace = debug_backtrace(); + + // Generate the class::method string + $methodName = "UnknownClass::unknownMethod"; + if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) { + $methodName = $backtrace[1]['class']."::".$backtrace[1]['function']; + } + // Debug instance is there? if (!is_null($this->getDebugInstance())) { // Output stub message diff --git a/inc/classes/main/helper/class_ b/inc/classes/main/helper/class_ index dff09f7..8a1892b 100644 --- a/inc/classes/main/helper/class_ +++ b/inc/classes/main/helper/class_ @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class extends BaseTemplateHelper { +class extends BaseHelper { /** * Private constructor * diff --git a/inc/classes/main/helper/class_BaseTemplateHelper.php b/inc/classes/main/helper/class_BaseHelper.php similarity index 88% rename from inc/classes/main/helper/class_BaseTemplateHelper.php rename to inc/classes/main/helper/class_BaseHelper.php index 8558386..11d636c 100644 --- a/inc/classes/main/helper/class_BaseTemplateHelper.php +++ b/inc/classes/main/helper/class_BaseHelper.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseTemplateHelper extends BaseFrameworkSystem { +class BaseHelper extends BaseFrameworkSystem { /** * Template engine instance */ @@ -56,7 +56,7 @@ class BaseTemplateHelper extends BaseFrameworkSystem { * @param $templateInstance An instance of a template engine class * @return void */ - public final function setTemplateInstance (CompileableTemplate $templateInstance) { + protected final function setTemplateInstance (CompileableTemplate $templateInstance) { $this->templateInstance = $templateInstance; } @@ -65,7 +65,7 @@ class BaseTemplateHelper extends BaseFrameworkSystem { * * @return $templateInstance An instance of a template engine class */ - public final function getTemplateInstance () { + protected final function getTemplateInstance () { return $this->templateInstance; } @@ -75,7 +75,7 @@ class BaseTemplateHelper extends BaseFrameworkSystem { * @param $newContent New content to add * @return void */ - public final function addContent ($newContent) { + protected final function addContent ($newContent) { $this->content .= (string) trim($newContent)."\r\n"; } @@ -84,7 +84,7 @@ class BaseTemplateHelper extends BaseFrameworkSystem { * * @return $content The rendered content by this helper */ - public final function getContent () { + protected final function getContent () { return $this->content; } } diff --git a/inc/classes/main/helper/web/class_HtmlFormHelper.php b/inc/classes/main/helper/web/class_HtmlFormHelper.php deleted file mode 100644 index 281f4d4..0000000 --- a/inc/classes/main/helper/web/class_HtmlFormHelper.php +++ /dev/null @@ -1,224 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software - * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class HtmlFormHelper extends BaseTemplateHelper { - /** - * Wether the form tag is opened (keep at false or else your forms will - * never work!) - */ - private $formOpened = false; - - /** - * Name of the form - */ - private $formName = ""; - - /** - * Wether the group is opened or not - */ - private $groupOpened = false; - - /** - * Wether the sub group is opened or not - */ - private $subGroupOpened = false; - - // Class Constants - const EXCEPTION_FORM_NAME_INVALID = 0xb00; - const EXCEPTION_CLOSED_FORM = 0xb01; - const EXCEPTION_OPENED_FORM = 0xb02; - - /** - * Private constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Set part description - $this->setObjectDescription("HTML-Formularhilfsklasse"); - } - - /** - * Creates the helper class with the given template engine instance and form name - * - * @param $templateInstance An instance of a valid template engine - * @param $formName Name of the form - * @param $formId Value for "id" attribute (default: $formName) - * @return $helperInstance A preparedf instance of this class - */ - public final static function createHtmlFormHelper (CompileableTemplate $templateInstance, $formName, $formId = false) { - // Get new instance - $helperInstance = new HtmlFormHelper(); - - // Set template instance - $helperInstance->setTemplateInstance($templateInstance); - - // Is the form id not set? - if ($formId === false) { - // Use form id from form name - $formId = $formName; - } - - // Create the form - $helperInstance->addFormTag($formName, $formId); - - // Return the prepared instance - return $helperInstance; - } - - /** - * Add the form tag or close it an already opened form tag - * - * @param $formName Name of the form (default: false) - * @param $formId Id of the form (attribute "id"; default: false) - * @return void - * @throws InvalidFormNameException If the form name is invalid (=false) - */ - public function addFormTag ($formName = false, $formId = false) { - // When the form is not yet opened at least form name must be valid - if ((!$this->formOpened) && ($formName === false)) { - // Thrown an exception - throw new InvalidFormNameException ($this, self::EXCEPTION_FORM_NAME_INVALID); - } - - // Close the form is default - $formContent = ""; - - // Check wether we shall open or close the form - if (!$this->formOpened) { - // Add HTML code - $formContent = sprintf("
getConfigInstance()->readConfig("form_action"), - $this->getConfigInstance()->readConfig("form_method"), - $this->getConfigInstance()->readConfig("form_target") - ); - - // Is the form id set? - if ($formId !== false) { - // Then add it as well - $formContent .= sprintf(" id=\"%s\"", - $formId - ); - } - - // Add close bracket - $formContent .= ">"; - - // Open the form and remeber the form name - $this->formOpened = true; - $this->formName = $formName; - } else { - // Add the hidden field required to identify safely this form - $this->addInputHiddenField("form", $this->formName); - - // @TODO Add some unique PIN here to bypass problems with some browser and/or extensions - // Simply close it - $this->formOpened = false; - } - - // Add it to the content - $this->addContent($formContent); - } - - /** - * Add an input tag to the form or throw an exception if it is not yet - * opened. The field's name will be set as id. - * - * @param $fieldName Input field name - * @param $fieldSize Input size - * @param $fieldMaxLength Input max length - * @param $fieldValue Input default value (default: empty) - * @return void - * @throws FormClosedException If the form is not yet opened - */ - public function addInputTextField ($fieldName, $fieldSize, $fieldMaxLength, $fieldValue = "") { - // Is the form opened? - if (!$this->formOpened) { - // Throw an exception - throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); - } - - // Generate the content - $inputContent = sprintf("", - $fieldName, $fieldName, $fieldSize, $fieldMaxLength, $fieldValue); - - // And add it - $this->addContent($inputContent); - } - - /** - * Flushs the content out (not yet secured against open forms, etc.!) or - * throw an exception if it is not yet closed - * - * @return void - * @throws FormOpenedException If the form is still open - */ - public function flushContent () { - // Is the form opened? - if ($this->formOpened) { - // Throw an exception - throw new FormOpenedException ($this, self::EXCEPTION_OPENED_FORM); - } - - // Send content to template engine - $this->getTemplateInstance()->assignVariable($this->formName, $this->getContent()); - } - - /** - * Add a form group or close an already opened and open a new one - * - * @param $groupName Name of the group - * @param $groupText Text including HTML to show above this group - * @return void - * @throws EmptyVariableException If $groupName is not set - */ - public function addFormGroup ($groupName, $groupText) { - // At least the group name should be set - if (empty($groupName)) { - // Throw exception here - throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } - - // Not fully finished! - $this->partialStub(__METHOD__); - - // Is this group opened? - if (!$this->groupOpened) { - // Switch the state - $this->groupOpened = true; - } else { - // Switch the state - $this->groupOpened = false; - - // All call it again - $this->addFormGroup($groupName, $groupText); - } - } -} - -// [EOF] -?> diff --git a/inc/classes/main/helper/web/class_WebFormHelper.php b/inc/classes/main/helper/web/class_WebFormHelper.php new file mode 100644 index 0000000..41ad0fd --- /dev/null +++ b/inc/classes/main/helper/web/class_WebFormHelper.php @@ -0,0 +1,574 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class WebFormHelper extends BaseHelper { + /** + * Wether the form tag is opened (keep at false or else your forms will + * never work!) + */ + private $formOpened = false; + + /** + * Name of the form + */ + private $formName = ""; + + /** + * Wether the group is opened or not + */ + private $groupOpened = false; + + /** + * Wether the sub group is opened or not + */ + private $subGroupOpened = false; + + /** + * Name of the sub group + */ + private $subGroupName = ""; + + // Class Constants + const EXCEPTION_FORM_NAME_INVALID = 0xb00; + const EXCEPTION_CLOSED_FORM = 0xb01; + const EXCEPTION_OPENED_FORM = 0xb02; + const EXCEPTION_UNEXPECTED_CLOSED_GROUP = 0xb03; + + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("HTML-Formularhilfsklasse"); + } + + /** + * Creates the helper class with the given template engine instance and form name + * + * @param $templateInstance An instance of a valid template engine + * @param $formName Name of the form + * @param $formId Value for "id" attribute (default: $formName) + * @return $helperInstance A preparedf instance of this class + */ + public final static function createWebFormHelper (CompileableTemplate $templateInstance, $formName, $formId = false) { + // Get new instance + $helperInstance = new WebFormHelper(); + + // Set template instance + $helperInstance->setTemplateInstance($templateInstance); + + // Is the form id not set? + if ($formId === false) { + // Use form id from form name + $formId = $formName; + } + + // Create the form + $helperInstance->addFormTag($formName, $formId); + + // Return the prepared instance + return $helperInstance; + } + + /** + * Add the form tag or close it an already opened form tag + * + * @param $formName Name of the form (default: false) + * @param $formId Id of the form (attribute "id"; default: false) + * @return void + * @throws InvalidFormNameException If the form name is invalid (=false) + */ + public function addFormTag ($formName = false, $formId = false) { + // When the form is not yet opened at least form name must be valid + if (($this->formOpened === false) && ($formName === false)) { + // Thrown an exception + throw new InvalidFormNameException ($this, self::EXCEPTION_FORM_NAME_INVALID); + } + + // Close the form is default + $formContent = ""; + + // Check wether we shall open or close the form + if ($this->formOpened === false) { + // Add HTML code + $formContent = sprintf("
getConfigInstance()->readConfig("form_action"), + $this->getConfigInstance()->readConfig("form_method"), + $this->getConfigInstance()->readConfig("form_target") + ); + + // Is the form id set? + if ($formId !== false) { + // Then add it as well + $formContent .= sprintf(" id=\"%s_form\"", + $formId + ); + } + + // Add close bracket + $formContent .= ">"; + + // Open the form and remeber the form name + $this->formOpened = true; + $this->formName = $formName; + } else { + // Add the hidden field required to identify safely this form + $this->addInputHiddenField("form", $this->formName); + + // Is a group open? + if ($this->groupOpened === true) { + // Then automatically close it here + $this->addFormGroup("", ""); + } + + // @TODO Add some unique PIN here to bypass problems with some browser and/or extensions + // Simply close it + $this->formOpened = false; + } + + // Add it to the content + $this->addContent($formContent); + } + + /** + * Add a text input tag to the form or throw an exception if it is not yet + * opened. The field's name will be set as id. + * + * @param $fieldName Input field name + * @param $fieldSize Input size + * @param $fieldMaxLength Input max length + * @param $fieldValue Input default value (default: empty) + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputTextField ($fieldName, $fieldSize, $fieldMaxLength, $fieldValue = "") { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $fieldName, $fieldName, $fieldSize, $fieldMaxLength, $fieldValue); + + // And add it maybe with a "li" tag + $this->addContent($inputContent); + } + + /** + * Add a password input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $fieldName Input field name + * @param $fieldSize Input size + * @param $fieldMaxLength Input max length + * @param $fieldValue Input default value (default: empty) + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputPasswordField ($fieldName, $fieldSize, $fieldMaxLength, $fieldValue = "") { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $fieldName, $fieldName, $fieldSize, $fieldMaxLength, $fieldValue); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a hidden input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $fieldName Input field name + * @param $fieldValue Input default value (default: empty) + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputHiddenField ($fieldName, $fieldValue = "") { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $fieldName, + $fieldValue + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a checkbox input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $fieldName Input field name + * @param $fieldChecked Wether the field is checked (defaut: checked) + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputCheckboxField ($fieldName, $fieldChecked = true) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Set wether the check box is checked... + $checked = " checked=\"checked\""; + if ($fieldChecked === false) $checked = " "; + + // Generate the content + $inputContent = sprintf("", + $fieldName, + $fieldName, + $checked + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a reset input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $buttonText Text displayed on the button + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputResetButton ($buttonText) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, "reset"), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $this->formName, + $buttonText + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a reset input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $buttonText Text displayed on the button + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputSubmitButton ($buttonText) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, "submit"), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $this->formName, + $this->formName, + $buttonText + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a form group or close an already opened and open a new one + * + * @param $groupName Name of the group + * @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) { + // Is a form opened? + if ($this->formOpened === false) { + // Throw exception here + throw new FormClosedException(array($this, $groupName), self::EXCEPTION_CLOSED_FORM); + } + + // At least the group name should be set + if ((empty($groupName)) && ($this->groupOpened === false)) { + // Throw exception here + throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } + + // Initialize content with closing div by default + $content = " \n"; + + // Is this group opened? + if ($this->groupOpened === false) { + // Begin the div/span blocks + $content = sprintf(" +
+ + %s + +
", + $groupName, + $groupName, + $groupName, + $groupText, + $groupName + ); + + // Add the content + $this->addContent($content); + + // Switch the state + $this->groupOpened = true; + } else { + // Is a sub group opened? + if ($this->subGroupOpened === true) { + // Close it here + $this->addFormSubGroup("", ""); + } + + // Add the content + $this->addContent($content); + + // Switch the state + $this->groupOpened = false; + + // All call it again if the group name is not empty + if (!empty($groupName)) { + $this->addFormGroup($groupName, $groupText); + } + } + } + + /** + * 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. + * + * @param $subGroupName Name of the group + * @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) { + // Is a group opened? + if ($this->groupOpened === false) { + // Throw exception here + throw new FormGroupClosedException(array($this, $subGroupName), self::EXCEPTION_UNEXPECTED_CLOSED_GROUP); + } + + // At least the sub group name should be set + if ((empty($subGroupName)) && ($this->subGroupOpened === false)) { + // Throw exception here + throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } + + // Initialize content with closing div by default + $content = "
\n
"; + + // Is this group opened? + if ($this->subGroupOpened === false) { + // Begin the span block + $content = sprintf(" +
+ + %s + +
", + $subGroupName, + $subGroupName, + $subGroupName, + $subGroupText, + $subGroupName + ); + + // Add the content + $this->addContent($content); + + // Switch the state and remeber the name + $this->subGroupOpened = true; + $this->subGroupName = $subGroupName; + } else { + // Add the content + $this->addContent($content); + + // Switch the state + $this->subGroupOpened = false; + + // All call it again if sub group name is not empty + if (!empty($subGroupName)) { + $this->addFormSubGroup($subGroupName, $subGroupText); + } + } + } + + /** + * Add text surrounded by a span block when there is a group opened before + * or else by a div block. + * + * @param $fieldName Field name + * @param $fieldText Text for the field + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addFieldText ($fieldName, $fieldText) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Set the block type + $block = "div"; + if ($this->groupOpened === true) $block = "span"; + + // Generate the content + $inputContent = sprintf(" <%s id=\"%s_text\"> + %s + ", + $block, + $fieldName, + $fieldText, + $block + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add text (notes) surrounded by a div block. Still opened groups or sub + * groups will be automatically closed. + * + * @param $formNotes The form notes we shell addd + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addFormNote ($formNotes) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, "form_notes"), self::EXCEPTION_CLOSED_FORM); + } + + // Is a group open? + if ($this->groupOpened === true) { + // Then automatically close it here + $this->addFormGroup("unknown", ""); + } + + // Generate the content + $inputContent = sprintf("
+ %s +
", + $formNotes + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * 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 shall be asked + */ + public function ifRegisterIncludesProfile () { + $required = ($this->getConfigInstance()->readConfig("register_includes_profile") == "Y"); + return $required; + } + + /** + * Checks wether personal data shall be asked + * + * @return $required Wether personal data shall be asked + */ + public function ifRegisterIncludesPersonaData () { + $required = ($this->getConfigInstance()->readConfig("register_personal_data") == "Y"); + return $required; + } + + /** + * Checks wether the specified chat protocol is enabled in this form + * + * @return $required Wether the specified chat protocol is enabled + */ + public function ifChatEnabled ($chatProtocol) { + $required = ($this->getConfigInstance()->readConfig(sprintf("chat_enabled_%s", $chatProtocol)) == "Y"); + return $required; + } + + /** + * Flushs the content out (not yet secured against open forms, etc.!) or + * throw an exception if it is not yet closed + * + * @return void + * @throws FormOpenedException If the form is still open + */ + public function flushContent () { + // Is the form still open? + if ($this->formOpened === true) { + // Throw an exception + throw new FormOpenedException ($this, self::EXCEPTION_OPENED_FORM); + } + + // Send content to template engine + $this->getTemplateInstance()->assignVariable($this->formName, $this->getContent()); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/template/class_TemplateEngine.php b/inc/classes/main/template/class_TemplateEngine.php index e2961f8..ee01937 100644 --- a/inc/classes/main/template/class_TemplateEngine.php +++ b/inc/classes/main/template/class_TemplateEngine.php @@ -975,7 +975,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate // Run the compilation twice to get content from helper classes in $cnt = 0; - while ($cnt < 2) { + while ($cnt < 3) { // Finalize the compilation of template variables $this->finalizeVariableCompilation(); diff --git a/inc/config.php b/inc/config.php index 536a89d..a3ea28e 100644 --- a/inc/config.php +++ b/inc/config.php @@ -141,17 +141,5 @@ $cfg->setConfigEntry("default_application", "selector"); // CFG: VERBOSE-LEVEL $cfg->setConfigEntry("verbose_level", 0); -// CFG: COMMAND-PARAMETER -$cfg->setConfigEntry("command_parameter", "page"); - -// CFG: FORM-ACTION -$cfg->setConfigEntry("form_action", "index.php?app={?app_short_name?}&{?command_parameter?}=do_form"); - -// CFG: FORM-METHOD -$cfg->setConfigEntry("form_method", "POST"); - -// CFG: FORM-TARGET -$cfg->setConfigEntry("form_target", "_self"); - // [EOF] ?> diff --git a/templates/de/code/header.ctp b/templates/de/code/header.ctp index b82ab23..cce8460 100644 --- a/templates/de/code/header.ctp +++ b/templates/de/code/header.ctp @@ -1,4 +1,4 @@ - + -- 2.39.5