@@ -12,12 +12,12 @@ |
||
| 12 | 12 | |
| 13 | 13 | class PageRequestSubmitted extends PublicInterfacePageBase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Main function for this page, when no specific actions are called. |
|
| 17 | - * @return void |
|
| 18 | - */ |
|
| 19 | - protected function main() |
|
| 20 | - { |
|
| 21 | - $this->setTemplate('request/email-confirmed.tpl'); |
|
| 22 | - } |
|
| 15 | + /** |
|
| 16 | + * Main function for this page, when no specific actions are called. |
|
| 17 | + * @return void |
|
| 18 | + */ |
|
| 19 | + protected function main() |
|
| 20 | + { |
|
| 21 | + $this->setTemplate('request/email-confirmed.tpl'); |
|
| 22 | + } |
|
| 23 | 23 | } |
| 24 | 24 | \ No newline at end of file |
@@ -29,8 +29,7 @@ |
||
| 29 | 29 | foreach ($teamData as $name => $item) { |
| 30 | 30 | if (count($item['Role']) == 0) { |
| 31 | 31 | $inactive[$name] = $item; |
| 32 | - } |
|
| 33 | - else { |
|
| 32 | + } else { |
|
| 34 | 33 | $active[$name] = $item; |
| 35 | 34 | } |
| 36 | 35 | } |
@@ -12,44 +12,44 @@ |
||
| 12 | 12 | |
| 13 | 13 | class PageTeam extends InternalPageBase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Main function for this page, when no specific actions are called. |
|
| 17 | - * @return void |
|
| 18 | - */ |
|
| 19 | - protected function main() |
|
| 20 | - { |
|
| 21 | - $path = $this->getSiteConfiguration()->getFilePath() . '/team.json'; |
|
| 22 | - $json = file_get_contents($path); |
|
| 23 | - |
|
| 24 | - $teamData = json_decode($json, true); |
|
| 25 | - |
|
| 26 | - $active = array(); |
|
| 27 | - $inactive = array(); |
|
| 28 | - |
|
| 29 | - foreach ($teamData as $name => $item) { |
|
| 30 | - if (count($item['Role']) == 0) { |
|
| 31 | - $inactive[$name] = $item; |
|
| 32 | - } |
|
| 33 | - else { |
|
| 34 | - $active[$name] = $item; |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - $this->assign('developer', $this->assocArrayShuffle($active)); |
|
| 39 | - $this->assign('inactiveDeveloper', $this->assocArrayShuffle($inactive)); |
|
| 40 | - $this->setTemplate('team/team.tpl'); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - private function assocArrayShuffle($array) |
|
| 44 | - { |
|
| 45 | - $arrayKeys = array_keys($array); |
|
| 46 | - shuffle($arrayKeys); |
|
| 47 | - |
|
| 48 | - $sorted = []; |
|
| 49 | - foreach ($arrayKeys as $k) { |
|
| 50 | - $sorted[$k] = $array[$k]; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - return $sorted; |
|
| 54 | - } |
|
| 15 | + /** |
|
| 16 | + * Main function for this page, when no specific actions are called. |
|
| 17 | + * @return void |
|
| 18 | + */ |
|
| 19 | + protected function main() |
|
| 20 | + { |
|
| 21 | + $path = $this->getSiteConfiguration()->getFilePath() . '/team.json'; |
|
| 22 | + $json = file_get_contents($path); |
|
| 23 | + |
|
| 24 | + $teamData = json_decode($json, true); |
|
| 25 | + |
|
| 26 | + $active = array(); |
|
| 27 | + $inactive = array(); |
|
| 28 | + |
|
| 29 | + foreach ($teamData as $name => $item) { |
|
| 30 | + if (count($item['Role']) == 0) { |
|
| 31 | + $inactive[$name] = $item; |
|
| 32 | + } |
|
| 33 | + else { |
|
| 34 | + $active[$name] = $item; |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + $this->assign('developer', $this->assocArrayShuffle($active)); |
|
| 39 | + $this->assign('inactiveDeveloper', $this->assocArrayShuffle($inactive)); |
|
| 40 | + $this->setTemplate('team/team.tpl'); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + private function assocArrayShuffle($array) |
|
| 44 | + { |
|
| 45 | + $arrayKeys = array_keys($array); |
|
| 46 | + shuffle($arrayKeys); |
|
| 47 | + |
|
| 48 | + $sorted = []; |
|
| 49 | + foreach ($arrayKeys as $k) { |
|
| 50 | + $sorted[$k] = $array[$k]; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + return $sorted; |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -42,8 +42,7 @@ discard block |
||
| 42 | 42 | $this->doCustomClose($currentUser, $request, $database); |
| 43 | 43 | |
| 44 | 44 | $this->redirect(); |
| 45 | - } |
|
| 46 | - else { |
|
| 45 | + } else { |
|
| 47 | 46 | $this->assignCSRFToken(); |
| 48 | 47 | $this->showCustomCloseForm($database, $request); |
| 49 | 48 | } |
@@ -185,16 +184,14 @@ discard block |
||
| 185 | 184 | |
| 186 | 185 | // Send the mail after the save, since save can be rolled back |
| 187 | 186 | $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
| 188 | - } |
|
| 189 | - else { |
|
| 187 | + } else { |
|
| 190 | 188 | if (array_key_exists($action, $availableRequestStates)) { |
| 191 | 189 | // Defer to other state |
| 192 | 190 | $this->deferRequest($request, $database, $action, $availableRequestStates, $messageBody); |
| 193 | 191 | |
| 194 | 192 | // Send the mail after the save, since save can be rolled back |
| 195 | 193 | $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
| 196 | - } |
|
| 197 | - else { |
|
| 194 | + } else { |
|
| 198 | 195 | $request->setReserved(null); |
| 199 | 196 | $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
| 200 | 197 | $request->save(); |
@@ -236,8 +233,7 @@ discard block |
||
| 236 | 233 | if ($action == EmailTemplate::CREATED) { |
| 237 | 234 | $logCloseType = 'custom-y'; |
| 238 | 235 | $notificationCloseType = "Custom, Created"; |
| 239 | - } |
|
| 240 | - else { |
|
| 236 | + } else { |
|
| 241 | 237 | $logCloseType = 'custom-n'; |
| 242 | 238 | $notificationCloseType = "Custom, Not Created"; |
| 243 | 239 | } |
@@ -24,279 +24,279 @@ |
||
| 24 | 24 | |
| 25 | 25 | class PageCustomClose extends PageCloseRequest |
| 26 | 26 | { |
| 27 | - use RequestData; |
|
| 28 | - |
|
| 29 | - protected function main() |
|
| 30 | - { |
|
| 31 | - $database = $this->getDatabase(); |
|
| 32 | - |
|
| 33 | - $request = $this->getRequest($database); |
|
| 34 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
| 35 | - |
|
| 36 | - if ($request->getStatus() === 'Closed') { |
|
| 37 | - throw new ApplicationLogicException('Request is already closed'); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - // Dual-mode page |
|
| 41 | - if (WebRequest::wasPosted()) { |
|
| 42 | - $this->validateCSRFToken(); |
|
| 43 | - $this->doCustomClose($currentUser, $request, $database); |
|
| 44 | - |
|
| 45 | - $this->redirect(); |
|
| 46 | - } |
|
| 47 | - else { |
|
| 48 | - $this->assignCSRFToken(); |
|
| 49 | - $this->showCustomCloseForm($database, $request); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param $database |
|
| 55 | - * |
|
| 56 | - * @return Request |
|
| 57 | - * @throws ApplicationLogicException |
|
| 58 | - */ |
|
| 59 | - protected function getRequest(PdoDatabase $database) |
|
| 60 | - { |
|
| 61 | - $requestId = WebRequest::getInt('request'); |
|
| 62 | - if ($requestId === null) { |
|
| 63 | - throw new ApplicationLogicException('Request ID not found'); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** @var Request $request */ |
|
| 67 | - $request = Request::getById($requestId, $database); |
|
| 68 | - |
|
| 69 | - if ($request === false) { |
|
| 70 | - throw new ApplicationLogicException('Request not found'); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return $request; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param PdoDatabase $database |
|
| 78 | - * |
|
| 79 | - * @return EmailTemplate|null |
|
| 80 | - */ |
|
| 81 | - protected function getTemplate(PdoDatabase $database) |
|
| 82 | - { |
|
| 83 | - $templateId = WebRequest::getInt('template'); |
|
| 84 | - if ($templateId === null) { |
|
| 85 | - return null; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** @var EmailTemplate $template */ |
|
| 89 | - $template = EmailTemplate::getById($templateId, $database); |
|
| 90 | - if ($template === false || !$template->getActive()) { |
|
| 91 | - return null; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $template; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @param $database |
|
| 99 | - * @param $request |
|
| 100 | - * |
|
| 101 | - * @throws Exception |
|
| 102 | - */ |
|
| 103 | - protected function showCustomCloseForm(PdoDatabase $database, Request $request) |
|
| 104 | - { |
|
| 105 | - $currentUser = User::getCurrent($database); |
|
| 106 | - $config = $this->getSiteConfiguration(); |
|
| 107 | - |
|
| 108 | - $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 109 | - if (!$allowedPrivateData) { |
|
| 110 | - // we probably shouldn't be showing the user this form if they're not allowed to access private data... |
|
| 111 | - throw new AccessDeniedException($this->getSecurityManager()); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $template = $this->getTemplate($database); |
|
| 115 | - |
|
| 116 | - // Preload data |
|
| 117 | - $this->assign('defaultAction', ''); |
|
| 118 | - $this->assign('preloadText', ''); |
|
| 119 | - $this->assign('preloadTitle', ''); |
|
| 120 | - |
|
| 121 | - if ($template !== null) { |
|
| 122 | - $this->assign('defaultAction', $template->getDefaultAction()); |
|
| 123 | - $this->assign('preloadText', $template->getText()); |
|
| 124 | - $this->assign('preloadTitle', $template->getName()); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // Static data |
|
| 128 | - $this->assign('requeststates', $config->getRequestStates()); |
|
| 129 | - |
|
| 130 | - // request data |
|
| 131 | - $this->assign('requestId', $request->getIp()); |
|
| 132 | - $this->assign('updateVersion', $request->getUpdateVersion()); |
|
| 133 | - $this->setupBasicData($request, $config); |
|
| 134 | - $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 135 | - $this->setupPrivateData($request); |
|
| 136 | - $this->setupRelatedRequests($request, $config, $database); |
|
| 137 | - |
|
| 138 | - // IP location |
|
| 139 | - $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 140 | - $this->assign('iplocation', $this->getLocationProvider()->getIpLocation($trustedIp)); |
|
| 141 | - |
|
| 142 | - // Confirmations |
|
| 143 | - $this->assign('confirmEmailAlreadySent', $this->checkEmailAlreadySent($request)); |
|
| 144 | - |
|
| 145 | - $this->assign('canSkipCcMailingList', $this->barrierTest('skipCcMailingList', $currentUser)); |
|
| 146 | - |
|
| 147 | - $this->assign('allowWelcomeSkip', false); |
|
| 148 | - $this->assign('forceWelcomeSkip', false); |
|
| 149 | - |
|
| 150 | - $oauth = new OAuthUserHelper($currentUser, $this->getDatabase(), $this->getOAuthProtocolHelper(), $config); |
|
| 151 | - |
|
| 152 | - if ($currentUser->getWelcomeTemplate() != 0) { |
|
| 153 | - $this->assign('allowWelcomeSkip', true); |
|
| 154 | - |
|
| 155 | - if (!$oauth->canWelcome()) { |
|
| 156 | - $this->assign('forceWelcomeSkip', true); |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - // template |
|
| 162 | - $this->setTemplate('custom-close.tpl'); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @param User $currentUser |
|
| 167 | - * @param Request $request |
|
| 168 | - * @param PdoDatabase $database |
|
| 169 | - * |
|
| 170 | - * @throws ApplicationLogicException |
|
| 171 | - */ |
|
| 172 | - protected function doCustomClose(User $currentUser, Request $request, PdoDatabase $database) |
|
| 173 | - { |
|
| 174 | - $messageBody = WebRequest::postString('msgbody'); |
|
| 175 | - if ($messageBody === null || trim($messageBody) === '') { |
|
| 176 | - throw new ApplicationLogicException('Message body cannot be blank'); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $ccMailingList = true; |
|
| 180 | - if ($this->barrierTest('skipCcMailingList', $currentUser)) { |
|
| 181 | - $ccMailingList = WebRequest::postBoolean('ccMailingList'); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if ($request->getStatus() === 'Closed') { |
|
| 185 | - throw new ApplicationLogicException('Request is already closed'); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - if (!(WebRequest::postBoolean('confirmEmailAlreadySent')) |
|
| 189 | - ) { |
|
| 190 | - throw new ApplicationLogicException('Not all confirmations checked'); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - $action = WebRequest::postString('action'); |
|
| 194 | - $availableRequestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 195 | - |
|
| 196 | - if ($action === EmailTemplate::CREATED || $action === EmailTemplate::NOT_CREATED) { |
|
| 197 | - // Close request |
|
| 198 | - $this->closeRequest($request, $database, $action, $messageBody); |
|
| 199 | - |
|
| 200 | - $this->processWelcome($action); |
|
| 201 | - |
|
| 202 | - // Send the mail after the save, since save can be rolled back |
|
| 203 | - $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 204 | - } |
|
| 205 | - else { |
|
| 206 | - if (array_key_exists($action, $availableRequestStates)) { |
|
| 207 | - // Defer to other state |
|
| 208 | - $this->deferRequest($request, $database, $action, $availableRequestStates, $messageBody); |
|
| 209 | - |
|
| 210 | - // Send the mail after the save, since save can be rolled back |
|
| 211 | - $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 212 | - } |
|
| 213 | - else { |
|
| 214 | - $request->setReserved(null); |
|
| 215 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 216 | - $request->save(); |
|
| 217 | - |
|
| 218 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE |
|
| 219 | - // and be rolled back. |
|
| 220 | - |
|
| 221 | - // Send mail |
|
| 222 | - $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 223 | - |
|
| 224 | - Logger::sentMail($database, $request, $messageBody); |
|
| 225 | - Logger::unreserve($database, $request); |
|
| 226 | - |
|
| 227 | - $this->getNotificationHelper()->sentMail($request); |
|
| 228 | - SessionAlert::success("Sent mail to Request {$request->getId()}"); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @param Request $request |
|
| 235 | - * @param PdoDatabase $database |
|
| 236 | - * @param string $action |
|
| 237 | - * @param string $messageBody |
|
| 238 | - * |
|
| 239 | - * @throws Exception |
|
| 240 | - * @throws OptimisticLockFailedException |
|
| 241 | - */ |
|
| 242 | - protected function closeRequest(Request $request, PdoDatabase $database, $action, $messageBody) |
|
| 243 | - { |
|
| 244 | - $request->setStatus('Closed'); |
|
| 245 | - $request->setReserved(null); |
|
| 246 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 247 | - $request->save(); |
|
| 248 | - |
|
| 249 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
| 250 | - // be rolled back. |
|
| 251 | - |
|
| 252 | - if ($action == EmailTemplate::CREATED) { |
|
| 253 | - $logCloseType = 'custom-y'; |
|
| 254 | - $notificationCloseType = "Custom, Created"; |
|
| 255 | - } |
|
| 256 | - else { |
|
| 257 | - $logCloseType = 'custom-n'; |
|
| 258 | - $notificationCloseType = "Custom, Not Created"; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - Logger::closeRequest($database, $request, $logCloseType, $messageBody); |
|
| 262 | - $this->getNotificationHelper()->requestClosed($request, $notificationCloseType); |
|
| 263 | - |
|
| 264 | - $requestName = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8'); |
|
| 265 | - SessionAlert::success("Request {$request->getId()} ({$requestName}) closed as {$notificationCloseType}."); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * @param Request $request |
|
| 270 | - * @param PdoDatabase $database |
|
| 271 | - * @param string $action |
|
| 272 | - * @param $availableRequestStates |
|
| 273 | - * @param string $messageBody |
|
| 274 | - * |
|
| 275 | - * @throws Exception |
|
| 276 | - * @throws OptimisticLockFailedException |
|
| 277 | - */ |
|
| 278 | - protected function deferRequest( |
|
| 279 | - Request $request, |
|
| 280 | - PdoDatabase $database, |
|
| 281 | - $action, |
|
| 282 | - $availableRequestStates, |
|
| 283 | - $messageBody |
|
| 284 | - ) { |
|
| 285 | - $request->setStatus($action); |
|
| 286 | - $request->setReserved(null); |
|
| 287 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 288 | - $request->save(); |
|
| 289 | - |
|
| 290 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE |
|
| 291 | - // and be rolled back. |
|
| 292 | - |
|
| 293 | - $deferToLog = $availableRequestStates[$action]['defertolog']; |
|
| 294 | - Logger::sentMail($database, $request, $messageBody); |
|
| 295 | - Logger::deferRequest($database, $request, $deferToLog); |
|
| 296 | - |
|
| 297 | - $this->getNotificationHelper()->requestDeferredWithMail($request); |
|
| 298 | - |
|
| 299 | - $deferTo = $availableRequestStates[$action]['deferto']; |
|
| 300 | - SessionAlert::success("Request {$request->getId()} deferred to $deferTo, sending an email."); |
|
| 301 | - } |
|
| 27 | + use RequestData; |
|
| 28 | + |
|
| 29 | + protected function main() |
|
| 30 | + { |
|
| 31 | + $database = $this->getDatabase(); |
|
| 32 | + |
|
| 33 | + $request = $this->getRequest($database); |
|
| 34 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
| 35 | + |
|
| 36 | + if ($request->getStatus() === 'Closed') { |
|
| 37 | + throw new ApplicationLogicException('Request is already closed'); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + // Dual-mode page |
|
| 41 | + if (WebRequest::wasPosted()) { |
|
| 42 | + $this->validateCSRFToken(); |
|
| 43 | + $this->doCustomClose($currentUser, $request, $database); |
|
| 44 | + |
|
| 45 | + $this->redirect(); |
|
| 46 | + } |
|
| 47 | + else { |
|
| 48 | + $this->assignCSRFToken(); |
|
| 49 | + $this->showCustomCloseForm($database, $request); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param $database |
|
| 55 | + * |
|
| 56 | + * @return Request |
|
| 57 | + * @throws ApplicationLogicException |
|
| 58 | + */ |
|
| 59 | + protected function getRequest(PdoDatabase $database) |
|
| 60 | + { |
|
| 61 | + $requestId = WebRequest::getInt('request'); |
|
| 62 | + if ($requestId === null) { |
|
| 63 | + throw new ApplicationLogicException('Request ID not found'); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** @var Request $request */ |
|
| 67 | + $request = Request::getById($requestId, $database); |
|
| 68 | + |
|
| 69 | + if ($request === false) { |
|
| 70 | + throw new ApplicationLogicException('Request not found'); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return $request; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param PdoDatabase $database |
|
| 78 | + * |
|
| 79 | + * @return EmailTemplate|null |
|
| 80 | + */ |
|
| 81 | + protected function getTemplate(PdoDatabase $database) |
|
| 82 | + { |
|
| 83 | + $templateId = WebRequest::getInt('template'); |
|
| 84 | + if ($templateId === null) { |
|
| 85 | + return null; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** @var EmailTemplate $template */ |
|
| 89 | + $template = EmailTemplate::getById($templateId, $database); |
|
| 90 | + if ($template === false || !$template->getActive()) { |
|
| 91 | + return null; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $template; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @param $database |
|
| 99 | + * @param $request |
|
| 100 | + * |
|
| 101 | + * @throws Exception |
|
| 102 | + */ |
|
| 103 | + protected function showCustomCloseForm(PdoDatabase $database, Request $request) |
|
| 104 | + { |
|
| 105 | + $currentUser = User::getCurrent($database); |
|
| 106 | + $config = $this->getSiteConfiguration(); |
|
| 107 | + |
|
| 108 | + $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 109 | + if (!$allowedPrivateData) { |
|
| 110 | + // we probably shouldn't be showing the user this form if they're not allowed to access private data... |
|
| 111 | + throw new AccessDeniedException($this->getSecurityManager()); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $template = $this->getTemplate($database); |
|
| 115 | + |
|
| 116 | + // Preload data |
|
| 117 | + $this->assign('defaultAction', ''); |
|
| 118 | + $this->assign('preloadText', ''); |
|
| 119 | + $this->assign('preloadTitle', ''); |
|
| 120 | + |
|
| 121 | + if ($template !== null) { |
|
| 122 | + $this->assign('defaultAction', $template->getDefaultAction()); |
|
| 123 | + $this->assign('preloadText', $template->getText()); |
|
| 124 | + $this->assign('preloadTitle', $template->getName()); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // Static data |
|
| 128 | + $this->assign('requeststates', $config->getRequestStates()); |
|
| 129 | + |
|
| 130 | + // request data |
|
| 131 | + $this->assign('requestId', $request->getIp()); |
|
| 132 | + $this->assign('updateVersion', $request->getUpdateVersion()); |
|
| 133 | + $this->setupBasicData($request, $config); |
|
| 134 | + $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 135 | + $this->setupPrivateData($request); |
|
| 136 | + $this->setupRelatedRequests($request, $config, $database); |
|
| 137 | + |
|
| 138 | + // IP location |
|
| 139 | + $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 140 | + $this->assign('iplocation', $this->getLocationProvider()->getIpLocation($trustedIp)); |
|
| 141 | + |
|
| 142 | + // Confirmations |
|
| 143 | + $this->assign('confirmEmailAlreadySent', $this->checkEmailAlreadySent($request)); |
|
| 144 | + |
|
| 145 | + $this->assign('canSkipCcMailingList', $this->barrierTest('skipCcMailingList', $currentUser)); |
|
| 146 | + |
|
| 147 | + $this->assign('allowWelcomeSkip', false); |
|
| 148 | + $this->assign('forceWelcomeSkip', false); |
|
| 149 | + |
|
| 150 | + $oauth = new OAuthUserHelper($currentUser, $this->getDatabase(), $this->getOAuthProtocolHelper(), $config); |
|
| 151 | + |
|
| 152 | + if ($currentUser->getWelcomeTemplate() != 0) { |
|
| 153 | + $this->assign('allowWelcomeSkip', true); |
|
| 154 | + |
|
| 155 | + if (!$oauth->canWelcome()) { |
|
| 156 | + $this->assign('forceWelcomeSkip', true); |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + // template |
|
| 162 | + $this->setTemplate('custom-close.tpl'); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param User $currentUser |
|
| 167 | + * @param Request $request |
|
| 168 | + * @param PdoDatabase $database |
|
| 169 | + * |
|
| 170 | + * @throws ApplicationLogicException |
|
| 171 | + */ |
|
| 172 | + protected function doCustomClose(User $currentUser, Request $request, PdoDatabase $database) |
|
| 173 | + { |
|
| 174 | + $messageBody = WebRequest::postString('msgbody'); |
|
| 175 | + if ($messageBody === null || trim($messageBody) === '') { |
|
| 176 | + throw new ApplicationLogicException('Message body cannot be blank'); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $ccMailingList = true; |
|
| 180 | + if ($this->barrierTest('skipCcMailingList', $currentUser)) { |
|
| 181 | + $ccMailingList = WebRequest::postBoolean('ccMailingList'); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if ($request->getStatus() === 'Closed') { |
|
| 185 | + throw new ApplicationLogicException('Request is already closed'); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + if (!(WebRequest::postBoolean('confirmEmailAlreadySent')) |
|
| 189 | + ) { |
|
| 190 | + throw new ApplicationLogicException('Not all confirmations checked'); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + $action = WebRequest::postString('action'); |
|
| 194 | + $availableRequestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 195 | + |
|
| 196 | + if ($action === EmailTemplate::CREATED || $action === EmailTemplate::NOT_CREATED) { |
|
| 197 | + // Close request |
|
| 198 | + $this->closeRequest($request, $database, $action, $messageBody); |
|
| 199 | + |
|
| 200 | + $this->processWelcome($action); |
|
| 201 | + |
|
| 202 | + // Send the mail after the save, since save can be rolled back |
|
| 203 | + $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 204 | + } |
|
| 205 | + else { |
|
| 206 | + if (array_key_exists($action, $availableRequestStates)) { |
|
| 207 | + // Defer to other state |
|
| 208 | + $this->deferRequest($request, $database, $action, $availableRequestStates, $messageBody); |
|
| 209 | + |
|
| 210 | + // Send the mail after the save, since save can be rolled back |
|
| 211 | + $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 212 | + } |
|
| 213 | + else { |
|
| 214 | + $request->setReserved(null); |
|
| 215 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 216 | + $request->save(); |
|
| 217 | + |
|
| 218 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE |
|
| 219 | + // and be rolled back. |
|
| 220 | + |
|
| 221 | + // Send mail |
|
| 222 | + $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 223 | + |
|
| 224 | + Logger::sentMail($database, $request, $messageBody); |
|
| 225 | + Logger::unreserve($database, $request); |
|
| 226 | + |
|
| 227 | + $this->getNotificationHelper()->sentMail($request); |
|
| 228 | + SessionAlert::success("Sent mail to Request {$request->getId()}"); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * @param Request $request |
|
| 235 | + * @param PdoDatabase $database |
|
| 236 | + * @param string $action |
|
| 237 | + * @param string $messageBody |
|
| 238 | + * |
|
| 239 | + * @throws Exception |
|
| 240 | + * @throws OptimisticLockFailedException |
|
| 241 | + */ |
|
| 242 | + protected function closeRequest(Request $request, PdoDatabase $database, $action, $messageBody) |
|
| 243 | + { |
|
| 244 | + $request->setStatus('Closed'); |
|
| 245 | + $request->setReserved(null); |
|
| 246 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 247 | + $request->save(); |
|
| 248 | + |
|
| 249 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
| 250 | + // be rolled back. |
|
| 251 | + |
|
| 252 | + if ($action == EmailTemplate::CREATED) { |
|
| 253 | + $logCloseType = 'custom-y'; |
|
| 254 | + $notificationCloseType = "Custom, Created"; |
|
| 255 | + } |
|
| 256 | + else { |
|
| 257 | + $logCloseType = 'custom-n'; |
|
| 258 | + $notificationCloseType = "Custom, Not Created"; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + Logger::closeRequest($database, $request, $logCloseType, $messageBody); |
|
| 262 | + $this->getNotificationHelper()->requestClosed($request, $notificationCloseType); |
|
| 263 | + |
|
| 264 | + $requestName = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8'); |
|
| 265 | + SessionAlert::success("Request {$request->getId()} ({$requestName}) closed as {$notificationCloseType}."); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * @param Request $request |
|
| 270 | + * @param PdoDatabase $database |
|
| 271 | + * @param string $action |
|
| 272 | + * @param $availableRequestStates |
|
| 273 | + * @param string $messageBody |
|
| 274 | + * |
|
| 275 | + * @throws Exception |
|
| 276 | + * @throws OptimisticLockFailedException |
|
| 277 | + */ |
|
| 278 | + protected function deferRequest( |
|
| 279 | + Request $request, |
|
| 280 | + PdoDatabase $database, |
|
| 281 | + $action, |
|
| 282 | + $availableRequestStates, |
|
| 283 | + $messageBody |
|
| 284 | + ) { |
|
| 285 | + $request->setStatus($action); |
|
| 286 | + $request->setReserved(null); |
|
| 287 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 288 | + $request->save(); |
|
| 289 | + |
|
| 290 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE |
|
| 291 | + // and be rolled back. |
|
| 292 | + |
|
| 293 | + $deferToLog = $availableRequestStates[$action]['defertolog']; |
|
| 294 | + Logger::sentMail($database, $request, $messageBody); |
|
| 295 | + Logger::deferRequest($database, $request, $deferToLog); |
|
| 296 | + |
|
| 297 | + $this->getNotificationHelper()->requestDeferredWithMail($request); |
|
| 298 | + |
|
| 299 | + $deferTo = $availableRequestStates[$action]['deferto']; |
|
| 300 | + SessionAlert::success("Request {$request->getId()} deferred to $deferTo, sending an email."); |
|
| 301 | + } |
|
| 302 | 302 | } |
@@ -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,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 | } |
@@ -48,8 +48,7 @@ |
||
| 48 | 48 | |
| 49 | 49 | if ($external) { |
| 50 | 50 | return $smarty->fetch("offline/external.tpl"); |
| 51 | - } |
|
| 52 | - else { |
|
| 51 | + } else { |
|
| 53 | 52 | $hideCulprit = true; |
| 54 | 53 | |
| 55 | 54 | // Use the provided message if possible |
@@ -17,16 +17,16 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | class Offline |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Determines if the tool is offline |
|
| 22 | - * @return bool |
|
| 23 | - */ |
|
| 24 | - public static function isOffline() |
|
| 25 | - { |
|
| 26 | - global $dontUseDb; |
|
| 20 | + /** |
|
| 21 | + * Determines if the tool is offline |
|
| 22 | + * @return bool |
|
| 23 | + */ |
|
| 24 | + public static function isOffline() |
|
| 25 | + { |
|
| 26 | + global $dontUseDb; |
|
| 27 | 27 | |
| 28 | - return (bool)$dontUseDb; |
|
| 29 | - } |
|
| 28 | + return (bool)$dontUseDb; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Gets the offline message |
@@ -37,39 +37,39 @@ discard block |
||
| 37 | 37 | * @return string |
| 38 | 38 | * @throws SmartyException |
| 39 | 39 | */ |
| 40 | - public static function getOfflineMessage($external, $message = null) |
|
| 41 | - { |
|
| 42 | - global $dontUseDbCulprit, $dontUseDbReason, $baseurl; |
|
| 40 | + public static function getOfflineMessage($external, $message = null) |
|
| 41 | + { |
|
| 42 | + global $dontUseDbCulprit, $dontUseDbReason, $baseurl; |
|
| 43 | 43 | |
| 44 | - $smarty = new Smarty(); |
|
| 45 | - $smarty->assign("baseurl", $baseurl); |
|
| 46 | - $smarty->assign("resourceCacheEpoch", 0); |
|
| 47 | - $smarty->assign("alerts", []); |
|
| 48 | - $smarty->assign("toolversion", Environment::getToolVersion()); |
|
| 44 | + $smarty = new Smarty(); |
|
| 45 | + $smarty->assign("baseurl", $baseurl); |
|
| 46 | + $smarty->assign("resourceCacheEpoch", 0); |
|
| 47 | + $smarty->assign("alerts", []); |
|
| 48 | + $smarty->assign("toolversion", Environment::getToolVersion()); |
|
| 49 | 49 | |
| 50 | - if (!headers_sent()) { |
|
| 51 | - header("HTTP/1.1 503 Service Unavailable"); |
|
| 52 | - } |
|
| 50 | + if (!headers_sent()) { |
|
| 51 | + header("HTTP/1.1 503 Service Unavailable"); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - if ($external) { |
|
| 55 | - return $smarty->fetch("offline/external.tpl"); |
|
| 56 | - } |
|
| 57 | - else { |
|
| 58 | - $hideCulprit = true; |
|
| 54 | + if ($external) { |
|
| 55 | + return $smarty->fetch("offline/external.tpl"); |
|
| 56 | + } |
|
| 57 | + else { |
|
| 58 | + $hideCulprit = true; |
|
| 59 | 59 | |
| 60 | - // Use the provided message if possible |
|
| 61 | - if ($message === null) { |
|
| 62 | - $hideCulprit = false; |
|
| 63 | - $message = $dontUseDbReason; |
|
| 64 | - } |
|
| 60 | + // Use the provided message if possible |
|
| 61 | + if ($message === null) { |
|
| 62 | + $hideCulprit = false; |
|
| 63 | + $message = $dontUseDbReason; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - $smarty->assign("hideCulprit", $hideCulprit); |
|
| 67 | - $smarty->assign("dontUseDbCulprit", $dontUseDbCulprit); |
|
| 68 | - $smarty->assign("dontUseDbReason", $message); |
|
| 69 | - $smarty->assign("alerts", array()); |
|
| 70 | - $smarty->assign('currentUser', User::getCommunity()); |
|
| 66 | + $smarty->assign("hideCulprit", $hideCulprit); |
|
| 67 | + $smarty->assign("dontUseDbCulprit", $dontUseDbCulprit); |
|
| 68 | + $smarty->assign("dontUseDbReason", $message); |
|
| 69 | + $smarty->assign("alerts", array()); |
|
| 70 | + $smarty->assign('currentUser', User::getCommunity()); |
|
| 71 | 71 | |
| 72 | - return $smarty->fetch("offline/internal.tpl"); |
|
| 73 | - } |
|
| 74 | - } |
|
| 72 | + return $smarty->fetch("offline/internal.tpl"); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -340,8 +340,7 @@ discard block |
||
| 340 | 340 | if (count($pathInfo) === 0) { |
| 341 | 341 | // No pathInfo, so no page to load. Load the main page. |
| 342 | 342 | return $this->getDefaultRoute(); |
| 343 | - } |
|
| 344 | - elseif (count($pathInfo) === 1) { |
|
| 343 | + } elseif (count($pathInfo) === 1) { |
|
| 345 | 344 | // Exactly one path info segment, it's got to be a page. |
| 346 | 345 | $classSegment = $pathInfo[0]; |
| 347 | 346 | |
@@ -353,8 +352,7 @@ discard block |
||
| 353 | 352 | // Let's handle more than two, and collapse it down into two. |
| 354 | 353 | $requestedAction = array_pop($pathInfo); |
| 355 | 354 | $classSegment = implode('/', $pathInfo); |
| 356 | - } |
|
| 357 | - else { |
|
| 355 | + } else { |
|
| 358 | 356 | // Two path info segments. |
| 359 | 357 | $classSegment = $pathInfo[0]; |
| 360 | 358 | $requestedAction = $pathInfo[1]; |
@@ -383,8 +381,7 @@ discard block |
||
| 383 | 381 | $action = 'main'; |
| 384 | 382 | |
| 385 | 383 | return array($pageClass, $action); |
| 386 | - } |
|
| 387 | - else { |
|
| 384 | + } else { |
|
| 388 | 385 | // Doesn't exist in map. Fall back to 404 |
| 389 | 386 | $pageClass = Page404::class; |
| 390 | 387 | $action = "main"; |
@@ -413,16 +410,14 @@ discard block |
||
| 413 | 410 | $action = $requestedAction; |
| 414 | 411 | |
| 415 | 412 | return array($pageClass, $action); |
| 416 | - } |
|
| 417 | - else { |
|
| 413 | + } else { |
|
| 418 | 414 | // Valid page, invalid action. 404 our way out. |
| 419 | 415 | $pageClass = Page404::class; |
| 420 | 416 | $action = 'main'; |
| 421 | 417 | |
| 422 | 418 | return array($pageClass, $action); |
| 423 | 419 | } |
| 424 | - } |
|
| 425 | - else { |
|
| 420 | + } else { |
|
| 426 | 421 | // Class doesn't exist in map. Fall back to 404 |
| 427 | 422 | $pageClass = Page404::class; |
| 428 | 423 | $action = 'main'; |
@@ -63,445 +63,445 @@ |
||
| 63 | 63 | */ |
| 64 | 64 | class RequestRouter implements IRequestRouter |
| 65 | 65 | { |
| 66 | - /** |
|
| 67 | - * This is the core routing table for the application. The basic idea is: |
|
| 68 | - * |
|
| 69 | - * array( |
|
| 70 | - * "foo" => |
|
| 71 | - * array( |
|
| 72 | - * "class" => PageFoo::class, |
|
| 73 | - * "actions" => array("bar", "other") |
|
| 74 | - * ), |
|
| 75 | - * ); |
|
| 76 | - * |
|
| 77 | - * Things to note: |
|
| 78 | - * - If no page is requested, we go to PageMain. PageMain can't have actions defined. |
|
| 79 | - * |
|
| 80 | - * - If a page is defined and requested, but no action is requested, go to that page's main() method |
|
| 81 | - * - If a page is defined and requested, and an action is defined and requested, go to that action's method. |
|
| 82 | - * - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main() |
|
| 83 | - * method. |
|
| 84 | - * - If a page is NOT defined and requested, go to Page404 and it's main() method. |
|
| 85 | - * |
|
| 86 | - * - Query parameters are ignored. |
|
| 87 | - * |
|
| 88 | - * The key point here is request routing with validation that this is allowed, before we start hitting the |
|
| 89 | - * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested |
|
| 90 | - * before we start calling random methods through the web UI. |
|
| 91 | - * |
|
| 92 | - * Examples: |
|
| 93 | - * /internal.php => returns instance of PageMain, routed to main() |
|
| 94 | - * /internal.php?query => returns instance of PageMain, routed to main() |
|
| 95 | - * /internal.php/foo => returns instance of PageFoo, routed to main() |
|
| 96 | - * /internal.php/foo?query => returns instance of PageFoo, routed to main() |
|
| 97 | - * /internal.php/foo/bar => returns instance of PageFoo, routed to bar() |
|
| 98 | - * /internal.php/foo/bar?query => returns instance of PageFoo, routed to bar() |
|
| 99 | - * /internal.php/foo/baz => returns instance of Page404, routed to main() |
|
| 100 | - * /internal.php/foo/baz?query => returns instance of Page404, routed to main() |
|
| 101 | - * /internal.php/bar => returns instance of Page404, routed to main() |
|
| 102 | - * /internal.php/bar?query => returns instance of Page404, routed to main() |
|
| 103 | - * /internal.php/bar/baz => returns instance of Page404, routed to main() |
|
| 104 | - * /internal.php/bar/baz?query => returns instance of Page404, routed to main() |
|
| 105 | - * |
|
| 106 | - * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need |
|
| 107 | - * to change the key, then you'll likely have to update a lot of files. |
|
| 108 | - * |
|
| 109 | - * @var array |
|
| 110 | - */ |
|
| 111 | - private $routeMap = array( |
|
| 112 | - |
|
| 113 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 114 | - // Login and registration |
|
| 115 | - 'logout' => |
|
| 116 | - array( |
|
| 117 | - 'class' => PageLogout::class, |
|
| 118 | - 'actions' => array(), |
|
| 119 | - ), |
|
| 120 | - 'login' => |
|
| 121 | - array( |
|
| 122 | - 'class' => PagePasswordLogin::class, |
|
| 123 | - 'actions' => array(), |
|
| 124 | - ), |
|
| 125 | - 'login/otp' => |
|
| 126 | - array( |
|
| 127 | - 'class' => PageOtpLogin::class, |
|
| 128 | - 'actions' => array(), |
|
| 129 | - ), |
|
| 130 | - 'login/u2f' => |
|
| 131 | - array( |
|
| 132 | - 'class' => PageU2FLogin::class, |
|
| 133 | - 'actions' => array(), |
|
| 134 | - ), |
|
| 135 | - 'forgotPassword' => |
|
| 136 | - array( |
|
| 137 | - 'class' => PageForgotPassword::class, |
|
| 138 | - 'actions' => array('reset'), |
|
| 139 | - ), |
|
| 140 | - 'register' => |
|
| 141 | - array( |
|
| 142 | - 'class' => PageRegisterOption::class, |
|
| 143 | - 'actions' => array(), |
|
| 144 | - ), |
|
| 145 | - 'register/standard' => |
|
| 146 | - array( |
|
| 147 | - 'class' => PageRegisterStandard::class, |
|
| 148 | - 'actions' => array('done'), |
|
| 149 | - ), |
|
| 150 | - |
|
| 151 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 152 | - // Discovery |
|
| 153 | - 'search' => |
|
| 154 | - array( |
|
| 155 | - 'class' => PageSearch::class, |
|
| 156 | - 'actions' => array(), |
|
| 157 | - ), |
|
| 158 | - 'logs' => |
|
| 159 | - array( |
|
| 160 | - 'class' => PageLog::class, |
|
| 161 | - 'actions' => array(), |
|
| 162 | - ), |
|
| 163 | - |
|
| 164 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 165 | - // Administration |
|
| 166 | - 'bans' => |
|
| 167 | - array( |
|
| 168 | - 'class' => PageBan::class, |
|
| 169 | - 'actions' => array('set', 'remove'), |
|
| 170 | - ), |
|
| 171 | - 'userManagement' => |
|
| 172 | - array( |
|
| 173 | - 'class' => PageUserManagement::class, |
|
| 174 | - 'actions' => array( |
|
| 175 | - 'approve', |
|
| 176 | - 'decline', |
|
| 177 | - 'rename', |
|
| 178 | - 'editUser', |
|
| 179 | - 'suspend', |
|
| 180 | - 'editRoles', |
|
| 181 | - ), |
|
| 182 | - ), |
|
| 183 | - 'siteNotice' => |
|
| 184 | - array( |
|
| 185 | - 'class' => PageSiteNotice::class, |
|
| 186 | - 'actions' => array(), |
|
| 187 | - ), |
|
| 188 | - 'emailManagement' => |
|
| 189 | - array( |
|
| 190 | - 'class' => PageEmailManagement::class, |
|
| 191 | - 'actions' => array('create', 'edit', 'view'), |
|
| 192 | - ), |
|
| 193 | - 'jobQueue' => |
|
| 194 | - array( |
|
| 195 | - 'class' => PageJobQueue::class, |
|
| 196 | - 'actions' => array('acknowledge', 'requeue', 'view', 'all'), |
|
| 197 | - ), |
|
| 198 | - |
|
| 199 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 200 | - // Personal preferences |
|
| 201 | - 'preferences' => |
|
| 202 | - array( |
|
| 203 | - 'class' => PagePreferences::class, |
|
| 204 | - 'actions' => array( |
|
| 205 | - 'refreshOAuth' |
|
| 206 | - ), |
|
| 207 | - ), |
|
| 208 | - 'changePassword' => |
|
| 209 | - array( |
|
| 210 | - 'class' => PageChangePassword::class, |
|
| 211 | - 'actions' => array(), |
|
| 212 | - ), |
|
| 213 | - 'multiFactor' => |
|
| 214 | - array( |
|
| 215 | - 'class' => PageMultiFactor::class, |
|
| 216 | - 'actions' => array( |
|
| 217 | - 'scratch', |
|
| 218 | - 'enableYubikeyOtp', |
|
| 219 | - 'disableYubikeyOtp', |
|
| 220 | - 'enableTotp', |
|
| 221 | - 'disableTotp', |
|
| 222 | - 'enableU2F', |
|
| 223 | - 'disableU2F', |
|
| 224 | - ), |
|
| 225 | - ), |
|
| 226 | - 'oauth' => |
|
| 227 | - array( |
|
| 228 | - 'class' => PageOAuth::class, |
|
| 229 | - 'actions' => array('detach', 'attach'), |
|
| 230 | - ), |
|
| 231 | - 'oauth/callback' => |
|
| 232 | - array( |
|
| 233 | - 'class' => PageOAuthCallback::class, |
|
| 234 | - 'actions' => array('authorise', 'create'), |
|
| 235 | - ), |
|
| 236 | - |
|
| 237 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 238 | - // Welcomer configuration |
|
| 239 | - 'welcomeTemplates' => |
|
| 240 | - array( |
|
| 241 | - 'class' => PageWelcomeTemplateManagement::class, |
|
| 242 | - 'actions' => array('select', 'edit', 'delete', 'add', 'view'), |
|
| 243 | - ), |
|
| 244 | - |
|
| 245 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 246 | - // Statistics |
|
| 247 | - 'statistics' => |
|
| 248 | - array( |
|
| 249 | - 'class' => StatsMain::class, |
|
| 250 | - 'actions' => array(), |
|
| 251 | - ), |
|
| 252 | - 'statistics/fastCloses' => |
|
| 253 | - array( |
|
| 254 | - 'class' => StatsFastCloses::class, |
|
| 255 | - 'actions' => array(), |
|
| 256 | - ), |
|
| 257 | - 'statistics/inactiveUsers' => |
|
| 258 | - array( |
|
| 259 | - 'class' => StatsInactiveUsers::class, |
|
| 260 | - 'actions' => array(), |
|
| 261 | - ), |
|
| 262 | - 'statistics/monthlyStats' => |
|
| 263 | - array( |
|
| 264 | - 'class' => StatsMonthlyStats::class, |
|
| 265 | - 'actions' => array(), |
|
| 266 | - ), |
|
| 267 | - 'statistics/reservedRequests' => |
|
| 268 | - array( |
|
| 269 | - 'class' => StatsReservedRequests::class, |
|
| 270 | - 'actions' => array(), |
|
| 271 | - ), |
|
| 272 | - 'statistics/templateStats' => |
|
| 273 | - array( |
|
| 274 | - 'class' => StatsTemplateStats::class, |
|
| 275 | - 'actions' => array(), |
|
| 276 | - ), |
|
| 277 | - 'statistics/topCreators' => |
|
| 278 | - array( |
|
| 279 | - 'class' => StatsTopCreators::class, |
|
| 280 | - 'actions' => array(), |
|
| 281 | - ), |
|
| 282 | - 'statistics/users' => |
|
| 283 | - array( |
|
| 284 | - 'class' => StatsUsers::class, |
|
| 285 | - 'actions' => array('detail'), |
|
| 286 | - ), |
|
| 287 | - |
|
| 288 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 289 | - // Zoom page |
|
| 290 | - 'viewRequest' => |
|
| 291 | - array( |
|
| 292 | - 'class' => PageViewRequest::class, |
|
| 293 | - 'actions' => array(), |
|
| 294 | - ), |
|
| 295 | - 'viewRequest/reserve' => |
|
| 296 | - array( |
|
| 297 | - 'class' => PageReservation::class, |
|
| 298 | - 'actions' => array(), |
|
| 299 | - ), |
|
| 300 | - 'viewRequest/breakReserve' => |
|
| 301 | - array( |
|
| 302 | - 'class' => PageBreakReservation::class, |
|
| 303 | - 'actions' => array(), |
|
| 304 | - ), |
|
| 305 | - 'viewRequest/defer' => |
|
| 306 | - array( |
|
| 307 | - 'class' => PageDeferRequest::class, |
|
| 308 | - 'actions' => array(), |
|
| 309 | - ), |
|
| 310 | - 'viewRequest/comment' => |
|
| 311 | - array( |
|
| 312 | - 'class' => PageComment::class, |
|
| 313 | - 'actions' => array(), |
|
| 314 | - ), |
|
| 315 | - 'viewRequest/sendToUser' => |
|
| 316 | - array( |
|
| 317 | - 'class' => PageSendToUser::class, |
|
| 318 | - 'actions' => array(), |
|
| 319 | - ), |
|
| 320 | - 'viewRequest/close' => |
|
| 321 | - array( |
|
| 322 | - 'class' => PageCloseRequest::class, |
|
| 323 | - 'actions' => array(), |
|
| 324 | - ), |
|
| 325 | - 'viewRequest/create' => |
|
| 326 | - array( |
|
| 327 | - 'class' => PageCreateRequest::class, |
|
| 328 | - 'actions' => array(), |
|
| 329 | - ), |
|
| 330 | - 'viewRequest/drop' => |
|
| 331 | - array( |
|
| 332 | - 'class' => PageDropRequest::class, |
|
| 333 | - 'actions' => array(), |
|
| 334 | - ), |
|
| 335 | - 'viewRequest/custom' => |
|
| 336 | - array( |
|
| 337 | - 'class' => PageCustomClose::class, |
|
| 338 | - 'actions' => array(), |
|
| 339 | - ), |
|
| 340 | - 'editComment' => |
|
| 341 | - array( |
|
| 342 | - 'class' => PageEditComment::class, |
|
| 343 | - 'actions' => array(), |
|
| 344 | - ), |
|
| 345 | - |
|
| 346 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 347 | - // Misc stuff |
|
| 348 | - 'team' => |
|
| 349 | - array( |
|
| 350 | - 'class' => PageTeam::class, |
|
| 351 | - 'actions' => array(), |
|
| 352 | - ), |
|
| 353 | - 'requestList' => |
|
| 354 | - array( |
|
| 355 | - 'class' => PageExpandedRequestList::class, |
|
| 356 | - 'actions' => array(), |
|
| 357 | - ), |
|
| 358 | - 'xffdemo' => |
|
| 359 | - array( |
|
| 360 | - 'class' => PageXffDemo::class, |
|
| 361 | - 'actions' => array(), |
|
| 362 | - ), |
|
| 363 | - ); |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * @return IRoutedTask |
|
| 367 | - * @throws Exception |
|
| 368 | - */ |
|
| 369 | - final public function route() |
|
| 370 | - { |
|
| 371 | - $pathInfo = WebRequest::pathInfo(); |
|
| 372 | - |
|
| 373 | - list($pageClass, $action) = $this->getRouteFromPath($pathInfo); |
|
| 374 | - |
|
| 375 | - /** @var IRoutedTask $page */ |
|
| 376 | - $page = new $pageClass(); |
|
| 377 | - |
|
| 378 | - // Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so |
|
| 379 | - // let's use our own. |
|
| 380 | - if (!($page instanceof IRoutedTask)) { |
|
| 381 | - throw new Exception('Expected a page, but this is not a page.'); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - // OK, I'm happy at this point that we know we're running a page, and we know it's probably what we want if it |
|
| 385 | - // inherits PageBase and has been created from the routing map. |
|
| 386 | - $page->setRoute($action); |
|
| 387 | - |
|
| 388 | - return $page; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * @param $pathInfo |
|
| 393 | - * |
|
| 394 | - * @return array |
|
| 395 | - */ |
|
| 396 | - protected function getRouteFromPath($pathInfo) |
|
| 397 | - { |
|
| 398 | - if (count($pathInfo) === 0) { |
|
| 399 | - // No pathInfo, so no page to load. Load the main page. |
|
| 400 | - return $this->getDefaultRoute(); |
|
| 401 | - } |
|
| 402 | - elseif (count($pathInfo) === 1) { |
|
| 403 | - // Exactly one path info segment, it's got to be a page. |
|
| 404 | - $classSegment = $pathInfo[0]; |
|
| 405 | - |
|
| 406 | - return $this->routeSinglePathSegment($classSegment); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - // OK, we have two or more segments now. |
|
| 410 | - if (count($pathInfo) > 2) { |
|
| 411 | - // Let's handle more than two, and collapse it down into two. |
|
| 412 | - $requestedAction = array_pop($pathInfo); |
|
| 413 | - $classSegment = implode('/', $pathInfo); |
|
| 414 | - } |
|
| 415 | - else { |
|
| 416 | - // Two path info segments. |
|
| 417 | - $classSegment = $pathInfo[0]; |
|
| 418 | - $requestedAction = $pathInfo[1]; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - $routeMap = $this->routePathSegments($classSegment, $requestedAction); |
|
| 422 | - |
|
| 423 | - if ($routeMap[0] === Page404::class) { |
|
| 424 | - $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - return $routeMap; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * @param $classSegment |
|
| 432 | - * |
|
| 433 | - * @return array |
|
| 434 | - */ |
|
| 435 | - final protected function routeSinglePathSegment($classSegment) |
|
| 436 | - { |
|
| 437 | - $routeMap = $this->getRouteMap(); |
|
| 438 | - if (array_key_exists($classSegment, $routeMap)) { |
|
| 439 | - // Route exists, but we don't have an action in path info, so default to main. |
|
| 440 | - $pageClass = $routeMap[$classSegment]['class']; |
|
| 441 | - $action = 'main'; |
|
| 442 | - |
|
| 443 | - return array($pageClass, $action); |
|
| 444 | - } |
|
| 445 | - else { |
|
| 446 | - // Doesn't exist in map. Fall back to 404 |
|
| 447 | - $pageClass = Page404::class; |
|
| 448 | - $action = "main"; |
|
| 449 | - |
|
| 450 | - return array($pageClass, $action); |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * @param $classSegment |
|
| 456 | - * @param $requestedAction |
|
| 457 | - * |
|
| 458 | - * @return array |
|
| 459 | - */ |
|
| 460 | - final protected function routePathSegments($classSegment, $requestedAction) |
|
| 461 | - { |
|
| 462 | - $routeMap = $this->getRouteMap(); |
|
| 463 | - if (array_key_exists($classSegment, $routeMap)) { |
|
| 464 | - // Route exists, but we don't have an action in path info, so default to main. |
|
| 465 | - |
|
| 466 | - if (isset($routeMap[$classSegment]['actions']) |
|
| 467 | - && array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false |
|
| 468 | - ) { |
|
| 469 | - // Action exists in allowed action list. Allow both the page and the action |
|
| 470 | - $pageClass = $routeMap[$classSegment]['class']; |
|
| 471 | - $action = $requestedAction; |
|
| 472 | - |
|
| 473 | - return array($pageClass, $action); |
|
| 474 | - } |
|
| 475 | - else { |
|
| 476 | - // Valid page, invalid action. 404 our way out. |
|
| 477 | - $pageClass = Page404::class; |
|
| 478 | - $action = 'main'; |
|
| 479 | - |
|
| 480 | - return array($pageClass, $action); |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - else { |
|
| 484 | - // Class doesn't exist in map. Fall back to 404 |
|
| 485 | - $pageClass = Page404::class; |
|
| 486 | - $action = 'main'; |
|
| 487 | - |
|
| 488 | - return array($pageClass, $action); |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * @return array |
|
| 494 | - */ |
|
| 495 | - protected function getRouteMap() |
|
| 496 | - { |
|
| 497 | - return $this->routeMap; |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * @return array |
|
| 502 | - */ |
|
| 503 | - protected function getDefaultRoute() |
|
| 504 | - { |
|
| 505 | - return array(PageMain::class, "main"); |
|
| 506 | - } |
|
| 66 | + /** |
|
| 67 | + * This is the core routing table for the application. The basic idea is: |
|
| 68 | + * |
|
| 69 | + * array( |
|
| 70 | + * "foo" => |
|
| 71 | + * array( |
|
| 72 | + * "class" => PageFoo::class, |
|
| 73 | + * "actions" => array("bar", "other") |
|
| 74 | + * ), |
|
| 75 | + * ); |
|
| 76 | + * |
|
| 77 | + * Things to note: |
|
| 78 | + * - If no page is requested, we go to PageMain. PageMain can't have actions defined. |
|
| 79 | + * |
|
| 80 | + * - If a page is defined and requested, but no action is requested, go to that page's main() method |
|
| 81 | + * - If a page is defined and requested, and an action is defined and requested, go to that action's method. |
|
| 82 | + * - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main() |
|
| 83 | + * method. |
|
| 84 | + * - If a page is NOT defined and requested, go to Page404 and it's main() method. |
|
| 85 | + * |
|
| 86 | + * - Query parameters are ignored. |
|
| 87 | + * |
|
| 88 | + * The key point here is request routing with validation that this is allowed, before we start hitting the |
|
| 89 | + * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested |
|
| 90 | + * before we start calling random methods through the web UI. |
|
| 91 | + * |
|
| 92 | + * Examples: |
|
| 93 | + * /internal.php => returns instance of PageMain, routed to main() |
|
| 94 | + * /internal.php?query => returns instance of PageMain, routed to main() |
|
| 95 | + * /internal.php/foo => returns instance of PageFoo, routed to main() |
|
| 96 | + * /internal.php/foo?query => returns instance of PageFoo, routed to main() |
|
| 97 | + * /internal.php/foo/bar => returns instance of PageFoo, routed to bar() |
|
| 98 | + * /internal.php/foo/bar?query => returns instance of PageFoo, routed to bar() |
|
| 99 | + * /internal.php/foo/baz => returns instance of Page404, routed to main() |
|
| 100 | + * /internal.php/foo/baz?query => returns instance of Page404, routed to main() |
|
| 101 | + * /internal.php/bar => returns instance of Page404, routed to main() |
|
| 102 | + * /internal.php/bar?query => returns instance of Page404, routed to main() |
|
| 103 | + * /internal.php/bar/baz => returns instance of Page404, routed to main() |
|
| 104 | + * /internal.php/bar/baz?query => returns instance of Page404, routed to main() |
|
| 105 | + * |
|
| 106 | + * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need |
|
| 107 | + * to change the key, then you'll likely have to update a lot of files. |
|
| 108 | + * |
|
| 109 | + * @var array |
|
| 110 | + */ |
|
| 111 | + private $routeMap = array( |
|
| 112 | + |
|
| 113 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 114 | + // Login and registration |
|
| 115 | + 'logout' => |
|
| 116 | + array( |
|
| 117 | + 'class' => PageLogout::class, |
|
| 118 | + 'actions' => array(), |
|
| 119 | + ), |
|
| 120 | + 'login' => |
|
| 121 | + array( |
|
| 122 | + 'class' => PagePasswordLogin::class, |
|
| 123 | + 'actions' => array(), |
|
| 124 | + ), |
|
| 125 | + 'login/otp' => |
|
| 126 | + array( |
|
| 127 | + 'class' => PageOtpLogin::class, |
|
| 128 | + 'actions' => array(), |
|
| 129 | + ), |
|
| 130 | + 'login/u2f' => |
|
| 131 | + array( |
|
| 132 | + 'class' => PageU2FLogin::class, |
|
| 133 | + 'actions' => array(), |
|
| 134 | + ), |
|
| 135 | + 'forgotPassword' => |
|
| 136 | + array( |
|
| 137 | + 'class' => PageForgotPassword::class, |
|
| 138 | + 'actions' => array('reset'), |
|
| 139 | + ), |
|
| 140 | + 'register' => |
|
| 141 | + array( |
|
| 142 | + 'class' => PageRegisterOption::class, |
|
| 143 | + 'actions' => array(), |
|
| 144 | + ), |
|
| 145 | + 'register/standard' => |
|
| 146 | + array( |
|
| 147 | + 'class' => PageRegisterStandard::class, |
|
| 148 | + 'actions' => array('done'), |
|
| 149 | + ), |
|
| 150 | + |
|
| 151 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 152 | + // Discovery |
|
| 153 | + 'search' => |
|
| 154 | + array( |
|
| 155 | + 'class' => PageSearch::class, |
|
| 156 | + 'actions' => array(), |
|
| 157 | + ), |
|
| 158 | + 'logs' => |
|
| 159 | + array( |
|
| 160 | + 'class' => PageLog::class, |
|
| 161 | + 'actions' => array(), |
|
| 162 | + ), |
|
| 163 | + |
|
| 164 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 165 | + // Administration |
|
| 166 | + 'bans' => |
|
| 167 | + array( |
|
| 168 | + 'class' => PageBan::class, |
|
| 169 | + 'actions' => array('set', 'remove'), |
|
| 170 | + ), |
|
| 171 | + 'userManagement' => |
|
| 172 | + array( |
|
| 173 | + 'class' => PageUserManagement::class, |
|
| 174 | + 'actions' => array( |
|
| 175 | + 'approve', |
|
| 176 | + 'decline', |
|
| 177 | + 'rename', |
|
| 178 | + 'editUser', |
|
| 179 | + 'suspend', |
|
| 180 | + 'editRoles', |
|
| 181 | + ), |
|
| 182 | + ), |
|
| 183 | + 'siteNotice' => |
|
| 184 | + array( |
|
| 185 | + 'class' => PageSiteNotice::class, |
|
| 186 | + 'actions' => array(), |
|
| 187 | + ), |
|
| 188 | + 'emailManagement' => |
|
| 189 | + array( |
|
| 190 | + 'class' => PageEmailManagement::class, |
|
| 191 | + 'actions' => array('create', 'edit', 'view'), |
|
| 192 | + ), |
|
| 193 | + 'jobQueue' => |
|
| 194 | + array( |
|
| 195 | + 'class' => PageJobQueue::class, |
|
| 196 | + 'actions' => array('acknowledge', 'requeue', 'view', 'all'), |
|
| 197 | + ), |
|
| 198 | + |
|
| 199 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 200 | + // Personal preferences |
|
| 201 | + 'preferences' => |
|
| 202 | + array( |
|
| 203 | + 'class' => PagePreferences::class, |
|
| 204 | + 'actions' => array( |
|
| 205 | + 'refreshOAuth' |
|
| 206 | + ), |
|
| 207 | + ), |
|
| 208 | + 'changePassword' => |
|
| 209 | + array( |
|
| 210 | + 'class' => PageChangePassword::class, |
|
| 211 | + 'actions' => array(), |
|
| 212 | + ), |
|
| 213 | + 'multiFactor' => |
|
| 214 | + array( |
|
| 215 | + 'class' => PageMultiFactor::class, |
|
| 216 | + 'actions' => array( |
|
| 217 | + 'scratch', |
|
| 218 | + 'enableYubikeyOtp', |
|
| 219 | + 'disableYubikeyOtp', |
|
| 220 | + 'enableTotp', |
|
| 221 | + 'disableTotp', |
|
| 222 | + 'enableU2F', |
|
| 223 | + 'disableU2F', |
|
| 224 | + ), |
|
| 225 | + ), |
|
| 226 | + 'oauth' => |
|
| 227 | + array( |
|
| 228 | + 'class' => PageOAuth::class, |
|
| 229 | + 'actions' => array('detach', 'attach'), |
|
| 230 | + ), |
|
| 231 | + 'oauth/callback' => |
|
| 232 | + array( |
|
| 233 | + 'class' => PageOAuthCallback::class, |
|
| 234 | + 'actions' => array('authorise', 'create'), |
|
| 235 | + ), |
|
| 236 | + |
|
| 237 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 238 | + // Welcomer configuration |
|
| 239 | + 'welcomeTemplates' => |
|
| 240 | + array( |
|
| 241 | + 'class' => PageWelcomeTemplateManagement::class, |
|
| 242 | + 'actions' => array('select', 'edit', 'delete', 'add', 'view'), |
|
| 243 | + ), |
|
| 244 | + |
|
| 245 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 246 | + // Statistics |
|
| 247 | + 'statistics' => |
|
| 248 | + array( |
|
| 249 | + 'class' => StatsMain::class, |
|
| 250 | + 'actions' => array(), |
|
| 251 | + ), |
|
| 252 | + 'statistics/fastCloses' => |
|
| 253 | + array( |
|
| 254 | + 'class' => StatsFastCloses::class, |
|
| 255 | + 'actions' => array(), |
|
| 256 | + ), |
|
| 257 | + 'statistics/inactiveUsers' => |
|
| 258 | + array( |
|
| 259 | + 'class' => StatsInactiveUsers::class, |
|
| 260 | + 'actions' => array(), |
|
| 261 | + ), |
|
| 262 | + 'statistics/monthlyStats' => |
|
| 263 | + array( |
|
| 264 | + 'class' => StatsMonthlyStats::class, |
|
| 265 | + 'actions' => array(), |
|
| 266 | + ), |
|
| 267 | + 'statistics/reservedRequests' => |
|
| 268 | + array( |
|
| 269 | + 'class' => StatsReservedRequests::class, |
|
| 270 | + 'actions' => array(), |
|
| 271 | + ), |
|
| 272 | + 'statistics/templateStats' => |
|
| 273 | + array( |
|
| 274 | + 'class' => StatsTemplateStats::class, |
|
| 275 | + 'actions' => array(), |
|
| 276 | + ), |
|
| 277 | + 'statistics/topCreators' => |
|
| 278 | + array( |
|
| 279 | + 'class' => StatsTopCreators::class, |
|
| 280 | + 'actions' => array(), |
|
| 281 | + ), |
|
| 282 | + 'statistics/users' => |
|
| 283 | + array( |
|
| 284 | + 'class' => StatsUsers::class, |
|
| 285 | + 'actions' => array('detail'), |
|
| 286 | + ), |
|
| 287 | + |
|
| 288 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 289 | + // Zoom page |
|
| 290 | + 'viewRequest' => |
|
| 291 | + array( |
|
| 292 | + 'class' => PageViewRequest::class, |
|
| 293 | + 'actions' => array(), |
|
| 294 | + ), |
|
| 295 | + 'viewRequest/reserve' => |
|
| 296 | + array( |
|
| 297 | + 'class' => PageReservation::class, |
|
| 298 | + 'actions' => array(), |
|
| 299 | + ), |
|
| 300 | + 'viewRequest/breakReserve' => |
|
| 301 | + array( |
|
| 302 | + 'class' => PageBreakReservation::class, |
|
| 303 | + 'actions' => array(), |
|
| 304 | + ), |
|
| 305 | + 'viewRequest/defer' => |
|
| 306 | + array( |
|
| 307 | + 'class' => PageDeferRequest::class, |
|
| 308 | + 'actions' => array(), |
|
| 309 | + ), |
|
| 310 | + 'viewRequest/comment' => |
|
| 311 | + array( |
|
| 312 | + 'class' => PageComment::class, |
|
| 313 | + 'actions' => array(), |
|
| 314 | + ), |
|
| 315 | + 'viewRequest/sendToUser' => |
|
| 316 | + array( |
|
| 317 | + 'class' => PageSendToUser::class, |
|
| 318 | + 'actions' => array(), |
|
| 319 | + ), |
|
| 320 | + 'viewRequest/close' => |
|
| 321 | + array( |
|
| 322 | + 'class' => PageCloseRequest::class, |
|
| 323 | + 'actions' => array(), |
|
| 324 | + ), |
|
| 325 | + 'viewRequest/create' => |
|
| 326 | + array( |
|
| 327 | + 'class' => PageCreateRequest::class, |
|
| 328 | + 'actions' => array(), |
|
| 329 | + ), |
|
| 330 | + 'viewRequest/drop' => |
|
| 331 | + array( |
|
| 332 | + 'class' => PageDropRequest::class, |
|
| 333 | + 'actions' => array(), |
|
| 334 | + ), |
|
| 335 | + 'viewRequest/custom' => |
|
| 336 | + array( |
|
| 337 | + 'class' => PageCustomClose::class, |
|
| 338 | + 'actions' => array(), |
|
| 339 | + ), |
|
| 340 | + 'editComment' => |
|
| 341 | + array( |
|
| 342 | + 'class' => PageEditComment::class, |
|
| 343 | + 'actions' => array(), |
|
| 344 | + ), |
|
| 345 | + |
|
| 346 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 347 | + // Misc stuff |
|
| 348 | + 'team' => |
|
| 349 | + array( |
|
| 350 | + 'class' => PageTeam::class, |
|
| 351 | + 'actions' => array(), |
|
| 352 | + ), |
|
| 353 | + 'requestList' => |
|
| 354 | + array( |
|
| 355 | + 'class' => PageExpandedRequestList::class, |
|
| 356 | + 'actions' => array(), |
|
| 357 | + ), |
|
| 358 | + 'xffdemo' => |
|
| 359 | + array( |
|
| 360 | + 'class' => PageXffDemo::class, |
|
| 361 | + 'actions' => array(), |
|
| 362 | + ), |
|
| 363 | + ); |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * @return IRoutedTask |
|
| 367 | + * @throws Exception |
|
| 368 | + */ |
|
| 369 | + final public function route() |
|
| 370 | + { |
|
| 371 | + $pathInfo = WebRequest::pathInfo(); |
|
| 372 | + |
|
| 373 | + list($pageClass, $action) = $this->getRouteFromPath($pathInfo); |
|
| 374 | + |
|
| 375 | + /** @var IRoutedTask $page */ |
|
| 376 | + $page = new $pageClass(); |
|
| 377 | + |
|
| 378 | + // Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so |
|
| 379 | + // let's use our own. |
|
| 380 | + if (!($page instanceof IRoutedTask)) { |
|
| 381 | + throw new Exception('Expected a page, but this is not a page.'); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + // OK, I'm happy at this point that we know we're running a page, and we know it's probably what we want if it |
|
| 385 | + // inherits PageBase and has been created from the routing map. |
|
| 386 | + $page->setRoute($action); |
|
| 387 | + |
|
| 388 | + return $page; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * @param $pathInfo |
|
| 393 | + * |
|
| 394 | + * @return array |
|
| 395 | + */ |
|
| 396 | + protected function getRouteFromPath($pathInfo) |
|
| 397 | + { |
|
| 398 | + if (count($pathInfo) === 0) { |
|
| 399 | + // No pathInfo, so no page to load. Load the main page. |
|
| 400 | + return $this->getDefaultRoute(); |
|
| 401 | + } |
|
| 402 | + elseif (count($pathInfo) === 1) { |
|
| 403 | + // Exactly one path info segment, it's got to be a page. |
|
| 404 | + $classSegment = $pathInfo[0]; |
|
| 405 | + |
|
| 406 | + return $this->routeSinglePathSegment($classSegment); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + // OK, we have two or more segments now. |
|
| 410 | + if (count($pathInfo) > 2) { |
|
| 411 | + // Let's handle more than two, and collapse it down into two. |
|
| 412 | + $requestedAction = array_pop($pathInfo); |
|
| 413 | + $classSegment = implode('/', $pathInfo); |
|
| 414 | + } |
|
| 415 | + else { |
|
| 416 | + // Two path info segments. |
|
| 417 | + $classSegment = $pathInfo[0]; |
|
| 418 | + $requestedAction = $pathInfo[1]; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + $routeMap = $this->routePathSegments($classSegment, $requestedAction); |
|
| 422 | + |
|
| 423 | + if ($routeMap[0] === Page404::class) { |
|
| 424 | + $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + return $routeMap; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * @param $classSegment |
|
| 432 | + * |
|
| 433 | + * @return array |
|
| 434 | + */ |
|
| 435 | + final protected function routeSinglePathSegment($classSegment) |
|
| 436 | + { |
|
| 437 | + $routeMap = $this->getRouteMap(); |
|
| 438 | + if (array_key_exists($classSegment, $routeMap)) { |
|
| 439 | + // Route exists, but we don't have an action in path info, so default to main. |
|
| 440 | + $pageClass = $routeMap[$classSegment]['class']; |
|
| 441 | + $action = 'main'; |
|
| 442 | + |
|
| 443 | + return array($pageClass, $action); |
|
| 444 | + } |
|
| 445 | + else { |
|
| 446 | + // Doesn't exist in map. Fall back to 404 |
|
| 447 | + $pageClass = Page404::class; |
|
| 448 | + $action = "main"; |
|
| 449 | + |
|
| 450 | + return array($pageClass, $action); |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * @param $classSegment |
|
| 456 | + * @param $requestedAction |
|
| 457 | + * |
|
| 458 | + * @return array |
|
| 459 | + */ |
|
| 460 | + final protected function routePathSegments($classSegment, $requestedAction) |
|
| 461 | + { |
|
| 462 | + $routeMap = $this->getRouteMap(); |
|
| 463 | + if (array_key_exists($classSegment, $routeMap)) { |
|
| 464 | + // Route exists, but we don't have an action in path info, so default to main. |
|
| 465 | + |
|
| 466 | + if (isset($routeMap[$classSegment]['actions']) |
|
| 467 | + && array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false |
|
| 468 | + ) { |
|
| 469 | + // Action exists in allowed action list. Allow both the page and the action |
|
| 470 | + $pageClass = $routeMap[$classSegment]['class']; |
|
| 471 | + $action = $requestedAction; |
|
| 472 | + |
|
| 473 | + return array($pageClass, $action); |
|
| 474 | + } |
|
| 475 | + else { |
|
| 476 | + // Valid page, invalid action. 404 our way out. |
|
| 477 | + $pageClass = Page404::class; |
|
| 478 | + $action = 'main'; |
|
| 479 | + |
|
| 480 | + return array($pageClass, $action); |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + else { |
|
| 484 | + // Class doesn't exist in map. Fall back to 404 |
|
| 485 | + $pageClass = Page404::class; |
|
| 486 | + $action = 'main'; |
|
| 487 | + |
|
| 488 | + return array($pageClass, $action); |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * @return array |
|
| 494 | + */ |
|
| 495 | + protected function getRouteMap() |
|
| 496 | + { |
|
| 497 | + return $this->routeMap; |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * @return array |
|
| 502 | + */ |
|
| 503 | + protected function getDefaultRoute() |
|
| 504 | + { |
|
| 505 | + return array(PageMain::class, "main"); |
|
| 506 | + } |
|
| 507 | 507 | } |
@@ -18,9 +18,9 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | interface IRequestRouter |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @return IRoutedTask |
|
| 23 | - * @throws Exception |
|
| 24 | - */ |
|
| 25 | - public function route(); |
|
| 21 | + /** |
|
| 22 | + * @return IRoutedTask |
|
| 23 | + * @throws Exception |
|
| 24 | + */ |
|
| 25 | + public function route(); |
|
| 26 | 26 | } |
| 27 | 27 | \ No newline at end of file |
@@ -15,42 +15,42 @@ |
||
| 15 | 15 | |
| 16 | 16 | class PublicRequestRouter extends RequestRouter |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Gets the route map to be used by this request router. |
|
| 20 | - * |
|
| 21 | - * @return array |
|
| 22 | - */ |
|
| 23 | - protected function getRouteMap() |
|
| 24 | - { |
|
| 25 | - return array( |
|
| 26 | - // Page showing a message stating the request has been submitted to our internal queues |
|
| 27 | - 'requestSubmitted' => |
|
| 28 | - array( |
|
| 29 | - 'class' => PageRequestSubmitted::class, |
|
| 30 | - 'actions' => array(), |
|
| 31 | - ), |
|
| 32 | - // Page showing a message stating that email confirmation is required to continue |
|
| 33 | - 'emailConfirmationRequired' => |
|
| 34 | - array( |
|
| 35 | - 'class' => PageEmailConfirmationRequired::class, |
|
| 36 | - 'actions' => array(), |
|
| 37 | - ), |
|
| 38 | - // Action page which handles email confirmation |
|
| 39 | - 'confirmEmail' => |
|
| 40 | - array( |
|
| 41 | - 'class' => PageConfirmEmail::class, |
|
| 42 | - 'actions' => array(), |
|
| 43 | - ), |
|
| 44 | - ); |
|
| 45 | - } |
|
| 18 | + /** |
|
| 19 | + * Gets the route map to be used by this request router. |
|
| 20 | + * |
|
| 21 | + * @return array |
|
| 22 | + */ |
|
| 23 | + protected function getRouteMap() |
|
| 24 | + { |
|
| 25 | + return array( |
|
| 26 | + // Page showing a message stating the request has been submitted to our internal queues |
|
| 27 | + 'requestSubmitted' => |
|
| 28 | + array( |
|
| 29 | + 'class' => PageRequestSubmitted::class, |
|
| 30 | + 'actions' => array(), |
|
| 31 | + ), |
|
| 32 | + // Page showing a message stating that email confirmation is required to continue |
|
| 33 | + 'emailConfirmationRequired' => |
|
| 34 | + array( |
|
| 35 | + 'class' => PageEmailConfirmationRequired::class, |
|
| 36 | + 'actions' => array(), |
|
| 37 | + ), |
|
| 38 | + // Action page which handles email confirmation |
|
| 39 | + 'confirmEmail' => |
|
| 40 | + array( |
|
| 41 | + 'class' => PageConfirmEmail::class, |
|
| 42 | + 'actions' => array(), |
|
| 43 | + ), |
|
| 44 | + ); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Gets the default route if no explicit route is requested. |
|
| 49 | - * |
|
| 50 | - * @return callable |
|
| 51 | - */ |
|
| 52 | - protected function getDefaultRoute() |
|
| 53 | - { |
|
| 54 | - return array(PageRequestAccount::class, 'main'); |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * Gets the default route if no explicit route is requested. |
|
| 49 | + * |
|
| 50 | + * @return callable |
|
| 51 | + */ |
|
| 52 | + protected function getDefaultRoute() |
|
| 53 | + { |
|
| 54 | + return array(PageRequestAccount::class, 'main'); |
|
| 55 | + } |
|
| 56 | 56 | } |
| 57 | 57 | \ No newline at end of file |