PageRenderTime 54ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/class/eBPLS.Announcement.class.php

http://ebpls.googlecode.com/
PHP | 254 lines | 116 code | 101 blank | 37 comment | 24 complexity | 3aa086cd1a4d9923bcb65ce7a883baa7 MD5 | raw file
  1. <?
  2. /************************************************************************************
  3. Module : eBPLS.Announcement.class.php
  4. Dependencies :
  5. eBPLS.dbfuncs.php
  6. eBPLS.dataencapsulator.class.php
  7. Description :
  8. - encapsulates Announcement
  9. Created By : Robert M. Verzosa
  10. Email : rmv71279@yahoo.com, verzosar@dap.edu.ph
  11. Date Created : 12/12/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_ANNOUNCEMENT_TABLE,"ebpls_announcement");
  17. // Industry Sector Data Elements Constants
  18. define(EAID,"eaid");
  19. define(ANNOUNCEMENT,"announcements");
  20. define(ANNOUNCED_BY,"announced_by");
  21. define(DATE_MODIFIED,"date_modified");
  22. define(MODIFIED_BY,"modified_by");
  23. define(SMS_SEND,"sms_send");
  24. class EBPLSAnnouncement extends DataEncapsulator {
  25. var $m_dbLink,
  26. $rcount,
  27. $out;
  28. function EBPLSAnnouncement( $dbLink, $bDebug = false ) {
  29. $this->m_dbLink = $dbLink;
  30. $this->setDebugMode( $bDebug );
  31. // add data elements of class with their respective validation functions an params, used default value for 4th parameter
  32. // for error message pair in case validation failed
  33. $this->addDataElement( EAID, "is_not_empty", "[VALUES]");
  34. $this->addDataElement( ANNOUNCEMENT, "is_not_empty", "[VALUES]");
  35. $this->addDataElement( ANNOUNCED_BY, "is_not_empty", "[VALUES]");
  36. $this->addDataElement( DATE_MODIFIED, "is_not_empty", "[VALUES]");
  37. $this->addDataElement( MODIFIED_BY, "is_not_empty", "[VALUES]");
  38. $this->addDataElement( SMS_SEND, "is_not_empty", "[VALUES]");
  39. }
  40. function add(){
  41. if ( $this->m_dbLink ) {
  42. if ( ( $error_num = $this->validateData() ) > 0 ) {
  43. $strValues = $this->data_elems;
  44. $ret = ebpls_insert_data( $this->m_dbLink, EBPLS_ANNOUNCEMENT_TABLE, $strValues );
  45. if ( $ret < 0 ) {
  46. //$this->debug( "CREATE OCCUPNACY TYPE FAILED" );
  47. //$this->setError( $ret, get_db_error() );
  48. return $ret;
  49. } else {
  50. //$this->debug( "CREATE OCCUPNACY TYPE SUCCESSFULL" );
  51. $this->data_elems[ EAID ] = $ret;
  52. return $ret;
  53. }
  54. } else {
  55. //$this->debug( "CREATE INDUSTRY FAILED" );
  56. return $error_num;
  57. }
  58. } else {
  59. //$this->debug( "CREATE OWNER FAILED INVALID DB LINK $this->m_dbLink" );
  60. $this->setError( $ret, "Invalid Db link $this->m_dbLink" );
  61. return -1;
  62. }
  63. }
  64. /**
  65. * View owner data, loads data using owner id as param
  66. *
  67. */
  68. function update( $eaid ) {
  69. $arrData = $this->getData();
  70. foreach( $arrData as $key=>$value){
  71. if ( $arrData[$key] != NULL ) {
  72. $strValues[$key] = $value;
  73. }
  74. }
  75. if ( ( $error_num = $this->validateData(true) ) > 0 ) {
  76. $strWhere[EAID] = $eaid;
  77. $ret = ebpls_update_data( $this->m_dbLink, EBPLS_ANNOUNCEMENT_TABLE, $strValues, $strWhere );
  78. if ( $ret < 0 ) {
  79. return $ret;
  80. } else {
  81. return $ret;
  82. }
  83. } else {
  84. return -1;
  85. }
  86. }
  87. function delete( $eaid ) {
  88. $strWhere[EAID] = $eaid;
  89. $strValues[] = "count(*) as cnt";
  90. // check if owner have existing transactions
  91. $result = ebpls_delete_data ( $this->m_dbLink, EBPLS_ANNOUNCEMENT_TABLE, $strWhere );
  92. if ( $result < 0 ) {
  93. $this->setError( $result, get_db_error() );
  94. }
  95. return $result;
  96. }
  97. function search( $eaid = NULL, $announcement = NULL ) {
  98. if ( $eaid != NULL ) {
  99. $strWhere[EAID] = $eaid;
  100. }
  101. if ( $announcement != NULL ) {
  102. $strWhere[ANNOUNCEMENT] = $announcement;
  103. }
  104. // select all columns
  105. $strValues[] = "*";
  106. $strValues1[] = "count(*)";
  107. if ( $orderkey != NULL ) {
  108. $strOrder[$orderkey] = $orderkey;
  109. } else {
  110. $strOrder = $orderkey;
  111. }
  112. if ( count($strWhere) <= 0 ) {
  113. $this->setError ( -1, "No search parameters." );
  114. return -1;
  115. }
  116. $result = ebpls_select_data( $this->m_dbLink, EBPLS_ANNOUNCEMENT_TABLE, $strValues, $strWhere, NULL, NULL, NULL, NULL);
  117. $rowcount = ebpls_select_data( $this->m_dbLink, EBPLS_ANNOUNCEMENT_TABLE, $strValues1, $strWhere, NULL, NULL, NULL, NULL);
  118. $fetchrecord = ebpls_fetch_data( $this->m_dbLink, $result) ;
  119. $fetchcount = @mysql_fetch_row($rowcount);
  120. $this->out = $fetchrecord;
  121. $this->rcount = $fetchcount;
  122. }
  123. function pagesearch($page = 1, $maxrec = 1000000000, $orderkey = EAID, $is_desc = true ) {
  124. // select all columns
  125. $strValues1[] = "*";
  126. $strValues2[] = "count(*)";
  127. if ( $orderkey != NULL ) {
  128. $strOrder[$orderkey] = $orderkey;
  129. } else {
  130. $strOrder = $orderkey;
  131. }
  132. //echo $is_desc."Robert";
  133. $result = ebpls_select_data( $this->m_dbLink, EBPLS_ANNOUNCEMENT_TABLE, $strValues1, $strWhere, NULL, $strOrder, $is_desc, $maxrec, $page );
  134. $rowcount = ebpls_select_data( $this->m_dbLink, EBPLS_ANNOUNCEMENT_TABLE, $strValues2, $strWhere, NULL, $strOrder, $is_desc, NULL, NULL );
  135. //$sqlCount = $rowcount["count_sql"];
  136. $this->out = $result;
  137. $this->rcount = $rowcount;
  138. //echo $rowcount."VooDoo";
  139. }
  140. function searchcomp($bbo, $announcement) {
  141. $ifexist = @mysql_query("select * from ebpls_announcement where announcements = '$announcement' and eaid <> '$bbo'");
  142. //echo "select * from ebpls_announcement where announcements = '$announcement' and eaid <> '$bbo'";
  143. $ifexist = @mysql_num_rows($ifexist);
  144. $this->rcount = $ifexist;
  145. }
  146. }
  147. ?>