PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/ebpls-php-lib/ebpls.sysref.class.php

http://ebpls.googlecode.com/
PHP | 378 lines | 197 code | 145 blank | 36 comment | 38 complexity | 8e15de86df5c4eeae196a10431149f5c MD5 | raw file
  1. <?
  2. /************************************************************************************
  3. Module : ebpls.sysref.class.php
  4. Dependencies :
  5. ebpls.database.funcs.php
  6. ebpls.dataencapsulator.class.php
  7. ebpls.global.const.php
  8. ebpls.global.funcs.php
  9. Description :
  10. - encapsulates all system reference tables
  11. Created By : Stephen Lou B. Banal
  12. Email : sbanal@yahoo.com
  13. Date Created : 3/9/2004 9:04PM
  14. Last Updates :
  15. [ DATE / TIME ] - [ PROGRAMMER ]
  16. - < DETAILS 1 >
  17. - < DETAILS 2 >
  18. - < DETAILS 3 >
  19. Notes :
  20. ************************************************************************************/
  21. require_once("ebpls-php-lib/ebpls.dataencapsulator.class.php");
  22. require_once("ebpls-php-lib/ebpls.global.funcs.php");
  23. require_once("ebpls-php-lib/ebpls.database.funcs.php");
  24. // define system reference table keys
  25. define(EBPLS_BUSINESS_CATEGORY , "business_category");
  26. define(EBPLS_BUSINESS_CATEGORY_OFFC , "business_category");
  27. define(EBPLS_BUSINESS_NATURE,"business_nature");
  28. define(EBPLS_BUSINESS_REQUIREMENT,"business_requirement");
  29. define(EBPLS_BUSINESS_STATUS,"business_status");
  30. define(EBPLS_BUSINESS_TYPE,"business_type");
  31. define(EBPLS_CITY_MUNICIPALITY,"city_municipality");
  32. define(EBPLS_BARANGAY,"barangay");
  33. define(EBPLS_DISTRICT,"district");
  34. define(EBPLS_PROVINCE,"province");
  35. define(EBPLS_ZIP,"zip");
  36. define(EBPLS_ZONE,"zone");
  37. define(EBPLS_INDUSTRY_SECTOR,"industry_sector");
  38. define(EBPLS_OCCUPANCY_TYPE,"occupancy_type");
  39. $gSysRefTableKeys = array( EBPLS_BUSINESS_CATEGORY, EBPLS_BUSINESS_CATEGORY_OFFC, EBPLS_BUSINESS_NATURE, EBPLS_BUSINESS_REQUIREMENT,
  40. EBPLS_BUSINESS_STATUS, EBPLS_BUSINESS_STATUS, EBPLS_BUSINESS_TYPE, EBPLS_BUSINESS_TYPE, EBPLS_CITY_MUNICIPALITY,
  41. EBPLS_BARANGAY, EBPLS_DISTRICT, EBPLS_PROVINCE, EBPLS_ZIP, EBPLS_ZONE, EBPLS_INDUSTRY_SECTOR, EBPLS_OCCUPANCY_TYPE, EBPLS_OCCUPANCY_TYPE);
  42. define(SYSREF_CODE,"_code");
  43. define(SYSREF_DESC,"_desc");
  44. define(SYSREF_CREATE_TS,"_date_registered");
  45. define(SYSREF_UPDATE_TS,"_date_updated");
  46. define(SYSREF_ADMIN,"updated_by");
  47. define(SYSREF_NATURE_TAX_FEE_CODE,"tax_fee_code");
  48. define(SYSREF_NATURE_TAX_FEE_CODE2,"renew_tax_fee_code");
  49. define(SYSREF_SYSTEMDATA,"system_data");
  50. class EBPLSSysRef extends DataEncapsulator {
  51. var $m_dbLink;
  52. var $m_strTableKey;
  53. var $m_strCodeKey;
  54. var $m_strDescKey;
  55. var $m_strCreateKey;
  56. var $m_strUpdateKey;
  57. var $m_strAdminKey;
  58. var $m_strTableKeyConst;
  59. var $m_strCode;
  60. var $m_strDesc;
  61. var $m_tsCreate;
  62. var $m_tsUpdate;
  63. var $m_tsAdmin;
  64. /**
  65. * Instatiation method, set $bDebug to true to print debug messages otherwise set to false.
  66. * $dbLink is a valid database connection.
  67. *
  68. */
  69. function EBPLSSysRef( $dbLink, $strTableKey, $bDebug = false ) {
  70. global $gSysRefTableKeys;
  71. $this->m_dbLink = $dbLink;
  72. if ( !in_array( $strTableKey, $gSysRefTableKeys) ) {
  73. return NULL;
  74. }
  75. $this->m_strTableKeyConst = $strTableKey;
  76. $this->m_strTableKey = "ebpls_$strTableKey";
  77. $this->setDebugMode( $bDebug );
  78. $this->m_strCodeKey = $strTableKey . SYSREF_CODE;
  79. $this->m_strDescKey = $strTableKey . SYSREF_DESC;
  80. $this->m_strCreateKey = $strTableKey . SYSREF_CREATE_TS;
  81. $this->m_strUpdateKey = $strTableKey . SYSREF_UPDATE_TS;
  82. $this->m_strAdminKey = SYSREF_ADMIN;
  83. $this->addDataElement( $this->m_strCodeKey, "is_not_empty", "[VALUE]" );
  84. $this->addDataElement( $this->m_strDescKey, "is_not_empty", "[VALUE]" );
  85. $this->addDataElement( $this->m_strCreateKey, "is_valid_date", "[VALUE]" , true );
  86. $this->addDataElement( $this->m_strUpdateKey, "is_valid_date", "[VALUE]" , true );
  87. $this->addDataElement( $this->m_strAdminKey, "is_not_empty", "[VALUE]" );
  88. if ( EBPLS_BUSINESS_NATURE == $strTableKey ) {
  89. $this->addDataElement( SYSREF_NATURE_TAX_FEE_CODE, "is_not_empty", "[VALUE]" );
  90. $this->addDataElement( SYSREF_NATURE_TAX_FEE_CODE2, "is_not_empty", "[VALUE]" );
  91. $this->addDataElement( SYSREF_SYSTEMDATA, NULL, NULL );
  92. }
  93. }
  94. function add( $code, $desc, $user ){
  95. return $this->addExtra( $code, $desc, NULL, $user );
  96. }
  97. function addExtra( $code, $desc, $tf_code, $user ){
  98. if ( $this->m_dbLink ) {
  99. $this->setData($this->m_strCodeKey,$code);
  100. $this->setData($this->m_strDescKey,$desc);
  101. $this->setData($this->m_strAdminKey,$user);
  102. $this->data_elems[$this->m_strCreateKey] = date("Y-m-d H:i:s");
  103. $this->data_elems[$this->m_strUpdateKey] = date("Y-m-d H:i:s");
  104. if ( $this->m_strTableKeyConst == EBPLS_BUSINESS_NATURE ) {
  105. $this->data_elems[ SYSREF_NATURE_TAX_FEE_CODE ] = $tf_code[0];
  106. $this->data_elems[ SYSREF_NATURE_TAX_FEE_CODE2 ] = $tf_code[1];
  107. }
  108. $strValues = $this->getData();
  109. if ( ( $error_num = $this->validateData() ) > 0 ) {
  110. $ret = ebpls_insert_data( $this->m_dbLink, $this->m_strTableKey, $strValues );
  111. if ( $ret < 0 ) {
  112. $this->debug( "CREATE SYSREF $this->m_strTableKey FAILED [error:$ret,msg=" . get_db_error() . "]" );
  113. $this->setError( $ret, get_db_error() );
  114. return $ret;
  115. } else {
  116. $this->debug( "CREATE $this->m_strTableKey SUCCESSFULL [$ret]" );
  117. return $ret;
  118. }
  119. } else {
  120. $this->debug( "CREATE $this->m_strTableKey FAILED [error:$ret,msg=" . get_db_error() . "]" );
  121. return $error_num;
  122. }
  123. } else {
  124. $this->debug( "CREATE $this->m_strTableKey FAILED INVALID DB LINK $this->m_dbLink" );
  125. $this->setError( $ret, "Invalid Db link $this->m_dbLink" );
  126. return -1;
  127. }
  128. }
  129. function delete( $code ){
  130. $strWhere[$this->m_strCodeKey] = $code;
  131. $result = ebpls_delete_data ( $this->m_dbLink, $this->m_strTableKey, $strWhere );
  132. if ( $result < 0 ) {
  133. $this->setError( $result, get_db_error() );
  134. }
  135. return $result;
  136. }
  137. function updateExtra( $code, $desc, $tf_code, $user ) {
  138. $this->setData($this->m_strCodeKey,$code);
  139. $this->setData($this->m_strDescKey,$desc);
  140. $this->setData($this->m_strAdminKey,$user);
  141. if ( $this->m_strTableKeyConst == EBPLS_BUSINESS_NATURE ) {
  142. $this->data_elems[ SYSREF_NATURE_TAX_FEE_CODE ] = $tf_code[0];
  143. $this->data_elems[ SYSREF_NATURE_TAX_FEE_CODE2 ] = $tf_code[1];
  144. }
  145. if ( ( $error_num = $this->validateData(true) ) > 0 ) {
  146. $arrData = $this->getData();
  147. foreach( $arrData as $key=>$value){
  148. if ( $arrData[$key] != NULL ) {
  149. $strValues[$key] = $value;
  150. }
  151. }
  152. $this->setData($this->m_strUpdateKey,date("Y-m-d H:i:s"));
  153. $strWhere[$this->m_strCodeKey] = $code;
  154. $ret = ebpls_update_data( $this->m_dbLink, $this->m_strTableKey, $strValues, $strWhere );
  155. if ( $ret < 0 ) {
  156. $this->debug( "UPDATE $this->m_strTableKey FAILED [error:$ret,msg=" . get_db_error() . "]" );
  157. $this->setError( $ret, get_db_error() );
  158. return $ret;
  159. } else {
  160. $this->debug( "UPDATE $this->m_strTableKey SUCCESSFULL [$ret]" );
  161. return $ret;
  162. }
  163. } else {
  164. $this->debug( "CREATE $this->m_strTableKey FAILED [error:$ret,msg=" . get_db_error() . "]" );
  165. return -1;
  166. }
  167. }
  168. function select( $code = NULL, $page = 1, $maxrec = 100000000, $orderkey = SYSREF_CODE, $is_desc = true ){
  169. if ( $code != NULL )
  170. $strWhere[$this->m_strCodeKey] = $code;
  171. if ( $orderkey != SYSREF_CODE && $orderkey != SYSREF_DESC && $orderkey != SYSREF_CREATE_TS &&
  172. $orderkey != SYSREF_UPDATE_TS && $orderkey != SYSREF_ADMIN ) {
  173. $this->setError( -1, "Invalid order key value $orderkey.");
  174. return -1;
  175. }
  176. // select all columns
  177. $strValues[] = "*";
  178. if ( $orderkey != NULL ) {
  179. $strOrder[ $this->m_strTableKeyConst . $orderkey ] = $this->m_strTableKeyConst . $orderkey;
  180. } else {
  181. $strOrder = $this->m_strCodeKey;
  182. }
  183. $result = ebpls_select_data_bypage( $this->m_dbLink, $this->m_strTableKey, $strValues, $strWhere, NULL, $strOrder, $is_desc?"DESC":"ASC", $page, $maxrec );
  184. if ( !is_array($result) && $result < 0 ) {
  185. $this->setError ( $result, get_db_error());
  186. return $result;
  187. } else {
  188. // transform result to EBPLSSysRef object
  189. for ( $i = 0 ; $i < count($result["result"]); $i++ ) {
  190. $records[$i] = new EBPLSSysRef($this->m_dbLink, $this->m_strTableKey );
  191. $records[$i]->setData( NULL, $result["result"][$i] );
  192. $records[$i]->m_strCode = $records[$i]->getData($this->m_strCodeKey);
  193. $records[$i]->m_strDesc = $records[$i]->getData($this->m_strDescKey);
  194. $records[$i]->m_tsCreate = $records[$i]->getData($this->m_strCreateKey);
  195. $records[$i]->m_tsUpdate = $records[$i]->getData($this->m_strUpdateKey);
  196. $records[$i]->m_strAdmin = $records[$i]->getData($this->m_strAdminKey);
  197. }
  198. $result["result"] = $records;
  199. return $result;
  200. }
  201. }
  202. function getCode(){
  203. return $this->m_strCode;
  204. }
  205. function getDescription(){
  206. return $this->m_strDesc;
  207. }
  208. function getCreateTimeStamp(){
  209. return $this->m_tsCreate;
  210. }
  211. function getUpdateTimeStamp(){
  212. return $this->m_tsUpdate;
  213. }
  214. function getExtra(){
  215. return $this->data_elems[ SYSREF_NATURE_TAX_FEE_CODE ];
  216. }
  217. function getExtra2(){
  218. return $this->data_elems[ SYSREF_NATURE_TAX_FEE_CODE2 ];
  219. }
  220. function getAdmin(){
  221. return $this->m_strAdmin;
  222. }
  223. }
  224. ?>