/** * Helper class to build interactive forms to be used either in stand-alone * modal dialog or in "property-sheet" panes. * * @copyright Copyright (C) 2010-2012 Combodo SARL * @license http://opensource.org/licenses/AGPL-3.0 */ class DesignerForm { protected $aFieldSets; protected $sCurrentFieldSet; protected $sScript; protected $sReadyScript; protected $sFormId; protected $sFormPrefix; protected $sParamsContainer; protected $oParentForm; protected $aSubmitParams; protected $sSubmitTo; protected $bReadOnly; public function __construct() { $this->aFieldSets = array(); $this->sCurrentFieldSet = ''; $this->sScript = ''; $this->sReadyScript = ''; $this->sFormPrefix = ''; $this->sParamsContainer = ''; $this->sFormId = 'form_'.rand(); $this->oParentForm = null; $this->bReadOnly = false; $this->StartFieldSet($this->sCurrentFieldSet); } public function AddField(DesignerFormField $oField) { if (!is_array($this->aFieldSets[$this->sCurrentFieldSet])) { $this->aFieldSets[$this->sCurrentFieldSet] = array(); } $this->aFieldSets[$this->sCurrentFieldSet][] = $oField; $oField->SetForm($this); } public function StartFieldSet($sLabel) { $this->sCurrentFieldSet = $sLabel; if (!array_key_exists($this->sCurrentFieldSet, $this->aFieldSets)) { $this->aFieldSets[$this->sCurrentFieldSet] = array(); } } public function Render($oP, $bReturnHTML = false) { $sReturn = ''; if ($this->oParentForm == null) { $sFormId = $this->sFormId; $sReturn = '
'; } if($this->sScript != '') { $oP->add_script($this->sScript); } if($this->sReadyScript != '') { $oP->add_ready_script($this->sReadyScript); } if ($bReturnHTML) { return $sReturn; } else { $oP->add($sReturn); } } public function SetSubmitParams($sSubmitToUrl, $aSubmitParams) { $this->sSubmitTo = $sSubmitToUrl; $this->aSubmitParams = $aSubmitParams; } public function CopySubmitParams($oParentForm) { $this->sSubmitTo = $oParentForm->sSubmitTo; $this->aSubmitParams = $oParentForm->aSubmitParams; } public function RenderAsPropertySheet($oP, $bReturnHTML = false, $sNotifyParentSelector = null) { $sReturn = ''; $sActionUrl = addslashes($this->sSubmitTo); $sJSSubmitParams = json_encode($this->aSubmitParams); if ($this->oParentForm == null) { $sFormId = $this->sFormId; $sReturn = ''; $sReturn .= ''; // for the return of the submit operation } else { $sReturn .= $sHiddenFields; } $this->AddReadyScript( <<