<?php
/**
* An abstract class implementing generic functionality for processing user's input
*
* This class encapsulates generic functions for working
* with data coming from user forms. Descendants must only override certain
* functions that perform context-specific tasks, like custom checking of
* data, storing correct data, etc.
*
* @author Yuri Makassiouk <racer@bfpg.ru>,
* Mission & Media <firma@missionandmedia.com>
*/
class FormProcessor {
var $Name;
var $FirstTime;
var $Values;
var $Errors = array();
var $ErrorMessageFormat = '<br>%s';
var $wizardPage;
var $fieldPrefix = 'mm_form_data_';
function FormProcessor($Name, $wPage='') {
$this->Name = $Name;
$this->wizardPage = $wPage;
$this->Values = $GLOBALS[$this->fieldPrefix.$this->Name];
$this->FirstTime = (count($this->Values) == 0);
if (!$this->FirstTime)
$this->CustomCheck();
if ($this->IsCompleted()) {
$this->StoreData();
$GLOBALS['wizardPage'] = $this->NextWizardPage();
}
else
$this->DisplayForm();
}
function IsCompleted() {
return (!$this->FirstTime && count($this->Errors)<=0);
}
function CustomCheck() {}
//abstract
function DisplayForm() {}
//abstract
function NextWizardPage() {}
//abstract
function StoreData() {}
//abstract
function Additional() {
if ($this->wizardPage) :
?>
<input type="Hidden" name="wizardPage" value="<?php echo $this->wizardPage?>">
<?php endif;
}
function Set($Name, $Value) {
$this->$Name = $Value;
}
function ErrorReport($Name) {
if (isset($this->Errors[$Name]))
printf($this->ErrorMessageFormat, $this->Errors[$Name]);
}
function GetInitialValue($Name) {
if (isset($this->Values[$Name]))
return $this->Values[$Name];
else
return false;
}
function InitialValue($Name) {
echo $this->GetInitialValue($Name);
}
}
?>