Failed Conditions
Pull Request — newinternal (#527)
by Simon
16:02 queued 05:59
created
includes/Pages/Statistics/StatsMain.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -12,99 +12,99 @@
 block discarded – undo
12 12
 
13 13
 class StatsMain extends InternalPageBase
14 14
 {
15
-    public function main()
16
-    {
17
-        $this->setHtmlTitle('Statistics');
18
-
19
-        $this->assign('statsPageTitle', 'Account Creation Statistics');
20
-
21
-        $statsPages = array(
22
-            'fastCloses'       => 'Requests closed less than 30 seconds after reservation in the past 3 months',
23
-            'inactiveUsers'    => 'Inactive tool users',
24
-            'monthlyStats'     => 'Monthly Statistics',
25
-            'reservedRequests' => 'All currently reserved requests',
26
-            'templateStats'    => 'Template Stats',
27
-            'topCreators'      => 'Top Account Creators',
28
-            'users'            => 'Account Creation Tool users',
29
-        );
30
-
31
-        $this->generateSmallStatsTable();
32
-
33
-        $this->assign('statsPages', $statsPages);
34
-
35
-        $graphList = array('day', '2day', '4day', 'week', '2week', 'month', '3month');
36
-        $this->assign('graphList', $graphList);
37
-
38
-        $this->setTemplate('statistics/main.tpl');
39
-    }
40
-
41
-    /**
42
-     * Gets the relevant statistics from the database for the small statistics table
43
-     */
44
-    private function generateSmallStatsTable()
45
-    {
46
-        $database = $this->getDatabase();
47
-        $requestsQuery = <<<'SQL'
15
+	public function main()
16
+	{
17
+		$this->setHtmlTitle('Statistics');
18
+
19
+		$this->assign('statsPageTitle', 'Account Creation Statistics');
20
+
21
+		$statsPages = array(
22
+			'fastCloses'       => 'Requests closed less than 30 seconds after reservation in the past 3 months',
23
+			'inactiveUsers'    => 'Inactive tool users',
24
+			'monthlyStats'     => 'Monthly Statistics',
25
+			'reservedRequests' => 'All currently reserved requests',
26
+			'templateStats'    => 'Template Stats',
27
+			'topCreators'      => 'Top Account Creators',
28
+			'users'            => 'Account Creation Tool users',
29
+		);
30
+
31
+		$this->generateSmallStatsTable();
32
+
33
+		$this->assign('statsPages', $statsPages);
34
+
35
+		$graphList = array('day', '2day', '4day', 'week', '2week', 'month', '3month');
36
+		$this->assign('graphList', $graphList);
37
+
38
+		$this->setTemplate('statistics/main.tpl');
39
+	}
40
+
41
+	/**
42
+	 * Gets the relevant statistics from the database for the small statistics table
43
+	 */
44
+	private function generateSmallStatsTable()
45
+	{
46
+		$database = $this->getDatabase();
47
+		$requestsQuery = <<<'SQL'
48 48
 SELECT COUNT(*) FROM request WHERE status = :status AND emailconfirm = 'Confirmed';
49 49
 SQL;
50
-        $requestsStatement = $database->prepare($requestsQuery);
50
+		$requestsStatement = $database->prepare($requestsQuery);
51 51
 
52
-        $requestStates = $this->getSiteConfiguration()->getRequestStates();
52
+		$requestStates = $this->getSiteConfiguration()->getRequestStates();
53 53
 
54
-        $requestStateData = array();
54
+		$requestStateData = array();
55 55
 
56
-        foreach ($requestStates as $statusName => $data) {
57
-            $requestsStatement->execute(array(':status' => $statusName));
58
-            $requestCount = $requestsStatement->fetchColumn();
59
-            $requestsStatement->closeCursor();
60
-            $headerText = $data['header'];
61
-            $requestStateData[$headerText] = $requestCount;
62
-        }
56
+		foreach ($requestStates as $statusName => $data) {
57
+			$requestsStatement->execute(array(':status' => $statusName));
58
+			$requestCount = $requestsStatement->fetchColumn();
59
+			$requestsStatement->closeCursor();
60
+			$headerText = $data['header'];
61
+			$requestStateData[$headerText] = $requestCount;
62
+		}
63 63
 
64
-        $this->assign('requestCountData', $requestStateData);
64
+		$this->assign('requestCountData', $requestStateData);
65 65
 
66
-        // Unconfirmed requests
67
-        $unconfirmedStatement = $database->query(<<<SQL
66
+		// Unconfirmed requests
67
+		$unconfirmedStatement = $database->query(<<<SQL
68 68
 SELECT COUNT(*) FROM request WHERE emailconfirm != 'Confirmed' AND emailconfirm != '';
69 69
 SQL
70
-        );
71
-        $unconfirmed = $unconfirmedStatement->fetchColumn();
72
-        $unconfirmedStatement->closeCursor();
73
-        $this->assign('statsUnconfirmed', $unconfirmed);
74
-
75
-        $userStatusStatement = $database->prepare('SELECT COUNT(*) FROM user WHERE status = :status;');
76
-
77
-        // Admin users
78
-        $userStatusStatement->execute(array(':status' => 'Admin'));
79
-        $adminUsers = $userStatusStatement->fetchColumn();
80
-        $userStatusStatement->closeCursor();
81
-        $this->assign('statsAdminUsers', $adminUsers);
82
-
83
-        // Users
84
-        $userStatusStatement->execute(array(':status' => 'User'));
85
-        $users = $userStatusStatement->fetchColumn();
86
-        $userStatusStatement->closeCursor();
87
-        $this->assign('statsUsers', $users);
88
-
89
-        // Suspended users
90
-        $userStatusStatement->execute(array(':status' => 'Suspended'));
91
-        $suspendedUsers = $userStatusStatement->fetchColumn();
92
-        $userStatusStatement->closeCursor();
93
-        $this->assign('statsSuspendedUsers', $suspendedUsers);
94
-
95
-        // New users
96
-        $userStatusStatement->execute(array(':status' => 'New'));
97
-        $newUsers = $userStatusStatement->fetchColumn();
98
-        $userStatusStatement->closeCursor();
99
-        $this->assign('statsNewUsers', $newUsers);
100
-
101
-        // Most comments on a request
102
-        $mostCommentsStatement = $database->query(<<<SQL
70
+		);
71
+		$unconfirmed = $unconfirmedStatement->fetchColumn();
72
+		$unconfirmedStatement->closeCursor();
73
+		$this->assign('statsUnconfirmed', $unconfirmed);
74
+
75
+		$userStatusStatement = $database->prepare('SELECT COUNT(*) FROM user WHERE status = :status;');
76
+
77
+		// Admin users
78
+		$userStatusStatement->execute(array(':status' => 'Admin'));
79
+		$adminUsers = $userStatusStatement->fetchColumn();
80
+		$userStatusStatement->closeCursor();
81
+		$this->assign('statsAdminUsers', $adminUsers);
82
+
83
+		// Users
84
+		$userStatusStatement->execute(array(':status' => 'User'));
85
+		$users = $userStatusStatement->fetchColumn();
86
+		$userStatusStatement->closeCursor();
87
+		$this->assign('statsUsers', $users);
88
+
89
+		// Suspended users
90
+		$userStatusStatement->execute(array(':status' => 'Suspended'));
91
+		$suspendedUsers = $userStatusStatement->fetchColumn();
92
+		$userStatusStatement->closeCursor();
93
+		$this->assign('statsSuspendedUsers', $suspendedUsers);
94
+
95
+		// New users
96
+		$userStatusStatement->execute(array(':status' => 'New'));
97
+		$newUsers = $userStatusStatement->fetchColumn();
98
+		$userStatusStatement->closeCursor();
99
+		$this->assign('statsNewUsers', $newUsers);
100
+
101
+		// Most comments on a request
102
+		$mostCommentsStatement = $database->query(<<<SQL
103 103
 SELECT request FROM comment GROUP BY request ORDER BY COUNT(*) DESC LIMIT 1;
104 104
 SQL
105
-        );
106
-        $mostComments = $mostCommentsStatement->fetchColumn();
107
-        $mostCommentsStatement->closeCursor();
108
-        $this->assign('mostComments', $mostComments);
109
-    }
105
+		);
106
+		$mostComments = $mostCommentsStatement->fetchColumn();
107
+		$mostCommentsStatement->closeCursor();
108
+		$this->assign('mostComments', $mostComments);
109
+	}
110 110
 }
Please login to merge, or discard this patch.
includes/Pages/Statistics/StatsTemplateStats.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@  discard block
 block discarded – undo
13 13
 
14 14
 class StatsTemplateStats extends InternalPageBase
15 15
 {
16
-    public function main()
17
-    {
18
-        $this->setHtmlTitle('Template Stats :: Statistics');
16
+	public function main()
17
+	{
18
+		$this->setHtmlTitle('Template Stats :: Statistics');
19 19
 
20
-        $query = <<<SQL
20
+		$query = <<<SQL
21 21
 SELECT
22 22
     t.id AS templateid,
23 23
     t.usercode AS usercode,
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
         GROUP BY welcome_template
46 46
     ) u2 ON u2.allid = t.id;
47 47
 SQL;
48
-        $database = $this->getDatabase();
49
-        $statement = $database->query($query);
50
-        $data = $statement->fetchAll(PDO::FETCH_ASSOC);
51
-        $this->assign('dataTable', $data);
52
-        $this->assign('statsPageTitle', 'Template Stats');
53
-        $this->setTemplate('statistics/welcome-template-usage.tpl');
54
-    }
48
+		$database = $this->getDatabase();
49
+		$statement = $database->query($query);
50
+		$data = $statement->fetchAll(PDO::FETCH_ASSOC);
51
+		$this->assign('dataTable', $data);
52
+		$this->assign('statsPageTitle', 'Template Stats');
53
+		$this->setTemplate('statistics/welcome-template-usage.tpl');
54
+	}
55 55
 }
Please login to merge, or discard this patch.
includes/Pages/Statistics/StatsReservedRequests.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@  discard block
 block discarded – undo
13 13
 
14 14
 class StatsReservedRequests extends InternalPageBase
15 15
 {
16
-    public function main()
17
-    {
18
-        $this->setHtmlTitle('Reserved Requests :: Statistics');
16
+	public function main()
17
+	{
18
+		$this->setHtmlTitle('Reserved Requests :: Statistics');
19 19
 
20
-        $query = <<<sql
20
+		$query = <<<sql
21 21
 SELECT
22 22
     p.id AS requestid,
23 23
     p.name AS name,
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
 WHERE reserved != 0;
30 30
 sql;
31 31
 
32
-        $database = $this->getDatabase();
33
-        $statement = $database->query($query);
34
-        $data = $statement->fetchAll(PDO::FETCH_ASSOC);
35
-        $this->assign('dataTable', $data);
36
-        $this->assign('statsPageTitle', 'All currently reserved requests');
37
-        $this->setTemplate('statistics/reserved-requests.tpl');
38
-    }
32
+		$database = $this->getDatabase();
33
+		$statement = $database->query($query);
34
+		$data = $statement->fetchAll(PDO::FETCH_ASSOC);
35
+		$this->assign('dataTable', $data);
36
+		$this->assign('statsPageTitle', 'All currently reserved requests');
37
+		$this->setTemplate('statistics/reserved-requests.tpl');
38
+	}
39 39
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageBreakReservation.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -19,79 +19,79 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageReservation.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -17,58 +17,58 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageDeferRequest.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -17,57 +17,57 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageCustomClose.php 1 patch
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -23,264 +23,264 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageSendToUser.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -17,43 +17,43 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
includes/Pages/PageEmailManagement.php 1 patch
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -19,175 +19,175 @@
 block discarded – undo
19 19
 
20 20
 class PageEmailManagement extends InternalPageBase
21 21
 {
22
-    /**
23
-     * Main function for this page, when no specific actions are called.
24
-     * @return void
25
-     */
26
-    protected function main()
27
-    {
28
-        $this->setHtmlTitle('Close Emails');
29
-
30
-        // Get all active email templates
31
-        $activeTemplates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase());
32
-        $inactiveTemplates = EmailTemplate::getAllInactiveTemplates($this->getDatabase());
33
-
34
-        $this->assign('activeTemplates', $activeTemplates);
35
-        $this->assign('inactiveTemplates', $inactiveTemplates);
36
-
37
-        $user = User::getCurrent($this->getDatabase());
38
-        $this->assign('canCreate', $this->barrierTest('create', $user));
39
-        $this->assign('canEdit', $this->barrierTest('edit', $user));
40
-
41
-        $this->setTemplate('email-management/main.tpl');
42
-    }
43
-
44
-    protected function view()
45
-    {
46
-        $this->setHtmlTitle('Close Emails');
47
-
48
-        $database = $this->getDatabase();
49
-        $template = $this->getTemplate($database);
50
-
51
-        $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId();
52
-        $requestStates = $this->getSiteConfiguration()->getRequestStates();
53
-
54
-        $this->assign('id', $template->getId());
55
-        $this->assign('emailTemplate', $template);
56
-        $this->assign('createdid', $createdId);
57
-        $this->assign('requeststates', $requestStates);
58
-
59
-        $this->setTemplate('email-management/view.tpl');
60
-    }
61
-
62
-    /**
63
-     * @param PdoDatabase $database
64
-     *
65
-     * @return EmailTemplate
66
-     * @throws ApplicationLogicException
67
-     */
68
-    protected function getTemplate(PdoDatabase $database)
69
-    {
70
-        $templateId = WebRequest::getInt('id');
71
-        if ($templateId === null) {
72
-            throw new ApplicationLogicException('Template not specified');
73
-        }
74
-        $template = EmailTemplate::getById($templateId, $database);
75
-        if ($template === false || !is_a($template, EmailTemplate::class)) {
76
-            throw new ApplicationLogicException('Template not found');
77
-        }
78
-
79
-        return $template;
80
-    }
81
-
82
-    protected function edit()
83
-    {
84
-        $this->setHtmlTitle('Close Emails');
85
-
86
-        $database = $this->getDatabase();
87
-        $template = $this->getTemplate($database);
88
-
89
-        $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId();
90
-        $requestStates = $this->getSiteConfiguration()->getRequestStates();
91
-
92
-        if (WebRequest::wasPosted()) {
93
-            $this->validateCSRFToken();
94
-
95
-            $this->modifyTemplateData($template);
96
-
97
-            $other = EmailTemplate::getByName($template->getName(), $database);
98
-            if ($other !== false && $other->getId() !== $template->getId()) {
99
-                throw new ApplicationLogicException('A template with this name already exists');
100
-            }
101
-
102
-            if ($template->getId() === $createdId) {
103
-                $template->setDefaultAction(EmailTemplate::CREATED);
104
-                $template->setActive(true);
105
-                $template->setPreloadOnly(false);
106
-            }
107
-
108
-            // optimistically lock on load of edit form
109
-            $updateVersion = WebRequest::postInt('updateversion');
110
-            $template->setUpdateVersion($updateVersion);
111
-
112
-            $template->save();
113
-            Logger::editedEmail($database, $template);
114
-            $this->getNotificationHelper()->emailEdited($template);
115
-            SessionAlert::success("Email template has been saved successfully.");
116
-
117
-            $this->redirect('emailManagement');
118
-        }
119
-        else {
120
-            $this->assignCSRFToken();
121
-            $this->assign('id', $template->getId());
122
-            $this->assign('emailTemplate', $template);
123
-            $this->assign('createdid', $createdId);
124
-            $this->assign('requeststates', $requestStates);
125
-
126
-            $this->setTemplate('email-management/edit.tpl');
127
-        }
128
-    }
129
-
130
-    /**
131
-     * @param EmailTemplate $template
132
-     *
133
-     * @throws ApplicationLogicException
134
-     */
135
-    private function modifyTemplateData(EmailTemplate $template)
136
-    {
137
-        $name = WebRequest::postString('name');
138
-        if ($name === null || $name === '') {
139
-            throw new ApplicationLogicException('Name not specified');
140
-        }
141
-
142
-        $template->setName($name);
143
-
144
-        $text = WebRequest::postString('text');
145
-        if ($text === null || $text === '') {
146
-            throw new ApplicationLogicException('Text not specified');
147
-        }
148
-
149
-        $template->setText($text);
150
-
151
-        $template->setJsquestion(WebRequest::postString('jsquestion'));
152
-
153
-        $template->setDefaultAction(WebRequest::postString('defaultaction'));
154
-        $template->setActive(WebRequest::postBoolean('active'));
155
-        $template->setPreloadOnly(WebRequest::postBoolean('preloadonly'));
156
-    }
157
-
158
-    protected function create()
159
-    {
160
-        $this->setHtmlTitle('Close Emails');
161
-
162
-        $database = $this->getDatabase();
163
-
164
-        $requestStates = $this->getSiteConfiguration()->getRequestStates();
165
-
166
-        if (WebRequest::wasPosted()) {
167
-            $this->validateCSRFToken();
168
-            $template = new EmailTemplate();
169
-            $template->setDatabase($database);
170
-
171
-            $this->modifyTemplateData($template);
172
-
173
-            $other = EmailTemplate::getByName($template->getName(), $database);
174
-            if ($other !== false) {
175
-                throw new ApplicationLogicException('A template with this name already exists');
176
-            }
177
-
178
-            $template->save();
179
-
180
-            Logger::createEmail($database, $template);
181
-            $this->getNotificationHelper()->emailCreated($template);
182
-
183
-            SessionAlert::success("Email template has been saved successfully.");
184
-
185
-            $this->redirect('emailManagement');
186
-        }
187
-        else {
188
-            $this->assignCSRFToken();
189
-            $this->assign('requeststates', $requestStates);
190
-            $this->setTemplate('email-management/create.tpl');
191
-        }
192
-    }
22
+	/**
23
+	 * Main function for this page, when no specific actions are called.
24
+	 * @return void
25
+	 */
26
+	protected function main()
27
+	{
28
+		$this->setHtmlTitle('Close Emails');
29
+
30
+		// Get all active email templates
31
+		$activeTemplates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase());
32
+		$inactiveTemplates = EmailTemplate::getAllInactiveTemplates($this->getDatabase());
33
+
34
+		$this->assign('activeTemplates', $activeTemplates);
35
+		$this->assign('inactiveTemplates', $inactiveTemplates);
36
+
37
+		$user = User::getCurrent($this->getDatabase());
38
+		$this->assign('canCreate', $this->barrierTest('create', $user));
39
+		$this->assign('canEdit', $this->barrierTest('edit', $user));
40
+
41
+		$this->setTemplate('email-management/main.tpl');
42
+	}
43
+
44
+	protected function view()
45
+	{
46
+		$this->setHtmlTitle('Close Emails');
47
+
48
+		$database = $this->getDatabase();
49
+		$template = $this->getTemplate($database);
50
+
51
+		$createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId();
52
+		$requestStates = $this->getSiteConfiguration()->getRequestStates();
53
+
54
+		$this->assign('id', $template->getId());
55
+		$this->assign('emailTemplate', $template);
56
+		$this->assign('createdid', $createdId);
57
+		$this->assign('requeststates', $requestStates);
58
+
59
+		$this->setTemplate('email-management/view.tpl');
60
+	}
61
+
62
+	/**
63
+	 * @param PdoDatabase $database
64
+	 *
65
+	 * @return EmailTemplate
66
+	 * @throws ApplicationLogicException
67
+	 */
68
+	protected function getTemplate(PdoDatabase $database)
69
+	{
70
+		$templateId = WebRequest::getInt('id');
71
+		if ($templateId === null) {
72
+			throw new ApplicationLogicException('Template not specified');
73
+		}
74
+		$template = EmailTemplate::getById($templateId, $database);
75
+		if ($template === false || !is_a($template, EmailTemplate::class)) {
76
+			throw new ApplicationLogicException('Template not found');
77
+		}
78
+
79
+		return $template;
80
+	}
81
+
82
+	protected function edit()
83
+	{
84
+		$this->setHtmlTitle('Close Emails');
85
+
86
+		$database = $this->getDatabase();
87
+		$template = $this->getTemplate($database);
88
+
89
+		$createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId();
90
+		$requestStates = $this->getSiteConfiguration()->getRequestStates();
91
+
92
+		if (WebRequest::wasPosted()) {
93
+			$this->validateCSRFToken();
94
+
95
+			$this->modifyTemplateData($template);
96
+
97
+			$other = EmailTemplate::getByName($template->getName(), $database);
98
+			if ($other !== false && $other->getId() !== $template->getId()) {
99
+				throw new ApplicationLogicException('A template with this name already exists');
100
+			}
101
+
102
+			if ($template->getId() === $createdId) {
103
+				$template->setDefaultAction(EmailTemplate::CREATED);
104
+				$template->setActive(true);
105
+				$template->setPreloadOnly(false);
106
+			}
107
+
108
+			// optimistically lock on load of edit form
109
+			$updateVersion = WebRequest::postInt('updateversion');
110
+			$template->setUpdateVersion($updateVersion);
111
+
112
+			$template->save();
113
+			Logger::editedEmail($database, $template);
114
+			$this->getNotificationHelper()->emailEdited($template);
115
+			SessionAlert::success("Email template has been saved successfully.");
116
+
117
+			$this->redirect('emailManagement');
118
+		}
119
+		else {
120
+			$this->assignCSRFToken();
121
+			$this->assign('id', $template->getId());
122
+			$this->assign('emailTemplate', $template);
123
+			$this->assign('createdid', $createdId);
124
+			$this->assign('requeststates', $requestStates);
125
+
126
+			$this->setTemplate('email-management/edit.tpl');
127
+		}
128
+	}
129
+
130
+	/**
131
+	 * @param EmailTemplate $template
132
+	 *
133
+	 * @throws ApplicationLogicException
134
+	 */
135
+	private function modifyTemplateData(EmailTemplate $template)
136
+	{
137
+		$name = WebRequest::postString('name');
138
+		if ($name === null || $name === '') {
139
+			throw new ApplicationLogicException('Name not specified');
140
+		}
141
+
142
+		$template->setName($name);
143
+
144
+		$text = WebRequest::postString('text');
145
+		if ($text === null || $text === '') {
146
+			throw new ApplicationLogicException('Text not specified');
147
+		}
148
+
149
+		$template->setText($text);
150
+
151
+		$template->setJsquestion(WebRequest::postString('jsquestion'));
152
+
153
+		$template->setDefaultAction(WebRequest::postString('defaultaction'));
154
+		$template->setActive(WebRequest::postBoolean('active'));
155
+		$template->setPreloadOnly(WebRequest::postBoolean('preloadonly'));
156
+	}
157
+
158
+	protected function create()
159
+	{
160
+		$this->setHtmlTitle('Close Emails');
161
+
162
+		$database = $this->getDatabase();
163
+
164
+		$requestStates = $this->getSiteConfiguration()->getRequestStates();
165
+
166
+		if (WebRequest::wasPosted()) {
167
+			$this->validateCSRFToken();
168
+			$template = new EmailTemplate();
169
+			$template->setDatabase($database);
170
+
171
+			$this->modifyTemplateData($template);
172
+
173
+			$other = EmailTemplate::getByName($template->getName(), $database);
174
+			if ($other !== false) {
175
+				throw new ApplicationLogicException('A template with this name already exists');
176
+			}
177
+
178
+			$template->save();
179
+
180
+			Logger::createEmail($database, $template);
181
+			$this->getNotificationHelper()->emailCreated($template);
182
+
183
+			SessionAlert::success("Email template has been saved successfully.");
184
+
185
+			$this->redirect('emailManagement');
186
+		}
187
+		else {
188
+			$this->assignCSRFToken();
189
+			$this->assign('requeststates', $requestStates);
190
+			$this->setTemplate('email-management/create.tpl');
191
+		}
192
+	}
193 193
 }
Please login to merge, or discard this patch.