/
admintreasurer.ctrl.php
169 lines (153 loc) · 5.1 KB
/
admintreasurer.ctrl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/*
Copyright (c) 2007-2009 BeVolunteer
This file is part of BW Rox.
BW Rox is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
BW Rox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/> or
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/**
* @author shevek
*/
/**
* admintreasurer controller
* deals with actions that are available exclusively for treasurer tool
*
* @package apps
* @subpackage Admin
*/
class AdminTreasurerController extends AdminBaseController
{
public function __construct() {
parent::__construct();
$this->model = new AdminTreasurerModel();
}
public function __destruct() {
unset($this->model);
}
/**
* Treasurer overview method
*
* @access public
* @return object
*/
public function treasurerOverview()
{
list($member, $rights) = $this->checkRights('Treasurer');
$page = new AdminTreasurerPage($this->model);
return $page;
}
/**
*
*/
public function treasurerEditCreateDonationCallback(StdClass $args, ReadOnlyObject $action, ReadWriteObject $mem_redirect, ReadWriteObject $mem_resend)
{
if (empty($args->post))
{
return false;
}
$vars = $args->post;
$errors = $this->model->treasurerEditCreateDonationVarsOk($vars);
if (!empty($errors)) {
$mem_redirect->vars = $vars;
$mem_redirect->errors = $errors;
return false;
}
$countryid = $this->model->getGeonameIdForCountryCode($vars['donate-country']);
$id = $vars['id'];
if ($id == 0) {
$memberId = $vars['IdMember'] != 0 ? $vars['IdMember'] : null;
$success = $this->model->createDonation($vars['IdMember'], $vars['DonatedOn'],
$vars['donate-amount'], $vars['donate-comment'], $countryid);
} else {
$success = $this->model->updateDonation($id, $vars['IdMember'], $vars['DonatedOn'],
$vars['donate-amount'], $vars['donate-comment'], $countryid);
}
if (!$success) {
$mem_redirect->vars = $vars;
$mem_redirect->errors = array('AdminTreasurerDbUpdateFailed');
return false;
}
return $this->router->url('admin_treasurer_overview', array(), false);
}
/**
* Treasurer edit donation method
*
* @access public
* @return object
*/
public function treasurerEditCreateDonation()
{
list($member, $rights) = $this->checkRights('Treasurer');
$id = 0;
if (isset($this->route_vars['id'])) {
$id = $this->route_vars['id'];
}
$page = new AdminTreasurerEditCreateDonationPage($this->model, $id);
return $page;
}
/**
*
*/
public function treasurerStartDonationCampaignCallback(StdClass $args,
ReadOnlyObject $action, ReadWriteObject $mem_redirect, ReadWriteObject $mem_resend)
{
if (empty($args->post))
{
return false;
}
$vars = $args->post;
$errors = $this->model->treasurerStartDonationCampaignVarsOk($vars);
if (!empty($errors)) {
$mem_redirect->vars = $vars;
$mem_redirect->errors = $errors;
return false;
}
$success = $this->model->startDonationCampaign($vars);
if (!$success) {
$mem_redirect->vars = $vars;
$mem_redirect->errors = array('AdminTreasurerDbUpdateFailed');
return false;
}
$this->session->set( 'AdminTreasurerStatus', 'StartSuccess' );
return $this->router->url('admin_treasurer_overview', array(), false);
}
/**
* This enables the treasurer to start the donation campaign
*
* @access public
* @return object
*/
public function treasurerStartDonationCampaign()
{
list($member, $rights) = $this->checkRights('Treasurer');
$page = new AdminTreasurerStartDonationCampaignPage($this->model);
return $page;
}
/**
* This enables the treasurer to stop the donation campaign
*
* @access public
* @return object
*/
public function treasurerStopDonationCampaign()
{
list($member, $rights) = $this->checkRights('Treasurer');
$success = $this->model->stopDonationCampaign();
if ($success) {
$this->session->set( 'AdminTreasurerStatus', 'StopSuccess' );
} else {
$this->session->set( 'AdminTreasurerStatus', 'StopFailed' );
}
$this->redirectAbsolute($this->router->url('admin_treasurer_overview'));
}
}