// Get changed input fields (if available) $changedFields = ValidationOperator::getChangedFields($update); // Check inputs if (!empty($changedFields) && !ValidationOperator::hasEmtpyFields($update) && (!isset($changedFields["username"]) || !ValidationOperator::isTaken($update["username"]))) { // Update user information $user = SessionOperator::getUser(); QueryOperator::updateAccount($user->getUserId(), $update); // Update user session $user = QueryOperator::getAccount($user->getUserId()); SessionOperator::updateUser(new User($user)); // Set feedback session SessionOperator::setNotification(SessionOperator::UPDATED_PROFILE_INFO); } } 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));
require_once "../classes/class.query_operator.php"; // Only process when start auction button was clicked if (!isset($_POST["startAuction"])) { HelperOperator::redirectTo("../views/create_auction_view.php"); } // Store POST values $new_auction = ["item" => $_POST["item"], "itemName" => $_POST["itemName"], "itemBrand" => $_POST["itemBrand"], "itemCategory" => $_POST["itemCategory"], "itemCondition" => $_POST["itemCondition"], "itemDescription" => $_POST["itemDescription"], "quantity" => $_POST["quantity"], "startPrice" => $_POST["startPrice"], "reservePrice" => $_POST["reservePrice"], "startTime" => $_POST["startTime"], "endTime" => $_POST["endTime"]]; // Add empty string for default selects if ($new_auction["itemCategory"] == "Select") { $new_auction["itemCategory"] = ""; } if ($new_auction["itemCondition"] == "Select") { $new_auction["itemCondition"] = ""; } // Check inputs if (ValidationOperator::hasEmtpyFields($new_auction) || ($upload = ValidationOperator::checkImage()) == null || !ValidationOperator::checkPrizes($new_auction["startPrice"], $new_auction["reservePrice"])) { // Create a session for all inputs so that they can be recovered after the page returns SessionOperator::setFormInput($new_auction); // Redirect back HelperOperator::redirectTo("../views/create_auction_view.php"); } else { // Create random image name $newImageName = UPLOAD_ITEM_IMAGE . uniqid("", true) . "." . $upload["imageExtension"]; // Cannot upload image to file system, otherwise, image uploaded if (!move_uploaded_file($upload["image"], ROOT . $newImageName)) { $error["upload"] = "Image cannot be uploaded "; SessionOperator::setInputErrors($error); HelperOperator::redirectTo("../views/create_auction_view.php"); } // Get item category and condition id $ids = QueryOperator::getItemRelatedIds(addslashes($new_auction["itemCategory"]), $new_auction["itemCondition"]);