@@ -18,77 +18,77 @@ |
||
| 18 | 18 | |
| 19 | 19 | class PageExpandedRequestList extends InternalPageBase |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Main function for this page, when no specific actions are called. |
|
| 23 | - * @return void |
|
| 24 | - * @todo This is very similar to the PageMain code, we could probably generalise this somehow |
|
| 25 | - */ |
|
| 26 | - protected function main() |
|
| 27 | - { |
|
| 28 | - $config = $this->getSiteConfiguration(); |
|
| 21 | + /** |
|
| 22 | + * Main function for this page, when no specific actions are called. |
|
| 23 | + * @return void |
|
| 24 | + * @todo This is very similar to the PageMain code, we could probably generalise this somehow |
|
| 25 | + */ |
|
| 26 | + protected function main() |
|
| 27 | + { |
|
| 28 | + $config = $this->getSiteConfiguration(); |
|
| 29 | 29 | |
| 30 | - $requestedStatus = WebRequest::getString('status'); |
|
| 31 | - $requestStates = $config->getRequestStates(); |
|
| 30 | + $requestedStatus = WebRequest::getString('status'); |
|
| 31 | + $requestStates = $config->getRequestStates(); |
|
| 32 | 32 | |
| 33 | - if ($requestedStatus !== null && isset($requestStates[$requestedStatus])) { |
|
| 33 | + if ($requestedStatus !== null && isset($requestStates[$requestedStatus])) { |
|
| 34 | 34 | |
| 35 | - $this->assignCSRFToken(); |
|
| 35 | + $this->assignCSRFToken(); |
|
| 36 | 36 | |
| 37 | - $database = $this->getDatabase(); |
|
| 37 | + $database = $this->getDatabase(); |
|
| 38 | 38 | |
| 39 | - if ($config->getEmailConfirmationEnabled()) { |
|
| 40 | - $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 41 | - $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 42 | - } |
|
| 43 | - else { |
|
| 44 | - $query = "SELECT * FROM request WHERE status = :type;"; |
|
| 45 | - $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
|
| 46 | - } |
|
| 39 | + if ($config->getEmailConfirmationEnabled()) { |
|
| 40 | + $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 41 | + $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 42 | + } |
|
| 43 | + else { |
|
| 44 | + $query = "SELECT * FROM request WHERE status = :type;"; |
|
| 45 | + $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - $statement = $database->prepare($query); |
|
| 48 | + $statement = $database->prepare($query); |
|
| 49 | 49 | |
| 50 | - $totalRequestsStatement = $database->prepare($totalQuery); |
|
| 50 | + $totalRequestsStatement = $database->prepare($totalQuery); |
|
| 51 | 51 | |
| 52 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 52 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 53 | 53 | |
| 54 | - $type = $requestedStatus; |
|
| 54 | + $type = $requestedStatus; |
|
| 55 | 55 | |
| 56 | - $statement->bindValue(":type", $type); |
|
| 57 | - $statement->execute(); |
|
| 56 | + $statement->bindValue(":type", $type); |
|
| 57 | + $statement->execute(); |
|
| 58 | 58 | |
| 59 | - $requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class); |
|
| 59 | + $requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class); |
|
| 60 | 60 | |
| 61 | - /** @var Request $req */ |
|
| 62 | - foreach ($requests as $req) { |
|
| 63 | - $req->setDatabase($database); |
|
| 64 | - } |
|
| 61 | + /** @var Request $req */ |
|
| 62 | + foreach ($requests as $req) { |
|
| 63 | + $req->setDatabase($database); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - $this->assign('requests', $requests); |
|
| 67 | - $this->assign('header', $type); |
|
| 66 | + $this->assign('requests', $requests); |
|
| 67 | + $this->assign('header', $type); |
|
| 68 | 68 | |
| 69 | - $totalRequestsStatement->bindValue(':type', $type); |
|
| 70 | - $totalRequestsStatement->execute(); |
|
| 71 | - $totalRequests = $totalRequestsStatement->fetchColumn(); |
|
| 72 | - $totalRequestsStatement->closeCursor(); |
|
| 73 | - $this->assign('totalRequests', $totalRequests); |
|
| 69 | + $totalRequestsStatement->bindValue(':type', $type); |
|
| 70 | + $totalRequestsStatement->execute(); |
|
| 71 | + $totalRequests = $totalRequestsStatement->fetchColumn(); |
|
| 72 | + $totalRequestsStatement->closeCursor(); |
|
| 73 | + $this->assign('totalRequests', $totalRequests); |
|
| 74 | 74 | |
| 75 | - $userIds = array_map( |
|
| 76 | - function(Request $entry) { |
|
| 77 | - return $entry->getReserved(); |
|
| 78 | - }, |
|
| 79 | - $requests |
|
| 80 | - ); |
|
| 75 | + $userIds = array_map( |
|
| 76 | + function(Request $entry) { |
|
| 77 | + return $entry->getReserved(); |
|
| 78 | + }, |
|
| 79 | + $requests |
|
| 80 | + ); |
|
| 81 | 81 | |
| 82 | - $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchColumn('username'); |
|
| 83 | - $this->assign('userlist', $userList); |
|
| 82 | + $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchColumn('username'); |
|
| 83 | + $this->assign('userlist', $userList); |
|
| 84 | 84 | |
| 85 | - $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
| 85 | + $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
| 86 | 86 | |
| 87 | - $currentUser = User::getCurrent($database); |
|
| 88 | - $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 89 | - $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
| 87 | + $currentUser = User::getCurrent($database); |
|
| 88 | + $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 89 | + $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
| 90 | 90 | |
| 91 | - $this->setTemplate('mainpage/expandedrequestlist.tpl'); |
|
| 92 | - } |
|
| 93 | - } |
|
| 91 | + $this->setTemplate('mainpage/expandedrequestlist.tpl'); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | 94 | } |
@@ -19,79 +19,79 @@ |
||
| 19 | 19 | |
| 20 | 20 | class PageBreakReservation extends RequestActionBase |
| 21 | 21 | { |
| 22 | - protected function main() |
|
| 23 | - { |
|
| 24 | - $this->checkPosted(); |
|
| 25 | - $database = $this->getDatabase(); |
|
| 26 | - $request = $this->getRequest($database); |
|
| 22 | + protected function main() |
|
| 23 | + { |
|
| 24 | + $this->checkPosted(); |
|
| 25 | + $database = $this->getDatabase(); |
|
| 26 | + $request = $this->getRequest($database); |
|
| 27 | 27 | |
| 28 | - if ($request->getReserved() === null) { |
|
| 29 | - throw new ApplicationLogicException('Request is not reserved!'); |
|
| 30 | - } |
|
| 28 | + if ($request->getReserved() === null) { |
|
| 29 | + throw new ApplicationLogicException('Request is not reserved!'); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $currentUser = User::getCurrent($database); |
|
| 32 | + $currentUser = User::getCurrent($database); |
|
| 33 | 33 | |
| 34 | - if ($currentUser->getId() === $request->getReserved()) { |
|
| 35 | - $this->doUnreserve($request, $database); |
|
| 36 | - } |
|
| 37 | - else { |
|
| 38 | - // not the same user! |
|
| 39 | - if ($this->barrierTest('force', $currentUser)) { |
|
| 40 | - $this->doBreakReserve($request, $database); |
|
| 41 | - } |
|
| 42 | - else { |
|
| 43 | - throw new AccessDeniedException($this->getSecurityManager()); |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - } |
|
| 34 | + if ($currentUser->getId() === $request->getReserved()) { |
|
| 35 | + $this->doUnreserve($request, $database); |
|
| 36 | + } |
|
| 37 | + else { |
|
| 38 | + // not the same user! |
|
| 39 | + if ($this->barrierTest('force', $currentUser)) { |
|
| 40 | + $this->doBreakReserve($request, $database); |
|
| 41 | + } |
|
| 42 | + else { |
|
| 43 | + throw new AccessDeniedException($this->getSecurityManager()); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param Request $request |
|
| 50 | - * @param PdoDatabase $database |
|
| 51 | - * |
|
| 52 | - * @throws Exception |
|
| 53 | - */ |
|
| 54 | - protected function doUnreserve(Request $request, PdoDatabase $database) |
|
| 55 | - { |
|
| 56 | - // same user! we allow people to unreserve their own stuff |
|
| 57 | - $request->setReserved(null); |
|
| 58 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 59 | - $request->save(); |
|
| 48 | + /** |
|
| 49 | + * @param Request $request |
|
| 50 | + * @param PdoDatabase $database |
|
| 51 | + * |
|
| 52 | + * @throws Exception |
|
| 53 | + */ |
|
| 54 | + protected function doUnreserve(Request $request, PdoDatabase $database) |
|
| 55 | + { |
|
| 56 | + // same user! we allow people to unreserve their own stuff |
|
| 57 | + $request->setReserved(null); |
|
| 58 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 59 | + $request->save(); |
|
| 60 | 60 | |
| 61 | - Logger::unreserve($database, $request); |
|
| 62 | - $this->getNotificationHelper()->requestUnreserved($request); |
|
| 61 | + Logger::unreserve($database, $request); |
|
| 62 | + $this->getNotificationHelper()->requestUnreserved($request); |
|
| 63 | 63 | |
| 64 | - // Redirect home! |
|
| 65 | - $this->redirect(); |
|
| 66 | - } |
|
| 64 | + // Redirect home! |
|
| 65 | + $this->redirect(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @param Request $request |
|
| 70 | - * @param PdoDatabase $database |
|
| 71 | - * |
|
| 72 | - * @throws Exception |
|
| 73 | - */ |
|
| 74 | - protected function doBreakReserve(Request $request, PdoDatabase $database) |
|
| 75 | - { |
|
| 76 | - if (!WebRequest::postBoolean("confirm")) { |
|
| 77 | - $this->assignCSRFToken(); |
|
| 68 | + /** |
|
| 69 | + * @param Request $request |
|
| 70 | + * @param PdoDatabase $database |
|
| 71 | + * |
|
| 72 | + * @throws Exception |
|
| 73 | + */ |
|
| 74 | + protected function doBreakReserve(Request $request, PdoDatabase $database) |
|
| 75 | + { |
|
| 76 | + if (!WebRequest::postBoolean("confirm")) { |
|
| 77 | + $this->assignCSRFToken(); |
|
| 78 | 78 | |
| 79 | - $this->assign("request", $request->getId()); |
|
| 80 | - $this->assign("reservedUser", User::getById($request->getReserved(), $database)); |
|
| 81 | - $this->assign("updateversion", WebRequest::postInt('updateversion')); |
|
| 79 | + $this->assign("request", $request->getId()); |
|
| 80 | + $this->assign("reservedUser", User::getById($request->getReserved(), $database)); |
|
| 81 | + $this->assign("updateversion", WebRequest::postInt('updateversion')); |
|
| 82 | 82 | |
| 83 | - $this->setTemplate("confirmations/breakreserve.tpl"); |
|
| 84 | - } |
|
| 85 | - else { |
|
| 86 | - $request->setReserved(null); |
|
| 87 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 88 | - $request->save(); |
|
| 83 | + $this->setTemplate("confirmations/breakreserve.tpl"); |
|
| 84 | + } |
|
| 85 | + else { |
|
| 86 | + $request->setReserved(null); |
|
| 87 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 88 | + $request->save(); |
|
| 89 | 89 | |
| 90 | - Logger::breakReserve($database, $request); |
|
| 91 | - $this->getNotificationHelper()->requestReserveBroken($request); |
|
| 90 | + Logger::breakReserve($database, $request); |
|
| 91 | + $this->getNotificationHelper()->requestReserveBroken($request); |
|
| 92 | 92 | |
| 93 | - // Redirect home! |
|
| 94 | - $this->redirect(); |
|
| 95 | - } |
|
| 96 | - } |
|
| 93 | + // Redirect home! |
|
| 94 | + $this->redirect(); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -15,51 +15,51 @@ |
||
| 15 | 15 | |
| 16 | 16 | class PageComment extends RequestActionBase |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Main function for this page, when no specific actions are called. |
|
| 20 | - * @return void |
|
| 21 | - */ |
|
| 22 | - protected function main() |
|
| 23 | - { |
|
| 24 | - $this->checkPosted(); |
|
| 25 | - $database = $this->getDatabase(); |
|
| 26 | - $request = $this->getRequest($database); |
|
| 18 | + /** |
|
| 19 | + * Main function for this page, when no specific actions are called. |
|
| 20 | + * @return void |
|
| 21 | + */ |
|
| 22 | + protected function main() |
|
| 23 | + { |
|
| 24 | + $this->checkPosted(); |
|
| 25 | + $database = $this->getDatabase(); |
|
| 26 | + $request = $this->getRequest($database); |
|
| 27 | 27 | |
| 28 | - $commentText = WebRequest::postString('comment'); |
|
| 29 | - if ($commentText === false || $commentText == '') { |
|
| 30 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 28 | + $commentText = WebRequest::postString('comment'); |
|
| 29 | + if ($commentText === false || $commentText == '') { |
|
| 30 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 31 | 31 | |
| 32 | - return; |
|
| 33 | - } |
|
| 32 | + return; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - //Look for and detect IPv4/IPv6 addresses in comment text, and warn the commenter. |
|
| 36 | - $ipv4Regex = '/\b' . RegexConstants::IPV4 . '\b/'; |
|
| 37 | - $ipv6Regex = '/\b' . RegexConstants::IPV6 . '\b/'; |
|
| 35 | + //Look for and detect IPv4/IPv6 addresses in comment text, and warn the commenter. |
|
| 36 | + $ipv4Regex = '/\b' . RegexConstants::IPV4 . '\b/'; |
|
| 37 | + $ipv6Regex = '/\b' . RegexConstants::IPV6 . '\b/'; |
|
| 38 | 38 | |
| 39 | - $overridePolicy = WebRequest::postBoolean('privpol-check-override'); |
|
| 39 | + $overridePolicy = WebRequest::postBoolean('privpol-check-override'); |
|
| 40 | 40 | |
| 41 | - if ((preg_match($ipv4Regex, $commentText) || preg_match($ipv6Regex, $commentText)) && !$overridePolicy) { |
|
| 42 | - $this->assignCSRFToken(); |
|
| 43 | - $this->assign("request", $request); |
|
| 44 | - $this->assign("comment", $commentText); |
|
| 45 | - $this->setTemplate("privpol-warning.tpl"); |
|
| 41 | + if ((preg_match($ipv4Regex, $commentText) || preg_match($ipv6Regex, $commentText)) && !$overridePolicy) { |
|
| 42 | + $this->assignCSRFToken(); |
|
| 43 | + $this->assign("request", $request); |
|
| 44 | + $this->assign("comment", $commentText); |
|
| 45 | + $this->setTemplate("privpol-warning.tpl"); |
|
| 46 | 46 | |
| 47 | - return; |
|
| 48 | - } |
|
| 47 | + return; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - $visibility = WebRequest::postBoolean('adminOnly') ? 'admin' : 'user'; |
|
| 50 | + $visibility = WebRequest::postBoolean('adminOnly') ? 'admin' : 'user'; |
|
| 51 | 51 | |
| 52 | - $comment = new Comment(); |
|
| 53 | - $comment->setDatabase($database); |
|
| 52 | + $comment = new Comment(); |
|
| 53 | + $comment->setDatabase($database); |
|
| 54 | 54 | |
| 55 | - $comment->setRequest($request->getId()); |
|
| 56 | - $comment->setVisibility($visibility); |
|
| 57 | - $comment->setUser(User::getCurrent($database)->getId()); |
|
| 58 | - $comment->setComment($commentText); |
|
| 55 | + $comment->setRequest($request->getId()); |
|
| 56 | + $comment->setVisibility($visibility); |
|
| 57 | + $comment->setUser(User::getCurrent($database)->getId()); |
|
| 58 | + $comment->setComment($commentText); |
|
| 59 | 59 | |
| 60 | - $comment->save(); |
|
| 60 | + $comment->save(); |
|
| 61 | 61 | |
| 62 | - $this->getNotificationHelper()->commentCreated($comment, $request); |
|
| 63 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 64 | - } |
|
| 62 | + $this->getNotificationHelper()->commentCreated($comment, $request); |
|
| 63 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -17,58 +17,58 @@ |
||
| 17 | 17 | |
| 18 | 18 | class PageReservation extends RequestActionBase |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Main function for this page, when no specific actions are called. |
|
| 22 | - * @throws ApplicationLogicException |
|
| 23 | - */ |
|
| 24 | - protected function main() |
|
| 25 | - { |
|
| 26 | - $this->checkPosted(); |
|
| 27 | - $database = $this->getDatabase(); |
|
| 28 | - $request = $this->getRequest($database); |
|
| 20 | + /** |
|
| 21 | + * Main function for this page, when no specific actions are called. |
|
| 22 | + * @throws ApplicationLogicException |
|
| 23 | + */ |
|
| 24 | + protected function main() |
|
| 25 | + { |
|
| 26 | + $this->checkPosted(); |
|
| 27 | + $database = $this->getDatabase(); |
|
| 28 | + $request = $this->getRequest($database); |
|
| 29 | 29 | |
| 30 | - $closureDate = $request->getClosureDate(); |
|
| 30 | + $closureDate = $request->getClosureDate(); |
|
| 31 | 31 | |
| 32 | - $date = new DateTime(); |
|
| 33 | - $date->modify("-7 days"); |
|
| 34 | - $oneweek = $date->format("Y-m-d H:i:s"); |
|
| 32 | + $date = new DateTime(); |
|
| 33 | + $date->modify("-7 days"); |
|
| 34 | + $oneweek = $date->format("Y-m-d H:i:s"); |
|
| 35 | 35 | |
| 36 | - $currentUser = User::getCurrent($database); |
|
| 37 | - if ($request->getStatus() == "Closed" && $closureDate < $oneweek) { |
|
| 38 | - if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
| 39 | - throw new ApplicationLogicException( |
|
| 40 | - "You are not allowed to reserve a request that has been closed for over a week."); |
|
| 41 | - } |
|
| 42 | - } |
|
| 36 | + $currentUser = User::getCurrent($database); |
|
| 37 | + if ($request->getStatus() == "Closed" && $closureDate < $oneweek) { |
|
| 38 | + if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
| 39 | + throw new ApplicationLogicException( |
|
| 40 | + "You are not allowed to reserve a request that has been closed for over a week."); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - if ($request->getReserved() !== null && $request->getReserved() != $currentUser->getId()) { |
|
| 45 | - throw new ApplicationLogicException("Request is already reserved!"); |
|
| 46 | - } |
|
| 44 | + if ($request->getReserved() !== null && $request->getReserved() != $currentUser->getId()) { |
|
| 45 | + throw new ApplicationLogicException("Request is already reserved!"); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - if ($request->getReserved() === null) { |
|
| 49 | - // Check the number of requests a user has reserved already |
|
| 50 | - $doubleReserveCountQuery = $database->prepare("SELECT COUNT(*) FROM request WHERE reserved = :userid;"); |
|
| 51 | - $doubleReserveCountQuery->bindValue(":userid", $currentUser->getId()); |
|
| 52 | - $doubleReserveCountQuery->execute(); |
|
| 53 | - $doubleReserveCount = $doubleReserveCountQuery->fetchColumn(); |
|
| 54 | - $doubleReserveCountQuery->closeCursor(); |
|
| 48 | + if ($request->getReserved() === null) { |
|
| 49 | + // Check the number of requests a user has reserved already |
|
| 50 | + $doubleReserveCountQuery = $database->prepare("SELECT COUNT(*) FROM request WHERE reserved = :userid;"); |
|
| 51 | + $doubleReserveCountQuery->bindValue(":userid", $currentUser->getId()); |
|
| 52 | + $doubleReserveCountQuery->execute(); |
|
| 53 | + $doubleReserveCount = $doubleReserveCountQuery->fetchColumn(); |
|
| 54 | + $doubleReserveCountQuery->closeCursor(); |
|
| 55 | 55 | |
| 56 | - // User already has at least one reserved. |
|
| 57 | - if ($doubleReserveCount != 0) { |
|
| 58 | - SessionAlert::warning("You have multiple requests reserved!"); |
|
| 59 | - } |
|
| 56 | + // User already has at least one reserved. |
|
| 57 | + if ($doubleReserveCount != 0) { |
|
| 58 | + SessionAlert::warning("You have multiple requests reserved!"); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $request->setReserved($currentUser->getId()); |
|
| 62 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 63 | - $request->save(); |
|
| 61 | + $request->setReserved($currentUser->getId()); |
|
| 62 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 63 | + $request->save(); |
|
| 64 | 64 | |
| 65 | - Logger::reserve($database, $request); |
|
| 65 | + Logger::reserve($database, $request); |
|
| 66 | 66 | |
| 67 | - $this->getNotificationHelper()->requestReserved($request); |
|
| 67 | + $this->getNotificationHelper()->requestReserved($request); |
|
| 68 | 68 | |
| 69 | - SessionAlert::success("Reserved request {$request->getId()}."); |
|
| 70 | - } |
|
| 69 | + SessionAlert::success("Reserved request {$request->getId()}."); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 73 | - } |
|
| 72 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 73 | + } |
|
| 74 | 74 | } |
@@ -20,240 +20,240 @@ |
||
| 20 | 20 | |
| 21 | 21 | class PageCloseRequest extends RequestActionBase |
| 22 | 22 | { |
| 23 | - protected function main() |
|
| 24 | - { |
|
| 25 | - $this->processClose(); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Main function for this page, when no specific actions are called. |
|
| 30 | - * @throws ApplicationLogicException |
|
| 31 | - */ |
|
| 32 | - final protected function processClose() |
|
| 33 | - { |
|
| 34 | - $this->checkPosted(); |
|
| 35 | - $database = $this->getDatabase(); |
|
| 36 | - |
|
| 37 | - $currentUser = User::getCurrent($database); |
|
| 38 | - $template = $this->getTemplate($database); |
|
| 39 | - $request = $this->getRequest($database); |
|
| 40 | - |
|
| 41 | - if ($request->getStatus() === 'Closed') { |
|
| 42 | - throw new ApplicationLogicException('Request is already closed'); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if ($this->confirmEmailAlreadySent($request, $template)) { |
|
| 46 | - return; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if ($this->confirmReserveOverride($request, $template, $currentUser, $database)) { |
|
| 50 | - return; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if ($this->confirmAccountCreated($request, $template)) { |
|
| 54 | - return; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - // I think we're good here... |
|
| 58 | - $request->setStatus('Closed'); |
|
| 59 | - $request->setReserved(null); |
|
| 60 | - |
|
| 61 | - Logger::closeRequest($database, $request, $template->getId(), null); |
|
| 62 | - |
|
| 63 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 64 | - $request->save(); |
|
| 65 | - |
|
| 66 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
| 67 | - // be rolled back. |
|
| 68 | - |
|
| 69 | - $this->getNotificationHelper()->requestClosed($request, $template->getName()); |
|
| 70 | - SessionAlert::success("Request {$request->getId()} has been closed"); |
|
| 71 | - |
|
| 72 | - $this->sendMail($request, $template->getText(), $currentUser, false); |
|
| 73 | - |
|
| 74 | - $this->redirect(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param PdoDatabase $database |
|
| 79 | - * |
|
| 80 | - * @return EmailTemplate |
|
| 81 | - * @throws ApplicationLogicException |
|
| 82 | - */ |
|
| 83 | - protected function getTemplate(PdoDatabase $database) |
|
| 84 | - { |
|
| 85 | - $templateId = WebRequest::postInt('template'); |
|
| 86 | - if ($templateId === null) { |
|
| 87 | - throw new ApplicationLogicException('No template specified'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** @var EmailTemplate $template */ |
|
| 91 | - $template = EmailTemplate::getById($templateId, $database); |
|
| 92 | - if ($template === false || !$template->getActive()) { |
|
| 93 | - throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return $template; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @param Request $request |
|
| 101 | - * @param EmailTemplate $template |
|
| 102 | - * |
|
| 103 | - * @return bool |
|
| 104 | - */ |
|
| 105 | - protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 106 | - { |
|
| 107 | - if ($this->checkEmailAlreadySent($request)) { |
|
| 108 | - $this->showConfirmation($request, $template, 'close-confirmations/email-sent.tpl'); |
|
| 109 | - |
|
| 110 | - return true; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return false; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - protected function checkEmailAlreadySent(Request $request) |
|
| 117 | - { |
|
| 118 | - if ($request->getEmailSent() && !WebRequest::postBoolean('emailSentOverride')) { |
|
| 119 | - return true; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return false; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - protected function checkReserveOverride(Request $request, User $currentUser) |
|
| 126 | - { |
|
| 127 | - $reservationId = $request->getReserved(); |
|
| 128 | - |
|
| 129 | - if ($reservationId !== 0 && $reservationId !== null) { |
|
| 130 | - if (!WebRequest::postBoolean('reserveOverride')) { |
|
| 131 | - if ($currentUser->getId() !== $reservationId) { |
|
| 132 | - return true; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return false; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param Request $request |
|
| 142 | - * @param EmailTemplate $template |
|
| 143 | - * @param User $currentUser |
|
| 144 | - * @param PdoDatabase $database |
|
| 145 | - * |
|
| 146 | - * @return bool |
|
| 147 | - */ |
|
| 148 | - protected function confirmReserveOverride( |
|
| 149 | - Request $request, |
|
| 150 | - EmailTemplate $template, |
|
| 151 | - User $currentUser, |
|
| 152 | - PdoDatabase $database |
|
| 153 | - ) { |
|
| 154 | - if ($this->checkReserveOverride($request, $currentUser)) { |
|
| 155 | - $this->assign('reserveUser', User::getById($request->getReserved(), $database)->getUsername()); |
|
| 156 | - $this->showConfirmation($request, $template, 'close-confirmations/reserve-override.tpl'); |
|
| 157 | - |
|
| 158 | - return true; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @param Request $request |
|
| 166 | - * @param EmailTemplate $template |
|
| 167 | - * |
|
| 168 | - * @return bool |
|
| 169 | - * @throws \Waca\Exceptions\CurlException |
|
| 170 | - */ |
|
| 171 | - protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 172 | - { |
|
| 173 | - if ($this->checkAccountCreated($request, $template)) { |
|
| 174 | - $this->showConfirmation($request, $template, 'close-confirmations/account-created.tpl'); |
|
| 175 | - |
|
| 176 | - return true; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return false; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - protected function checkAccountCreated(Request $request, EmailTemplate $template) |
|
| 183 | - { |
|
| 184 | - if ($template->getDefaultAction() === EmailTemplate::CREATED && !WebRequest::postBoolean('createOverride')) { |
|
| 185 | - $parameters = array( |
|
| 186 | - 'action' => 'query', |
|
| 187 | - 'list' => 'users', |
|
| 188 | - 'format' => 'php', |
|
| 189 | - 'ususers' => $request->getName(), |
|
| 190 | - ); |
|
| 191 | - |
|
| 192 | - $content = $this->getHttpHelper()->get($this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 193 | - $parameters); |
|
| 194 | - |
|
| 195 | - $apiResult = unserialize($content); |
|
| 196 | - $exists = !isset($apiResult['query']['users']['0']['missing']); |
|
| 197 | - |
|
| 198 | - if (!$exists) { |
|
| 199 | - return true; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - return false; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * @param Request $request |
|
| 208 | - * @param string $mailText |
|
| 209 | - * @param User $currentUser |
|
| 210 | - * @param boolean $ccMailingList |
|
| 211 | - */ |
|
| 212 | - protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
| 213 | - { |
|
| 214 | - $headers = array( |
|
| 215 | - 'X-ACC-Request' => $request->getId(), |
|
| 216 | - 'X-ACC-UserID' => $currentUser->getId(), |
|
| 217 | - ); |
|
| 218 | - |
|
| 219 | - if ($ccMailingList) { |
|
| 220 | - $headers['Cc'] = '[email protected]'; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $helper = $this->getEmailHelper(); |
|
| 224 | - |
|
| 225 | - $emailSig = $currentUser->getEmailSig(); |
|
| 226 | - if ($emailSig !== '' || $emailSig !== null) { |
|
| 227 | - $emailSig = "\n\n" . $emailSig; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $subject = "RE: [ACC #{$request->getId()}] English Wikipedia Account Request"; |
|
| 231 | - $content = $mailText . $emailSig; |
|
| 232 | - |
|
| 233 | - $helper->sendMail($request->getEmail(), $subject, $content, $headers); |
|
| 234 | - |
|
| 235 | - $request->setEmailSent(true); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @param Request $request |
|
| 240 | - * @param EmailTemplate $template |
|
| 241 | - * @param string $templateName |
|
| 242 | - * |
|
| 243 | - * @throws Exception |
|
| 244 | - * @return void |
|
| 245 | - */ |
|
| 246 | - protected function showConfirmation(Request $request, EmailTemplate $template, $templateName) |
|
| 247 | - { |
|
| 248 | - $this->assignCSRFToken(); |
|
| 249 | - |
|
| 250 | - $this->assign('request', $request->getId()); |
|
| 251 | - $this->assign('template', $template->getId()); |
|
| 252 | - |
|
| 253 | - $this->assign('emailSentOverride', WebRequest::postBoolean('emailSentOverride') ? 'true' : 'false'); |
|
| 254 | - $this->assign('reserveOverride', WebRequest::postBoolean('reserveOverride') ? 'true' : 'false'); |
|
| 255 | - $this->assign('createOverride', WebRequest::postBoolean('createOverride') ? 'true' : 'false'); |
|
| 256 | - |
|
| 257 | - $this->setTemplate($templateName); |
|
| 258 | - } |
|
| 23 | + protected function main() |
|
| 24 | + { |
|
| 25 | + $this->processClose(); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Main function for this page, when no specific actions are called. |
|
| 30 | + * @throws ApplicationLogicException |
|
| 31 | + */ |
|
| 32 | + final protected function processClose() |
|
| 33 | + { |
|
| 34 | + $this->checkPosted(); |
|
| 35 | + $database = $this->getDatabase(); |
|
| 36 | + |
|
| 37 | + $currentUser = User::getCurrent($database); |
|
| 38 | + $template = $this->getTemplate($database); |
|
| 39 | + $request = $this->getRequest($database); |
|
| 40 | + |
|
| 41 | + if ($request->getStatus() === 'Closed') { |
|
| 42 | + throw new ApplicationLogicException('Request is already closed'); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if ($this->confirmEmailAlreadySent($request, $template)) { |
|
| 46 | + return; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if ($this->confirmReserveOverride($request, $template, $currentUser, $database)) { |
|
| 50 | + return; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if ($this->confirmAccountCreated($request, $template)) { |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + // I think we're good here... |
|
| 58 | + $request->setStatus('Closed'); |
|
| 59 | + $request->setReserved(null); |
|
| 60 | + |
|
| 61 | + Logger::closeRequest($database, $request, $template->getId(), null); |
|
| 62 | + |
|
| 63 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 64 | + $request->save(); |
|
| 65 | + |
|
| 66 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
| 67 | + // be rolled back. |
|
| 68 | + |
|
| 69 | + $this->getNotificationHelper()->requestClosed($request, $template->getName()); |
|
| 70 | + SessionAlert::success("Request {$request->getId()} has been closed"); |
|
| 71 | + |
|
| 72 | + $this->sendMail($request, $template->getText(), $currentUser, false); |
|
| 73 | + |
|
| 74 | + $this->redirect(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param PdoDatabase $database |
|
| 79 | + * |
|
| 80 | + * @return EmailTemplate |
|
| 81 | + * @throws ApplicationLogicException |
|
| 82 | + */ |
|
| 83 | + protected function getTemplate(PdoDatabase $database) |
|
| 84 | + { |
|
| 85 | + $templateId = WebRequest::postInt('template'); |
|
| 86 | + if ($templateId === null) { |
|
| 87 | + throw new ApplicationLogicException('No template specified'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** @var EmailTemplate $template */ |
|
| 91 | + $template = EmailTemplate::getById($templateId, $database); |
|
| 92 | + if ($template === false || !$template->getActive()) { |
|
| 93 | + throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return $template; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @param Request $request |
|
| 101 | + * @param EmailTemplate $template |
|
| 102 | + * |
|
| 103 | + * @return bool |
|
| 104 | + */ |
|
| 105 | + protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 106 | + { |
|
| 107 | + if ($this->checkEmailAlreadySent($request)) { |
|
| 108 | + $this->showConfirmation($request, $template, 'close-confirmations/email-sent.tpl'); |
|
| 109 | + |
|
| 110 | + return true; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + protected function checkEmailAlreadySent(Request $request) |
|
| 117 | + { |
|
| 118 | + if ($request->getEmailSent() && !WebRequest::postBoolean('emailSentOverride')) { |
|
| 119 | + return true; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return false; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + protected function checkReserveOverride(Request $request, User $currentUser) |
|
| 126 | + { |
|
| 127 | + $reservationId = $request->getReserved(); |
|
| 128 | + |
|
| 129 | + if ($reservationId !== 0 && $reservationId !== null) { |
|
| 130 | + if (!WebRequest::postBoolean('reserveOverride')) { |
|
| 131 | + if ($currentUser->getId() !== $reservationId) { |
|
| 132 | + return true; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return false; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param Request $request |
|
| 142 | + * @param EmailTemplate $template |
|
| 143 | + * @param User $currentUser |
|
| 144 | + * @param PdoDatabase $database |
|
| 145 | + * |
|
| 146 | + * @return bool |
|
| 147 | + */ |
|
| 148 | + protected function confirmReserveOverride( |
|
| 149 | + Request $request, |
|
| 150 | + EmailTemplate $template, |
|
| 151 | + User $currentUser, |
|
| 152 | + PdoDatabase $database |
|
| 153 | + ) { |
|
| 154 | + if ($this->checkReserveOverride($request, $currentUser)) { |
|
| 155 | + $this->assign('reserveUser', User::getById($request->getReserved(), $database)->getUsername()); |
|
| 156 | + $this->showConfirmation($request, $template, 'close-confirmations/reserve-override.tpl'); |
|
| 157 | + |
|
| 158 | + return true; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @param Request $request |
|
| 166 | + * @param EmailTemplate $template |
|
| 167 | + * |
|
| 168 | + * @return bool |
|
| 169 | + * @throws \Waca\Exceptions\CurlException |
|
| 170 | + */ |
|
| 171 | + protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 172 | + { |
|
| 173 | + if ($this->checkAccountCreated($request, $template)) { |
|
| 174 | + $this->showConfirmation($request, $template, 'close-confirmations/account-created.tpl'); |
|
| 175 | + |
|
| 176 | + return true; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return false; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + protected function checkAccountCreated(Request $request, EmailTemplate $template) |
|
| 183 | + { |
|
| 184 | + if ($template->getDefaultAction() === EmailTemplate::CREATED && !WebRequest::postBoolean('createOverride')) { |
|
| 185 | + $parameters = array( |
|
| 186 | + 'action' => 'query', |
|
| 187 | + 'list' => 'users', |
|
| 188 | + 'format' => 'php', |
|
| 189 | + 'ususers' => $request->getName(), |
|
| 190 | + ); |
|
| 191 | + |
|
| 192 | + $content = $this->getHttpHelper()->get($this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 193 | + $parameters); |
|
| 194 | + |
|
| 195 | + $apiResult = unserialize($content); |
|
| 196 | + $exists = !isset($apiResult['query']['users']['0']['missing']); |
|
| 197 | + |
|
| 198 | + if (!$exists) { |
|
| 199 | + return true; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + return false; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * @param Request $request |
|
| 208 | + * @param string $mailText |
|
| 209 | + * @param User $currentUser |
|
| 210 | + * @param boolean $ccMailingList |
|
| 211 | + */ |
|
| 212 | + protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
| 213 | + { |
|
| 214 | + $headers = array( |
|
| 215 | + 'X-ACC-Request' => $request->getId(), |
|
| 216 | + 'X-ACC-UserID' => $currentUser->getId(), |
|
| 217 | + ); |
|
| 218 | + |
|
| 219 | + if ($ccMailingList) { |
|
| 220 | + $headers['Cc'] = '[email protected]'; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $helper = $this->getEmailHelper(); |
|
| 224 | + |
|
| 225 | + $emailSig = $currentUser->getEmailSig(); |
|
| 226 | + if ($emailSig !== '' || $emailSig !== null) { |
|
| 227 | + $emailSig = "\n\n" . $emailSig; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $subject = "RE: [ACC #{$request->getId()}] English Wikipedia Account Request"; |
|
| 231 | + $content = $mailText . $emailSig; |
|
| 232 | + |
|
| 233 | + $helper->sendMail($request->getEmail(), $subject, $content, $headers); |
|
| 234 | + |
|
| 235 | + $request->setEmailSent(true); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @param Request $request |
|
| 240 | + * @param EmailTemplate $template |
|
| 241 | + * @param string $templateName |
|
| 242 | + * |
|
| 243 | + * @throws Exception |
|
| 244 | + * @return void |
|
| 245 | + */ |
|
| 246 | + protected function showConfirmation(Request $request, EmailTemplate $template, $templateName) |
|
| 247 | + { |
|
| 248 | + $this->assignCSRFToken(); |
|
| 249 | + |
|
| 250 | + $this->assign('request', $request->getId()); |
|
| 251 | + $this->assign('template', $template->getId()); |
|
| 252 | + |
|
| 253 | + $this->assign('emailSentOverride', WebRequest::postBoolean('emailSentOverride') ? 'true' : 'false'); |
|
| 254 | + $this->assign('reserveOverride', WebRequest::postBoolean('reserveOverride') ? 'true' : 'false'); |
|
| 255 | + $this->assign('createOverride', WebRequest::postBoolean('createOverride') ? 'true' : 'false'); |
|
| 256 | + |
|
| 257 | + $this->setTemplate($templateName); |
|
| 258 | + } |
|
| 259 | 259 | } |
@@ -17,57 +17,57 @@ |
||
| 17 | 17 | |
| 18 | 18 | class PageDeferRequest extends RequestActionBase |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Main function for this page, when no specific actions are called. |
|
| 22 | - * @throws ApplicationLogicException |
|
| 23 | - */ |
|
| 24 | - protected function main() |
|
| 25 | - { |
|
| 26 | - $this->checkPosted(); |
|
| 27 | - $database = $this->getDatabase(); |
|
| 28 | - $request = $this->getRequest($database); |
|
| 29 | - $currentUser = User::getCurrent($database); |
|
| 20 | + /** |
|
| 21 | + * Main function for this page, when no specific actions are called. |
|
| 22 | + * @throws ApplicationLogicException |
|
| 23 | + */ |
|
| 24 | + protected function main() |
|
| 25 | + { |
|
| 26 | + $this->checkPosted(); |
|
| 27 | + $database = $this->getDatabase(); |
|
| 28 | + $request = $this->getRequest($database); |
|
| 29 | + $currentUser = User::getCurrent($database); |
|
| 30 | 30 | |
| 31 | - $target = WebRequest::postString('target'); |
|
| 32 | - $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 31 | + $target = WebRequest::postString('target'); |
|
| 32 | + $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 33 | 33 | |
| 34 | - if (!array_key_exists($target, $requestStates)) { |
|
| 35 | - throw new ApplicationLogicException('Defer target not valid'); |
|
| 36 | - } |
|
| 34 | + if (!array_key_exists($target, $requestStates)) { |
|
| 35 | + throw new ApplicationLogicException('Defer target not valid'); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - if ($request->getStatus() == $target) { |
|
| 39 | - SessionAlert::warning('This request is already in the specified queue.'); |
|
| 40 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 38 | + if ($request->getStatus() == $target) { |
|
| 39 | + SessionAlert::warning('This request is already in the specified queue.'); |
|
| 40 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 41 | 41 | |
| 42 | - return; |
|
| 43 | - } |
|
| 42 | + return; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - $closureDate = $request->getClosureDate(); |
|
| 46 | - $date = new DateTime(); |
|
| 47 | - $date->modify("-7 days"); |
|
| 48 | - $oneweek = $date->format("Y-m-d H:i:s"); |
|
| 45 | + $closureDate = $request->getClosureDate(); |
|
| 46 | + $date = new DateTime(); |
|
| 47 | + $date->modify("-7 days"); |
|
| 48 | + $oneweek = $date->format("Y-m-d H:i:s"); |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | - if ($request->getStatus() == "Closed" && $closureDate < $oneweek) { |
|
| 52 | - if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
| 53 | - throw new ApplicationLogicException( |
|
| 54 | - "You are not allowed to re-open a request that has been closed for over a week."); |
|
| 55 | - } |
|
| 56 | - } |
|
| 51 | + if ($request->getStatus() == "Closed" && $closureDate < $oneweek) { |
|
| 52 | + if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
| 53 | + throw new ApplicationLogicException( |
|
| 54 | + "You are not allowed to re-open a request that has been closed for over a week."); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $request->setReserved(null); |
|
| 59 | - $request->setStatus($target); |
|
| 60 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 61 | - $request->save(); |
|
| 58 | + $request->setReserved(null); |
|
| 59 | + $request->setStatus($target); |
|
| 60 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 61 | + $request->save(); |
|
| 62 | 62 | |
| 63 | - $deto = $requestStates[$target]['deferto']; |
|
| 64 | - $detolog = $requestStates[$target]['defertolog']; |
|
| 63 | + $deto = $requestStates[$target]['deferto']; |
|
| 64 | + $detolog = $requestStates[$target]['defertolog']; |
|
| 65 | 65 | |
| 66 | - Logger::deferRequest($database, $request, $detolog); |
|
| 66 | + Logger::deferRequest($database, $request, $detolog); |
|
| 67 | 67 | |
| 68 | - $this->getNotificationHelper()->requestDeferred($request); |
|
| 69 | - SessionAlert::success("Request {$request->getId()} deferred to {$deto}"); |
|
| 68 | + $this->getNotificationHelper()->requestDeferred($request); |
|
| 69 | + SessionAlert::success("Request {$request->getId()} deferred to {$deto}"); |
|
| 70 | 70 | |
| 71 | - $this->redirect(); |
|
| 72 | - } |
|
| 71 | + $this->redirect(); |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -23,264 +23,264 @@ |
||
| 23 | 23 | |
| 24 | 24 | class PageCustomClose extends PageCloseRequest |
| 25 | 25 | { |
| 26 | - use RequestData; |
|
| 27 | - |
|
| 28 | - protected function main() |
|
| 29 | - { |
|
| 30 | - $database = $this->getDatabase(); |
|
| 31 | - |
|
| 32 | - $request = $this->getRequest($database); |
|
| 33 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
| 34 | - |
|
| 35 | - if ($request->getStatus() === 'Closed') { |
|
| 36 | - throw new ApplicationLogicException('Request is already closed'); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // Dual-mode page |
|
| 40 | - if (WebRequest::wasPosted()) { |
|
| 41 | - $this->validateCSRFToken(); |
|
| 42 | - $this->doCustomClose($currentUser, $request, $database); |
|
| 43 | - |
|
| 44 | - $this->redirect(); |
|
| 45 | - } |
|
| 46 | - else { |
|
| 47 | - $this->assignCSRFToken(); |
|
| 48 | - $this->showCustomCloseForm($database, $request); |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @param $database |
|
| 54 | - * |
|
| 55 | - * @return Request |
|
| 56 | - * @throws ApplicationLogicException |
|
| 57 | - */ |
|
| 58 | - protected function getRequest(PdoDatabase $database) |
|
| 59 | - { |
|
| 60 | - $requestId = WebRequest::getInt('request'); |
|
| 61 | - if ($requestId === null) { |
|
| 62 | - throw new ApplicationLogicException('Request ID not found'); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** @var Request $request */ |
|
| 66 | - $request = Request::getById($requestId, $database); |
|
| 67 | - |
|
| 68 | - if ($request === false) { |
|
| 69 | - throw new ApplicationLogicException('Request not found'); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return $request; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param PdoDatabase $database |
|
| 77 | - * |
|
| 78 | - * @return EmailTemplate|null |
|
| 79 | - */ |
|
| 80 | - protected function getTemplate(PdoDatabase $database) |
|
| 81 | - { |
|
| 82 | - $templateId = WebRequest::getInt('template'); |
|
| 83 | - if ($templateId === null) { |
|
| 84 | - return null; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** @var EmailTemplate $template */ |
|
| 88 | - $template = EmailTemplate::getById($templateId, $database); |
|
| 89 | - if ($template === false || !$template->getActive()) { |
|
| 90 | - return null; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return $template; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @param $database |
|
| 98 | - * @param $request |
|
| 99 | - * |
|
| 100 | - * @throws Exception |
|
| 101 | - */ |
|
| 102 | - protected function showCustomCloseForm(PdoDatabase $database, Request $request) |
|
| 103 | - { |
|
| 104 | - $currentUser = User::getCurrent($database); |
|
| 105 | - $config = $this->getSiteConfiguration(); |
|
| 106 | - |
|
| 107 | - $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 108 | - if (!$allowedPrivateData) { |
|
| 109 | - // we probably shouldn't be showing the user this form if they're not allowed to access private data... |
|
| 110 | - throw new AccessDeniedException($this->getSecurityManager()); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $template = $this->getTemplate($database); |
|
| 114 | - |
|
| 115 | - // Preload data |
|
| 116 | - $this->assign('defaultAction', ''); |
|
| 117 | - $this->assign('preloadText', ''); |
|
| 118 | - $this->assign('preloadTitle', ''); |
|
| 119 | - |
|
| 120 | - if ($template !== null) { |
|
| 121 | - $this->assign('defaultAction', $template->getDefaultAction()); |
|
| 122 | - $this->assign('preloadText', $template->getText()); |
|
| 123 | - $this->assign('preloadTitle', $template->getName()); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // Static data |
|
| 127 | - $this->assign('requeststates', $config->getRequestStates()); |
|
| 128 | - |
|
| 129 | - // request data |
|
| 130 | - $this->assign('requestId', $request->getIp()); |
|
| 131 | - $this->assign('updateVersion', $request->getUpdateVersion()); |
|
| 132 | - $this->setupBasicData($request, $config); |
|
| 133 | - $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 134 | - $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database); |
|
| 135 | - |
|
| 136 | - // IP location |
|
| 137 | - $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 138 | - $this->assign('iplocation', $this->getLocationProvider()->getIpLocation($trustedIp)); |
|
| 139 | - |
|
| 140 | - // Confirmations |
|
| 141 | - $this->assign('confirmEmailAlreadySent', $this->checkEmailAlreadySent($request)); |
|
| 142 | - $this->assign('confirmReserveOverride', $this->checkReserveOverride($request, $currentUser)); |
|
| 143 | - |
|
| 144 | - $this->assign('canSkipCcMailingList', $this->barrierTest('skipCcMailingList', $currentUser)); |
|
| 145 | - |
|
| 146 | - // template |
|
| 147 | - $this->setTemplate('custom-close.tpl'); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @param User $currentUser |
|
| 152 | - * @param Request $request |
|
| 153 | - * @param PdoDatabase $database |
|
| 154 | - * |
|
| 155 | - * @throws ApplicationLogicException |
|
| 156 | - */ |
|
| 157 | - protected function doCustomClose(User $currentUser, Request $request, PdoDatabase $database) |
|
| 158 | - { |
|
| 159 | - $messageBody = WebRequest::postString('msgbody'); |
|
| 160 | - if ($messageBody === null || trim($messageBody) === '') { |
|
| 161 | - throw new ApplicationLogicException('Message body cannot be blank'); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - $ccMailingList = true; |
|
| 165 | - if ($this->barrierTest('skipCcMailingList', $currentUser)) { |
|
| 166 | - $ccMailingList = WebRequest::postBoolean('ccMailingList'); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - if ($request->getStatus() === 'Closed') { |
|
| 170 | - throw new ApplicationLogicException('Request is already closed'); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if (!(WebRequest::postBoolean('confirmEmailAlreadySent') |
|
| 174 | - && WebRequest::postBoolean('confirmReserveOverride')) |
|
| 175 | - ) { |
|
| 176 | - throw new ApplicationLogicException('Not all confirmations checked'); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $action = WebRequest::postString('action'); |
|
| 180 | - $availableRequestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 181 | - |
|
| 182 | - if ($action === EmailTemplate::CREATED || $action === EmailTemplate::NOT_CREATED) { |
|
| 183 | - // Close request |
|
| 184 | - $this->closeRequest($request, $database, $action, $messageBody); |
|
| 185 | - |
|
| 186 | - // Send the mail after the save, since save can be rolled back |
|
| 187 | - $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 188 | - } |
|
| 189 | - else { |
|
| 190 | - if (array_key_exists($action, $availableRequestStates)) { |
|
| 191 | - // Defer to other state |
|
| 192 | - $this->deferRequest($request, $database, $action, $availableRequestStates, $messageBody); |
|
| 193 | - |
|
| 194 | - // Send the mail after the save, since save can be rolled back |
|
| 195 | - $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 196 | - } |
|
| 197 | - else { |
|
| 198 | - $request->setReserved(null); |
|
| 199 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 200 | - $request->save(); |
|
| 201 | - |
|
| 202 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE |
|
| 203 | - // and be rolled back. |
|
| 204 | - |
|
| 205 | - // Send mail |
|
| 206 | - $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 207 | - |
|
| 208 | - Logger::sentMail($database, $request, $messageBody); |
|
| 209 | - Logger::unreserve($database, $request); |
|
| 210 | - |
|
| 211 | - $this->getNotificationHelper()->sentMail($request); |
|
| 212 | - SessionAlert::success("Sent mail to Request {$request->getId()}"); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * @param Request $request |
|
| 219 | - * @param PdoDatabase $database |
|
| 220 | - * @param string $action |
|
| 221 | - * @param string $messageBody |
|
| 222 | - * |
|
| 223 | - * @throws Exception |
|
| 224 | - * @throws OptimisticLockFailedException |
|
| 225 | - */ |
|
| 226 | - protected function closeRequest(Request $request, PdoDatabase $database, $action, $messageBody) |
|
| 227 | - { |
|
| 228 | - $request->setStatus('Closed'); |
|
| 229 | - $request->setReserved(null); |
|
| 230 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 231 | - $request->save(); |
|
| 232 | - |
|
| 233 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
| 234 | - // be rolled back. |
|
| 235 | - |
|
| 236 | - if ($action == EmailTemplate::CREATED) { |
|
| 237 | - $logCloseType = 'custom-y'; |
|
| 238 | - $notificationCloseType = "Custom, Created"; |
|
| 239 | - } |
|
| 240 | - else { |
|
| 241 | - $logCloseType = 'custom-n'; |
|
| 242 | - $notificationCloseType = "Custom, Not Created"; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - Logger::closeRequest($database, $request, $logCloseType, $messageBody); |
|
| 246 | - $this->getNotificationHelper()->requestClosed($request, $notificationCloseType); |
|
| 247 | - |
|
| 248 | - $requestName = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8'); |
|
| 249 | - SessionAlert::success("Request {$request->getId()} ({$requestName}) marked as 'Done'."); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * @param Request $request |
|
| 254 | - * @param PdoDatabase $database |
|
| 255 | - * @param string $action |
|
| 256 | - * @param $availableRequestStates |
|
| 257 | - * @param string $messageBody |
|
| 258 | - * |
|
| 259 | - * @throws Exception |
|
| 260 | - * @throws OptimisticLockFailedException |
|
| 261 | - */ |
|
| 262 | - protected function deferRequest( |
|
| 263 | - Request $request, |
|
| 264 | - PdoDatabase $database, |
|
| 265 | - $action, |
|
| 266 | - $availableRequestStates, |
|
| 267 | - $messageBody |
|
| 268 | - ) { |
|
| 269 | - $request->setStatus($action); |
|
| 270 | - $request->setReserved(null); |
|
| 271 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 272 | - $request->save(); |
|
| 273 | - |
|
| 274 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE |
|
| 275 | - // and be rolled back. |
|
| 276 | - |
|
| 277 | - $deferToLog = $availableRequestStates[$action]['defertolog']; |
|
| 278 | - Logger::sentMail($database, $request, $messageBody); |
|
| 279 | - Logger::deferRequest($database, $request, $deferToLog); |
|
| 280 | - |
|
| 281 | - $this->getNotificationHelper()->requestDeferredWithMail($request); |
|
| 282 | - |
|
| 283 | - $deferTo = $availableRequestStates[$action]['deferto']; |
|
| 284 | - SessionAlert::success("Request {$request->getId()} deferred to $deferTo, sending an email."); |
|
| 285 | - } |
|
| 26 | + use RequestData; |
|
| 27 | + |
|
| 28 | + protected function main() |
|
| 29 | + { |
|
| 30 | + $database = $this->getDatabase(); |
|
| 31 | + |
|
| 32 | + $request = $this->getRequest($database); |
|
| 33 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
| 34 | + |
|
| 35 | + if ($request->getStatus() === 'Closed') { |
|
| 36 | + throw new ApplicationLogicException('Request is already closed'); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // Dual-mode page |
|
| 40 | + if (WebRequest::wasPosted()) { |
|
| 41 | + $this->validateCSRFToken(); |
|
| 42 | + $this->doCustomClose($currentUser, $request, $database); |
|
| 43 | + |
|
| 44 | + $this->redirect(); |
|
| 45 | + } |
|
| 46 | + else { |
|
| 47 | + $this->assignCSRFToken(); |
|
| 48 | + $this->showCustomCloseForm($database, $request); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @param $database |
|
| 54 | + * |
|
| 55 | + * @return Request |
|
| 56 | + * @throws ApplicationLogicException |
|
| 57 | + */ |
|
| 58 | + protected function getRequest(PdoDatabase $database) |
|
| 59 | + { |
|
| 60 | + $requestId = WebRequest::getInt('request'); |
|
| 61 | + if ($requestId === null) { |
|
| 62 | + throw new ApplicationLogicException('Request ID not found'); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** @var Request $request */ |
|
| 66 | + $request = Request::getById($requestId, $database); |
|
| 67 | + |
|
| 68 | + if ($request === false) { |
|
| 69 | + throw new ApplicationLogicException('Request not found'); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return $request; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param PdoDatabase $database |
|
| 77 | + * |
|
| 78 | + * @return EmailTemplate|null |
|
| 79 | + */ |
|
| 80 | + protected function getTemplate(PdoDatabase $database) |
|
| 81 | + { |
|
| 82 | + $templateId = WebRequest::getInt('template'); |
|
| 83 | + if ($templateId === null) { |
|
| 84 | + return null; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** @var EmailTemplate $template */ |
|
| 88 | + $template = EmailTemplate::getById($templateId, $database); |
|
| 89 | + if ($template === false || !$template->getActive()) { |
|
| 90 | + return null; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return $template; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @param $database |
|
| 98 | + * @param $request |
|
| 99 | + * |
|
| 100 | + * @throws Exception |
|
| 101 | + */ |
|
| 102 | + protected function showCustomCloseForm(PdoDatabase $database, Request $request) |
|
| 103 | + { |
|
| 104 | + $currentUser = User::getCurrent($database); |
|
| 105 | + $config = $this->getSiteConfiguration(); |
|
| 106 | + |
|
| 107 | + $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 108 | + if (!$allowedPrivateData) { |
|
| 109 | + // we probably shouldn't be showing the user this form if they're not allowed to access private data... |
|
| 110 | + throw new AccessDeniedException($this->getSecurityManager()); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $template = $this->getTemplate($database); |
|
| 114 | + |
|
| 115 | + // Preload data |
|
| 116 | + $this->assign('defaultAction', ''); |
|
| 117 | + $this->assign('preloadText', ''); |
|
| 118 | + $this->assign('preloadTitle', ''); |
|
| 119 | + |
|
| 120 | + if ($template !== null) { |
|
| 121 | + $this->assign('defaultAction', $template->getDefaultAction()); |
|
| 122 | + $this->assign('preloadText', $template->getText()); |
|
| 123 | + $this->assign('preloadTitle', $template->getName()); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // Static data |
|
| 127 | + $this->assign('requeststates', $config->getRequestStates()); |
|
| 128 | + |
|
| 129 | + // request data |
|
| 130 | + $this->assign('requestId', $request->getIp()); |
|
| 131 | + $this->assign('updateVersion', $request->getUpdateVersion()); |
|
| 132 | + $this->setupBasicData($request, $config); |
|
| 133 | + $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 134 | + $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database); |
|
| 135 | + |
|
| 136 | + // IP location |
|
| 137 | + $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 138 | + $this->assign('iplocation', $this->getLocationProvider()->getIpLocation($trustedIp)); |
|
| 139 | + |
|
| 140 | + // Confirmations |
|
| 141 | + $this->assign('confirmEmailAlreadySent', $this->checkEmailAlreadySent($request)); |
|
| 142 | + $this->assign('confirmReserveOverride', $this->checkReserveOverride($request, $currentUser)); |
|
| 143 | + |
|
| 144 | + $this->assign('canSkipCcMailingList', $this->barrierTest('skipCcMailingList', $currentUser)); |
|
| 145 | + |
|
| 146 | + // template |
|
| 147 | + $this->setTemplate('custom-close.tpl'); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @param User $currentUser |
|
| 152 | + * @param Request $request |
|
| 153 | + * @param PdoDatabase $database |
|
| 154 | + * |
|
| 155 | + * @throws ApplicationLogicException |
|
| 156 | + */ |
|
| 157 | + protected function doCustomClose(User $currentUser, Request $request, PdoDatabase $database) |
|
| 158 | + { |
|
| 159 | + $messageBody = WebRequest::postString('msgbody'); |
|
| 160 | + if ($messageBody === null || trim($messageBody) === '') { |
|
| 161 | + throw new ApplicationLogicException('Message body cannot be blank'); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + $ccMailingList = true; |
|
| 165 | + if ($this->barrierTest('skipCcMailingList', $currentUser)) { |
|
| 166 | + $ccMailingList = WebRequest::postBoolean('ccMailingList'); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + if ($request->getStatus() === 'Closed') { |
|
| 170 | + throw new ApplicationLogicException('Request is already closed'); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if (!(WebRequest::postBoolean('confirmEmailAlreadySent') |
|
| 174 | + && WebRequest::postBoolean('confirmReserveOverride')) |
|
| 175 | + ) { |
|
| 176 | + throw new ApplicationLogicException('Not all confirmations checked'); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $action = WebRequest::postString('action'); |
|
| 180 | + $availableRequestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 181 | + |
|
| 182 | + if ($action === EmailTemplate::CREATED || $action === EmailTemplate::NOT_CREATED) { |
|
| 183 | + // Close request |
|
| 184 | + $this->closeRequest($request, $database, $action, $messageBody); |
|
| 185 | + |
|
| 186 | + // Send the mail after the save, since save can be rolled back |
|
| 187 | + $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 188 | + } |
|
| 189 | + else { |
|
| 190 | + if (array_key_exists($action, $availableRequestStates)) { |
|
| 191 | + // Defer to other state |
|
| 192 | + $this->deferRequest($request, $database, $action, $availableRequestStates, $messageBody); |
|
| 193 | + |
|
| 194 | + // Send the mail after the save, since save can be rolled back |
|
| 195 | + $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 196 | + } |
|
| 197 | + else { |
|
| 198 | + $request->setReserved(null); |
|
| 199 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 200 | + $request->save(); |
|
| 201 | + |
|
| 202 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE |
|
| 203 | + // and be rolled back. |
|
| 204 | + |
|
| 205 | + // Send mail |
|
| 206 | + $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 207 | + |
|
| 208 | + Logger::sentMail($database, $request, $messageBody); |
|
| 209 | + Logger::unreserve($database, $request); |
|
| 210 | + |
|
| 211 | + $this->getNotificationHelper()->sentMail($request); |
|
| 212 | + SessionAlert::success("Sent mail to Request {$request->getId()}"); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * @param Request $request |
|
| 219 | + * @param PdoDatabase $database |
|
| 220 | + * @param string $action |
|
| 221 | + * @param string $messageBody |
|
| 222 | + * |
|
| 223 | + * @throws Exception |
|
| 224 | + * @throws OptimisticLockFailedException |
|
| 225 | + */ |
|
| 226 | + protected function closeRequest(Request $request, PdoDatabase $database, $action, $messageBody) |
|
| 227 | + { |
|
| 228 | + $request->setStatus('Closed'); |
|
| 229 | + $request->setReserved(null); |
|
| 230 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 231 | + $request->save(); |
|
| 232 | + |
|
| 233 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
| 234 | + // be rolled back. |
|
| 235 | + |
|
| 236 | + if ($action == EmailTemplate::CREATED) { |
|
| 237 | + $logCloseType = 'custom-y'; |
|
| 238 | + $notificationCloseType = "Custom, Created"; |
|
| 239 | + } |
|
| 240 | + else { |
|
| 241 | + $logCloseType = 'custom-n'; |
|
| 242 | + $notificationCloseType = "Custom, Not Created"; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + Logger::closeRequest($database, $request, $logCloseType, $messageBody); |
|
| 246 | + $this->getNotificationHelper()->requestClosed($request, $notificationCloseType); |
|
| 247 | + |
|
| 248 | + $requestName = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8'); |
|
| 249 | + SessionAlert::success("Request {$request->getId()} ({$requestName}) marked as 'Done'."); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * @param Request $request |
|
| 254 | + * @param PdoDatabase $database |
|
| 255 | + * @param string $action |
|
| 256 | + * @param $availableRequestStates |
|
| 257 | + * @param string $messageBody |
|
| 258 | + * |
|
| 259 | + * @throws Exception |
|
| 260 | + * @throws OptimisticLockFailedException |
|
| 261 | + */ |
|
| 262 | + protected function deferRequest( |
|
| 263 | + Request $request, |
|
| 264 | + PdoDatabase $database, |
|
| 265 | + $action, |
|
| 266 | + $availableRequestStates, |
|
| 267 | + $messageBody |
|
| 268 | + ) { |
|
| 269 | + $request->setStatus($action); |
|
| 270 | + $request->setReserved(null); |
|
| 271 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 272 | + $request->save(); |
|
| 273 | + |
|
| 274 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE |
|
| 275 | + // and be rolled back. |
|
| 276 | + |
|
| 277 | + $deferToLog = $availableRequestStates[$action]['defertolog']; |
|
| 278 | + Logger::sentMail($database, $request, $messageBody); |
|
| 279 | + Logger::deferRequest($database, $request, $deferToLog); |
|
| 280 | + |
|
| 281 | + $this->getNotificationHelper()->requestDeferredWithMail($request); |
|
| 282 | + |
|
| 283 | + $deferTo = $availableRequestStates[$action]['deferto']; |
|
| 284 | + SessionAlert::success("Request {$request->getId()} deferred to $deferTo, sending an email."); |
|
| 285 | + } |
|
| 286 | 286 | } |
@@ -17,43 +17,43 @@ |
||
| 17 | 17 | |
| 18 | 18 | class PageSendToUser extends RequestActionBase |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Main function for this page, when no specific actions are called. |
|
| 22 | - * @throws ApplicationLogicException |
|
| 23 | - * @throws Exception |
|
| 24 | - */ |
|
| 25 | - protected function main() |
|
| 26 | - { |
|
| 27 | - $this->checkPosted(); |
|
| 28 | - $database = $this->getDatabase(); |
|
| 29 | - $request = $this->getRequest($database); |
|
| 30 | - |
|
| 31 | - if ($request->getReserved() !== User::getCurrent($database)->getId()) { |
|
| 32 | - throw new ApplicationLogicException('You don\'t have this request reserved!'); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - $username = WebRequest::postString('user'); |
|
| 36 | - if ($username === null) { |
|
| 37 | - throw new ApplicationLogicException('User must be specified'); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - $user = User::getByUsername($username, $database); |
|
| 41 | - if ($user === false) { |
|
| 42 | - throw new ApplicationLogicException('User not found'); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if (!$user->isActive()) { |
|
| 46 | - throw new ApplicationLogicException('User is currently not active on the tool'); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - $request->setReserved($user->getId()); |
|
| 50 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 51 | - $request->save(); |
|
| 52 | - |
|
| 53 | - Logger::sendReservation($database, $request, $user); |
|
| 54 | - $this->getNotificationHelper()->requestReservationSent($request, $user); |
|
| 55 | - SessionAlert::success("Reservation sent successfully"); |
|
| 56 | - |
|
| 57 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 58 | - } |
|
| 20 | + /** |
|
| 21 | + * Main function for this page, when no specific actions are called. |
|
| 22 | + * @throws ApplicationLogicException |
|
| 23 | + * @throws Exception |
|
| 24 | + */ |
|
| 25 | + protected function main() |
|
| 26 | + { |
|
| 27 | + $this->checkPosted(); |
|
| 28 | + $database = $this->getDatabase(); |
|
| 29 | + $request = $this->getRequest($database); |
|
| 30 | + |
|
| 31 | + if ($request->getReserved() !== User::getCurrent($database)->getId()) { |
|
| 32 | + throw new ApplicationLogicException('You don\'t have this request reserved!'); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + $username = WebRequest::postString('user'); |
|
| 36 | + if ($username === null) { |
|
| 37 | + throw new ApplicationLogicException('User must be specified'); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + $user = User::getByUsername($username, $database); |
|
| 41 | + if ($user === false) { |
|
| 42 | + throw new ApplicationLogicException('User not found'); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if (!$user->isActive()) { |
|
| 46 | + throw new ApplicationLogicException('User is currently not active on the tool'); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + $request->setReserved($user->getId()); |
|
| 50 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 51 | + $request->save(); |
|
| 52 | + |
|
| 53 | + Logger::sendReservation($database, $request, $user); |
|
| 54 | + $this->getNotificationHelper()->requestReservationSent($request, $user); |
|
| 55 | + SessionAlert::success("Reservation sent successfully"); |
|
| 56 | + |
|
| 57 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -17,149 +17,149 @@ |
||
| 17 | 17 | |
| 18 | 18 | class PageForgotPassword extends InternalPageBase |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Main function for this page, when no specific actions are called. |
|
| 22 | - * |
|
| 23 | - * This is the forgotten password reset form |
|
| 24 | - * @category Security-Critical |
|
| 25 | - */ |
|
| 26 | - protected function main() |
|
| 27 | - { |
|
| 28 | - if (WebRequest::wasPosted()) { |
|
| 29 | - $this->validateCSRFToken(); |
|
| 30 | - $username = WebRequest::postString('username'); |
|
| 31 | - $email = WebRequest::postEmail('email'); |
|
| 32 | - $database = $this->getDatabase(); |
|
| 33 | - |
|
| 34 | - if ($username === null || trim($username) === "" || $email === null || trim($email) === "") { |
|
| 35 | - throw new ApplicationLogicException("Both username and email address must be specified!"); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - $user = User::getByUsername($username, $database); |
|
| 39 | - $this->sendResetMail($user, $email); |
|
| 40 | - |
|
| 41 | - SessionAlert::success('<strong>Your password reset request has been completed.</strong> Please check your e-mail.'); |
|
| 42 | - |
|
| 43 | - $this->redirect('login'); |
|
| 44 | - } |
|
| 45 | - else { |
|
| 46 | - $this->assignCSRFToken(); |
|
| 47 | - $this->setTemplate('forgot-password/forgotpw.tpl'); |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Sends a reset email if the user is authenticated |
|
| 53 | - * |
|
| 54 | - * @param User|boolean $user The user located from the database, or false. Doesn't really matter, since we do the |
|
| 55 | - * check anyway within this method and silently skip if we don't have a user. |
|
| 56 | - * @param string $email The provided email address |
|
| 57 | - */ |
|
| 58 | - private function sendResetMail($user, $email) |
|
| 59 | - { |
|
| 60 | - // If the user isn't found, or the email address is wrong, skip sending the details silently. |
|
| 61 | - if (!$user instanceof User) { |
|
| 62 | - return; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - if (strtolower($user->getEmail()) === strtolower($email)) { |
|
| 66 | - $clientIp = $this->getXffTrustProvider() |
|
| 67 | - ->getTrustedClientIp(WebRequest::remoteAddress(), WebRequest::forwardedAddress()); |
|
| 68 | - |
|
| 69 | - $this->assign("user", $user); |
|
| 70 | - $this->assign("hash", $user->getForgottenPasswordHash()); |
|
| 71 | - $this->assign("remoteAddress", $clientIp); |
|
| 72 | - |
|
| 73 | - $emailContent = $this->fetchTemplate('forgot-password/reset-mail.tpl'); |
|
| 74 | - |
|
| 75 | - $this->getEmailHelper()->sendMail($user->getEmail(), "", $emailContent); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Entry point for the reset action |
|
| 81 | - * |
|
| 82 | - * This is the reset password part of the form. |
|
| 83 | - * @category Security-Critical |
|
| 84 | - */ |
|
| 85 | - protected function reset() |
|
| 86 | - { |
|
| 87 | - $si = WebRequest::getString('si'); |
|
| 88 | - $id = WebRequest::getString('id'); |
|
| 89 | - |
|
| 90 | - if ($si === null || trim($si) === "" || $id === null || trim($id) === "") { |
|
| 91 | - throw new ApplicationLogicException("Link not valid, please ensure it has copied correctly"); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $database = $this->getDatabase(); |
|
| 95 | - $user = $this->getResettingUser($id, $database, $si); |
|
| 96 | - |
|
| 97 | - // Dual mode |
|
| 98 | - if (WebRequest::wasPosted()) { |
|
| 99 | - $this->validateCSRFToken(); |
|
| 100 | - try { |
|
| 101 | - $this->doReset($user); |
|
| 102 | - } |
|
| 103 | - catch (ApplicationLogicException $ex) { |
|
| 104 | - SessionAlert::error($ex->getMessage()); |
|
| 105 | - $this->redirect('forgotPassword', 'reset', array('si' => $si, 'id' => $id)); |
|
| 106 | - |
|
| 107 | - return; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - else { |
|
| 111 | - $this->assignCSRFToken(); |
|
| 112 | - $this->assign('user', $user); |
|
| 113 | - $this->setTemplate('forgot-password/forgotpwreset.tpl'); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Gets the user resetting their password from the database, or throwing an exception if that is not possible. |
|
| 119 | - * |
|
| 120 | - * @param integer $id The ID of the user to retrieve |
|
| 121 | - * @param PdoDatabase $database The database object to use |
|
| 122 | - * @param string $si The reset hash provided |
|
| 123 | - * |
|
| 124 | - * @return User |
|
| 125 | - * @throws ApplicationLogicException |
|
| 126 | - */ |
|
| 127 | - private function getResettingUser($id, $database, $si) |
|
| 128 | - { |
|
| 129 | - $user = User::getById($id, $database); |
|
| 130 | - |
|
| 131 | - if ($user === false || $user->getForgottenPasswordHash() !== $si || $user->isCommunityUser()) { |
|
| 132 | - throw new ApplicationLogicException("User not found"); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return $user; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Performs the setting of the new password |
|
| 140 | - * |
|
| 141 | - * @param User $user The user to set the password for |
|
| 142 | - * |
|
| 143 | - * @throws ApplicationLogicException |
|
| 144 | - */ |
|
| 145 | - private function doReset(User $user) |
|
| 146 | - { |
|
| 147 | - $pw = WebRequest::postString('pw'); |
|
| 148 | - $pw2 = WebRequest::postString('pw2'); |
|
| 149 | - |
|
| 150 | - if ($pw !== $pw2) { |
|
| 151 | - throw new ApplicationLogicException('Passwords do not match!'); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - $user->setPassword($pw); |
|
| 155 | - $user->save(); |
|
| 156 | - |
|
| 157 | - SessionAlert::success('You may now log in!'); |
|
| 158 | - $this->redirect('login'); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - protected function isProtectedPage() |
|
| 162 | - { |
|
| 163 | - return false; |
|
| 164 | - } |
|
| 20 | + /** |
|
| 21 | + * Main function for this page, when no specific actions are called. |
|
| 22 | + * |
|
| 23 | + * This is the forgotten password reset form |
|
| 24 | + * @category Security-Critical |
|
| 25 | + */ |
|
| 26 | + protected function main() |
|
| 27 | + { |
|
| 28 | + if (WebRequest::wasPosted()) { |
|
| 29 | + $this->validateCSRFToken(); |
|
| 30 | + $username = WebRequest::postString('username'); |
|
| 31 | + $email = WebRequest::postEmail('email'); |
|
| 32 | + $database = $this->getDatabase(); |
|
| 33 | + |
|
| 34 | + if ($username === null || trim($username) === "" || $email === null || trim($email) === "") { |
|
| 35 | + throw new ApplicationLogicException("Both username and email address must be specified!"); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + $user = User::getByUsername($username, $database); |
|
| 39 | + $this->sendResetMail($user, $email); |
|
| 40 | + |
|
| 41 | + SessionAlert::success('<strong>Your password reset request has been completed.</strong> Please check your e-mail.'); |
|
| 42 | + |
|
| 43 | + $this->redirect('login'); |
|
| 44 | + } |
|
| 45 | + else { |
|
| 46 | + $this->assignCSRFToken(); |
|
| 47 | + $this->setTemplate('forgot-password/forgotpw.tpl'); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Sends a reset email if the user is authenticated |
|
| 53 | + * |
|
| 54 | + * @param User|boolean $user The user located from the database, or false. Doesn't really matter, since we do the |
|
| 55 | + * check anyway within this method and silently skip if we don't have a user. |
|
| 56 | + * @param string $email The provided email address |
|
| 57 | + */ |
|
| 58 | + private function sendResetMail($user, $email) |
|
| 59 | + { |
|
| 60 | + // If the user isn't found, or the email address is wrong, skip sending the details silently. |
|
| 61 | + if (!$user instanceof User) { |
|
| 62 | + return; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + if (strtolower($user->getEmail()) === strtolower($email)) { |
|
| 66 | + $clientIp = $this->getXffTrustProvider() |
|
| 67 | + ->getTrustedClientIp(WebRequest::remoteAddress(), WebRequest::forwardedAddress()); |
|
| 68 | + |
|
| 69 | + $this->assign("user", $user); |
|
| 70 | + $this->assign("hash", $user->getForgottenPasswordHash()); |
|
| 71 | + $this->assign("remoteAddress", $clientIp); |
|
| 72 | + |
|
| 73 | + $emailContent = $this->fetchTemplate('forgot-password/reset-mail.tpl'); |
|
| 74 | + |
|
| 75 | + $this->getEmailHelper()->sendMail($user->getEmail(), "", $emailContent); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Entry point for the reset action |
|
| 81 | + * |
|
| 82 | + * This is the reset password part of the form. |
|
| 83 | + * @category Security-Critical |
|
| 84 | + */ |
|
| 85 | + protected function reset() |
|
| 86 | + { |
|
| 87 | + $si = WebRequest::getString('si'); |
|
| 88 | + $id = WebRequest::getString('id'); |
|
| 89 | + |
|
| 90 | + if ($si === null || trim($si) === "" || $id === null || trim($id) === "") { |
|
| 91 | + throw new ApplicationLogicException("Link not valid, please ensure it has copied correctly"); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $database = $this->getDatabase(); |
|
| 95 | + $user = $this->getResettingUser($id, $database, $si); |
|
| 96 | + |
|
| 97 | + // Dual mode |
|
| 98 | + if (WebRequest::wasPosted()) { |
|
| 99 | + $this->validateCSRFToken(); |
|
| 100 | + try { |
|
| 101 | + $this->doReset($user); |
|
| 102 | + } |
|
| 103 | + catch (ApplicationLogicException $ex) { |
|
| 104 | + SessionAlert::error($ex->getMessage()); |
|
| 105 | + $this->redirect('forgotPassword', 'reset', array('si' => $si, 'id' => $id)); |
|
| 106 | + |
|
| 107 | + return; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + else { |
|
| 111 | + $this->assignCSRFToken(); |
|
| 112 | + $this->assign('user', $user); |
|
| 113 | + $this->setTemplate('forgot-password/forgotpwreset.tpl'); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Gets the user resetting their password from the database, or throwing an exception if that is not possible. |
|
| 119 | + * |
|
| 120 | + * @param integer $id The ID of the user to retrieve |
|
| 121 | + * @param PdoDatabase $database The database object to use |
|
| 122 | + * @param string $si The reset hash provided |
|
| 123 | + * |
|
| 124 | + * @return User |
|
| 125 | + * @throws ApplicationLogicException |
|
| 126 | + */ |
|
| 127 | + private function getResettingUser($id, $database, $si) |
|
| 128 | + { |
|
| 129 | + $user = User::getById($id, $database); |
|
| 130 | + |
|
| 131 | + if ($user === false || $user->getForgottenPasswordHash() !== $si || $user->isCommunityUser()) { |
|
| 132 | + throw new ApplicationLogicException("User not found"); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return $user; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Performs the setting of the new password |
|
| 140 | + * |
|
| 141 | + * @param User $user The user to set the password for |
|
| 142 | + * |
|
| 143 | + * @throws ApplicationLogicException |
|
| 144 | + */ |
|
| 145 | + private function doReset(User $user) |
|
| 146 | + { |
|
| 147 | + $pw = WebRequest::postString('pw'); |
|
| 148 | + $pw2 = WebRequest::postString('pw2'); |
|
| 149 | + |
|
| 150 | + if ($pw !== $pw2) { |
|
| 151 | + throw new ApplicationLogicException('Passwords do not match!'); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + $user->setPassword($pw); |
|
| 155 | + $user->save(); |
|
| 156 | + |
|
| 157 | + SessionAlert::success('You may now log in!'); |
|
| 158 | + $this->redirect('login'); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + protected function isProtectedPage() |
|
| 162 | + { |
|
| 163 | + return false; |
|
| 164 | + } |
|
| 165 | 165 | } |