From 61557ff673d1e26b95fc125a57cca3598a717683 Mon Sep 17 00:00:00 2001 From: tyschreiver Date: Wed, 25 Apr 2018 20:17:05 -0400 Subject: [PATCH 1/4] built framework for buy now --- BuyNow.php | 115 ++++++++++++++++++++++++++++++ PhpScripts/DatabaseConnection.php | 16 ++--- PhpScripts/Templates/Nav.php | 8 ++- PhpScripts/ViewSixHundreds.php | 18 +++++ css/customStyles.css | 8 +++ procsViewsTriggers.sql | 10 ++- 6 files changed, 165 insertions(+), 10 deletions(-) create mode 100644 BuyNow.php create mode 100644 PhpScripts/ViewSixHundreds.php diff --git a/BuyNow.php b/BuyNow.php new file mode 100644 index 0000000..d893afb --- /dev/null +++ b/BuyNow.php @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
AuctionIdDescriptionValueQuantity
+
+
+ + +
Quantity cannot be negative
+
+ +
+ \ No newline at end of file diff --git a/PhpScripts/DatabaseConnection.php b/PhpScripts/DatabaseConnection.php index aca0d73..392440e 100644 --- a/PhpScripts/DatabaseConnection.php +++ b/PhpScripts/DatabaseConnection.php @@ -15,16 +15,16 @@ function Connect() $dbname = "fbcmtown_auctionITdb"; */ /* Master */ - $dbhost = "auctionit.fbcmtown.org"; - $dbuser = "fbcmtown_auction"; - $dbpass = ""; - $dbname = "fbcmtown_auctionITdb"; + // $dbhost = "auctionit.fbcmtown.org"; + // $dbuser = "fbcmtown_auction"; + // $dbpass = ""; + // $dbname = "fbcmtown_auctionITdb"; // Tyler - // $dbhost = "localhost"; - // $dbuser = "root"; - // $dbpass = ""; - // $dbname = "AuctionIT"; + $dbhost = "localhost"; + $dbuser = "root"; + $dbpass = ""; + $dbname = "AuctionIT"; /* Ewen $dbhost = "localhost"; diff --git a/PhpScripts/Templates/Nav.php b/PhpScripts/Templates/Nav.php index 345dfc2..b6d29f9 100644 --- a/PhpScripts/Templates/Nav.php +++ b/PhpScripts/Templates/Nav.php @@ -33,7 +33,10 @@ break; case("AccountEditor.php"): echo("Account Editor"); - break; + break; + case("BuyNow.php"): + echo("Buy Now"); + break; default: echo(basename($_SERVER['PHP_SELF'])); break; @@ -57,6 +60,9 @@
  • Add Bid

  • +
  • +

    Buy Now

    +
  • Reports

  • diff --git a/PhpScripts/ViewSixHundreds.php b/PhpScripts/ViewSixHundreds.php new file mode 100644 index 0000000..9ea1c16 --- /dev/null +++ b/PhpScripts/ViewSixHundreds.php @@ -0,0 +1,18 @@ +query($query); + $data = array(); + while( $rows = mysqli_fetch_assoc($result) ) { + $data[] = $rows; + } + $results = array( + "sEcho" => 1, + "iTotalRecords" => count($data), + "iTotalDisplayRecords" => count($data), + "aaData" => $data + ); + echo json_encode($results); + +?> \ No newline at end of file diff --git a/css/customStyles.css b/css/customStyles.css index d8a7410..12c7198 100644 --- a/css/customStyles.css +++ b/css/customStyles.css @@ -236,4 +236,12 @@ .bid-hist-title { display: inline; margin-left: 15px; +} + +.table-input { + border-radius: 5px; +} + +.after-table { + margin-top: 20px; } \ No newline at end of file diff --git a/procsViewsTriggers.sql b/procsViewsTriggers.sql index 340ac00..953c80f 100644 --- a/procsViewsTriggers.sql +++ b/procsViewsTriggers.sql @@ -1,7 +1,6 @@ drop view if exists viewunmarked; drop view if exists viewtwohundreds; drop view if exists viewthreehundreds; -drop view if exists viewsixhundreds; drop procedure if exists viewAuctionItemGroups; USE auctionit; @@ -36,6 +35,15 @@ VIEW `viewBidders` AS SELECT * FROM `bidders`; +drop view if exists viewsixsundreds; +CREATE + ALGORITHM = UNDEFINED + SQL SECURITY DEFINER +VIEW 'viewsixhundreds' AS + SELECT * + FROM `viewauctionitemssheet` + where `auctionId` >= 600; + /*View AuctionItemsSheet */ DROP VIEW IF EXISTS viewauctionitemssheet; From f2aaf528e14a560abca04f7f0a02fe69ea8c1b12 Mon Sep 17 00:00:00 2001 From: tyschreiver Date: Fri, 4 May 2018 20:34:32 -0400 Subject: [PATCH 2/4] finished buy noe --- AddBid.php | 1 - BuyNow.php | 105 +++++++++++++++++++++++++++++- PhpScripts/BuyNowDatabase.php | 29 +++++++++ PhpScripts/DatabaseConnection.php | 12 ++-- PhpScripts/ViewSixHundreds.php | 2 +- css/customStyles.css | 20 +++++- procsViewsTriggers.sql | 25 +++++-- 7 files changed, 179 insertions(+), 15 deletions(-) create mode 100644 PhpScripts/BuyNowDatabase.php diff --git a/AddBid.php b/AddBid.php index 9fae2c4..c6345c8 100644 --- a/AddBid.php +++ b/AddBid.php @@ -91,7 +91,6 @@ function( settings, data, dataIndex ) { oReq.send(); var oReq2 = new XMLHttpRequest(); - oReq2.onload = function() { bidders = JSON.parse(this.responseText).aaData; }; diff --git a/BuyNow.php b/BuyNow.php index d893afb..3f3ca23 100644 --- a/BuyNow.php +++ b/BuyNow.php @@ -21,6 +21,7 @@ @@ -94,6 +176,22 @@ function areYouSure() {
    + + + + @@ -109,6 +207,9 @@ function areYouSure() {
    Quantity cannot be negative
    +
    Must Enter BidderID
    +
    That Bidder Number does not exist
    + diff --git a/PhpScripts/BuyNowDatabase.php b/PhpScripts/BuyNowDatabase.php new file mode 100644 index 0000000..7eee5df --- /dev/null +++ b/PhpScripts/BuyNowDatabase.php @@ -0,0 +1,29 @@ +real_escape_string($_POST['auctionID']); +$bidderID = $conn->real_escape_string($_POST['bidderID']); +$amount = $conn->real_escape_string($_POST['amount']); + +$sql = "CALL buy_now(" . $auctionID. "," . $bidderID . "," . $amount .")"; +$result = $conn->query($sql); +session_start(); + +/* +if (!$result) { + $_SESSION['bidSuccess'] = 2; + die("Couldn't enter data: ".$conn->error); +} +else { +$_SESSION['bidSuccess'] = 1; +$_SESSION["result"] = $result; + +} */ + + +$conn->close(); +?> diff --git a/PhpScripts/DatabaseConnection.php b/PhpScripts/DatabaseConnection.php index 56ca1a5..5a0b3d9 100644 --- a/PhpScripts/DatabaseConnection.php +++ b/PhpScripts/DatabaseConnection.php @@ -3,11 +3,11 @@ function Connect() { - /* Ellie + // Ellie $dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; - $dbname = "fbcmtown_auctionITdb"; */ + $dbname = "fbcmtown_auctionITdb"; /* Master */ // $dbhost = "auctionit.fbcmtown.org"; @@ -16,10 +16,10 @@ function Connect() // $dbname = "fbcmtown_auctionITdb"; // Tyler - $dbhost = "localhost"; - $dbuser = "root"; - $dbpass = ""; - $dbname = "AuctionIT"; + // $dbhost = "localhost"; + // $dbuser = "root"; + // $dbpass = ""; + // $dbname = "AuctionIT"; /* Ewen $dbhost = "127.0.0.1"; diff --git a/PhpScripts/ViewSixHundreds.php b/PhpScripts/ViewSixHundreds.php index 9ea1c16..6f7b254 100644 --- a/PhpScripts/ViewSixHundreds.php +++ b/PhpScripts/ViewSixHundreds.php @@ -1,7 +1,7 @@ query($query); $data = array(); while( $rows = mysqli_fetch_assoc($result) ) { diff --git a/css/customStyles.css b/css/customStyles.css index 12c7198..65a331e 100644 --- a/css/customStyles.css +++ b/css/customStyles.css @@ -67,10 +67,12 @@ border-top: none; cursor: pointer; padding-left: 5px; + z-index: 1000; + background-color: white; } .dropdown:hover { - background-color: rgba(0,0,0, .05); + background-color:#f2f2f2; } .drop { @@ -244,4 +246,20 @@ .after-table { margin-top: 20px; +} + +.bidder-id-numbers { + display: inline-block; + width: auto; + margin-right: 40px; +} + +.bidder-id-search { + display: inline-block; + position: absolute; +} + +.search { + height: 65px; + overflow: visible; } \ No newline at end of file diff --git a/procsViewsTriggers.sql b/procsViewsTriggers.sql index 953c80f..b1a1b8d 100644 --- a/procsViewsTriggers.sql +++ b/procsViewsTriggers.sql @@ -35,14 +35,31 @@ VIEW `viewBidders` AS SELECT * FROM `bidders`; -drop view if exists viewsixsundreds; +drop view if exists view_six_hundreds; CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER -VIEW 'viewsixhundreds' AS +VIEW `view_six_hundreds` AS SELECT * - FROM `viewauctionitemssheet` - where `auctionId` >= 600; + FROM `view_auction_items_sheet` + where `auction_id` >= 600; + +drop procedure if exists buy_now; + +delimiter $$ +CREATE PROCEDURE buy_now (IN AuctionId INT, IN BidderId INT, IN Amount INT) +BEGIN +IF (AuctionId > 599 AND AuctionId < 700) THEN + IF EXISTS (SELECT * FROM purchases WHERE auction_id = AuctionId AND bidder_id = BidderId) THEN + UPDATE purchases + SET purchases.quantity = (purchases.quantity + Amount), purchases.price = (select `value` from auction_items where auction_id = AuctionId) + WHERE auction_id = AuctionId AND bidder_id = BidderId; + ELSE + INSERT INTO purchases (auction_id, bidder_id, price, quantity) + VALUES (AuctionId, BidderId, (select `value` from auction_items where auction_id = AuctionId), Amount); + End IF; +END IF; +END $$ /*View AuctionItemsSheet */ From 06db2bfc8ceff78e31107c55a70e460c1cc2cbdb Mon Sep 17 00:00:00 2001 From: Interapt Developer Date: Mon, 11 Jun 2018 22:18:11 -0400 Subject: [PATCH 3/4] Clean up --- PhpScripts/DatabaseConnection.php | 25 ++++--------------------- procsViewsTriggers.sql | 2 +- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/PhpScripts/DatabaseConnection.php b/PhpScripts/DatabaseConnection.php index 5a0b3d9..5ae734a 100644 --- a/PhpScripts/DatabaseConnection.php +++ b/PhpScripts/DatabaseConnection.php @@ -1,39 +1,22 @@ connect_error); return $conn; } - - - - - +?> diff --git a/procsViewsTriggers.sql b/procsViewsTriggers.sql index b1a1b8d..d8bec70 100644 --- a/procsViewsTriggers.sql +++ b/procsViewsTriggers.sql @@ -3,7 +3,7 @@ drop view if exists viewtwohundreds; drop view if exists viewthreehundreds; drop procedure if exists viewAuctionItemGroups; -USE auctionit; +USE `fbcmtown_auctionITdb`; /* View Donators */ drop view if exists viewDonators; From 57d4fe99e6d1dd7a862f3ca29a0481c1a727524e Mon Sep 17 00:00:00 2001 From: Ewen Date: Fri, 22 Jun 2018 11:42:14 -0400 Subject: [PATCH 4/4] Added buy now to new dataase file and updated receipts to display actual price paid for items --- NewDatabase.sql | 42 +++++++++++++++++++++++++------ PhpScripts/DatabaseConnection.php | 13 +++------- PhpScripts/FPDFWrapperHelpers.php | 18 ++++++------- PhpScripts/ViewSixHundreds.php | 24 ++++++++++-------- Templates/AuctionReceipt.txt | 2 +- 5 files changed, 61 insertions(+), 38 deletions(-) diff --git a/NewDatabase.sql b/NewDatabase.sql index 7baa761..83564fb 100644 --- a/NewDatabase.sql +++ b/NewDatabase.sql @@ -10,6 +10,7 @@ USE `fbcmtown_auctionITdb`; -- Table structure for table `accounts` -- + DROP TABLE IF EXISTS `accounts`; CREATE TABLE `accounts` ( `auto_id` int(11) NOT NULL AUTO_INCREMENT, @@ -191,12 +192,9 @@ VIEW `view_auction_items_sheet` AS (SELECT `auction_items`.`auction_id` AS `auction_id`, SUM(`auction_items`.`value`) AS `value`, - GROUP_CONCAT(DISTINCT `auction_items`.`description` - SEPARATOR ', ') AS `description`, - GROUP_CONCAT(DISTINCT `auction_items`.`description2` - SEPARATOR ', ') AS `description2`, - GROUP_CONCAT(DISTINCT `auction_items`.`donated_by` - SEPARATOR ', ') AS `donated_by`, + GROUP_CONCAT(DISTINCT `auction_items`.`description` SEPARATOR ', ') AS `description`, + GROUP_CONCAT(DISTINCT `auction_items`.`description2` SEPARATOR ', ') AS `description2`, + GROUP_CONCAT(DISTINCT `auction_items`.`donated_by` SEPARATOR ', ') AS `donated_by`, `b`.`bidder_id` AS `winning_bidder_id`, `bidders`.`name` AS `winning_bidder`, `b`.`amount` AS `winning_bid`, @@ -218,7 +216,9 @@ VIEW `view_auction_items_sheet` AS LEFT JOIN `bidders` ON ((`bidders`.`bidder_id` = `b`.`bidder_id`))) WHERE (`auction_items`.`auction_id` IS NOT NULL) - GROUP BY `auction_items`.`auction_id`) UNION (SELECT + GROUP BY `auction_items`.`auction_id`, `b`.`bidder_id`) + UNION + (SELECT `auction_items`.`auction_id` AS `auction_id`, `auction_items`.`value` AS `value`, `auction_items`.`description` AS `description`, @@ -335,6 +335,34 @@ VIEW `view_receipts` AS AND (`p`.`bidder_id` = `b`.`bidder_id`)); +drop view if exists view_six_hundreds; +CREATE + ALGORITHM = UNDEFINED + SQL SECURITY DEFINER +VIEW `view_six_hundreds` AS + SELECT * + FROM `view_auction_items_sheet` + where `auction_id` >= 600; + +drop procedure if exists buy_now; + +DELIMITER ;; +CREATE PROCEDURE buy_now (IN AuctionId INT, IN BidderId INT, IN Amount INT) +BEGIN +IF (AuctionId > 599 AND AuctionId < 700) THEN + IF EXISTS (SELECT * FROM purchases WHERE auction_id = AuctionId AND bidder_id = BidderId) THEN + UPDATE purchases + SET purchases.quantity = (purchases.quantity + Amount), purchases.price = (select `value` from auction_items where auction_id = AuctionId) + WHERE auction_id = AuctionId AND bidder_id = BidderId; + ELSE + INSERT INTO purchases (auction_id, bidder_id, price, quantity) + VALUES (AuctionId, BidderId, (select `value` from auction_items where auction_id = AuctionId), Amount); + End IF; +END IF; +END ;; + +DELIMITER ; + -- -- Dumping routines for database 'fbcmtown_auctionITdb' -- diff --git a/PhpScripts/DatabaseConnection.php b/PhpScripts/DatabaseConnection.php index 5ae734a..0cc6b72 100644 --- a/PhpScripts/DatabaseConnection.php +++ b/PhpScripts/DatabaseConnection.php @@ -2,16 +2,9 @@ function Connect() { - /* Master */ - // $dbhost = "auctionit.fbcmtown.org"; - // $dbuser = "fbcmtown_auction"; - // $dbpass = ""; - // $dbname = "fbcmtown_auctionITdb"; - - /* Dev */ - $dbhost = "127.0.0.1"; - $dbuser = "root"; - $dbpass = "testtest"; + $dbhost = "auctionit.fbcmtown.org"; + $dbuser = "fbcmtown_auction"; + $dbpass = ""; $dbname = "fbcmtown_auctionITdb"; // Create connection diff --git a/PhpScripts/FPDFWrapperHelpers.php b/PhpScripts/FPDFWrapperHelpers.php index 47d20b6..7d0c1ec 100644 --- a/PhpScripts/FPDFWrapperHelpers.php +++ b/PhpScripts/FPDFWrapperHelpers.php @@ -45,31 +45,31 @@ function GetReceiptsFromPurchases($purchases, $bidderID) { foreach ($purchases as $purchase) { - // Check if a receipt for that buyer is already started + // Check if the receipt is for a specific user and that the purchase is theirs if (!isset($bidderID) || ($purchase['bidder_id'] == $bidderID)) { + + // Check if a receipt for that buyer is already started if (isset($receipts[$purchase['bidder_id']])) { - $receipts[$purchase['bidder_id']]['total'] = $receipts[$purchase['bidder_id']]['total'] == '______' ? '______' : ($purchase['value'] > 0 ? $receipts[$purchase['bidder_id']]['total'] + $purchase['value'] : '______'); - $receipts[$purchase['bidder_id']]['items'][count($receipts[$purchase['bidder_id']]['items'])] = array( + $receipts[$purchase['bidder_id']]['total'] += $purchase['price'] * $purchase['quantity']; + $receipts[$purchase['bidder_id']]['items'][] = array( "auction_id" => $purchase['auction_id'], - "value" => $purchase['value'] > 0 ? $purchase['value'] : "______", + "price" => $purchase['price'] * $purchase['quantity'], "description" => $purchase['description'] ); } else { $receipts[$purchase['bidder_id']] = array( "bidder_id" => $purchase['bidder_id'], "name" => $purchase['name'], - "total" => $purchase['value'] > 0 ? $purchase['value'] : '______', + "total" => $purchase['price'] * $purchase['quantity'], "items" => array( array( "auction_id" => $purchase['auction_id'], - "value" => $purchase['value'] > 0 ? $purchase['value'] : "______", + "price" => $purchase['price'] * $purchase['quantity'], "description" => $purchase['description'] ) ) ); } - } else { - } } @@ -85,7 +85,7 @@ function GetDonorsAndTotals($donations) { // Check if a receipt for that buyer is already started if (isset($donors[$donation['donated_by']])) { $donors[$donation['donated_by']]['total'] = $donors[$donation['donated_by']]['total'] == '______' ? '______' : ($donation['value'] > 0 ? $donors[$donation['donated_by']]['total'] + $donation['value'] : '______'); - $donors[$donation['donated_by']]['items'][count($donors[$donation['donated_by']]['items'])] = array( + $donors[$donation['donated_by']]['items'][] = array( "auction_id" => $donation['auction_id'], "value" => $donation['value'] > 0 ? $donation['value'] : "______", "description" => $donation['description'] diff --git a/PhpScripts/ViewSixHundreds.php b/PhpScripts/ViewSixHundreds.php index 6f7b254..485aa52 100644 --- a/PhpScripts/ViewSixHundreds.php +++ b/PhpScripts/ViewSixHundreds.php @@ -1,18 +1,20 @@ query($query); - $data = array(); + + $conn = Connect(); + $result = $conn->query("SELECT * FROM view_six_hundreds"); + $data = array(); + while( $rows = mysqli_fetch_assoc($result) ) { $data[] = $rows; } - $results = array( - "sEcho" => 1, - "iTotalRecords" => count($data), - "iTotalDisplayRecords" => count($data), - "aaData" => $data - ); - echo json_encode($results); + + echo json_encode(array( + "sEcho" => 1, + "iTotalRecords" => count($data), + "iTotalDisplayRecords" => count($data), + "aaData" => $data + )); ?> \ No newline at end of file diff --git a/Templates/AuctionReceipt.txt b/Templates/AuctionReceipt.txt index 4155de7..059d9c3 100644 --- a/Templates/AuctionReceipt.txt +++ b/Templates/AuctionReceipt.txt @@ -8,7 +8,7 @@ Purchased By ID Number: {{bidder_id}} { "size": 15, "weight": "B", "align": "L", "height": "10", "width": "-60", "left": "30" } {{auction_id}}. {{description}} { "size": 15, "weight": "B", "height": "10", "align": "R", "top": "-10" } -${{value}} +${{price}} { "endRepeatable": 1, "repeatOn": "items" } { "size": 15, "weight": "B", "align": "L", "height": "10", "left": "30" }