<?php

require_once "../classes/class.helper_operator.php";
require_once "../config/config.php";
require_once "../classes/class.query_operator.php";
require_once "../classes/class.session_operator.php";
// Delete profile image from file system and image name from database
$user = SessionOperator::getUser();
unlink(ROOT . $user->getImage());
QueryOperator::uploadImage($user->getUserId(), null, "users");
// Update user session
$user = QueryOperator::getAccount(SessionOperator::getUser()->getUserId());
SessionOperator::updateUser(new User($user));
// Set feedback session
SessionOperator::setNotification(SessionOperator::DELETED_PROFILE_PHOTO);
HelperOperator::redirectTo("../views/profile_view.php");
$feedback = ["score" => $_POST["score"], "comment" => $_POST["comment"]];
if (ValidationOperator::hasEmtpyFields($feedback)) {
    // Create a session for all inputs so that they can be recovered after the page returns
    SessionOperator::setFormInput($feedback);
    // Redirect back
    HelperOperator::redirectTo($redirectUrl);
}
$auctionId = $_POST["auctionId"];
$creatorId = SessionOperator::getUser()->getUserId();
//get the id of receiver
$receiverUsername = $_POST["receiverUsername"];
/* @var DbUser $receiver */
$receiver = DbUser::withConditions("WHERE username = '******'")->first();
//check receiver exists AND there is no existing feedback (we only allow one)
if ($receiver == null or DbFeedback::withConditions("WHERE auctionId = " . $auctionId . " AND creatorId = " . $creatorId . " AND receiverId = " . $receiver->getId())->exists()) {
    HelperOperator::redirectTo($redirectUrl);
}
// Create Feedback
$now = new DateTime("now", new DateTimeZone(TIMEZONE));
$feedback = new DbFeedback(array("auctionId" => $_POST["auctionId"], "creatorId" => SessionOperator::getUser()->getUserId(), "receiverId" => $receiver->getId(), "score" => $_POST["score"], "comment" => $_POST["comment"], "time" => $now->format('Y-m-d H:i:s')));
$feedback->create();
// Notify receiver
$auction = DbAuction::find($auctionId);
$item = DbItem::find($auction->getField("itemId"));
$comment = "You received a feedback from \"" . SessionOperator::getUser()->getUserName() . "\" in your participation in \"";
$comment .= $item->getField("itemName") . " - " . $item->getField("itemBrand") . "\".";
QueryOperator::addNotification($receiver->getId(), $comment, QueryOperator::NOTIFICATION_FEEDBACK_RECEIVED);
// Set feedback session
SessionOperator::setNotification(SessionOperator::FEEDBACK_SENT);
// Return to page
HelperOperator::redirectTo($redirectUrl);
<?php

require_once "../classes/class.helper_operator.php";
require_once "../classes/class.session_operator.php";
require_once "../classes/class.validation_operator.php";
require_once "../classes/class.query_operator.php";
require_once "../classes/class.db_auction_watch.php";
/* @var User $user*/
$user = SessionOperator::getUser();
$auctionId = $_GET["liveAuction"];
if (!is_numeric($auctionId)) {
    HelperOperator::redirectTo("../views/open_live_auction_view.php?" . $_SERVER['QUERY_STRING']);
}
// Check user hasn't already watched
$alreadyWatching = DbAuctionWatch::withConditions("WHERE userId = " . $user->getUserId() . " AND auctionId =" . $auctionId)->exists() ? true : false;
if ($alreadyWatching) {
    HelperOperator::redirectTo("../views/open_live_auction_view.php?" . $_SERVER['QUERY_STRING']);
}
// Create an auction_watch
$watch = new DbAuctionWatch(array("userId" => $user->getUserId(), "auctionId" => $auctionId));
// Add to watch list
$watch->create();
// Set feedback session
SessionOperator::setNotification(SessionOperator::CREATED_WATCH);
HelperOperator::redirectTo("../views/open_live_auction_view.php?" . $_SERVER['QUERY_STRING']);
// Prevent sql injection
if (!is_numeric($auctionId)) {
    HelperOperator::redirectTo("../views/my_live_auctions_view.php");
}
/* @var User $user */
$user = SessionOperator::getUser();
$userId = $user->getUserId();
/* @var DbAuction $auction */
/* @var DbItem $item */
$auction = DbAuction::find($auctionId);
$item = DbItem::find($auction->getField("itemId"));
// User owns auction
if ($item->getField("userId") == $userId) {
    // Notifiy current highest bidder
    $highestBid = QueryOperator::getAuctionBids($auctionId, 1)[0];
    if (!empty($highestBid)) {
        $comment = "The auction \"" . $item->getField("itemName") . " " . $item->getField("itemBrand") . "\" with ";
        $comment .= "your current highest bid of " . $highestBid->getBidPrice() . " GSP was deleted by " . $user->getUsername() . ".";
        QueryOperator::addNotification($highestBid->getBidderId(), $comment, QueryOperator::NOTIFICATION_AUCTION_DELETED);
    }
    // Delete auction
    $auction->delete();
    if (!empty($imageName = $item->getField("image"))) {
        unlink(ROOT . $imageName);
    }
    // Delete auction event
    QueryOperator::dropAuctionEvent($auctionId);
    // Set feedback session
    SessionOperator::setNotification(SessionOperator::DELETED_AUCTION);
}
HelperOperator::redirectTo("../views/my_live_auctions_view.php");
<?php

require_once "../classes/class.helper_operator.php";
require_once "../classes/class.session_operator.php";
require_once "../classes/class.validation_operator.php";
require_once "../classes/class.query_operator.php";
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/class.db_auction.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/class.db_auction_watch.php';
$watchId = $_GET["id"];
// Prevent sql injection
if (!is_numeric($watchId)) {
    HelperOperator::redirectTo("../views/my_watch_list_view.php");
}
/* @var User $user */
$userId = SessionOperator::getUser()->getUserId();
/* @var DbAuctionWatch $auction */
$watch = DbAuctionWatch::find($watchId);
// User owns watch
if ($watch->getField("userId") == $userId) {
    // Delete watch
    $watch->delete();
    // Set feedback session
    SessionOperator::setNotification(SessionOperator::DELETED_WATCH);
}
HelperOperator::redirectTo("../views/my_watch_list_view.php");
Esempio n. 6
0
    $auctionId = (int) $_GET["auctionId"];
    $bidPrice = $_GET["bidPrice"];
    $auction = QueryOperator::getLiveAuction($auctionId);
    $user = SessionOperator::getUser();
    $userId = (int) $user->getUserId();
    // Incorrect inputs
    if (ValidationOperator::hasEmtpyFields($_GET) || !ValidationOperator::isPositiveNumber($bidPrice, "bidPrice") || !ValidationOperator::checkBidPrice($bidPrice, $auctionId)) {
        // Create a session for bid price so that it can be recovered after the page returns
        SessionOperator::setFormInput(["bidPrice" => $bidPrice]);
    } else {
        // Notify outbid user (only if it is not the same user)
        $highestBidderId = $auction->getHighestBidderId();
        if (!is_null($highestBidderId) && $highestBidderId != $userId) {
            $comment = "You were outbid on the auction \"" . $auction->getItemName() . " " . $auction->getItemBrand() . "\" by ";
            $comment .= "by \"" . $user->getUserName() . "\". The new highest bid is " . $bidPrice . " GSP.";
            QueryOperator::addNotification($highestBidderId, $comment, QueryOperator::NOTIFICATION_OUTBID);
        }
        $comment = "You received a new bid on the auction \"" . $auction->getItemName() . " " . $auction->getItemBrand() . "\" by ";
        $comment .= "by \"" . $user->getUserName() . "\". The new highest bid is " . $bidPrice . " GSP.";
        QueryOperator::addNotification($auction->getSellerId(), $comment, QueryOperator::NOTIFICATION_NEW_BID);
        // Place bid
        QueryOperator::placeBid($auctionId, $userId, $bidPrice);
        $dbAuction = DbAuction::find($auctionId);
        $dbAuction->setField("highestBidderId", $userId);
        $dbAuction->save();
        // Set feedback session
        SessionOperator::setNotification(SessionOperator::PLACED_BID);
    }
}
// Return back to page
HelperOperator::redirectTo("../views/open_live_auction_view.php?liveAuction=" . $auctionId . "&s=1");
<?php

require_once "../classes/class.helper_operator.php";
require_once "../classes/class.session_operator.php";
// Ignore manual calls to 'confirmation.php'
if (isset($_GET["email"]) && isset($_GET["confirm_code"])) {
    // Retrieve email and confirmation code from link
    $email = $_GET["email"];
    $confirm_code = $_GET["confirm_code"];
    // Check if email and confirmation code originate from an unverified user account
    require_once "../classes/class.query_operator.php";
    $result = QueryOperator::checkVerificationLink($email, $confirm_code);
    // Verification link is correct
    if (!empty($result)) {
        // Active user account
        QueryOperator::activateAccount($result["userId"]);
        // Create a session for completed registration
        SessionOperator::setNotification(SessionOperator::COMPLETED_REGISTRATION);
        // Email a registration confirmation to the user
        require_once "../classes/class.email.php";
        $mail = new Email($email, $result["firstName"], $result["lastName"]);
        $mail->prepareRegistrationConfirmEmail();
        $mail->sentEmail();
    }
}
// Redirect to homepage
HelperOperator::redirectTo("../index.php");
        }
    } else {
        $error = [];
        if (($upload = ValidationOperator::checkImage()) != null) {
            // A user is logged in
            if (!is_null($user = SessionOperator::getUser())) {
                // Create random image name
                $newImageName = UPLOAD_PROFILE_IMAGE . uniqid("", true) . "." . $upload["imageExtension"];
                // Upload new profile picture to file system
                if (move_uploaded_file($upload["image"], ROOT . $newImageName)) {
                    // Delete old profile pic (if exists)
                    if (!empty($imageName = $user->getImage())) {
                        unlink(ROOT . $imageName);
                    }
                    // Store image name in database
                    QueryOperator::uploadImage($user->getUserId(), $newImageName, "users");
                    // Update user session
                    $user = QueryOperator::getAccount($user->getUserId());
                    SessionOperator::updateUser(new User($user));
                    // Set feedback session
                    SessionOperator::setNotification(SessionOperator::UPLOADED_PROFILE_PHOTO);
                } else {
                    $error["upload"] = "Image cannot be uploaded ";
                    SessionOperator::setInputErrors($error);
                }
            }
        }
    }
}
// Redirect back
HelperOperator::redirectTo("../views/profile_view.php");
Esempio n. 9
0
            SessionOperator::setNotification(SessionOperator::CHANGED_PASSWORD);
            // Send a password changed confirmation email to the user
            $mail = new Email($email, $userDetails["firstName"], $userDetails["lastName"]);
            $mail->preparePasswordConfirmEmail();
            $mail->sentEmail();
            HelperOperator::redirectTo("../index.php");
        } else {
            SessionOperator::setFormInput($passwordFields);
        }
        HelperOperator::redirectTo("../views/change_password_view.php?email=" . $email);
    } else {
        if (isset($_POST["changePasswordSignedIn"])) {
            // Retrieve Passwords
            $passwordFields = ["currentPassword" => $_POST["currentPassword"], "password1" => $_POST["password1"], "password2" => $_POST["password2"]];
            // Get current user session
            $user = SessionOperator::getUser();
            // Current password is correct and both new passwords are valid and match
            if (!ValidationOperator::hasEmtpyFields($passwordFields) && ValidationOperator::isCurrentPassword($passwordFields["currentPassword"]) && ValidationOperator::validPasswords($passwordFields["password1"], $passwordFields["password2"])) {
                QueryOperator::updatePassword($user->getEmail(), $passwordFields["password2"]);
                SessionOperator::setNotification(SessionOperator::CHANGED_PASSWORD);
                // Send a password changed confirmation email to the user
                $mail = new Email($user->getEmail(), $user->getFirstName(), $user->getLastName());
                $mail->preparePasswordConfirmEmail();
                $mail->sentEmail();
            } else {
                SessionOperator::setFormInput($passwordFields);
            }
            HelperOperator::redirectTo("../views/account_view.php");
        }
    }
}
Esempio n. 10
0
require_once "../classes/class.validation_operator.php";
require_once "../classes/class.query_operator.php";
// Only process when sign up button was clicked
if (!isset($_POST["signUp"])) {
    HelperOperator::redirectTo("../index.php");
}
// Store POST values
$registration = ["username" => $_POST["username"], "email" => $_POST["email"], "firstName" => $_POST["firstName"], "lastName" => $_POST["lastName"], "address" => $_POST["address"], "postcode" => $_POST["postcode"], "city" => $_POST["city"], "country" => $_POST["country"], "password1" => $_POST["password1"], "password2" => $_POST["password2"]];
// Add empty string for default country
if ($registration["country"] == "Country") {
    $registration["country"] = "";
}
// Check inputs
if (ValidationOperator::hasEmtpyFields($registration) || ValidationOperator::isTaken($registration["username"], $registration["email"]) || !ValidationOperator::validPasswords($registration["password1"], $registration["password2"])) {
    // Create a session for all inputs so that they can be recovered after the page returns
    SessionOperator::setFormInput($registration);
} else {
    // Create new user
    $registration["country"] = QueryOperator::getCountryId($registration["country"]);
    $encryptedPassword = password_hash($registration["password1"], PASSWORD_BCRYPT);
    $confirmCode = QueryOperator::addAccount(array($registration["username"], $registration["email"], $registration["firstName"], $registration["lastName"], $registration["address"], $registration["postcode"], $registration["city"], $registration["country"], $encryptedPassword));
    // Create a session for the successfully submitted registration (account not verified yet)
    SessionOperator::setNotification(SessionOperator::SUBMITTED_REGISTRATION);
    // Email a verification link to the user - must be verified before accessing the new account
    require_once "../classes/class.email.php";
    $mail = new Email($registration["email"], $registration["firstName"], $registration["lastName"]);
    $mail->prepareVerificationEmail($confirmCode);
    $mail->sentEmail();
}
// Redirect back
HelperOperator::redirectTo("../index.php");
    }
    // Get item category and condition id
    $ids = QueryOperator::getItemRelatedIds(addslashes($new_auction["itemCategory"]), $new_auction["itemCondition"]);
    // Prepare item parameters
    $item[] = SessionOperator::getUser()->getUserId();
    $item[] = $new_auction["itemName"];
    $item[] = $new_auction["itemBrand"];
    $item[] = $ids["categoryId"];
    $item[] = $ids["conditionId"];
    $item[] = $new_auction["itemDescription"];
    $item[] = $newImageName;
    // Prepare auction parameters
    $startTime = date_create($new_auction["startTime"])->format('Y-m-d H:i:s');
    $endTime = date_create($new_auction["endTime"])->format('Y-m-d H:i:s');
    $auction[] = "";
    $auction[] = $new_auction["quantity"];
    $auction[] = $new_auction["startPrice"];
    $auction[] = $new_auction["reservePrice"];
    $auction[] = $startTime;
    $auction[] = $endTime;
    // Store auction in database
    $ids = QueryOperator::addAuction($item, $auction);
    // Set event timer
    QueryOperator::addAuctionEvent($endTime, SessionOperator::getUser()->getUserId(), $ids["auctionId"]);
    // Store image name in database
    QueryOperator::uploadImage($ids["itemId"], $newImageName, "items");
    // Set feedback session
    SessionOperator::setNotification(SessionOperator::CREATED_AUCTION);
    // Return to live auctions page
    HelperOperator::redirectTo("../views/my_live_auctions_view.php");
}