diff --git a/controllers/AdminController.php b/controllers/AdminController.php index ba67358..febbd07 100755 --- a/controllers/AdminController.php +++ b/controllers/AdminController.php @@ -98,6 +98,12 @@ static public function handleEditUser($app, $twig, $username) { $temppassword = $user->resetPassword(); $successmessage = "Password for $username reset to '$temppassword'."; } + + if (isset($_POST['renewmembership'])) { + $user->renewMembership(); + $nextExpiry = date("Y-m-d", strtotime($user->expiry)); + $successmessage = "Membership renewed until $nextExpiry."; + } if (isset($_POST['update'])) { $user->displayname = $_POST["displayname"]; diff --git a/model/User.php b/model/User.php index 4e9ba2c..8f1ab4f 100755 --- a/model/User.php +++ b/model/User.php @@ -177,7 +177,7 @@ public function save() { global $conf; if (self::get($this->username) == null) { - //create new user (POST) + //create new user (POST) $details = get_object_vars($this); $user = $_SESSION['username']; @@ -190,6 +190,17 @@ public function save() { if ($response->headers['Status'] != "200 OK") { return false; } else { + + /* There is a bug in the API's use of computeExpiry. The + * subroutine itself works and is passing unit tests but + * somewhere in the user creation process the expiry date is + * getting decremented by one day. So call renewMembership + * here to compensate for that until the bug is fixed. + */ + // TODO: Fix the API's createUser computeExpiry bug + + $this->renewMembership(); + return true; } } else { @@ -212,10 +223,36 @@ public function save() { } } + public function renewMembership() { + $this->expiry = $this->computeExpiry(); + $this->paid = "TRUE"; + return $this->save(); + } + public function isAdmin() { return $this->isAdmin; } + // Maybe this could be done in the API + public function computeExpiry() { + $now = time(); + $thisYear = date("Y", $now); + $nextYear = $thisYear + 1; + + $newYearsDay = mktime(0, 0, 0, 1, 1, $thisYear); + $hogmanay = mktime(0, 0, 0, 12, 31, $thisYear); + $threshold = strtotime("last Friday of May $thisYear"); + + $nextExpiryString = 'first Friday of October'; + + if ($now >= $newYearsDay and $now < $threshold) { + $nextExpiryString .= " $thisYear"; + } else { + $nextExpiryString .= " $nextYear"; + } + + return $nextExpiryString; + } } diff --git a/views/admin/editUser.html b/views/admin/editUser.html index 2ef5667..33d4e64 100755 --- a/views/admin/editUser.html +++ b/views/admin/editUser.html @@ -72,6 +72,14 @@ {{ user.status }} + {{ user.status == 'Expired' or user.status == 'Expiring' ? " +