-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rearranged controller classes and manage profile done.
- Loading branch information
1 parent
76d6e43
commit a21860b
Showing
11 changed files
with
204 additions
and
93 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
<?php | ||
|
||
class OrderContr extends Order { | ||
|
||
class OrderContr extends Dbhandler { | ||
private $orderID; | ||
private $orderItems; | ||
|
||
function __construct($orderID) { | ||
$this->orderID = $orderID; | ||
$this->updateOrderItems(); | ||
} | ||
|
||
// update order items related to this order | ||
protected function updateOrderItems() { | ||
$sql = "SELECT OrderItemID FROM OrderItems WHERE ORDERID = '$this->orderID'"; | ||
$result = $this->conn()->query($sql) or die($this->conn()->error); | ||
|
||
// create multiple OrderItem instances | ||
$this->orderItems = array(); | ||
while ($row = $result->fetch_assoc()) | ||
array_push($this->orderItems, new OrderItem($row["OrderItemID"])); | ||
} | ||
|
||
public function getOrderID() { return $this->orderID; } | ||
public function getOrderItems() { return $this->orderItems; } | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,40 @@ | ||
<?php | ||
|
||
class OrderItemContr extends OrderItem{ | ||
class OrderItemContr extends Dbhandler{ | ||
private $orderItemID; | ||
private $itemID; | ||
private $price; | ||
private $quantity; | ||
private $addedDateTime; | ||
|
||
function __construct($orderItemID) | ||
{ | ||
$this->orderItemID = $orderItemID; | ||
$this->initData(); | ||
} | ||
|
||
protected function initData() { | ||
$sql = "SELECT * FROM OrderItems WHERE OrderItemID = $this->orderItemID"; | ||
$result = $this->conn()->query($sql) or die($this->conn()->error); | ||
$row = $result->fetch_assoc(); | ||
$this->itemID = $row["ItemID"]; | ||
$this->price = $row["Price"]; | ||
$this->quantity = $row["Quantity"]; | ||
$this->addedDateTime = $row["AddedDatetime"]; | ||
} | ||
|
||
protected function DeleteOrders() { | ||
$sql = "DELETE * FROM OrderItems WHERE OrderItemID = ?"; | ||
$stmt = $this->conn()->prepare($sql); | ||
$stmt->execute($this->orderItemID); | ||
|
||
mysqli_stmt_close($stmt); | ||
return $stmt; | ||
} | ||
|
||
public function GetOrderItemID() { return $this->orderItemID; } | ||
public function GetItemID() { return $this->itemID; } | ||
public function GetPrice() { return $this->price; } | ||
public function GetQuantity() { return $this->quantity; } | ||
public function GetAddedDateTime() { return $this->addedDateTime; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
class ProfileContr extends CommonUtil{ | ||
private $username; | ||
private $pwd; | ||
private $repeatPwd; | ||
private $email; | ||
private $memberID; | ||
|
||
public function __construct($username, $pwd, $repeatPwd, $email, $memberID) | ||
{ | ||
$this->username = $username; | ||
$this->pwd = $pwd; | ||
$this->repeatPwd = $repeatPwd; | ||
$this->email = $email; | ||
$this->memberID = $memberID; | ||
} | ||
|
||
private function setUserAccount($username, $pwd, $email, $memberID) { | ||
$hashedPwd = password_hash($pwd, PASSWORD_DEFAULT); | ||
$sql = "UPDATE Members SET Username = ?, Password=?, Email = ? where MemberID = ?;"; | ||
$stmt = $this->conn()->stmt_init(); | ||
if (!$stmt->prepare($sql)) { | ||
header("location: ../manage_profile.php?error=Statementfailed"); | ||
exit(); | ||
} | ||
|
||
$hashedPwd = password_hash($pwd, PASSWORD_DEFAULT); | ||
|
||
$stmt->bind_param("sssi", $username, $hashedPwd, $email, $memberID); | ||
$stmt->execute(); | ||
$stmt->close(); | ||
|
||
session_start(); | ||
/** @var Member $member */ | ||
$member = $_SESSION["Member"]; | ||
$member->setUsername($username); | ||
$member->setEmail($email); | ||
$_SESSION["Member"] = $member; | ||
} | ||
|
||
public function updateUserAccount() { | ||
if ($this->pwdNotMatch($this->pwd, $this->repeatPwd)) | ||
{ | ||
header("location: ../manage_profile.php?error=passwords_dont_match"); | ||
exit(); | ||
} | ||
else if ($this->emptyInput($this->username, $this->pwd, $this->repeatPwd, $this->email)) | ||
{ | ||
header("location: ../manage_profile.php?error=empty_input"); | ||
exit(); | ||
} | ||
|
||
$this->setUserAccount($this->username, $this->pwd, $this->email, $this->memberID); | ||
|
||
header("location: ../manage_profile.php?error=none"); | ||
exit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
include_once "class_autoloader.php"; | ||
|
||
if (isset($_POST["update"])) | ||
{ | ||
$username = $_POST["username"]; | ||
$pwd = $_POST["pwd"]; | ||
$repeatPwd = $_POST["repeat_pwd"]; | ||
$email = $_POST["email"]; | ||
$memberID = $_POST["id"]; | ||
|
||
$setAcc = new ProfileContr($username, $pwd, $repeatPwd, $email, $memberID); | ||
$setAcc->updateUserAccount(); | ||
} | ||
else | ||
{ | ||
header("location: ../manage_profile.php"); | ||
exit(); | ||
} |
Oops, something went wrong.