PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): GPL-2.0, LGPL-3.0

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

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