View difference between Paste ID: iSLhNQZv and PDkEpUuD
SHOW: | | - or go back to the newest paste.
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
32+
    private function checkList(){ //check if there are any active auctions
33-
        if($fulldata == 1){
33+
        $check_list = $this->db_connection->prepare("SELECT * FROM crstube_posts
34-
            $check_list = $this->db_connection->prepare("SELECT * FROM crstube_posts
34+
            INNER JOIN crstube_postmeta ON crstube_posts.ID = crstube_postmeta.post_id
35-
                INNER JOIN crstube_postmeta ON crstube_posts.ID = crstube_postmeta.post_id
35+
            WHERE meta_key = 'wdm_listing_ends'
36-
                WHERE meta_key = 'wdm_listing_ends'
36+
            AND meta_value < DATE_ADD(NOW(), INTERVAL 60 HOUR) AND meta_value > NOW()
37-
                AND meta_value < DATE_ADD(NOW(), INTERVAL 60 HOUR) AND meta_value > NOW()
37+
            OR meta_key = 'wdm_listing_ends'
38-
				OR meta_key = 'wdm_listing_ends'
38+
            AND NOW() < DATE_ADD(meta_value, INTERVAL 5 HOUR) AND meta_value < NOW()
39-
                AND NOW() < DATE_ADD(meta_value, INTERVAL 5 HOUR) AND meta_value < NOW()
39+
            ORDER BY meta_value ASC");
40-
				ORDER BY meta_value ASC");
40+
41-
        }else{
41+
42-
            $check_list = $this->db_connection->prepare("SELECT ID FROM crstube_posts
42+
43-
                INNER JOIN crstube_postmeta ON crstube_posts.ID = crstube_postmeta.post_id
43+
44-
                WHERE meta_key = 'wdm_listing_ends'
44+
45-
                AND meta_value <=  DATE_ADD(NOW(), INTERVAL 60 HOUR)
45+
46-
                AND meta_value > now() ORDER BY meta_value ASC");
46+
47
 
48
    private function getData($id, $text){
49
        $check_list = $this->db_connection->prepare("SELECT * FROM crstube_postmeta WHERE post_id = :postid AND meta_key = :metavalue");
50
        $check_list->bindValue(':postid', $id, PDO::PARAM_INT);
51
        $check_list->bindValue(':metavalue', $text, PDO::PARAM_STR);
52
        $check_list->execute();
53
        if($check_list->rowcount() != 0){
54
            $data = $check_list->fetchAll(PDO::FETCH_ASSOC);
55
            return $data[0]['meta_value'];
56
        }
57
        return false;//there is no active auctions, return false
58
    }
59
 
60
    public function createDonationPage(){
61
        if($this->checkList() != false){
62
            $auction_list = $this->checkList();?>
63
            <?php
64
            $timercounter = 1;
65
            $returndata = array();
66
            foreach($auction_list as $single_auction):
67
                $image1 = $this->getData($single_auction['ID'], 'wdm-image-1');
68
                $description = $single_auction['post_excerpt']; // content <!-- <?php echo $description; 
69-
        if($this->checkList(0) != false){
69+
70-
            $auction_list = $this->checkList(1);?>
70+
71
 
72
                $get_bids = $this->db_connection->prepare("SELECT * FROM crstube_wdm_bidders
73
                   WHERE auction_id = :idvar ORDER BY bid DESC");
74
                $get_bids->bindValue(':idvar', $single_auction['ID'], PDO::PARAM_INT);
75
                $get_bids->execute();
76
                $get_bid = $get_bids->fetchAll(PDO::FETCH_ASSOC);
77
 
78
                if(count($get_bid) == 0){
79
                    $price = $this->getData($single_auction['ID'], 'wdm_opening_bid');
80
                }else{
81
                    $price = number_format($get_bid[0]['bid']);
82
                }
83
                ?>
84
                <a class="auctions" href='<?php echo $link; ?>'>
85
                <fieldset>
86
                    <legend><b><?php echo $title; ?></b> <?php echo $price; ?>$</legend>
87
                    <img src=<?php echo $image1; ?>> </br>
88
                    <div id="padZeroes<?php echo $timercounter; ?>"></div>
89
                </fieldset></a>
90
               
91
                <script type="text/javascript">
92
                    var t<?php echo $timercounter; ?> = "<?php echo $single_auction['meta_value']; ?>".split(/[- :]/);
93
                    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]);
94
                    $(document).ready(function(){
95
                        <?php echo "$('#padZeroes".$timercounter."').countdown({until: $.countdown.UTCDate(-5, liftoffTime". $timercounter."), padZeroes: true, compact: true});"; ?>
96
                    });
97
                </script>
98
            <?php $timercounter++;
99
            endforeach;
100
        }
101
    }
102
}