PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/class/eBPLS.economic.class.php

http://ebpls.googlecode.com/
PHP | 339 lines | 129 code | 112 blank | 98 comment | 26 complexity | 2279bbbb926795565d501e5cd5d8efe4 MD5 | raw file
  1. <?
  2. /************************************************************************************
  3. Module : eBPLS.economic.class.php
  4. Dependencies :
  5. eBPLS.dbfuncs.php
  6. eBPLS.dataencapsulator.class.php
  7. Description :
  8. - encapsulates citizenship
  9. Created By : Robert M. Verzosa
  10. Email : rmv71279@yahoo.com, verzosar@dap.edu.ph
  11. Date Created : 9/29/2005
  12. ************************************************************************************/
  13. require_once("class/eBPLS.dataencapsulator.class.php");
  14. require_once("lib/eBPLS.dbfuncs.php");
  15. // keys for getData method
  16. define(EBPLS_ECONOMIC_TABLE,"ebpls_economic_area");
  17. // Industry Sector Data Elements Constants
  18. define(ECONOMIC_AREA_ID,"economic_area_id");
  19. define(ECONOMIC_AREA_CODE,"economic_area_code");
  20. define(ECONOMIC_AREA_DESC,"economic_area_desc");
  21. define(UPDATED_BY,"updated_by");
  22. define(DATE_UPDATED,"date_updated");
  23. class EBPLSEconomic extends DataEncapsulator {
  24. var $m_dbLink,
  25. $rcount,
  26. $out;
  27. /**
  28. * Instatiation method, set $bDebug to true to print debug messages otherwise set to false.
  29. * $dbLink is a valid database connection.
  30. *
  31. */
  32. function EBPLSEconomic( $dbLink, $bDebug = false ) {
  33. $this->m_dbLink = $dbLink;
  34. $this->setDebugMode( $bDebug );
  35. // add data elements of class with their respective validation functions an params, used default value for 4th parameter
  36. // for error message pair in case validation failed
  37. $this->addDataElement( ECONOMIC_AREA_ID, "is_not_empty", "[VALUES]");
  38. $this->addDataElement( ECONOMIC_AREA_CODE, "is_not_empty", "[VALUES]");
  39. $this->addDataElement( ECONOMIC_AREA_DESC, "is_not_empty", "[VALUES]");
  40. $this->addDataElement( UPDATED_BY, "is_not_empty", "[VALUES]");
  41. $this->addDataElement( DATE_UPDATED, "is_not_empty", "[VALUES]");
  42. }
  43. /**
  44. * Adds new Industry Sector to ebls_INDUSTRY_SECTOR table
  45. *
  46. */
  47. function add(){
  48. if ( $this->m_dbLink ) {
  49. if ( ( $error_num = $this->validateData() ) > 0 ) {
  50. $strValues = $this->data_elems;
  51. $ret = ebpls_insert_data( $this->m_dbLink, EBPLS_ECONOMIC_TABLE, $strValues );
  52. if ( $ret < 0 ) {
  53. //$this->debug( "CREATE OCCUPNACY TYPE FAILED" );
  54. //$this->setError( $ret, get_db_error() );
  55. return $ret;
  56. } else {
  57. //$this->debug( "CREATE OCCUPNACY TYPE SUCCESSFULL" );
  58. $this->data_elems[ OWNER_ID ] = $ret;
  59. return $ret;
  60. }
  61. } else {
  62. //$this->debug( "CREATE INDUSTRY FAILED" );
  63. return $error_num;
  64. }
  65. } else {
  66. //$this->debug( "CREATE OWNER FAILED INVALID DB LINK $this->m_dbLink" );
  67. $this->setError( $ret, "Invalid Db link $this->m_dbLink" );
  68. return -1;
  69. }
  70. }
  71. /**
  72. * View owner data, loads data using owner id as param
  73. *
  74. */
  75. function view( $owner_id ) {
  76. $strValues[$key] = "*";
  77. $strWhere[OWNER_ID] = $owner_id;
  78. $result = ebpls_select_data( $this->m_dbLink, EBPLS_ECONOMIC_TABLE, $strValues, $strWhere, NULL, $strOrderBy, "DESC", NULL );
  79. if ( is_array($result) ) {
  80. $this->data_elems = $result[0];
  81. return $result[0][OWNER_ID];
  82. } else {
  83. $this->setError( $result, get_db_error() );
  84. return -1;
  85. }
  86. }
  87. /**
  88. * Update owner data
  89. *
  90. *
  91. **/
  92. function update( $economic_id ) {
  93. $arrData = $this->getData();
  94. foreach( $arrData as $key=>$value){
  95. if ( $arrData[$key] != NULL ) {
  96. $strValues[$key] = $value;
  97. }
  98. }
  99. if ( ( $error_num = $this->validateData(true) ) > 0 ) {
  100. $strWhere[ECONOMIC_AREA_ID] = $economic_id;
  101. $ret = ebpls_update_data( $this->m_dbLink, EBPLS_ECONOMIC_TABLE, $strValues, $strWhere );
  102. if ( $ret < 0 ) {
  103. return $ret;
  104. } else {
  105. return $ret;
  106. }
  107. } else {
  108. return -1;
  109. }
  110. }
  111. function delete( $economic_area_id ) {
  112. $strWhere[ECONOMIC_AREA_ID] = $economic_area_id;
  113. $strValues[] = "count(*) as cnt";
  114. // check if owner have existing transactions
  115. $result = ebpls_delete_data ( $this->m_dbLink, EBPLS_ECONOMIC_TABLE, $strWhere );
  116. if ( $result < 0 ) {
  117. $this->setError( $result, get_db_error() );
  118. }
  119. return $result;
  120. }
  121. /*
  122. function view( $owner_id ) {
  123. $strWhere[OWNER_ID] = $owner_id;
  124. $strValues[] = "*";
  125. // check if owner have existing transactions
  126. $result = ebpls_select_data( $this->m_dbLink, EBPLS_ECONOMIC_TABLE, $strValues, $strWhere, NULL, NULL, NULL, NULL );
  127. if ( is_array( $result ) ) {
  128. $this->debug( "LOAD OWNER OK");
  129. $this->setData( NULL, $result[0] );
  130. return 1;
  131. } else {
  132. $this->debug( "LOAD OWNER FAILED [error:$ret,msg=" . get_db_error() . "]");
  133. return -1;
  134. }
  135. }
  136. */
  137. /**
  138. * Find function searches Owner table for users having exact values for firstname, lastname, middlename, email address, birthdate.
  139. *
  140. * Set a NULL value to any of the parameters a users wishes not included on the search function.
  141. *
  142. * Search uses AND on query on all of the non-NULL parameters provided. Exact string match is implemented.
  143. *
  144. * Search result can be order by setting orderkey as any of the pre-defined data elements constants defined above,
  145. * set $is_desc to true to use DESC otherwise set to false.
  146. *
  147. * Paging is automatically provided by letting users of this method provide the page number and the max records per page.
  148. * Page result are automaticallly selected give these information, by rule $maxrec should be > 0 and $page should be > 1 and < maxpages
  149. *
  150. * Result of this method is a 2-dim array, having keys "page_info" and "result"
  151. * First element of result having key "page_info" contains all the information regarding the query
  152. * total = number of total records of search
  153. * max_pages = number of pages in search
  154. * count = number of records on current page
  155. * page = current page selected
  156. * Second element of array having key "result" contains result of the search. "result" search value is an array of EBLPSCTC objects
  157. *
  158. *
  159. */
  160. function search( $economic_area_id = NULL, $economic_area_code = NULL ) {
  161. if ( $economic_area_id != NULL ) {
  162. $strWhere[ECONOMIC_AREA_ID] = $economic_area_id;
  163. }
  164. if ( $economic_area_code != NULL ) {
  165. $strWhere[ECONOMIC_AREA_CODE] = $economic_area_code;
  166. }
  167. // select all columns
  168. $strValues[] = "*";
  169. if ( $orderkey != NULL ) {
  170. $strOrder[$orderkey] = $orderkey;
  171. } else {
  172. $strOrder = $orderkey;
  173. }
  174. if ( count($strWhere) <= 0 ) {
  175. $this->setError ( -1, "No search parameters." );
  176. return -1;
  177. }
  178. $result = ebpls_select_data( $this->m_dbLink, EBPLS_ECONOMIC_TABLE, $strValues, $strWhere, NULL, NULL, NULL, NULL);
  179. $fetchrecord = ebpls_fetch_data( $this->m_dbLink, $result) ;
  180. $this->out = $fetchrecord;
  181. }
  182. function searchedit($new_code, $origid,$tble,$prim_key)
  183. {
  184. $tx = mysql_query("select * from $tble where economic_area_id = '$origid' ");
  185. $tx = mysql_fetch_array($tx);
  186. $origid = $tx[economic_area_code];
  187. $rx=mysql_query("select * from $tble where $prim_key = '$new_code' and $prim_key <> '$origid' ");
  188. $this->outnumrow = mysql_num_rows($rx);
  189. }
  190. function numrows($result)
  191. {
  192. $this->outnumrow = mysql_num_rows($result);
  193. }
  194. function pagesearch($page = 1, $maxrec = 1000000000, $orderkey = ECONOMIC_AREA_CODE, $is_desc = true ) {
  195. // select all columns
  196. $strValues1[] = "*";
  197. $strValues2[] = "count(*)";
  198. if ( $orderkey != NULL ) {
  199. $strOrder[$orderkey] = $orderkey;
  200. } else {
  201. $strOrder = $orderkey;
  202. }
  203. //echo $is_desc."Robert";
  204. $result = ebpls_select_data( $this->m_dbLink, EBPLS_ECONOMIC_TABLE, $strValues1, $strWhere, NULL, $strOrder, $is_desc, $maxrec, $page );
  205. $rowcount = ebpls_select_data( $this->m_dbLink, EBPLS_ECONOMIC_TABLE, $strValues2, $strWhere, NULL, $strOrder, $is_desc, NULL, NULL );
  206. //$sqlCount = $rowcount["count_sql"];
  207. $this->out = $result;
  208. $this->rcount = $rowcount;
  209. //echo $rowcount."VooDoo";
  210. }
  211. }
  212. ?>