00001 <?php
00025 class EasyFormWizard extends EasyForm
00026 {
00027 protected $m_DropSession = false;
00028
00035 public function getSessionVars($sessionContext)
00036 {
00037 $sessionContext->getObjVar($this->m_Name, "ActiveRecord", $this->m_ActiveRecord, true);
00038 $sessionContext->getObjVar($this->m_Name, "FormInputs", $this->m_FormInputs, true);
00039 $this->setActiveRecord($this->m_ActiveRecord);
00040 }
00041
00048 public function setSessionVars($sessionContext)
00049 {
00050 if ($this->m_DropSession)
00051 $sessionContext->cleanObj($this->m_Name, true);
00052 else {
00053 $sessionContext->setObjVar($this->m_Name, "ActiveRecord", $this->m_ActiveRecord, true);
00054 $sessionContext->setObjVar($this->m_Name, "FormInputs", $this->m_FormInputs, true);
00055 }
00056 }
00057
00065 public function goNext($commit=false)
00066 {
00067
00068 $recArr = $this->readInputRecord();
00069 $this->setActiveRecord($recArr);
00070
00071 try
00072 {
00073 if ($this->ValidateForm() == false)
00074 return;
00075 }catch (ValidationException $e)
00076 {
00077 $this->processFormObjError($e->m_Errors);
00078 return;
00079 }
00080
00081 $this->m_ActiveRecord = $this->readInputRecord();
00082 $viewObj = $this->getViewObject();
00083
00084 if($viewObj->getCurrentStep()){
00085 $step = $viewObj->getCurrentStep();
00086 }else{
00087 $step = $_GET['step'];
00088 }
00089 if (!$step || $step=="")
00090 $step=1;
00091
00092
00093
00094
00095 $viewObj->renderStep($step+1);
00096 }
00097
00104 public function skip()
00105 {
00106 $viewObj = $this->getViewObject();
00107
00108 if($viewObj->getCurrentStep()){
00109 $step = $viewObj->getCurrentStep();
00110 }else{
00111 $step = $_GET['step'];
00112 }
00113 if (!$step || $step=="")
00114 $step=1;
00115
00116 $viewObj->renderStep($step+2);
00117 }
00118
00125 public function goBack()
00126 {
00127 $recArr = $this->readInputRecord();
00128 $this->setActiveRecord($recArr);
00129 $this->m_ActiveRecord = $this->readInputRecord();
00130
00131 $viewObj = $this->getViewObject();
00132
00133
00134 if($viewObj->getCurrentStep()){
00135 $step = $viewObj->getCurrentStep();
00136 }else{
00137 $step = $_GET['step'];
00138 }
00139
00140
00141
00142
00143 $viewObj->renderStep($step-1);
00144 }
00145
00152 public function doFinish()
00153
00154 {
00155
00156 $recArr = $this->readInputRecord();
00157 $this->setActiveRecord($recArr);
00158 $this->setFormInputs($this->m_FormInputs);
00159
00160 try
00161 {
00162 if ($this->ValidateForm() == false)
00163 return;
00164 }catch (ValidationException $e)
00165 {
00166 $this->processFormObjError($e->m_Errors);
00167 return;
00168 }
00169
00170 $this->m_ActiveRecord = $this->readInputRecord();
00171
00172
00173 $viewObj = $this->getViewObject();
00174
00175 $r = $viewObj->commit();
00176 if (!$r)
00177 return;
00178
00179 $this->processPostAction();
00180 }
00181
00188 public function doCancel()
00189
00190 {
00191
00192 $viewObj = $this->getViewObject();
00193 $viewObj->cancel();
00194
00195 $this->processPostAction();
00196 }
00197
00203 public function commit()
00204 {
00205
00206 $recArr = $this->m_ActiveRecord;
00207
00208 if (strtoupper($this->m_FormType) == "NEW")
00209 $dataRec = new DataRecord(null, $this->getDataObj());
00210 else
00211 {
00212
00213 $currentRec = array();
00214 $dataRec = new DataRecord($currentRec, $this->getDataObj());
00215 }
00216
00217 foreach ($recArr as $k => $v)
00218 $dataRec[$k] = $v;
00219 try
00220 {
00221 $dataRec->save();
00222 } catch (BDOException $e)
00223 {
00224 $this->processBDOException($e);
00225 return false;
00226 }
00227
00228 return true;
00229 }
00230
00231 public function dropSession(){
00232
00233 $this->m_DropSession = true;
00234 }
00235
00236
00242 public function cancel()
00243 {
00244
00245 $this->m_DropSession = true;
00246 }
00247
00253 public function render()
00254 {
00255 $viewobj = $this->getViewObject();
00256 $viewobj->setFormState($this->m_Name, 'visited', 1);
00257
00258 return parent::render();
00259 }
00260 public function outputAttrs()
00261 {
00262 $output = parent::outputAttrs();
00263 $viewobj = $this->getViewObject();
00264 $forms = array();
00265 $viewobj->m_FormRefs->rewind();
00266 while($viewobj->m_FormRefs->valid()){
00267 $form=$viewobj->m_FormRefs->current();
00268 $forms[$form->m_Name] = $form;
00269 $viewobj->m_FormRefs->next();
00270 }
00271 $output['forms'] = $forms;
00272 $output['step'] = $viewobj->getCurrentStep();
00273 return $output;
00274 }
00275 }
00276 ?>