00001 <?php
00025 class PickerForm extends EasyForm
00026 {
00031 public $m_ParentFormElemName = "";
00032
00037 public $m_PickerMap = "";
00038
00039 public $m_ParentFormRecord ;
00046 public function getSessionVars($sessionContext)
00047 {
00048 parent::getSessionVars($sessionContext);
00049 $sessionContext->getObjVar($this->m_Name, "ParentFormElemName", $this->m_ParentFormElemName);
00050 $sessionContext->getObjVar($this->m_Name, "PickerMap", $this->m_PickerMap);
00051 $sessionContext->getObjVar($this->m_Name, "ParentFormRecord", $this->m_ParentFormRecord);
00052 }
00053
00060 public function setSessionVars($sessionContext)
00061 {
00062 parent::setSessionVars($sessionContext);
00063 $sessionContext->setObjVar($this->m_Name, "ParentFormElemName", $this->m_ParentFormElemName);
00064 $sessionContext->setObjVar($this->m_Name, "PickerMap", $this->m_PickerMap);
00065 $sessionContext->setObjVar($this->m_Name, "ParentFormRecord", $this->m_ParentFormRecord);
00066 }
00067
00076 public function setParentFormData($formName, $elemName=null, $pickerMap=null)
00077 {
00078 $this->m_ParentFormName = $formName;
00079 $this->m_ParentFormElemName = $elemName;
00080 $this->m_PickerMap = $pickerMap;
00081 }
00082
00090 public function pickToParent($recId=null)
00091 {
00092 if ($recId==null || $recId=='')
00093 $recId = BizSystem::clientProxy()->getFormInputs('_selectedId');
00094
00095 $selIds = BizSystem::clientProxy()->getFormInputs('row_selections', false);
00096 if ($selIds == null)
00097 $selIds[] = $recId;
00098
00099
00100 if (!$this->m_ParentFormElemName)
00101 {
00102 $this->addToParent($selIds);
00103 }
00104
00105
00106 if ($this->m_ParentFormElemName && $this->m_PickerMap)
00107 {
00108 $this->joinToParent($selIds);
00109 }
00110
00111 }
00112
00113 public function insertToParent()
00114 {
00115
00116 $recArr = $this->readInputRecord();
00117 $this->setActiveRecord($recArr);
00118 if (count($recArr) == 0)
00119 return;
00120
00121 try
00122 {
00123 $this->ValidateForm();
00124 }
00125 catch (ValidationException $e)
00126 {
00127 $this->processFormObjError($e->m_Errors);
00128 return;
00129 }
00130
00131
00132 if (!$this->m_ParentFormElemName)
00133 {
00134
00135 $parentForm = BizSystem::objectFactory()->getObject($this->m_ParentFormName);
00136
00137 $parentDo = $parentForm->getDataObj();
00138
00139 $column = $parentDo->m_Association['Column'];
00140 $field = $parentDo->getFieldNameByColumn($column);
00141 $parentRefVal = $parentDo->m_Association["FieldRefVal"];
00142
00143 $recArr[$field] = $parentRefVal;
00144 if($parentDo->m_Association['Relationship']=='1-M'){
00145 $cond_column = $parentDo->m_Association['CondColumn'];
00146 $cond_value = $parentDo->m_Association['CondValue'];
00147 if($cond_column)
00148 {
00149 $cond_field = $parentDo->getFieldNameByColumn($cond_column);
00150 $recArr[$cond_field] = $cond_value;
00151 }
00152 $recId = $parentDo->InsertRecord($recArr);
00153 }else{
00154 $recId = $this->getDataObj()->InsertRecord($recArr);
00155 $this->addToParent($recId);
00156 }
00157 }
00158
00159 if ($this->m_ParentFormElemName && $this->m_PickerMap)
00160 {
00161 return ;
00162 }
00163
00164
00165 $selIds[] = $recId;
00166
00167 $this->close();
00168 if($parentForm->m_ParentFormName){
00169 $parentParentForm = BizSystem::objectFactory()->getObject($parentForm->m_ParentFormName);
00170 $parentParentForm->rerender();
00171 }
00172 else
00173 {
00174 $parentForm->rerender();
00175 }
00176 }
00177
00184 public function joinToParent($recIds=null)
00185 {
00186 if(!is_array($recIds))
00187 {
00188 $recIdArr = array();
00189 $recIdArr[] = $recIds;
00190 }else{
00191 $recIdArr = $recIds;
00192 }
00193
00194 $parentForm = BizSystem::objectFactory()->getObject($this->m_ParentFormName);
00195 $updArray = array();
00196 $updRec = $this->m_ParentFormRecord;
00197
00198 foreach($recIdArr as $recId)
00199 {
00200 $rec = $this->getDataObj()->fetchById($recId);
00201
00202
00203 if ($this->m_PickerMap)
00204 {
00205 $pickerList = $this->_parsePickerMap($this->m_PickerMap);
00206 foreach ($pickerList as $ctrlPair)
00207 {
00208 $this_ctrl = $this->getElement($ctrlPair[1]);
00209 if (!$this_ctrl)
00210 continue;
00211
00212 $this_ctrl_val = $rec[$this_ctrl->m_FieldName];
00213 $other_ctrl = $parentForm->getElement($ctrlPair[0]);
00214 if ($other_ctrl)
00215 {
00216 if(!$updArray[$other_ctrl->m_Name]){
00217 $updArray[$other_ctrl->m_Name] = $this_ctrl_val;
00218 $updRec[$other_ctrl->m_FieldName] = $this_ctrl_val;
00219 }else{
00220 $updArray[$other_ctrl->m_Name] .= ';'.$this_ctrl_val;
00221 $updRec[$other_ctrl->m_FieldName] .= ';'.$this_ctrl_val;
00222 }
00223 }
00224 }
00225 }
00226 else
00227 return;
00228 }
00229
00230 $this->close();
00231 $elem = $parentForm->getElement($this->m_ParentFormElemName);
00232 if($elem->m_UpdateForm=='Y'){
00233 $parentForm->setActiveRecord($updRec);
00234 $parentForm->rerender();
00235 }else{
00236 BizSystem::clientProxy()->updateFormElements($parentForm->m_Name, $updArray);
00237 foreach($updArray as $elemName=>$value)
00238 {
00239 $elem = $parentForm->getElement($elemName);
00240 $elemEvents = $elem->getEvents();
00241 foreach($elemEvents as $event=>$function)
00242 {
00243 if(strtolower($event)=='onchange')
00244 {
00245
00246 if(is_array($function)){
00247 foreach($function as $f){
00248 $function_str.=$f.";";
00249 }
00250 }else{
00251 $function_str .= $function;
00252 }
00253 BizSystem::clientProxy()->runClientScript("<script>$function_str</script>");
00254 }
00255 }
00256 }
00257 }
00258 }
00259
00265 public function addToParent($recIds=null)
00266 {
00267 if(!is_array($recIds))
00268 {
00269 $recIdArr = array();
00270 $recIdArr[] = $recIds;
00271 }else{
00272 $recIdArr = $recIds;
00273 }
00274
00275
00276 $parentForm = BizSystem::objectFactory()->getObject($this->m_ParentFormName);
00277 foreach($recIdArr as $recId)
00278 {
00279
00280
00281 $this->m_SearchRule="";
00282 $parentForm->getDataObj()->clearSearchRule();
00283
00284 $do = $this->getDataObj();
00285 $baseSearchRule = $do->m_BaseSearchRule;
00286 $do->m_BaseSearchRule = "";
00287 $do->clearSearchRule();
00288 $rec = $do->fetchById($recId);
00289 $do->m_BaseSearchRule = $baseSearchRule;
00290
00291 if(!$rec){
00292 $rec=BizSystem::getObject($do->m_Name,1)->fetchById($recId);
00293 }
00294
00295
00296 $ok = $parentForm->getDataObj()->addRecord($rec, $bPrtObjUpdated);
00297 if (!$ok){
00298 return $parentForm->processDataObjError($ok);
00299 }
00300 }
00301
00302 $this->close();
00303
00304 $parentForm->rerender();
00305 if($parentForm->m_ParentFormName){
00306 $parentForm->renderParent();
00307 }
00308 }
00309
00310
00317 private function _parsePickerMap($pickerMap)
00318 {
00319 $returnList = array();
00320 $pickerList = explode(",", $pickerMap);
00321 foreach ($pickerList as $pair)
00322 {
00323 $controlMap = explode(":", $pair);
00324 $controlMap[0] = trim($controlMap[0]);
00325 $controlMap[1] = trim($controlMap[1]);
00326 $returnList[] = $controlMap;
00327 }
00328 return $returnList;
00329 }
00330 }
00331 ?>