PageRenderTime 116ms CodeModel.GetById 61ms app.highlight 36ms RepoModel.GetById 1ms app.codeStats 1ms

/cubi/openbiz/bin/easy/EasyForm.php

http://openbiz-cubi.googlecode.com/
PHP | 2404 lines | 1658 code | 212 blank | 534 comment | 298 complexity | 26cbc3f42d50feb7ce3e51bd5605dc8e MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/**
   3 * PHPOpenBiz Framework
   4 *
   5 * LICENSE
   6 *
   7 * This source file is subject to the BSD license that is bundled
   8 * with this package in the file LICENSE.txt.
   9 *
  10 * @package   openbiz.bin.easy
  11 * @copyright Copyright (c) 2005-2011, Rocky Swen
  12 * @license   http://www.opensource.org/licenses/bsd-license.php
  13 * @link      http://www.phpopenbiz.org/
  14 * @version   $Id: EasyForm.php 4203 2011-06-01 07:33:23Z rockys $
  15 */
  16
  17//include_once(OPENBIZ_BIN."/easy/Panel.php");
  18//include_once(OPENBIZ_BIN."/easy/FormRenderer.php");
  19//include_once(OPENBIZ_BIN."/util/QueryStringParam.php");
  20
  21/**
  22 * EasyForm class - contains form object metadata functions
  23 *
  24 * @package openbiz.bin.easy
  25 * @author Rocky Swen
  26 * @copyright Copyright (c) 2005-2009
  27 * @access public
  28 */
  29class EasyForm extends MetaObject implements iSessionObject
  30{
  31    public $DATAFORMAT = 'RECORD';
  32
  33    // metadata vars are public, necessary for metadata inheritance
  34    public $m_Title;
  35    public $m_Icon;
  36    public $m_Description;
  37    public $m_jsClass;
  38    public $m_DataObjName;
  39    public $m_Height;
  40    public $m_Width;
  41    public $m_DefaultForm;
  42  
  43    public $m_CanUpdateRecord;
  44    public $m_DirectMethodList = null; //list of method that can directly from browser
  45
  46    public $m_Panels; 
  47
  48    /**
  49     * Name of inherited form (meta-form)
  50     *
  51     * @var string
  52     */
  53    public $m_InheritFrom;
  54    
  55    /**
  56     * Data Panel object
  57     *
  58     * @var Panel
  59     */
  60    public $m_DataPanel;
  61    /**
  62     * Action Panel object
  63     * @var Panel
  64     */
  65    public $m_ActionPanel;
  66    /**
  67     * Navigation Panel object
  68     * @var Panel
  69     */
  70    public $m_NavPanel;
  71    /**
  72     * Search Panel object
  73     * @var Panel
  74     */
  75    public $m_SearchPanel;
  76
  77    public $m_TemplateEngine;
  78    public $m_TemplateFile;
  79    public $m_FormType;
  80    public $m_SubForms = null;
  81    public $m_EventName;
  82    public $m_Range = 10;
  83    public $m_CacheLifeTime = 0;
  84    public $m_FormParams;
  85
  86    // parent form is the form that trigger the popup. "this" form is a popup form
  87    public $m_ParentFormName;
  88    // the form that drives navigation - the 1st form deplayed in the view
  89    public $m_DefaultFormName = null;
  90
  91    public $m_Errors;   // errors array (error_element, error_message)
  92    public $m_Notices;  // list of notice messages
  93
  94    // basic form vars
  95    protected $m_DataObj;
  96    protected $m_RecordId = null;
  97    public $m_ActiveRecord = null;
  98    public $m_FormInputs = null;
  99    public $m_SearchRule = null;
 100    public $m_FixSearchRule = null; // FixSearchRule is the search rule always applying on the search
 101    
 102    public $m_SortRule = null;
 103    
 104    protected $m_DefaultFixSearchRule = null;
 105    protected $m_Referer = "";
 106    public $m_MessageFile = null;
 107    protected $m_hasError = false;
 108    protected $m_ValidateErrors = array();
 109	protected $queryParams = array();
 110
 111    // vars for grid(list)
 112    protected $m_CurrentPage = 1;
 113    protected $m_StartItem = 1;
 114    public $m_TotalPages = 1;
 115    protected $m_TotalRecords = 0;
 116    protected $m_RecordSet = null;
 117    protected $m_RefreshData = false;
 118    protected $m_Resource = "";
 119
 120    protected $m_Messages;
 121    protected $m_InvokingElement = null;
 122    
 123    public $m_AutoRefresh=0;
 124    
 125    public $m_ReferenceFormName; //switch from which form
 126    protected $m_RecordAllowAccess = true;
 127
 128    /**
 129     * Initialize BizForm with xml array
 130     *
 131     * @param array $xmlArr
 132     * @return void
 133     */
 134    function __construct(&$xmlArr)
 135    {
 136        $this->readMetadata($xmlArr);
 137        //echo $_GET['referer'];
 138        $this->inheritParentObj();
 139    }
 140
 141    public function allowAccess($access=null)
 142    {
 143    	if(!$this->m_RecordAllowAccess)
 144    	{
 145    		/**
 146    		 * if the record is now allowed to access, then deny form render
 147    		 * instead of display an empty form
 148    		 */
 149    		return false; 
 150    	}
 151    	$result = parent::allowAccess($access);    	
 152    	return $result ;
 153    }
 154    
 155    /**
 156     * Read array meta data, and store to meta object
 157     *
 158     * @param array $xmlArr
 159     * @return void
 160     */
 161    protected function readMetadata(&$xmlArr)
 162    {
 163        parent::readMetaData($xmlArr);
 164        $this->m_InheritFrom = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["INHERITFROM"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["INHERITFROM"] : null;        
 165        $this->m_Title = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["TITLE"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["TITLE"] : null;
 166        $this->m_Icon = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["ICON"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["ICON"] : null;        
 167        $this->m_Description = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["DESCRIPTION"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["DESCRIPTION"] : null;
 168        $this->m_jsClass = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["JSCLASS"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["JSCLASS"] : null;
 169        $this->m_Height = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["HEIGHT"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["HEIGHT"] : null;
 170        $this->m_Width = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["WIDTH"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["WIDTH"] : null;
 171        $this->m_DefaultForm = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["DEFAULTFORM"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["DEFAULTFORM"] : null;
 172        $this->m_TemplateEngine = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["TEMPLATEENGINE"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["TEMPLATEENGINE"] : null;
 173        $this->m_TemplateFile = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["TEMPLATEFILE"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["TEMPLATEFILE"] : null;
 174        $this->m_FormType = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["FORMTYPE"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["FORMTYPE"] : null;
 175        $this->m_Range = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["PAGESIZE"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["PAGESIZE"] : $this->m_Range;
 176        $this->m_FixSearchRule = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["SEARCHRULE"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["SEARCHRULE"] : null;
 177        $this->m_SortRule = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["SORTRULE"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["SORTRULE"] : null;
 178		$this->m_DefaultFixSearchRule = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["SEARCHRULE"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["SEARCHRULE"] : null;
 179        
 180        $this->m_Name = $this->prefixPackage($this->m_Name);
 181        if ($this->m_InheritFrom == '@sourceMeta') $this->m_InheritFrom = '@'.$this->m_Name;
 182        else $this->m_InheritFrom = $this->prefixPackage($this->m_InheritFrom);
 183        $this->m_DataObjName = $this->prefixPackage($xmlArr["EASYFORM"]["ATTRIBUTES"]["BIZDATAOBJ"]);
 184
 185        if (isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["DIRECTMETHOD"]))
 186            $this->m_DirectMethodList = explode(",", strtolower(str_replace(" ", "",$xmlArr["EASYFORM"]["ATTRIBUTES"]["DIRECTMETHOD"])));
 187
 188        $this->m_DataPanel = new Panel($xmlArr["EASYFORM"]["DATAPANEL"]["ELEMENT"],"",$this);
 189        $this->m_ActionPanel = new Panel($xmlArr["EASYFORM"]["ACTIONPANEL"]["ELEMENT"],"",$this);
 190        $this->m_NavPanel = new Panel($xmlArr["EASYFORM"]["NAVPANEL"]["ELEMENT"],"",$this);
 191        $this->m_SearchPanel = new Panel($xmlArr["EASYFORM"]["SEARCHPANEL"]["ELEMENT"],"",$this);
 192        $this->m_Panels = array($this->m_DataPanel, $this->m_ActionPanel, $this->m_NavPanel, $this->m_SearchPanel);
 193
 194        $this->m_FormType = strtoupper($this->m_FormType);
 195
 196        $this->m_EventName = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["EVENTNAME"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["EVENTNAME"] : null;
 197
 198        $this->m_MessageFile = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["MESSAGEFILE"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["MESSAGEFILE"] : null;
 199        $this->m_Messages = Resource::loadMessage($this->m_MessageFile , $this->m_Package);
 200
 201        $this->m_CacheLifeTime = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["CACHELIFETIME"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["CACHELIFETIME"] : "0";
 202
 203        $this->m_CurrentPage = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["STARTPAGE"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["STARTPAGE"] : 1;
 204        $this->m_StartItem = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["STARTITEM"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["STARTITEM"] : 1;
 205
 206        $this->m_AutoRefresh = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["AUTOREFRESH"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["AUTOREFRESH"] : 0;
 207        
 208        // parse access
 209        if ($this->m_Access)
 210        {
 211            $arr = explode (".", $this->m_Access);
 212            $this->m_Resource = $arr[0];
 213        }
 214        if ($this->m_jsClass == "jbForm" && strtoupper($this->m_FormType) == "LIST") $this->m_jsClass = "Openbiz.TableForm";
 215        if ($this->m_jsClass == "jbForm") $this->m_jsClass = "Openbiz.Form";
 216        
 217		$this->translate();	// translate for multi-language support
 218    }
 219
 220    /**
 221     * Inherit from parent object. Name, Package, Class cannot be inherited
 222     *
 223     * @return void
 224     */
 225    protected function inheritParentObj()
 226    {
 227        if (!$this->m_InheritFrom) return;
 228        $parentObj = BizSystem::getObject($this->m_InheritFrom);
 229
 230        $this->m_Title = $this->m_Title ? $this->m_Title : $parentObj->m_Title;
 231        $this->m_Icon = $this->m_Icon ? $this->m_Icon : $parentObj->m_Icon;        
 232        $this->m_Description  = $this->m_Description ? $this->m_Description : $parentObj->m_Description;
 233        $this->m_jsClass   = $this->m_jsClass ? $this->m_jsClass : $parentObj->m_jsClass;
 234        $this->m_Height   = $this->m_Height ? $this->m_Height : $parentObj->m_Height;
 235        $this->m_Width   = $this->m_Width ? $this->m_Width : $parentObj->m_Width;
 236        $this->m_DefaultForm   = $this->m_DefaultForm ? $this->m_DefaultForm : $parentObj->m_DefaultForm;        
 237        $this->m_TemplateEngine   = $this->m_TemplateEngine ? $this->m_TemplateEngine : $parentObj->m_TemplateEngine;
 238        $this->m_TemplateFile   = $this->m_TemplateFile ? $this->m_TemplateFile : $parentObj->m_TemplateFile;        
 239        $this->m_FormType   = $this->m_FormType ? $this->m_FormType : $parentObj->m_FormType;
 240        $this->m_Range   = $this->m_Range ? $this->m_Range : $parentObj->m_Range;
 241        $this->m_FixSearchRule   = $this->m_FixSearchRule ? $this->m_FixSearchRule : $parentObj->m_FixSearchRule;
 242        $this->m_DefaultFixSearchRule   = $this->m_DefaultFixSearchRule ? $this->m_DefaultFixSearchRule : $parentObj->m_DefaultFixSearchRule;		        
 243        $this->m_DataObjName   = $this->m_DataObjName ? $this->m_DataObjName : $parentObj->m_DataObjName;
 244        $this->m_DirectMethodList   = $this->m_DirectMethodList ? $this->m_DirectMethodList : $parentObj->m_DirectMethodList;
 245        $this->m_EventName   = $this->m_EventName ? $this->m_EventName : $parentObj->m_EventName;
 246        $this->m_MessageFile   = $this->m_MessageFile ? $this->m_MessageFile : $parentObj->m_MessageFile;
 247        $this->m_Messages = Resource::loadMessage($this->m_MessageFile , $this->m_Package);
 248		$this->m_CacheLifeTime   = $this->m_CacheLifeTime ? $this->m_CacheLifeTime : $parentObj->m_CacheLifeTime;
 249		$this->m_CurrentPage   = $this->m_CurrentPage ? $this->m_CurrentPage : $parentObj->m_CurrentPage;
 250		$this->m_StartItem   = $this->m_StartItem ? $this->m_StartItem : $parentObj->m_StartItem;        
 251        
 252        $this->m_DataPanel->merge($parentObj->m_DataPanel);
 253        $this->m_ActionPanel->merge($parentObj->m_ActionPanel);
 254        $this->m_NavPanel->merge($parentObj->m_NavPanel);
 255        $this->m_SearchPanel->merge($parentObj->m_SearchPanel);        
 256
 257        if($this->m_DataPanel->current()){
 258	        foreach ($this->m_DataPanel as $elem)
 259	            $elem->adjustFormName($this->m_Name);
 260        }
 261        if($this->m_ActionPanel->current()){
 262	        foreach ($this->m_ActionPanel as $elem)
 263	            $elem->adjustFormName($this->m_Name);
 264        }
 265        if($this->m_NavPanel->current()){                
 266	        foreach ($this->m_NavPanel as $elem)
 267	            $elem->adjustFormName($this->m_Name);
 268        }
 269        if($this->m_SearchPanel->current()){
 270	        foreach ($this->m_SearchPanel as $elem)
 271	            $elem->adjustFormName($this->m_Name);            
 272        }   
 273		$this->m_Panels = array($this->m_DataPanel, $this->m_ActionPanel, $this->m_NavPanel, $this->m_SearchPanel);            
 274    }    
 275    
 276    /**
 277     * Get message, and translate it
 278     *
 279     * @param string $messageId message Id
 280     * @param array $params
 281     * @return string message string
 282     */
 283    public function getMessage($messageId, $params=array())
 284    {
 285        $message = isset($this->m_Messages[$messageId]) ? $this->m_Messages[$messageId] : constant($messageId);
 286        //$message = I18n::getInstance()->translate($message);
 287        $message = I18n::t($message, $messageId, $this->getModuleName($this->m_Name));        
 288        $msg = @vsprintf($message,$params);
 289        if(!$msg){ //maybe in translation missing some %s can cause it returns null
 290        	$msg = $message;
 291        }
 292        return $msg;
 293    }
 294
 295    public function canDisplayForm()
 296    {
 297    	
 298    	if($this->getDataObj()->m_DataPermControl=='Y')
 299        {
 300        	switch(strtolower($this->m_FormType))
 301        	{
 302        		default:
 303        		case 'list':
 304        			return true;
 305        			break;
 306        		case 'detail':
 307        			$permCode=1;
 308        			break;  
 309        			
 310        		case 'edit':
 311        			$permCode=2;
 312        			break;        		      		
 313        	}
 314	        $svcObj = BizSystem::GetService(DATAPERM_SERVICE);
 315	        $result = $svcObj->checkDataPerm($this->fetchData(),$permCode,$this->getDataObj());
 316	        if($result == false)
 317	        {
 318	        	return false;
 319	        }
 320        }    	
 321        return true;
 322    }
 323
 324    public function canDeleteRecord($rec)
 325    {
 326    	
 327    	if($this->getDataObj()->m_DataPermControl=='Y')
 328        {        	        	
 329	        $svcObj = BizSystem::GetService(DATAPERM_SERVICE);
 330	        $result = $svcObj->checkDataPerm($rec,3,$this->getDataObj());
 331	        if($result == false)
 332	        {
 333	        	return false;
 334	        }
 335        }    	
 336        return true;
 337    }
 338    
 339    
 340    /**
 341     * Get/Retrieve Session data of this object
 342     *
 343     * @param SessionContext $sessionContext
 344     * @return void
 345     */
 346    public function getSessionVars($sessionContext)
 347    {
 348        $sessionContext->getObjVar($this->m_Name, "RecordId", $this->m_RecordId);
 349        $sessionContext->getObjVar($this->m_Name, "FixSearchRule", $this->m_FixSearchRule);
 350        $sessionContext->getObjVar($this->m_Name, "SearchRule", $this->m_SearchRule);
 351        $sessionContext->getObjVar($this->m_Name, "QueryParams", $this->queryParams);
 352        $sessionContext->getObjVar($this->m_Name, "SubForms", $this->m_SubForms);
 353        $sessionContext->getObjVar($this->m_Name, "ParentFormName", $this->m_ParentFormName);
 354        $sessionContext->getObjVar($this->m_Name, "DefaultFormName", $this->m_DefaultFormName);
 355        $sessionContext->getObjVar($this->m_Name, "CurrentPage", $this->m_CurrentPage);
 356        $sessionContext->getObjVar($this->m_Name, "PageSize", $this->m_Range);
 357        $sessionContext->getObjVar($this->m_Name, "ReferenceFormName", $this->m_ReferenceFormName);
 358        $sessionContext->getObjVar($this->m_Name, "SearchPanelValues", $this->m_SearchPanelValues);
 359    }
 360
 361    /**
 362     * Save object variable to session context
 363     *
 364     * @param SessionContext $sessionContext
 365     * @return void
 366     */
 367    public function setSessionVars($sessionContext)
 368    {
 369        $sessionContext->setObjVar($this->m_Name, "RecordId", $this->m_RecordId);
 370        $sessionContext->setObjVar($this->m_Name, "FixSearchRule", $this->m_FixSearchRule);
 371        $sessionContext->setObjVar($this->m_Name, "SearchRule", $this->m_SearchRule);        
 372        $sessionContext->setObjVar($this->m_Name, "QueryParams", $this->queryParams);
 373        $sessionContext->setObjVar($this->m_Name, "SubForms", $this->m_SubForms);
 374        $sessionContext->setObjVar($this->m_Name, "ParentFormName", $this->m_ParentFormName);
 375        $sessionContext->setObjVar($this->m_Name, "DefaultFormName", $this->m_DefaultFormName);
 376        $sessionContext->setObjVar($this->m_Name, "CurrentPage", $this->m_CurrentPage);
 377        $sessionContext->setObjVar($this->m_Name, "PageSize", $this->m_Range);
 378        $sessionContext->setObjVar($this->m_Name, "ReferenceFormName", $this->m_ReferenceFormName);
 379        $sessionContext->setObjVar($this->m_Name, "SearchPanelValues", $this->m_SearchPanelValues);        
 380    }
 381
 382    /**
 383     * Invoke the action passed from browser
 384     *
 385     * @return mixed the function result, or false on error.
 386     */
 387    public function invoke()
 388    {
 389        $argList = func_get_args();
 390        $param1 = array_shift($argList);
 391        // first one is element:eventhandler
 392        list ($elementName, $eventHandlerName) = explode(":", $param1);        
 393        $element = $this->getElement($elementName);
 394        $eventHandler = $element->m_EventHandlers->get($eventHandlerName);
 395        $this->m_InvokingElement = array($element, $eventHandler);
 396        // find the matching function
 397        list($funcName, $funcParams) = $eventHandler->parseFunction($eventHandler->m_OrigFunction);
 398        // call the function with rest parameters
 399        return call_user_func_array(array($this, $funcName), $argList);
 400    }
 401    
 402    /**
 403     * Validate request from client (browser)
 404     * 
 405     * @param string $methodName called from the client
 406     * @return boolean
 407     */
 408    public function validateRequest($methodName)
 409    {
 410        $methodName = strtolower($methodName);
 411        
 412        if ($methodName == "selectrecord" || $methodName == "invoke" || $methodName="sortrecord") 
 413            return true;
 414        // element, eventhandler
 415        list($element, $eventHandler) = $this->getInvokingElement();
 416        if ($element && $eventHandler)
 417        {
 418            if (stripos($eventHandler->m_OrigFunction, $methodName)===0)
 419                return true;
 420        }
 421        // scan elements to match method
 422        foreach ($this->m_Panels as $panel)
 423        {
 424            foreach ($panel as $elem) 
 425                if ($elem->matchRemoteMethod($methodName)) return true;
 426        }
 427
 428        if (is_array($this->m_DirectMethodList))
 429        {
 430            foreach ($this->m_DirectMethodList as $value)
 431            {
 432                if ($methodName == $value) return true;
 433            }
 434        }
 435
 436        return false;
 437    }
 438
 439    /**
 440     * Get object property
 441     * This method get element object if propertyName is "Elements[elementName]" format.
 442     *
 443     * @param string $propertyName
 444     * @return <type>
 445     */
 446    public function getProperty($propertyName)
 447    {
 448        $ret = parent::getProperty($propertyName);
 449        if ($ret !== null) return $ret;
 450
 451        $pos1 = strpos($propertyName, "[");
 452        $pos2 = strpos($propertyName, "]");
 453        if ($pos1>0 && $pos2>$pos1)
 454        {
 455            $propType = substr($propertyName, 0, $pos1);
 456            $elementName = substr($propertyName, $pos1+1,$pos2-$pos1-1);
 457            switch(strtolower($propType))
 458            {
 459				case 'param':            	
 460            	case 'params':
 461            		$result = $this->m_FormParams[$elementName];
 462            		break;
 463            	default:
 464            		
 465            		$result = $this->getElement($elementName);
 466            		break;
 467            }            
 468            return $result;
 469        }
 470    }
 471
 472    /**
 473     * Get object instance of {@link BizDataObj} defined in it's metadata file
 474     *
 475     * @return BizDataObj
 476     */
 477    public function getDataObj()
 478    {
 479        if (!$this->m_DataObj)
 480        {
 481            if ($this->m_DataObjName)
 482                $this->m_DataObj = BizSystem::objectFactory()->getObject($this->m_DataObjName);
 483            if($this->m_DataObj)
 484                $this->m_DataObj->m_BizFormName = $this->m_Name;
 485            else
 486            {
 487                //BizSystem::clientProxy()->showErrorMessage("Cannot get DataObj of ".$this->m_DataObjName.", please check your metadata file.");
 488                return null;
 489            }
 490        }
 491        return $this->m_DataObj;
 492    }
 493
 494    /**
 495     * Set data object {@link BizDataObj} with specified instant from parameter
 496     *
 497     * @param BizDataObj $dataObj
 498     * @return void
 499     */
 500    final public function setDataObj($dataObj)
 501    {
 502        $this->m_DataObj = $dataObj;
 503    }
 504
 505    /**
 506     * Get output attributs as array
 507     *
 508     * @return array array of attributs
 509     * @todo rename to getOutputAttribute or getAttribute (2.5?)
 510     */
 511    public function outputAttrs()
 512    {
 513        $output['name'] = $this->m_Name;
 514        $output['title'] = Expression::evaluateExpression($this->m_Title, $this);
 515        $output['icon'] = $this->m_Icon;
 516        $output['hasSubform'] = $this->m_SubForms ? 1 : 0;
 517        $output['currentPage'] = $this->m_CurrentPage;
 518        $output['currentRecordId'] = $this->m_RecordId;
 519        $output['totalPages'] = $this->m_TotalPages;
 520        $output['totalRecords'] = $this->m_TotalRecords;
 521        $output['description'] = str_replace('\n', "<br />", Expression::evaluateExpression($this->m_Description,$this));
 522        $output['elementSets'] = $this->getElementSet();
 523        $output['tabSets'] = $this->getTabSet();
 524        $output['ActionElementSets'] = $this->getElementSet($this->m_ActionPanel);    
 525        if($output['icon'])
 526        {   
 527	        if(preg_match("/{.*}/si",$output['icon']))
 528	        {
 529	        	$output['icon'] = Expression::evaluateExpression($output['icon'], null);
 530	        }
 531	        else
 532	        {
 533	        	$output['icon'] = THEME_URL . "/" . Resource::getCurrentTheme() . "/images/".$output['icon'];
 534	        }
 535        }
 536        return $output;
 537    }
 538
 539    /**
 540     * Handle the error from {@link BizDataObj::getErrorMessage} method,
 541     * report the error as an alert window and log.
 542     *
 543     * @param int $errCode
 544     * @return void
 545     */
 546    public function processDataObjError($errCode = 0)
 547    {
 548        $errorMsg = $this->getDataObj()->getErrorMessage();
 549        BizSystem::log(LOG_ERR, "DATAOBJ", "DataObj error = ".$errorMsg);
 550        BizSystem::clientProxy()->showErrorMessage($errorMsg);
 551    }
 552
 553    /**
 554     * Process error of form object
 555     *
 556     * @param array $errors
 557     * @return string - HTML text of this form's read mode
 558     */
 559    public function processFormObjError($errors)
 560    {
 561        $this->m_Errors = $errors;
 562        $this->m_hasError = true;
 563        return $this->rerender();
 564    }
 565
 566    /**
 567     * Handle the exception from DataObj method,
 568     *  report the error as an alert window
 569     *
 570     * @param int $errCode
 571     * @return string
 572     */
 573    public function processBDOException($e)
 574    {
 575        $errorMsg = $e->getMessage();
 576        BizSystem::log(LOG_ERR, "DATAOBJ", "DataObj error = ".$errorMsg);
 577        //BizSystem::clientProxy()->showClientAlert($errorMsg);   //showErrorMessage($errorMsg);
 578        //BizSystem::clientProxy()->showErrorMessage($errorMsg);	
 579        $e->no_exit=true;        
 580	    OB_ErrorHandler::ExceptionHandler($e);
 581    }
 582
 583    /**
 584     * Set the sub forms of this form. This form is parent of other forms
 585     *
 586     * @param string $subForms - sub controls string with format: ctrl1;ctrl2...
 587     * @return void
 588     */
 589    final public function setSubForms($subForms)
 590    {
 591        // sub controls string with format: ctrl1;ctrl2...
 592        if (!$subForms || strlen($subForms) < 1)
 593        {
 594            $this->m_SubForms = null;
 595            return;
 596        }
 597        $subFormArr = explode(";", $subForms);
 598        unset($this->m_SubForms);
 599        foreach ($subFormArr as $subForm)
 600        {
 601            $this->m_SubForms[] = $this->prefixPackage($subForm);
 602        }
 603    }
 604
 605    /**
 606     * Get view object
 607     *
 608     * @global BizSystem $g_BizSystem
 609     * @return EasyView
 610     */
 611    public function getViewObject()
 612    {
 613        global $g_BizSystem;
 614        $viewName = $g_BizSystem->getCurrentViewName();
 615        if (!$viewName) return null;
 616        $viewObj = BizSystem::getObject($viewName);
 617        return $viewObj;
 618    }
 619
 620    /**
 621     * Get sub form of this form
 622     *
 623     * @return EasyForm
 624     */
 625    public function getSubForms()
 626    {
 627        // ask view to give its subforms if not set yet
 628        return $this->m_SubForms;
 629    }
 630
 631    /**
 632     * Get an element object
 633     *
 634     * @param string $elementName - name of the control
 635     * @return Element
 636     */
 637    public function getElement($elementName)
 638    {
 639        if ($this->m_DataPanel->get($elementName)) return $this->m_DataPanel->get($elementName);
 640        if ($this->m_ActionPanel->get($elementName)) return $this->m_ActionPanel->get($elementName);
 641        if ($this->m_NavPanel->get($elementName)) return $this->m_NavPanel->get($elementName);
 642        if ($this->m_SearchPanel->get($elementName)) return $this->m_SearchPanel->get($elementName);
 643        if($this->m_WizardPanel)
 644        {
 645        	if ($this->m_WizardPanel->get($elementName)) return $this->m_WizardPanel->get($elementName);
 646        }
 647    }
 648    
 649    public function getElementSet($panel = null)
 650    {
 651    	if(!$panel){
 652    		$panel = $this->m_DataPanel;
 653    	}
 654    	$setArr = array();
 655    	$panel->rewind();
 656        while($panel->valid())    	    	
 657        {      
 658        	$elem = $panel->current();
 659        	$panel->next();    
 660        	if($elem->m_ElementSet && $elem->canDisplayed()){
 661        		//is it in array
 662        		if(in_array($elem->m_ElementSet,$setArr)){
 663        			continue;
 664        		}else{
 665        			array_push($setArr,$elem->m_ElementSet);
 666        		}
 667        	}                          
 668        }
 669        return $setArr;
 670    }
 671    
 672	public function getTabSet($panel = null)
 673    {
 674    	if(!$panel){
 675    		$panel = $this->m_DataPanel;
 676    	}
 677    	$setArr = array();
 678    	$tabSetArr = array();
 679    	$panel->rewind();
 680        while($panel->valid())    	    	
 681        {      
 682        	$elem = $panel->current();
 683        	$panel->next();    
 684        	if($elem->m_TabSet && $elem->canDisplayed()){
 685        		//is it in array
 686        		if(in_array($elem->m_TabSet,$setArr)){
 687        			continue;
 688        		}else{
 689         			$setArr[$elem->m_TabSetCode]=$elem->m_TabSet;
 690        		}
 691        	}          	                                  
 692        }
 693        foreach($setArr as $tabsetCode=>$tabset)
 694        {
 695        	$elemSetArr = array();
 696        	$panel->rewind();
 697	        while($panel->valid())    	    	
 698	        {      
 699	        	$elem = $panel->current();
 700	        	$panel->next();    
 701	        	if($elem->m_ElementSet && $elem->canDisplayed()){
 702	        		//is it in array
 703	        		if( $elem->m_TabSetCode!= $tabsetCode || 
 704	        			in_array($elem->m_ElementSet,$elemSetArr)){
 705	        			continue;
 706	        		}else{
 707	        			array_push($elemSetArr,$elem->m_ElementSet);
 708	        		}
 709	        	}          	                                  
 710	        }
 711	        $tabSetArr[$tabsetCode]['SetName'] = $tabset;
 712	        $tabSetArr[$tabsetCode]['Elems'] = $elemSetArr;
 713        }
 714        return $tabSetArr;
 715    }    
 716
 717    /**
 718     * Get error elements
 719     *
 720     * @param array $fields
 721     * @return array
 722     */
 723    public function getErrorElements($fields)
 724    {
 725        $errElements = array();
 726        foreach ($fields as $field=>$error)
 727        {
 728            $element = $this->m_DataPanel->getByField($field);
 729            $errElements[$element->m_Name]=$error;
 730        }
 731        return $errElements;
 732    }
 733
 734    /**
 735     * Popup a selection EasyForm in a dynamically generated EasyView
 736     *
 737     * @param string $viewName
 738     * @param string $formName
 739     * @param string $elementName
 740     * @return void
 741     * @access remote
 742     */
 743    public function loadPicker($formName, $elementName="")
 744    {
 745        // set the ParentFormName and ParentCtrlName of the popup form
 746        /* @var $pickerForm EasyForm */
 747        $pickerForm = BizSystem::objectFactory()->getObject($formName);
 748
 749        if ($elementName != "")
 750        {
 751            // set the picker map as well
 752            $element = $this->getElement($elementName);
 753            $pickerMap = $element->m_PickerMap;
 754        }
 755		$currentRecord = $this->readInputRecord();
 756		$pickerForm->setParentForm($this->m_Name);
 757        $pickerForm->setParentFormData($this->m_Name, $elementName, $pickerMap);
 758        $pickerForm->m_ParentFormRecord = $currentRecord;
 759        BizSystem::clientProxy()->redrawForm("DIALOG", $pickerForm->render());
 760    }
 761    
 762    public function loadDialog($formName, $id=null,$transId=false)
 763    {
 764    	$paramFields = array();
 765        if ($id!=null)
 766            $paramFields["Id"] = $id;
 767        if ($transId!=false)
 768            $paramFields["Id"] = $this->m_RecordId;
 769        $this->_showForm($formName, "Dialog", $paramFields);
 770    }
 771	
 772	public function setParentForm($parentFormName)
 773	{
 774		$this->m_ParentFormName = $parentFormName;
 775	}
 776
 777    /**
 778     * Call/Invoke service method, this EasyForm name is passed to the method
 779     *
 780     * @param string $class
 781     * @param string $method
 782     * @param string $param
 783     * @return mixed - return value of the service method
 784     */
 785    public function callService($class, $method, $param = null)
 786    {
 787        $service = BizSystem::getService($class);
 788        if($param){
 789        	return $service->$method($param);
 790        }else{
 791        	return $service->$method($this->m_Name);
 792        }
 793    }
 794
 795    /**
 796     * Set request parameters
 797     *
 798     * @param array $paramFields
 799     * @return void
 800     */
 801    public function setRequestParams($paramFields)
 802    {    	    	
 803        if ($paramFields)
 804        {
 805        	$this->m_FixSearchRule=null; // reset fixsearchrule to clean the previous one in session
 806            foreach($paramFields as $fieldName=>$val)
 807            {
 808                $element = $this->m_DataPanel->getByField($fieldName);
 809                if($element->m_AllowURLParam=='Y')
 810                {                	
 811                	if(!$this->getDataObj())return;
 812                	if($this->getDataObj()->getField($fieldName)){
 813	                    if($this->getDataObj()->getField($fieldName)->checkValueType($val))
 814	                    {
 815	                        $this->setFixSearchRule("[$fieldName]='$val'");
 816	                    }
 817                	}
 818                }
 819            }
 820        }
 821    }
 822
 823    public function setCurrentPage($pageid)
 824    {
 825    	$this->m_CurrentPage = $pageid;
 826    }
 827    /**
 828     * Close the popup window
 829     *
 830     * @return void
 831     */
 832    public function close()
 833    {
 834        BizSystem::clientProxy()->closePopup();
 835    }
 836
 837    /**
 838     * Render parent form
 839     *
 840     * @return void
 841     */
 842    public function renderParent()
 843    {
 844        /* @var $parentForm EasyForm */
 845        $parentForm = BizSystem::objectFactory()->getObject($this->m_ParentFormName);
 846        $parentForm->rerender();
 847    }
 848
 849    /**
 850     * Set the dependent search rule of the bizform, this search rule will apply on its BizDataObj.
 851     * The dependent search rule (session var) will always be with bizform until it get set to other value
 852     *
 853     * @param string $rule - search rule has format "[fieldName1] opr1 Value1 AND/OR [fieldName2] opr2 Value2"
 854     * @param boolean $cleanActualRule
 855     * @return void
 856     */
 857    public function setFixSearchRule($rule = null, $cleanActualRule = true)
 858    {
 859        if ($cleanActualRule)
 860            $this->m_FixSearchRule = $this->m_DefaultFixSearchRule;
 861            
 862        if ($this->m_FixSearchRule && $rule)
 863        {        	
 864            if (strpos($this->m_FixSearchRule, $rule) === false)
 865            {
 866                $this->m_FixSearchRule = $this->m_FixSearchRule . " AND " . $rule;
 867            }
 868        }
 869        if (!$this->m_FixSearchRule && $rule){
 870            $this->m_FixSearchRule = $rule;
 871        }
 872    }
 873
 874    /**
 875     * Fetch record set
 876     *
 877     * @return array array of record
 878     */
 879    public function fetchDataSet()
 880    {
 881        $dataObj = $this->getDataObj();
 882
 883        if (!$dataObj) return null;
 884        
 885        if ($this->m_RefreshData)
 886            $dataObj->resetRules();
 887        else
 888            $dataObj->clearSearchRule();
 889
 890        if ($this->m_FixSearchRule)
 891        {
 892            if ($this->m_SearchRule)
 893                $searchRule = $this->m_SearchRule . " AND " . $this->m_FixSearchRule;
 894            else
 895                $searchRule = $this->m_FixSearchRule;
 896        }
 897        else
 898            $searchRule = $this->m_SearchRule;
 899
 900		$dataObj->setQueryParameters($this->queryParams);
 901        $dataObj->setSearchRule($searchRule);        
 902        if($this->m_StartItem>1)
 903        {
 904            $dataObj->setLimit($this->m_Range, $this->m_StartItem);
 905        }
 906        else
 907        {
 908            $dataObj->setLimit($this->m_Range, ($this->m_CurrentPage-1)*$this->m_Range);
 909        }      
 910        if($this->m_SortRule && $this->m_SortRule != $this->getDataObj()->m_SortRule)
 911        {
 912        		$dataObj->setSortRule($this->m_SortRule);
 913        }          
 914        $resultRecords = $dataObj->fetch();
 915        $this->m_TotalRecords = $dataObj->count();
 916        if ($this->m_Range && $this->m_Range > 0)
 917            $this->m_TotalPages = ceil($this->m_TotalRecords/$this->m_Range);
 918        $selectedIndex = 0;
 919        
 920        //if current page is large than total pages ,then reset current page to last page
 921        if($this->m_CurrentPage>$this->m_TotalPages && $this->m_TotalPages>0)
 922        {
 923        	$this->m_CurrentPage = $this->m_TotalPages;
 924        	$dataObj->setLimit($this->m_Range, ($this->m_CurrentPage-1)*$this->m_Range);
 925        	$resultRecords = $dataObj->fetch();
 926        }
 927        
 928        $this->getDataObj()->setActiveRecord($resultRecords[$selectedIndex]);
 929
 930		if(!$this->m_RecordId)
 931		{
 932			$this->m_RecordId = $resultRecords[0]["Id"];
 933		}else{
 934			$foundRecordId = false;
 935			foreach($resultRecords as $record)
 936			{
 937				if($this->m_RecordId==$record['Id'])
 938				{
 939					$foundRecordId = true;
 940				}
 941			}
 942			if($foundRecordId == false)
 943			{
 944				$this->m_RecordId=$result[0]['Id'];
 945			}			
 946		}
 947		
 948        return $resultRecords;
 949    }
 950
 951    /**
 952     * Fetch single record
 953     *
 954     * @return array one record array
 955     */
 956    public function fetchData()
 957    {    	
 958        // if has valid active record, return it, otherwise do a query
 959        if ($this->m_ActiveRecord != null)
 960            return $this->m_ActiveRecord;
 961        
 962        $dataObj = $this->getDataObj();
 963        if ($dataObj == null) return;
 964
 965        if (strtoupper($this->m_FormType) == "NEW")
 966            return $this->getNewRecord();
 967		
 968        if (!$this->m_FixSearchRule && !$this->m_SearchRule){ 
 969        	//if its a default sub form,even no search rule, but can still fetch a default record 
 970        	if(!is_array($this->getDataObj()->m_Association)){
 971        		//only if its a default sub form and without any association then return emply array
 972        		return array();
 973        	}
 974        }else{	
 975	        if ($this->m_RefreshData)   $dataObj->resetRules();
 976	        else $dataObj->clearSearchRule();
 977	
 978	        if ($this->m_FixSearchRule)
 979	        {
 980	            if ($this->m_SearchRule)
 981	                $searchRule = $this->m_SearchRule . " AND " . $this->m_FixSearchRule;
 982	            else
 983	                $searchRule = $this->m_FixSearchRule;
 984	        }
 985	        
 986	        $dataObj->setSearchRule($searchRule);
 987	        $dataObj->setLimit(1);
 988        }
 989        $resultRecords = $dataObj->fetch();
 990		if(!count($resultRecords))
 991		{
 992			$this->m_RecordAllowAccess=false;
 993		}
 994
 995        $this->m_RecordId = $resultRecords[0]['Id'];
 996        $this->setActiveRecord($resultRecords[0]);    	
 997        
 998    	if($this->getDataObj()){
 999			$this->m_CanUpdateRecord = (int)$this->getDataObj()->canUpdateRecord();
1000    	}        
1001        return $resultRecords[0];
1002    }
1003
1004    /**
1005     * Goto page specified by $page parameter, and ReRender
1006     * If page not specified, goto page 1
1007     *
1008     * @param number $page
1009     */
1010    public function gotoPage($page=1)
1011    {
1012        $tgtPage = intval($page);
1013        if ($tgtPage == 0) $tgtPage = 1;
1014        $this->m_CurrentPage = $tgtPage;
1015        $this->rerender();
1016    }
1017    public function gotoSelectedPage($elemName)
1018    {
1019        $page = BizSystem::clientProxy()->getFormInputs(str_replace(".","_", $this->m_Name).'_'.$elemName);
1020    	$this->gotoPage($page);
1021    }
1022    public function setPageSize($elemName)
1023    {
1024        $pagesize = BizSystem::clientProxy()->getFormInputs(str_replace(".","_", $this->m_Name).'_'.$elemName);
1025    	$this->m_Range=$pagesize;
1026    	$this->UpdateForm();
1027    }    
1028    /**
1029     * Sort Record, for list form
1030     *
1031     * @param string $sortCol column name to sort
1032     * @param string $order 'dec' (decending) or 'asc' (ascending)
1033     * @access remote
1034     * @return void
1035     */
1036    public function sortRecord($sortCol, $order='ASC')
1037    {
1038        $element = $this->getElement($sortCol);
1039        // turn off the OnSort flag of the old onsort field
1040        $element->setSortFlag(null);
1041        // turn on the OnSort flag of the new onsort field
1042        if ($order == "ASC")
1043            $order = "DESC";
1044        else
1045            $order = "ASC";
1046        $element->setSortFlag($order);
1047
1048        // change the sort rule and issue the query
1049        $this->getDataObj()->setSortRule("[" . $element->m_FieldName . "] " . $order);
1050
1051        // move to 1st page
1052        $this->m_CurrentPage = 1;
1053        $this->m_SortRule = "";
1054
1055        $this->rerender();
1056    }
1057
1058    /**
1059     * Run Search
1060     *
1061     * @return void
1062     */
1063    public function runSearch()
1064    {
1065        static $isSearchHelperLoaded = false;
1066        
1067        if (!$isSearchHelperLoaded) {
1068            include_once(OPENBIZ_BIN."/easy/SearchHelper.php");
1069            $isSearchHelperLoaded = true;
1070        }
1071        $searchRule = "";
1072        $this->queryParams = array();
1073        foreach ($this->m_SearchPanel as $element)
1074        {
1075            $searchStr = '';
1076        	if(method_exists($element,"getSearchRule")){
1077        		$searchStr = $element->getSearchRule();        		
1078        	}else{        	
1079	            if (!$element->m_FieldName)
1080	                continue;
1081	
1082	            $value = BizSystem::clientProxy()->getFormInputs($element->m_Name);            
1083	            if($element->m_FuzzySearch=="Y")
1084	            {
1085	                $value="*$value*";
1086	            }
1087	            if ($value!='')
1088	            {
1089	                //$searchStr = inputValToRule($element->m_FieldName, $value, $this);
1090	                $this->queryParams[$element->m_FieldName] = $value;
1091	            }
1092        	}
1093
1094            //BizSystem::clientProxy()->showClientAlert($searchStr);
1095        	if($searchStr){
1096        		if ($searchRule == "")
1097                    $searchRule .= $searchStr;
1098                else
1099                    $searchRule .= " AND " . $searchStr;
1100        	}
1101        }
1102
1103
1104        $this->m_SearchRule = $searchRule;
1105
1106        $this->m_RefreshData = true;
1107
1108        $this->m_CurrentPage = 1;
1109
1110        BizSystem::log(LOG_DEBUG,"FORMOBJ",$this->m_Name."::runSearch(), SearchRule=".$this->m_SearchRule);
1111
1112		$recArr = $this->readInputRecord();		
1113		
1114		$this->m_SearchPanelValues = $recArr;
1115		        
1116        $this->runEventLog();
1117        $this->rerender();
1118    }
1119
1120    /**
1121     * Reset search
1122     * 
1123     * @return void
1124     */
1125    public function resetSearch()
1126    {
1127        $this->m_SearchRule = "";
1128        $this->m_RefreshData = true;
1129        $this->m_CurrentPage = 1;
1130        $this->runEventLog();
1131        $this->rerender();
1132    }
1133    
1134    public function setSearchRule($searchRule, $queryParams=null)
1135    {
1136    	$this->m_SearchRule = $searchRule;
1137    	$this->queryParams = $queryParams;
1138    	$this->m_RefreshData = true;
1139        $this->m_CurrentPage = 1;
1140    }
1141    
1142    /**
1143     * New record, be default, just redirect to the new record page
1144     *
1145     * @return void
1146     */
1147    public function newRecord()
1148    {
1149        $this->processPostAction();
1150    }
1151
1152    /**
1153     * Copy record to new record     *
1154     *
1155     * @param mixed $id id of record that want to copy,
1156     * it parameter not passed, id is '_selectedId'
1157     * @return void
1158     */
1159    public function copyRecord($id=null)
1160    {
1161        if ($id==null || $id=='')
1162            $id = BizSystem::clientProxy()->getFormInputs('_selectedId');
1163
1164        if (!$id)
1165        {
1166            BizSystem::clientProxy()->showClientAlert($this->getMessage("PLEASE_EDIT_A_RECORD"));
1167            return;
1168        }
1169        $this->getActiveRecord($id);
1170        $this->processPostAction();
1171    }
1172
1173    /**
1174     * Edit Record
1175     * NOTE: append fld:Id=$id to the redirect page url
1176     *
1177     * @param mixed $id
1178     * @return void
1179     */
1180    public function editRecord($id=null)
1181    {
1182        if ($id==null || $id=='')
1183            $id = BizSystem::clientProxy()->getFormInputs('_selectedId');
1184		
1185        if (!isset($id))
1186        {
1187            BizSystem::clientProxy()->showClientAlert($this->getMessage("PLEASE_EDIT_A_RECORD"));
1188            return;
1189        }
1190
1191        // update the active record with new update record
1192        $this->getActiveRecord($id);
1193
1194        $this->processPostAction();
1195    }
1196
1197    /**
1198     * Show form
1199     *
1200     * @param string $formName
1201     * @param string $target target type: Popup or other
1202     * @param array $paramFields
1203     * @return void
1204     */
1205    protected function _showForm($formName, $target, $paramFields)
1206    {
1207    	
1208    	$formName_org = $formName;
1209        if (!$this->m_DefaultFormName)
1210    		$this->m_DefaultFormName = $this->m_Name;
1211    	if ($formName == null)
1212    	{
1213    		if($this->m_ReferenceFormName == null)
1214    		{
1215    			$formName = $this->m_DefaultFormName;
1216    		}else{
1217    			if($formName = $this->m_ReferenceFormName){
1218    				//this judgement is for anti endless loop between swtich forms
1219    				$formObj = BizSystem::objectFactory()->getObject($this->m_ReferenceFormName);
1220    				if($formObj->m_ReferenceFormName == $this->m_Name){    					
1221    					$formName = $this->m_DefaultFormName;
1222    				}else{    				
1223    					$formName = $this->m_ReferenceFormName;
1224    				}
1225    			}
1226    		}
1227    	}
1228    	//if($this->getViewObject()->isInFormRefLibs($formName))
1229        {
1230            // get the form object
1231            /* @var $formObj EasyForm */
1232            $formObj = BizSystem::objectFactory()->getObject($formName);
1233            $formObj->m_DefaultFormName = $this->m_DefaultFormName;
1234            if($formName_org){
1235            	//RefenerenceForm records where the from switch from
1236     			if( $this->m_FormType!='EDIT' &&
1237     				$this->m_FormType!='NEW' &&
1238     				$this->m_FormType!='COPY' ){
1239 	      	     	$formObj->m_ReferenceFormName = $this->m_Name;
1240    			} 
1241            }
1242            
1243            //if has more than Id field as params then $clearFixSearchRule is false, means join all where rules
1244            $paramTemp = $paramFields;           
1245            unset($paramTemp['Id']);
1246            if(count($paramTemp)){
1247            	$clearFixSearchRule = false;
1248            }else{
1249            	$clearFixSearchRule = true;
1250            }
1251            foreach($paramFields as $fieldName=>$val){            	
1252            	$formObj->m_FormParams[$fieldName] = $val;
1253                $formObj->setFixSearchRule("[$fieldName]='$val'",$clearFixSearchRule);                
1254                if($fieldName=="Id"){
1255                	$formObj->setRecordId($val);
1256                }
1257            }
1258
1259            if(!$formObj->canDisplayForm())
1260            {
1261            	$formObj->m_ErrorMessage = $this->getMessage("FORM_OPERATION_NOT_PERMITTED",$formObj->m_Name);
1262         
1263        		if (strtoupper($this->m_FormType) == "LIST"){
1264        			BizSystem::log(LOG_ERR, "DATAOBJ", "DataObj error = ".$errorMsg);
1265        			BizSystem::clientProxy()->showClientAlert($formObj->m_ErrorMessage);
1266        		}else{
1267        			$this->processFormObjError(array($formObj->m_ErrorMessage));	
1268        		}
1269	            
1270	            return false;
1271            }           
1272             
1273            switch ($target)
1274            {
1275                case "Popup":
1276                    $formObj->setParentForm($this->m_Name);
1277                    echo $formObj->render();
1278                    break;
1279                case "Dialog":
1280                    $formObj->setParentForm($this->m_Name);
1281                    BizSystem::clientProxy()->redrawForm("DIALOG", $formObj->render());
1282                    break;
1283                default:
1284                    BizSystem::clientProxy()->redrawForm($this->m_Name, $formObj->render());
1285            }
1286        }
1287    }
1288
1289    /**
1290     * Delete Record
1291     * NOTE: use redirectpage attr of eventhandler to redirect or redirect to previous page by default
1292     *
1293     * @param string $id
1294     * @return void
1295     */
1296    public function deleteRecord($id=null)
1297    {
1298        if ($id==null || $id=='')
1299            $id = BizSystem::clientProxy()->getFormInputs('_selectedId');
1300
1301        $selIds = BizSystem::clientProxy()->getFormInputs('row_selections', false);
1302        if ($selIds == null)
1303            $selIds[] = $id;
1304        foreach ($selIds as $id)
1305        {        	
1306            $dataRec = $this->getDataObj()->fetchById($id);
1307            $this->getDataObj()->setActiveRecord($dataRec);
1308            
1309            if(!$this->canDeleteRecord($dataRec))
1310            {
1311            	$this->m_ErrorMessage = $this->getMessage("FORM_OPERATION_NOT_PERMITTED",$this->m_Name);         
1312        		if (strtoupper($this->m_FormType) == "LIST"){
1313        			BizSystem::log(LOG_ERR, "DATAOBJ", "DataObj error = ".$errorMsg);
1314        			BizSystem::clientProxy()->showClientAlert($this->m_ErrorMessage);
1315        		}else{
1316        			$this->processFormObjError(array($this->m_ErrorMessage));	
1317        		}	
1318        		return;
1319            }
1320            
1321            // take care of exception
1322            try
1323            {
1324                $dataRec->delete();
1325            } catch (BDOException $e)
1326            {
1327                // call $this->processBDOException($e);
1328                $this->processBDOException($e);
1329                return;
1330            }
1331        }
1332        if (strtoupper($this->m_FormType) == "LIST")
1333            $this->rerender();
1334
1335        $this->runEventLog();
1336        $this->processPostAction();
1337    }
1338
1339    /**
1340     * Remove the record out of the associate relationship
1341     *
1342     * @return void
1343     */
1344    public function removeRecord ($id=null)
1345    {
1346    	if ($id==null || $id=='')
1347            $id = BizSystem::clientProxy()->getFormInputs('_selectedId');
1348
1349        $selIds = BizSystem::clientProxy()->getFormInputs('row_selections', false);
1350        if ($selIds == null)
1351            $selIds[] = $id;
1352        foreach ($selIds as $id)
1353        { 
1354        	
1355        	$rec = $this->getDataObj()->fetchById($id);
1356	        $ok = $this->getDataObj()->removeRecord($rec, $bPrtObjUpdated);
1357	        if (! $ok)
1358	            return $this->processDataObjError($ok);
1359        }        
1360
1361        $this->runEventLog();
1362        $this->rerender();
1363		if($this->m_ParentFormName)
1364		{
1365			$this->renderParent();
1366		}
1367     }
1368
1369    /**
1370     * Select Record
1371     *
1372     * @param string $recId
1373     * @access remote
1374     * @return void
1375     */
1376    public function selectRecord($recId)
1377    {
1378        if ($recId==null || $recId=='')
1379            $recId = BizSystem::clientProxy()->getFormInputs('_selectedId');
1380        $this->m_RecordId = $recId;
1381        if($this->getDataObj()){
1382        	$this->getDataObj()->setActiveRecordId($this->m_RecordId);
1383        }
1384        $this->rerender(false); // not redraw the this form, but draw the subforms
1385        //$this->rerender(); 
1386    }
1387
1388    /**
1389     * Get element Id
1390     *
1391     * @return mixed
1392     */
1393    public function getElementID()
1394    {
1395        $id = $this->m_DataPanel->getByField('Id')->getValue();
1396        if($id)
1397        {
1398            return (int)$id;
1399        }
1400        else
1401        {
1402            return (int)$this->m_RecordId;
1403        }
1404    }
1405
1406    /**
1407     * Save input and redirect page to a new view
1408     * use redirectpage attr of eventhandler to redirect or redirect to previous page by default
1409     * NOTE: For Edit/New form type
1410     * 
1411     * @return void
1412     */
1413    public function saveRecord()
1414    {
1415        if (strtoupper($this->m_FormType) == "NEW")
1416        {
1417            $this->insertRecord();
1418        }
1419        else
1420        {
1421            $this->updateRecord();
1422        }
1423    }
1424
1425    /**
1426     * Update record
1427     *
1428     * @return mixed
1429     */
1430    public function updateRecord()
1431    {
1432        $currentRec = $this->fetchData();
1433        $recArr = $this->readInputRecord();
1434        $this->setActiveRecord($recArr);
1435        if (count($recArr) != 0){
1436            	
1437	        try
1438	        {
1439	            $this->ValidateForm();
1440	        }
1441	        catch (ValidationException $e)
1442	        {
1443	            $this->processFormObjError($e->m_Errors);
1444	            return;
1445	        }
1446	
1447	        if ($this->_doUpdate($recArr, $currentRec) == false)
1448	            return;
1449			
1450			$this->commitFormElements(); // commit change in FormElement
1451        }
1452		
1453        // in case of popup form, close it, then rerender the parent form
1454        if ($this->m_ParentFormName)
1455        {
1456            $this->close();
1457
1458            $this->renderParent();
1459        }
1460        
1461        $this->processPostAction();
1462    }
1463
1464    
1465	public function updateFieldValueAdd($id,$fld_name,$value,$min,$max)
1466    {    	
1467    	if($value>=$max){
1468    		$value = $min;
1469    	}else{
1470    		$value++;
1471    	}
1472		return $this->updateFieldValue($id,$fld_name,$value);
1473    }        
1474    
1475	public function updateFieldValueXor($id,$fld_name,$value)
1476    {    	
1477    	if($value>0){
1478    		$value_xor = 0;
1479    	}else{
1480    		$value_xor = 1;
1481    	}
1482		return $this->updateFieldValue($id,$fld_name,$value_xor);
1483    }    
1484    
1485	/**
1486     * Update record
1487     *
1488     * @return mixed
1489     */
1490    public function updateFieldValue($Id,$fld_name,$value)
1491    {
1492    	
1493		$element = $this->m_DataPanel->get($fld_name);
1494		$fieldname = $element->m_FieldName;
1495        $currentRec = $this->getActiveRecord($Id);
1496        $recArr = $this->getActiveRecord($Id);
1497		$recArr[$fieldname]=$value;
1498        if ($this->_doUpdate($recArr, $currentRec) == false)
1499            return;
1500		$this->UpdateForm();
1501    }
1502    /**
1503     * Do update record
1504     *
1505 

Large files files are truncated, but you can click here to view the full file