Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @package database
- * @author Lukafurlan
- * @version 1.0
- *
- */
- class database {
- public function db()
- {
- $connection = new PDO("mysql:host=;port=3306;dbname=", "", "");
- $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- return $connection;
- }
- //REGISTRATION//
- public function register($username, $email, $password, $paypalEmail, $serverName, $serverWebsite, $claimCommand, $storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("INSERT INTO members (username, email, password, paypalEmail, serverName, serverWebsite, claimCommand, storeId) VALUES (:username, :email, :password, :paypalEmail, :serverName, :serverWebsite, :claimCommand, :storeId)");
- $stmt->bindParam(":username", $username);
- $stmt->bindParam(":email", $email);
- $stmt->bindParam(":password", $password);
- $stmt->bindParam(":paypalEmail", $paypalEmail);
- $stmt->bindParam(":serverName", $serverName);
- $stmt->bindParam(":serverWebsite", $serverWebsite);
- $stmt->bindParam(":claimCommand", $claimCommand);
- $stmt->bindParam(":storeId", $storeId);
- $stmt->execute();
- }
- catch (PDOException $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function usernameExists($username)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT COUNT(*) FROM members WHERE username = :username");
- $stmt->bindParam(':username', $username);
- $stmt->execute();
- $rows = $stmt->fetchColumn();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function emailExists($email)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT COUNT(*) FROM members WHERE email = :email");
- $stmt->bindParam(':emailAdress', $email);
- $stmt->execute();
- $rows = $stmt->fetchColumn();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- //LOGIN//
- public function checkPassword($username)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT password FROM members WHERE username = :username");
- $stmt->bindParam(':username', $username);
- $stmt->execute();
- $row = $stmt->fetch();
- return $row['password'];
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function getEmail($username)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT email FROM members WHERE username = :username");
- $stmt->bindParam(':username', $username);
- $stmt->execute();
- $row = $stmt->fetch();
- return $row['email'];
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- //CHECK//
- public function getUserData($username)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT * FROM members WHERE username = :username");
- $stmt->bindParam(':username', $username);
- $stmt->execute();
- $row = $stmt->fetch();
- return $row;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- //SETTINGS//
- public function changePassword($username, $password)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("UPDATE members SET password = :password WHERE username = :username");
- $stmt->bindParam(':password', $password);
- $stmt->bindParam(':username', $username);
- $stmt->execute();
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- //PRODUCTS//
- public function addProduct($storeId, $productName, $productPrice, $productDescription, $productImage, $productCategoryId, $productCategoryName)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("INSERT INTO products (storeId, productName, productPrice, productDescription, productImage, productCategoryId, productCategoryName) VALUES (:storeId, :productName, :productPrice, :productDescription, :productImage, :productCategoryId, :productCategoryName)");
- $stmt->bindParam(":storeId", $storeId);
- $stmt->bindParam(":productName", $productName);
- $stmt->bindParam(":productPrice", $productPrice);
- $stmt->bindParam(":productDescription", $productDescription);
- $stmt->bindParam(":productImage", $productImage);
- $stmt->bindParam(":productCategoryId", $productCategoryId);
- $stmt->bindParam(":productCategoryName", $productCategoryName);
- $stmt->execute();
- }
- catch (PDOException $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function editProduct($storeId, $productName, $productPrice, $productDescription, $productImage, $productId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("UPDATE products SET productName = :productName, productPrice = :productPrice, productDescription = :productDescription, productImage = :productImage WHERE storeId = :storeId AND id = :productId");
- $stmt->bindParam(":storeId", $storeId);
- $stmt->bindParam(":productId", $productId);
- $stmt->bindParam(":productName", $productName);
- $stmt->bindParam(":productPrice", $productPrice);
- $stmt->bindParam(":productDescription", $productDescription);
- $stmt->bindParam(":productImage", $productImage);
- $stmt->execute();
- }
- catch (PDOException $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function deleteProduct($productId, $storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("DELETE FROM products WHERE id = :id AND storeId = :storeId");
- $stmt->bindParam(":id", $productId);
- $stmt->bindParam(":storeId", $storeId);
- $stmt->execute();
- }
- catch (PDOException $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function promoteProduct($productId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("UPDATE products SET isPromoted=1 WHERE id = :id");
- $stmt->bindParam(":id", $productId);
- $stmt->execute();
- }
- catch (PDOException $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function changeDescription($username, $desc)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("UPDATE members SET description = :desc WHERE username = :username");
- $stmt->bindParam(":username", $username);
- $stmt->bindParam(":desc", $desc);
- $stmt->execute();
- }
- catch (PDOException $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function demoteProduct($productId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("UPDATE products SET isPromoted=0 WHERE id = :id");
- $stmt->bindParam(":id", $productId);
- $stmt->execute();
- }
- catch (PDOException $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function deleteCategory($categoryId, $storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("DELETE FROM categories WHERE id = :id AND storeId = :storeId");
- $stmt->bindParam(":id", $categoryId);
- $stmt->bindParam(":storeId", $storeId);
- $stmt->execute();
- }
- catch (PDOException $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function addCategory($categoryName, $storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("INSERT INTO categories (storeId, categoryName) VALUES (:storeId, :categoryName)");
- $stmt->bindParam(":storeId", $storeId);
- $stmt->bindParam(":categoryName", $categoryName);
- $stmt->execute();
- }
- catch (PDOException $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function getCategoryCount($storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT COUNT(*) FROM categories WHERE storeId = :storeId");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->execute();
- $rows = $stmt->fetchColumn();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function getCategories($storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT * FROM categories WHERE storeId = :storeId");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->execute();
- $rows = $stmt->fetchAll();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function getProducts($storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT * FROM products WHERE storeId = :storeId");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->execute();
- $rows = $stmt->fetchAll();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function getCategoryNameForId($categoryId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT categoryName FROM categories WHERE id = :categoryId");
- $stmt->bindParam(':categoryId', $categoryId);
- $stmt->execute();
- $row = $stmt->fetch();
- return $row['categoryName'];
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- //GATEWAYS//
- public function changePaypal($email, $uid)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("UPDATE members SET paypalEmail = :paypalEmail WHERE id = :uid");
- $stmt->bindParam(':paypalEmail', $email);
- $stmt->bindParam(':uid', $uid);
- $stmt->execute();
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- //WEBSTORE//
- public function webstore($storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT COUNT(*) FROM members WHERE storeId = :storeId");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->execute();
- $rows = $stmt->fetchColumn();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function webstoreData($storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT id, claimCommand, description, storeId, serverName, serverWebsite, paypalEmail, isPremium FROM members WHERE storeId = :storeId");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->execute();
- $rows = $stmt->fetchAll();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function countPromotedProducts($storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT COUNT(*) FROM products WHERE storeId = :storeId AND isPromoted = 1");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->execute();
- $rows = $stmt->fetchColumn();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function getPromotedProducts($storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT * FROM products WHERE storeId = :storeId AND isPromoted = 1");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->execute();
- $rows = $stmt->fetchAll();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function tabExists($tabId, $storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT COUNT(*) FROM categories WHERE storeId = :storeId AND id = :tabId");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->bindParam(':tabId', $tabId);
- $stmt->execute();
- $rows = $stmt->fetchColumn();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function getProductsForCategory($tab, $storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT * FROM products WHERE storeId = :storeId AND productCategoryId = :tab");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->bindParam(':tab', $tab);
- $stmt->execute();
- $rows = $stmt->fetchAll();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function getProductsForId($productId, $storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT * FROM products WHERE storeId = :storeId AND id = :productId");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->bindParam(':productId', $productId);
- $stmt->execute();
- $rows = $stmt->fetchAll();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function productBelongsToStore($productId, $storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT COUNT(*) FROM products WHERE storeId = :storeId AND id = :productId");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->bindParam(':productId', $productId);
- $stmt->execute();
- $rows = $stmt->fetchColumn();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- //IPN//
- public function purchaseData($itemName, $itemNumber, $paymentStatus, $mcGross, $txnId, $payerEmail, $storeId, $purchaseId, $purchaseDate, $purchaseMonth)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("INSERT INTO paymentData (payerEmail, itemNumber, paymentStatus, mcGros, txnId, storeId, purchaseId, purchaseDate, purchaseMonth) VALUES (:payerEmail, :itemNumber, :paymentStatus, :mcGros, :txnId, :storeId, :purchaseId, :purchaseDate, :purchaseMonth)");
- $stmt->bindParam(":payerEmail", $payerEmail);
- $stmt->bindParam(":itemNumber", $itemNumber);
- $stmt->bindParam(":paymentStatus", $paymentStatus);
- $stmt->bindParam(":mcGros", $mcGross);
- $stmt->bindParam(":txnId", $txnId);
- $stmt->bindParam(":storeId", $storeId);
- $stmt->bindParam(":purchaseId", $purchaseId);
- $stmt->bindParam(":purchaseDate", $purchaseDate);
- $stmt->bindParam(":purchaseMonth", $purchaseMonth);
- $stmt->execute();
- }
- catch (PDOException $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function updatePurchase($storeId, $purchaseId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("UPDATE checkout SET canClaim = 1 WHERE storeId = :storeId AND checkoutId = :purchaseId");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->bindParam(':purchaseId', $purchaseId);
- $stmt->execute();
- $rows = $stmt->fetchColumn();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function checkout($storeId, $productId, $purchaseId, $customEncryption, $playerName, $ip, $quantity)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("INSERT INTO checkout (storeId, productId, checkoutId, customEncryption, playerName, ip, date, quantity) VALUES (:storeId, :productId, :purchaseId, :customEncryption, :playerName, :ip, :date, :quantity)");
- $stmt->bindParam(":storeId", $storeId);
- $stmt->bindParam(":productId", $productId);
- $stmt->bindParam(":purchaseId", $purchaseId);
- $stmt->bindParam(":customEncryption", $customEncryption);
- $stmt->bindParam(":playerName", $playerName);
- $stmt->bindParam(":ip", $ip);
- $stmt->bindParam(":quantity", $quantity);
- $stmt->bindParam(":date", date("D M j G:i:s T Y"));
- $stmt->execute();
- }
- catch (PDOException $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function getPurchaseData($storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT * FROM paymentData WHERE storeId = :storeId");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->execute();
- $rows = $stmt->fetchAll();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function paymentAlreadyRecieved($purchaseId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT COUNT(*) FROM paymentData WHERE purchaseId = :purchaseId");
- $stmt->bindParam(':purchaseId', $purchaseId);
- $stmt->execute();
- $rows = $stmt->fetchColumn();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function updatePayment($purchaseId, $paymentStatus, $txnId)
- {
- $chargeBackVar = 3;
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("UPDATE paymentData SET paymentStatus = :paymentStatus WHERE purchaseId = :purchaseId");
- $stmt->bindParam(':purchaseId', $purchaseId);
- $stmt->bindParam(':paymentStatus', $paymentStatus);
- $stmt->execute();
- $stmt = $this->connection->prepare("UPDATE checkout SET canClaim = :paymentStatus, txnId = :txnId WHERE checkoutId = :purchaseId");
- $stmt->bindParam(':purchaseId', $purchaseId);
- $stmt->bindParam(':paymentStatus', 2);
- $stmt->bindParam(':txnId', $txnId);
- $stmt->execute();
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function getCheckoutData($storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT * FROM checkout WHERE storeId = :storeId");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->execute();
- $rows = $stmt->fetchAll();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function getTransactionsPerMonth($storeId, $month)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT COUNT(*) FROM paymentData WHERE storeId = :storeId AND purchaseMonth = :purchaseMonth");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->bindParam(':purchaseMonth', $month);
- $stmt->execute();
- $rows = $stmt->fetchColumn();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function totalProfit($storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT SUM(mcGros) FROM paymentData WHERE storeId = :storeId");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->execute();
- $rows = $stmt->fetchColumn();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function totalProfitThisMonth($storeId, $month)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT SUM(mcGros) FROM paymentData WHERE storeId = :storeId AND purchaseMonth = :purchaseMonth");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->bindParam(':purchaseMonth', $month);
- $stmt->execute();
- $rows = $stmt->fetchColumn();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function upgradeToPremium($storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("UPDATE members SET isPremium = 1 WHERE storeId = :storeId");
- $stmt->bindParam(':storeId', $storeId);
- $stmt->execute();
- $rows = $stmt->fetchColumn();
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function paymentAuthenticity($totalPrice, $checkoutId, $storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("INSERT INTO paymentauthenticity (totalPrice, checkoutId, storeId) VALUES (:totalPrice, :checkoutId, :storeId)");
- $stmt->bindParam(':totalPrice', $totalPrice);
- $stmt->bindParam(':checkoutId', $checkoutId);
- $stmt->bindParam(':storeId', $storeId);
- $stmt->execute();
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- public function checkAuthenticity($checkoutId, $storeId)
- {
- try
- {
- $this->connection = $this->db();
- $stmt = $this->connection->prepare("SELECT totalPrice FROM paymentauthenticity WHERE storeId = :storeId AND checkoutId = :checkoutId");
- $stmt->bindParam(':checkoutId', $checkoutId);
- $stmt->bindParam(':storeId', $storeId);
- $stmt->execute();
- $rows = $stmt->fetch(PDO::FETCH_OBJ);
- return $rows;
- }
- catch (Exception $exception)
- {
- echo $exception->getMessage();
- }
- }
- }
Add Comment
Please, Sign In to add comment