[75f74d9] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | session_start();
|
---|
| 4 |
|
---|
| 5 | // Check if user is logged in
|
---|
| 6 | if (!isset($_SESSION['userid'])) {
|
---|
| 7 | header("Location: ./Sign&Log.php");
|
---|
| 8 | exit;
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 | require './connect.php';
|
---|
| 12 |
|
---|
| 13 | // check if was or is still a member
|
---|
| 14 | $sql = "SELECT users.*, member.* FROM users INNER JOIN member ON member.memberid = users.userid WHERE memberid = :userid";
|
---|
| 15 | $stmt = $conn->prepare($sql);
|
---|
| 16 | $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
| 17 | $stmt->execute();
|
---|
| 18 | $res = $stmt->fetch(PDO::FETCH_ASSOC);
|
---|
| 19 |
|
---|
| 20 | if ($_SERVER['REQUEST_METHOD'] === 'POST' && $stmt->rowCount() >= 1) {
|
---|
| 21 |
|
---|
| 22 | $cur = date('Y-m-d', strtotime('+30 days'));
|
---|
| 23 | $status = 'Active';
|
---|
| 24 |
|
---|
| 25 | $sql = "UPDATE member SET membership_status = :membership_status, expired_date =:expired_date WHERE userid = :userid";
|
---|
| 26 | $stmt = $conn->prepare($sql);
|
---|
| 27 | $stmt->bindParam(':membership_status', $status, PDO::PARAM_STR);
|
---|
| 28 | $stmt->bindParam(':expired_date', $cur, PDO::PARAM_STR);
|
---|
| 29 | $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
| 30 | $stmt->execute();
|
---|
| 31 |
|
---|
| 32 | header('location: ./Profile.php');
|
---|
| 33 | die();
|
---|
| 34 | }
|
---|
| 35 | else if($_SERVER['REQUEST_METHOD'] === 'POST' && $stmt->rowCount() <= 0) {
|
---|
| 36 |
|
---|
| 37 | $cur = date('Y-m-d', strtotime('+30 days'));
|
---|
| 38 | $status = 'Active';
|
---|
| 39 |
|
---|
| 40 | $sql = "INSERT INTO member (membership_status, expired_date, userid) VALUES (:membership_status, :expired_date, :userid)";
|
---|
| 41 | $stmt = $conn->prepare($sql);
|
---|
| 42 | $stmt->bindParam(':membership_status', $status, PDO::PARAM_STR);
|
---|
| 43 | $stmt->bindParam(':expired_date', $cur, PDO::PARAM_STR);
|
---|
| 44 | $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
| 45 | $stmt->execute();
|
---|
| 46 |
|
---|
| 47 | header('location: ./Profile.php');
|
---|
| 48 | die();
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | $sql = "SELECT users.*, member.* FROM users INNER JOIN member ON member.memberid = users.userid WHERE memberid = :userid;";
|
---|
| 53 | $stmt = $conn->prepare($sql);
|
---|
| 54 | $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
| 55 | $stmt->execute();
|
---|
| 56 |
|
---|
| 57 | $new_membership_required = false;
|
---|
| 58 |
|
---|
| 59 | $users['expired_date'] = date('Y-m-d', strtotime('+30 days'));
|
---|
| 60 |
|
---|
| 61 | if($stmt->rowCount() == 0) {
|
---|
| 62 |
|
---|
| 63 | $users['membership_status'] = "Inactive";
|
---|
| 64 | $new_membership_required = true;
|
---|
| 65 | /*
|
---|
| 66 | $cur = date('Y-m-d', strtotime('+30 days'));
|
---|
| 67 | $sql = "INSERT INTO member (membership_status, expired_date, memberid) VALUES ('Active', :expired_date, :userid)";
|
---|
| 68 | $stmt = $conn->prepare($sql);
|
---|
| 69 | $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
| 70 | $stmt->bindParam(':expired_date', $cur, PDO::PARAM_STR);
|
---|
| 71 | $stmt->execute();
|
---|
| 72 | //header('location: ./Profile.php');
|
---|
| 73 | //die();
|
---|
| 74 | */
|
---|
| 75 | }
|
---|
| 76 | else {
|
---|
| 77 | $res = $stmt->fetch(PDO::FETCH_ASSOC);
|
---|
| 78 | $users['membership_status'] = $res['membership_status'];
|
---|
| 79 |
|
---|
| 80 | if($users['expired_date'] < date('Y-m-d')) {
|
---|
| 81 | $new_membership_required = true;
|
---|
| 82 | }
|
---|
| 83 | /*
|
---|
| 84 | $users = $stmt->fetch(PDO::FETCH_ASSOC);
|
---|
| 85 |
|
---|
| 86 | $sql = "UPDATE member SET expired_date = :expired_date, membership_status = :membership_status WHERE memberid = :userid";
|
---|
| 87 | $stmt = $conn->prepare($sql);
|
---|
| 88 | $stmt->bindParam(':expired_date', $users['expired_date'], PDO::PARAM_STR);
|
---|
| 89 | $stmt->bindParam(':membership_status', $users['membership_status'], PDO::PARAM_STR);
|
---|
| 90 | $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
| 91 | $stmt->execute();
|
---|
| 92 |
|
---|
| 93 | header('location: ./Profile.php');
|
---|
| 94 | die();
|
---|
| 95 | */
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | ?>
|
---|
| 99 |
|
---|
| 100 | <!DOCTYPE html>
|
---|
| 101 | <html lang="en">
|
---|
| 102 | <head>
|
---|
| 103 | <meta charset="UTF-8">
|
---|
| 104 | <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
---|
| 105 | <title>Renew Membership</title>
|
---|
| 106 | <link rel="stylesheet" href="./CSS/Renew.css">
|
---|
| 107 | </head>
|
---|
| 108 | <body>
|
---|
| 109 |
|
---|
| 110 | <form action="./Renew.php" method="POST">
|
---|
| 111 | <div class="renew-container">
|
---|
| 112 | <h2>Renew Membership</h2>
|
---|
| 113 | <p>Your current membership status: <strong><?php echo $users['membership_status']; ?></strong></p>
|
---|
| 114 | <?php if(!$new_membership_required) {?>
|
---|
| 115 | <p>Your membership is valid until: <strong><?php echo $users['expired_date']; ?></strong></p>
|
---|
| 116 | <?php } else {?>
|
---|
| 117 | <p>Your new membership will be valid until: <strong><?php echo $users['expired_date']; ?></strong></p>
|
---|
| 118 | <?php } ?>
|
---|
| 119 | <div class="button-group">
|
---|
| 120 | <a href="Profile.php" class="cancel-link">Cancel</a>
|
---|
| 121 | <button type='submit' class="renew-link">Renew Membership</button>
|
---|
| 122 | </div>
|
---|
| 123 | </div>
|
---|
| 124 | </from>
|
---|
| 125 |
|
---|
| 126 | </body>
|
---|
| 127 | </html> |
---|