Advertisement
Crecket

Untitled

Aug 3rd, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.82 KB | None | 0 0
  1.     private function checkDonations(){
  2.         if($this->AuthFunction() == true){
  3.             $full_insert_data = array();
  4.             $data = $this->getSoldDonations();
  5.             $this->donationmessages[] = "Found ".count($data)." finished auctions";
  6.  
  7.             foreach($data as $auction){
  8.                 $check_donation_list = $this->db_connection->prepare("SELECT *
  9.                                                                     FROM auction WHERE auctionid = :id");
  10.                 $check_donation_list->bindValue(':id', $auction, PDO::PARAM_INT);
  11.                 $check_donation_list->execute();
  12.  
  13.                 if($check_donation_list->rowcount() == 0){
  14.                     $get_postMeta = $this->db_connection->prepare("SELECT post_id, meta_key, meta_value FROM wp_postmeta
  15.                        WHERE post_id = :id AND meta_value = 'added' AND meta_key = 'auction_added_status'");
  16.                     $get_postMeta->bindValue(':id', $auction, PDO::PARAM_INT);
  17.                     $get_postMeta->execute();
  18.                     if($get_postMeta->rowcount() == 0){
  19.                         $this->donationmessages[] = "Found a new auction with auction id: ".$auction;
  20.                         $get_bid = $this->db_connection->prepare("SELECT bid, name, email, auction_id FROM wp_wdm_bidders
  21.                            WHERE auction_id = :id ORDER BY bid DESC");
  22.                         $get_bid->bindValue(':id', $auction, PDO::PARAM_INT);
  23.                         $get_bid->execute();
  24.                         if($get_bid->rowcount() > 0){
  25.                             $biddata = $get_bid->fetch(PDO::FETCH_ASSOC);
  26.                             $auctionpost = $this->getSettings($auction, "gettitle");
  27.                            
  28.                             $get_userip = $this->db_connection->prepare("SELECT ip FROM wp_user_login_log WHERE user_login = :id");
  29.                             $get_userip->bindValue(':id', $biddata['name'], PDO::PARAM_STR);
  30.                             $get_userip->execute();
  31.                             if($get_userip->rowcount() > 0){
  32.                                 $userip = $get_userip->fetchAll(PDO::FETCH_ASSOC);
  33.                                 $userip = $userip[0]["ip"];
  34.                             }else{
  35.                                 $userip = "NOIP";
  36.                             }
  37.                             $full_insert_data[$auction]['bid'] = $biddata['bid'];
  38.                             $full_insert_data[$auction]['itemname'] = $auctionpost;
  39.                             $full_insert_data[$auction]['username'] = $biddata['name'];
  40.                             $full_insert_data[$auction]['email'] = $biddata['email'];
  41.                             $full_insert_data[$auction]['ip'] = $userip;
  42.  
  43.                             $this->donationmessages[] = "The highest bid for this auction was: ".$full_insert_data[$auction]['bid'];
  44.                         try{
  45.                             $set_new_donation = $this->db_connectionSecond->prepare("INSERT INTO
  46.                                auction (itemname, price, username, email, ip)
  47.                                VALUES (:itemname, :price, :username, :email, :ip)");
  48.                             $set_new_donation->bindValue(':itemname', $full_insert_data[$auction]['itemname'], PDO::PARAM_STR);
  49.                             $set_new_donation->bindValue(':price', $full_insert_data[$auction]['bid'], PDO::PARAM_INT);
  50.                             $set_new_donation->bindValue(':username', $full_insert_data[$auction]['username'], PDO::PARAM_STR);
  51.                             $set_new_donation->bindValue(':email', $full_insert_data[$auction]['email'], PDO::PARAM_STR);
  52.                             $set_new_donation->bindValue(':ip', $full_insert_data[$auction]['ip'], PDO::PARAM_STR);
  53.                             $set_new_donation->execute();
  54.  
  55.                         catch(PDOException $e) {
  56.                             echo "Something went wrong. Please report this error.";
  57.                             file_put_contents('/PDOErrors.txt', $e->getMessage(), FILE_APPEND);
  58.                         }
  59.                             if($set_new_donation->rowcount() > 0){
  60.                                 $this->donationmessages[] = "A new donation has been added. Auction number: ".$auction;
  61.                                 $this->create_post_meta($auction, "auction_added_status", "added", true);
  62.                             }else{
  63.                                 $this->donationmessages[] = "A new donation has NOT been added. Auction number: ".$auction;
  64.                             }
  65.                         }else{
  66.                             $payamount = 0;
  67.                             $this->donationmessages[] = "There were no bids for this auction.";
  68.                         }
  69.                     }
  70.                 }
  71.             }  
  72.         }  
  73.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement