function render() { $oView = new \BaikalAdmin\View\Settings\System(); $oView->setData("message", \Formal\Core\Message::notice("Do not change anything on this page unless you really know what you are doing.<br />You might break Baïkal if you misconfigure something here.", "Warning !", false)); $oView->setData("form", $this->oForm->render()); return $oView->render(); }
public function render() { $sActionUrl = \Flake\Util\Tools::getCurrentUrl(); $sSubmittedFlagName = "auth"; $sMessage = ""; if (self::isSubmitted() && !\BaikalAdmin\Core\Auth::isAuthenticated()) { $sMessage = \Formal\Core\Message::error("The login/password you provided is invalid. Please retry.", "Authentication error"); } elseif (self::justLoggedOut()) { $sMessage = \Formal\Core\Message::notice("You have been disconnected from your session.", "Session ended", FALSE); } $sLogin = htmlspecialchars(\Flake\Util\Tools::POST("login")); $sPassword = htmlspecialchars(\Flake\Util\Tools::POST("password")); if (trim($sLogin) === "") { $sLogin = "******"; } $oView = new \BaikalAdmin\View\Login(); $oView->setData("message", $sMessage); $oView->setData("actionurl", $sActionUrl); $oView->setData("submittedflagname", $sSubmittedFlagName); $oView->setData("login", $sLogin); $oView->setData("password", $sPassword); return $oView->render(); }
public function execute() { # Obtaining morphology from model object $oMorpho = $this->getMorpho(); $this->aErrors = array(); $oMorpho->elements()->reset(); foreach ($oMorpho->elements() as $oElement) { # If element is readonly, skip process if ($oElement->option("readonly")) { continue; } $sPropName = $oElement->option("prop"); # posted value is fetched, then passes to element before persistance if ($oElement->posted()) { $sPostValue = $this->postValue($sPropName); $oElement->setValue($sPostValue); $sValue = $oElement->value(); $this->modelInstance()->set($sPropName, $sValue); } else { $oElement->setValue($this->modelInstance()->get($sPropName)); } } $oMorpho->elements()->reset(); foreach ($oMorpho->elements() as $oElement) { $aValidation = $oElement->optionArray("validation"); if (empty($aValidation)) { continue; } $sValue = $oElement->value(); foreach ($aValidation as $sValidation) { # If element is readonly, skip process if ($oElement->option("readonly")) { continue; } $sParam = FALSE; if (strpos($sValidation, ":") !== FALSE) { $sValidation = strtok($sValidation, ":"); $sParam = strtok(":"); } $sMethod = "validate" . ucfirst(strtolower($sValidation)); if (!method_exists($this, $sMethod)) { throw new \Exception("\\Formal\\Form::execute(): no validation method for '" . htmlspecialchars($sValidation) . "'"); } if ($sParam === FALSE) { $mValid = $this->{$sMethod}($sValue, $oMorpho, $oElement); } else { $mValid = $this->{$sMethod}($sValue, $oMorpho, $oElement, $sParam); } if ($mValid !== TRUE) { $this->declareError($oElement, $mValid); break; # one error per element per submit } } } # Calling validation hook if defined if (($aHook = $this->option("hook.validation")) !== FALSE) { call_user_func($aHook, $this, $oMorpho); } if (!$this->refreshed() && empty($this->aErrors)) { # Model object is persisted # Last chance to generate a confirm message corresponding to what *was* submitted ("Creating", instead of "Editing") if ($this->floatingModelInstance()) { $this->sDisplayMessage = \Formal\Core\Message::notice($this->modelInstance()->humanName() . " <i class='" . $this->modelInstance()->icon() . "'></i> <strong>" . $this->modelInstance()->label() . "</strong> has been created.", "", FALSE); $bWasFloating = TRUE; } else { $bWasFloating = FALSE; $this->sDisplayMessage = \Formal\Core\Message::notice("Changes on <i class='" . $this->modelInstance()->icon() . "'></i> <strong>" . $this->modelInstance()->label() . "</strong> have been saved.", FALSE, FALSE); } $this->modelInstance()->persist(); if ($bWasFloating === FALSE) { # Title is generated now, as submitted data might have changed the model instance label $this->sDisplayTitle = "Editing " . $this->modelInstance()->humanName() . "<i class=" . $this->modelInstance()->mediumicon() . "></i><strong>" . $this->modelInstance()->label() . "</strong>"; } $this->bPersisted = TRUE; } else { $this->bPersisted = FALSE; } }