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)
{
$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(
<<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 RenderAsDialog($oPage, $sDialogId, $sDialogTitle, $iDialogWidth, $sOkButtonLabel)
{
$sDialogTitle = addslashes($sDialogTitle);
$sOkButtonLabel = addslashes($sOkButtonLabel);
$sCancelButtonLabel = 'Cancel'; //TODO: localize
$oPage->add("");
$this->Render($oPage);
$oPage->add('
');
$oPage->add_ready_script(
<<aFieldSets as $sLabel => $aFields)
{
foreach($aFields as $oField)
{
$oField->ReadParam($aValues);
}
}
return $aValues;
}
public function SetPrefix($sPrefix)
{
$this->sFormPrefix = $sPrefix;
}
public function GetPrefix()
{
return $this->sFormPrefix;
}
public function SetReadOnly($bReadOnly = true)
{
$this->bReadOnly = $bReadOnly;
}
public function IsReadOnly()
{
if ($this->oParentForm == null)
{
return $this->bReadOnly;
}
else
{
return $this->oParentForm->IsReadOnly();
}
}
public function SetParamsContainer($sParamsContainer)
{
$this->sParamsContainer = $sParamsContainer;
}
public function GetParamsContainer()
{
if ($this->oParentForm == null)
{
return $this->sParamsContainer;
}
else
{
return $this->oParentForm->GetParamsContainer();
}
}
public function SetParentForm($oParentForm)
{
$this->oParentForm = $oParentForm;
}
public function AddScript($sScript)
{
$this->sScript .= $sScript;
}
public function AddReadyScript($sScript)
{
$this->sReadyScript .= $sScript;
}
public function GetFieldId($sCode)
{
return $this->sFormPrefix.'attr_'.$sCode;
}
public function GetFieldName($sCode)
{
return 'attr_'.$sCode;
}
public function GetParamName($sCode)
{
return 'attr_'.$sCode;
}
public function GetValidationArea($sCode)
{
return "sFormPrefix}attr_$sCode\">";
}
public function GetAsyncActionClass()
{
return $this->sAsyncActionClass;
}
}
class DesignerTabularForm extends DesignerForm
{
protected $aTable;
public function __construct()
{
parent::__construct();
$this->aTable = array();
}
public function AddRow($aRow)
{
$this->aTable[] = $aRow;
}
public function Render($oP, $bReturnHTML = false)
{
$sReturn = '';
if ($this->oParentForm == null)
{
$sFormId = $this->sFormId;
$sReturn = '