Guest User

Untitled

a guest
Aug 13th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class customDonations {
  5.  
  6. private $db_connection = null;
  7. public $debugging = 1;
  8. public $auctionmessages = array();
  9.  
  10. public function __construct(){
  11. $this->databaseConnection();
  12. }
  13.  
  14. private function databaseConnection(){ //database connection
  15. if ($this->db_connection != null) {
  16. return true;
  17. } else {
  18. try {
  19. $this->db_connection = new PDO('mysql:host='. DB_HOST .';dbname='. DB_NAME . ';charset='.DB_CHARSET, DB_USER, DB_PASSWORD);
  20. if($this->debugging == 1){
  21. $this->db_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  22. $this->db_connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); //debugging
  23. }
  24. return true;
  25. } catch (PDOException $e) {
  26. $this->auctionmessages[] = $e->getMessage();
  27. }
  28. }
  29. return false;
  30. }
  31.  
  32. private function checkList($fulldata = 0){ //check if there are any active auctions
  33. if($fulldata == 1){
  34. $check_list = $this->db_connection->prepare("SELECT * FROM crstube_posts
  35. INNER JOIN crstube_postmeta ON crstube_posts.ID = crstube_postmeta.post_id
  36. WHERE meta_key = 'wdm_listing_ends'
  37. AND meta_value < DATE_ADD(NOW(), INTERVAL 60 HOUR) AND meta_value > NOW()
  38. OR meta_key = 'wdm_listing_ends'
  39. AND NOW() < DATE_ADD(meta_value, INTERVAL 5 HOUR) AND meta_value < NOW()
  40. ORDER BY meta_value ASC");
  41. }else{
  42. $check_list = $this->db_connection->prepare("SELECT ID FROM crstube_posts
  43. INNER JOIN crstube_postmeta ON crstube_posts.ID = crstube_postmeta.post_id
  44. WHERE meta_key = 'wdm_listing_ends'
  45. AND meta_value <= DATE_ADD(NOW(), INTERVAL 60 HOUR)
  46. AND meta_value > now() ORDER BY meta_value ASC");
  47. }
  48. $check_list->execute();
  49. if($check_list->rowcount() != 0){
  50. return $check_list->fetchAll(PDO::FETCH_ASSOC);
  51. }
  52. return false;//there are activeauctions, return false
  53. }
  54.  
  55.  
  56. private function getData($id, $text){
  57. $check_list = $this->db_connection->prepare("SELECT * FROM crstube_postmeta WHERE post_id = :postid AND meta_key = :metavalue");
  58. $check_list->bindValue(':postid', $id, PDO::PARAM_INT);
  59. $check_list->bindValue(':metavalue', $text, PDO::PARAM_STR);
  60. $check_list->execute();
  61. if($check_list->rowcount() != 0){
  62. $data = $check_list->fetchAll(PDO::FETCH_ASSOC);
  63. return $data[0]['meta_value'];
  64. }
  65. return false;//there is no active auctions, return false
  66. }
  67.  
  68. public function createDonationPage(){
  69. if($this->checkList(0) != false){
  70. $auction_list = $this->checkList(1);?>
  71. <?php
  72. $timercounter = 1;
  73. $returndata = array();
  74. foreach($auction_list as $single_auction):
  75. $image1 = $this->getData($single_auction['ID'], 'wdm-image-1');
  76. $description = $single_auction['post_excerpt']; // content <!-- <?php echo $description;
  77. $title = $single_auction['post_title'];
  78. $link = "http://creative-scape.net/crstube/auctions/?ult_auc_id=".$single_auction['ID'];
  79.  
  80. $get_bids = $this->db_connection->prepare("SELECT * FROM crstube_wdm_bidders
  81. WHERE auction_id = :idvar ORDER BY bid DESC");
  82. $get_bids->bindValue(':idvar', $single_auction['ID'], PDO::PARAM_INT);
  83. $get_bids->execute();
  84. $get_bid = $get_bids->fetchAll(PDO::FETCH_ASSOC);
  85.  
  86. if(count($get_bid) == 0){
  87. $price = $this->getData($single_auction['ID'], 'wdm_opening_bid');
  88. }else{
  89. $price = number_format($get_bid[0]['bid']);
  90. }
  91. ?>
  92. <a class="auctions" href='<?php echo $link; ?>'>
  93. <fieldset>
  94. <legend><b><?php echo $title; ?></b> <?php echo $price; ?>$</legend>
  95. <img src=<?php echo $image1; ?>> </br>
  96. <div id="padZeroes<?php echo $timercounter; ?>"></div>
  97. </fieldset></a>
  98.  
  99. <script type="text/javascript">
  100. var t<?php echo $timercounter; ?> = "<?php echo $single_auction['meta_value']; ?>".split(/[- :]/);
  101. var liftoffTime<?php echo $timercounter; ?> = new Date(t<?php echo $timercounter; ?>[0], t<?php echo $timercounter; ?>[1]-1, t<?php echo $timercounter; ?>[2], t<?php echo $timercounter; ?>[3], t<?php echo $timercounter; ?>[4], t<?php echo $timercounter; ?>[5]);
  102. $(document).ready(function(){
  103. <?php echo "$('#padZeroes".$timercounter."').countdown({until: $.countdown.UTCDate(-5, liftoffTime". $timercounter."), padZeroes: true, compact: true});"; ?>
  104. });
  105. </script>
  106. <?php $timercounter++;
  107. endforeach;
  108. }
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment