PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/class/eBPLS.industry.class.php

http://ebpls.googlecode.com/
PHP | 339 lines | 127 code | 115 blank | 97 comment | 26 complexity | 453f0edf5f2f3aea2cb6956288760d83 MD5 | raw file
  1. <?
  2. /************************************************************************************
  3. Module : eBPLS.industry.class.php
  4. Dependencies :
  5. eBPLS.dbfuncs.php
  6. eBPLS.dataencapsulator.class.php
  7. Description :
  8. - encapsulates fund
  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_INDUSTRY_SECTOR_TABLE',"ebpls_industry_sector");
  17. // Industry Sector Data Elements Constants
  18. define('INDUSTRY_SECTOR_CODE',"industry_sector_code");
  19. define('INDUSTRY_SECTOR_DESC',"industry_sector_desc");
  20. define('INDUSTRY_SECTOR_DATE_REGISTERED',"industry_sector_date_registered");
  21. define('INDUSTRY_SECTOR_DATE_UPDATED',"industry_sector_date_updated");
  22. define('UPDATED_BY',"updated_by");
  23. class EBPLSIndustry 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 EBPLSIndustry( $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( INDUSTRY_SECTOR_CODE, "is_not_empty", "[VALUES]");
  38. $this->addDataElement( INDUSTRY_SECTOR_DESC, "is_not_empty", "[VALUES]");
  39. $this->addDataElement( INDUSTRY_SECTOR_DATE_REGISTERED, "is_not_empty", "[VALUES]" );
  40. $this->addDataElement( INDUSTRY_SECTOR_DATE_UPDATED, "is_not_empty", "[VALUES]" );
  41. $this->addDataElement( UPDATED_BY, "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_INDUSTRY_SECTOR_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_INDUSTRY_SECTOR_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( $industry_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[INDUSTRY_SECTOR_CODE] = $industry_id;
  101. $ret = ebpls_update_data( $this->m_dbLink, EBPLS_INDUSTRY_SECTOR_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( $owner_id ) {
  112. $strWhere[INDUSTRY_SECTOR_CODE] = $owner_id;
  113. $strValues[] = "count(*) as cnt";
  114. $result = ebpls_delete_data ( $this->m_dbLink, EBPLS_INDUSTRY_SECTOR_TABLE, $strWhere );
  115. if ( $result < 0 ) {
  116. $this->setError( $result, get_db_error() );
  117. }
  118. return $result;
  119. }
  120. /*
  121. function view( $owner_id ) {
  122. $strWhere[OWNER_ID] = $owner_id;
  123. $strValues[] = "*";
  124. // check if owner have existing transactions
  125. $result = ebpls_select_data( $this->m_dbLink, EBPLS_INDUSTRY_SECTOR_TABLE, $strValues, $strWhere, NULL, NULL, NULL, NULL );
  126. if ( is_array( $result ) ) {
  127. $this->debug( "LOAD OWNER OK");
  128. $this->setData( NULL, $result[0] );
  129. return 1;
  130. } else {
  131. $this->debug( "LOAD OWNER FAILED [error:$ret,msg=" . get_db_error() . "]");
  132. return -1;
  133. }
  134. }
  135. */
  136. /**
  137. * Find function searches Owner table for users having exact values for firstname, lastname, middlename, email address, birthdate.
  138. *
  139. * Set a NULL value to any of the parameters a users wishes not included on the search function.
  140. *
  141. * Search uses AND on query on all of the non-NULL parameters provided. Exact string match is implemented.
  142. *
  143. * Search result can be order by setting orderkey as any of the pre-defined data elements constants defined above,
  144. * set $is_desc to true to use DESC otherwise set to false.
  145. *
  146. * Paging is automatically provided by letting users of this method provide the page number and the max records per page.
  147. * Page result are automaticallly selected give these information, by rule $maxrec should be > 0 and $page should be > 1 and < maxpages
  148. *
  149. * Result of this method is a 2-dim array, having keys "page_info" and "result"
  150. * First element of result having key "page_info" contains all the information regarding the query
  151. * total = number of total records of search
  152. * max_pages = number of pages in search
  153. * count = number of records on current page
  154. * page = current page selected
  155. * Second element of array having key "result" contains result of the search. "result" search value is an array of EBLPSCTC objects
  156. *
  157. *
  158. */
  159. function search( $industry_sector_code = NULL, $industry_sector_desc = NULL ) {
  160. if ( $industry_sector_code != NULL ) {
  161. $strWhere[INDUSTRY_SECTOR_CODE] = $industry_sector_code;
  162. }
  163. if ( $industry_sector_desc != NULL ) {
  164. $strWhere[INDUSTRY_SECTOR_DESC] = $industry_sector_desc;
  165. }
  166. // select all columns
  167. $strValues[] = "*";
  168. if ( $orderkey != NULL ) {
  169. $strOrder[$orderkey] = $orderkey;
  170. } else {
  171. $strOrder = $orderkey;
  172. }
  173. if ( count($strWhere) <= 0 ) {
  174. $this->setError ( -1, "No search parameters." );
  175. return -1;
  176. }
  177. $result = ebpls_select_data( $this->m_dbLink, EBPLS_INDUSTRY_SECTOR_TABLE, $strValues, $strWhere, NULL, NULL, NULL, NULL);
  178. $fetchrecord = ebpls_fetch_data( $this->m_dbLink, $result) ;
  179. $this->out = $fetchrecord;
  180. }
  181. function searchedit($new_code, $origid,$tble,$prim_key)
  182. {
  183. $rx=mysql_query("select * from $tble where $prim_key = '$new_code' and $prim_key <> '$origid' ");
  184. $this->outnumrow = mysql_num_rows($rx);
  185. }
  186. function numrows($result)
  187. {
  188. $this->outnumrow = mysql_num_rows($result);
  189. }
  190. function pagesearch($page = 1, $maxrec = 1000000000, $orderkey = INDUSTRY_SECTOR_CODE, $is_desc = true ) {
  191. // select all columns
  192. $strValues1[] = "*";
  193. $strValues2[] = "count(*)";
  194. if ( $orderkey != NULL ) {
  195. $strOrder[$orderkey] = $orderkey;
  196. } else {
  197. $strOrder = $orderkey;
  198. }
  199. //echo $is_desc."Robert";
  200. $strWhere = isset($strWhere) ? $strWhere : ''; //2008.05.13
  201. $result = ebpls_select_data( $this->m_dbLink, EBPLS_INDUSTRY_SECTOR_TABLE, $strValues1, $strWhere, NULL, $strOrder, $is_desc, $maxrec, $page );
  202. $rowcount = ebpls_select_data( $this->m_dbLink, EBPLS_INDUSTRY_SECTOR_TABLE, $strValues2, $strWhere, NULL, $strOrder, $is_desc, NULL, NULL );
  203. //$sqlCount = $rowcount["count_sql"];
  204. $this->out = $result;
  205. $this->rcount = $rowcount;
  206. //echo $rowcount."VooDoo";
  207. }
  208. }
  209. ?>