Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Page for displaying list of Payment-Instrument | |
38 | */ | |
39 | class CRM_Member_Page_DashBoard extends CRM_Core_Page { | |
40 | ||
41 | /** | |
42 | * Heart of the viewing process. The runner gets all the meta data for | |
43 | * the contact and calls the appropriate type of page to view. | |
44 | * | |
45 | * @return void | |
6a488035 | 46 | */ |
00be9182 | 47 | public function preProcess() { |
46c91013 E |
48 | |
49 | //CRM-13901 don't show dashboard to contacts with limited view writes & it does not relect | |
50 | //what they have access to | |
51 | //@todo implement acls on dashboard querys (preferably via api to enhance that at the same time) | |
feead5e7 | 52 | if (!CRM_Core_Permission::check('view all contacts') && !CRM_Core_Permission::check('edit all contacts')) { |
46c91013 E |
53 | $this->showMembershipSummary = FALSE; |
54 | $this->assign('membershipSummary', FALSE); | |
55 | return; | |
56 | } | |
57 | $this->assign('membershipSummary', TRUE); | |
6a488035 TO |
58 | CRM_Utils_System::setTitle(ts('CiviMember')); |
59 | $membershipSummary = array(); | |
4e636a74 AH |
60 | $preMonth = date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))); |
61 | $preMonthEnd = date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))); | |
6a488035 TO |
62 | |
63 | $preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4)); | |
64 | ||
4e636a74 AH |
65 | $today = getdate(); |
66 | $date = CRM_Utils_Date::getToday(); | |
6a488035 TO |
67 | $isCurrentMonth = 0; |
68 | ||
4e636a74 | 69 | // You can force the dashboard to display based upon a certain date |
6a488035 | 70 | $ym = CRM_Utils_Array::value('date', $_GET); |
8ef12e64 | 71 | |
6a488035 TO |
72 | if ($ym) { |
73 | if (preg_match('/^\d{6}$/', $ym) == 0 || | |
74 | !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) || | |
75 | substr($ym, 0, 1) == 0 | |
76 | ) { | |
77 | CRM_Core_Error::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym))); | |
78 | } | |
79 | ||
80 | $isPreviousMonth = 0; | |
4e636a74 AH |
81 | $isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon']; |
82 | $ymd = date('Y-m-d', mktime(0, 0, -1, substr($ym, 4, 2) + 1, 1, substr($ym, 0, 4))); | |
83 | $monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4)); | |
84 | $current = CRM_Utils_Date::customFormat($date, '%Y-%m-%d'); | |
85 | $ym = substr($ym, 0, 4) . '-' . substr($ym, 4, 2); | |
6a488035 TO |
86 | } |
87 | else { | |
4e636a74 AH |
88 | $ym = sprintf("%04d-%02d", $today['year'], $today['mon']); |
89 | $ymd = sprintf("%04d-%02d-%02d", $today['year'], $today['mon'], $today['mday']); | |
90 | $monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']); | |
91 | $current = CRM_Utils_Date::customFormat($date, '%Y-%m-%d'); | |
92 | $isCurrentMonth = 1; | |
6a488035 TO |
93 | $isPreviousMonth = 1; |
94 | } | |
4e636a74 AH |
95 | $monthStart = $ym . '-01'; |
96 | $yearStart = substr($ym, 0, 4) . '-01-01'; | |
6a488035 TO |
97 | |
98 | $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE); | |
99 | // added | |
100 | //$membership = new CRM_Member_BAO_Membership; | |
101 | ||
102 | foreach ($membershipTypes as $key => $value) { | |
103 | ||
b09fe5ed | 104 | $membershipSummary[$key]['premonth']['new'] = array( |
353ffa53 | 105 | 'count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $preMonth, $preMonthEnd), |
6a488035 TO |
106 | 'name' => $value, |
107 | ); | |
108 | ||
b09fe5ed | 109 | $membershipSummary[$key]['premonth']['renew'] = array( |
353ffa53 | 110 | 'count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $preMonth, $preMonthEnd), |
6a488035 TO |
111 | 'name' => $value, |
112 | ); | |
113 | ||
b09fe5ed | 114 | $membershipSummary[$key]['premonth']['total'] = array( |
353ffa53 | 115 | 'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd), |
6a488035 TO |
116 | 'name' => $value, |
117 | ); | |
118 | ||
b09fe5ed | 119 | $membershipSummary[$key]['month']['new'] = array( |
353ffa53 | 120 | 'count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $monthStart, $ymd), |
6a488035 TO |
121 | 'name' => $value, |
122 | ); | |
123 | ||
b09fe5ed | 124 | $membershipSummary[$key]['month']['renew'] = array( |
353ffa53 | 125 | 'count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $monthStart, $ymd), |
6a488035 TO |
126 | 'name' => $value, |
127 | ); | |
128 | ||
b09fe5ed | 129 | $membershipSummary[$key]['month']['total'] = array( |
353ffa53 | 130 | 'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd), |
6a488035 TO |
131 | 'name' => $value, |
132 | ); | |
133 | ||
b09fe5ed | 134 | $membershipSummary[$key]['year']['new'] = array( |
353ffa53 | 135 | 'count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $yearStart, $ymd), |
6a488035 TO |
136 | 'name' => $value, |
137 | ); | |
138 | ||
b09fe5ed | 139 | $membershipSummary[$key]['year']['renew'] = array( |
353ffa53 | 140 | 'count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $yearStart, $ymd), |
6a488035 TO |
141 | 'name' => $value, |
142 | ); | |
143 | ||
b09fe5ed | 144 | $membershipSummary[$key]['year']['total'] = array( |
353ffa53 | 145 | 'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd), |
6a488035 TO |
146 | 'name' => $value, |
147 | ); | |
148 | ||
b09fe5ed | 149 | $membershipSummary[$key]['current']['total'] = array( |
353ffa53 | 150 | 'count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current), |
6a488035 TO |
151 | 'name' => $value, |
152 | ); | |
153 | ||
154 | $membershipSummary[$key]['total']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd)); | |
155 | ||
156 | //LCD also get summary stats for membership owners | |
b09fe5ed | 157 | $membershipSummary[$key]['premonth_owner']['premonth_owner'] = array( |
353ffa53 | 158 | 'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd, 0, 1), |
6a488035 TO |
159 | 'name' => $value, |
160 | ); | |
161 | ||
b09fe5ed | 162 | $membershipSummary[$key]['month_owner']['month_owner'] = array( |
353ffa53 | 163 | 'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd, 0, 1), |
6a488035 TO |
164 | 'name' => $value, |
165 | ); | |
166 | ||
b09fe5ed | 167 | $membershipSummary[$key]['year_owner']['year_owner'] = array( |
353ffa53 | 168 | 'count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd, 0, 1), |
6a488035 TO |
169 | 'name' => $value, |
170 | ); | |
171 | ||
b09fe5ed | 172 | $membershipSummary[$key]['current_owner']['current_owner'] = array( |
353ffa53 | 173 | 'count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current, 0, 1), |
6a488035 TO |
174 | 'name' => $value, |
175 | ); | |
176 | ||
177 | $membershipSummary[$key]['total_owner']['total_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd, 0, 1)); | |
178 | //LCD end | |
179 | } | |
180 | ||
6a488035 TO |
181 | $status = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent(); |
182 | $status = implode(',', $status); | |
183 | ||
4e636a74 AH |
184 | foreach ($membershipSummary as $typeID => $details) { |
185 | if (!$isCurrentMonth) { | |
186 | $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System::url('civicrm/member/search', | |
187 | "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID" | |
188 | ); | |
189 | $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID&owner=1"); | |
190 | } | |
191 | else { | |
192 | $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System::url('civicrm/member/search', | |
193 | "reset=1&force=1&status=$status" | |
194 | ); | |
195 | $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"); | |
196 | } | |
197 | $membershipSummary[$typeID]['current']['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID"); | |
198 | $membershipSummary[$typeID]['current_owner']['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1"); | |
199 | } | |
6a488035 TO |
200 | |
201 | $totalCount = array(); | |
202 | ||
203 | $newCountPreMonth = $newCountMonth = $newCountYear = 0; | |
204 | $renewCountPreMonth = $renewCountMonth = $renewCountYear = 0; | |
205 | ||
206 | $totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0; | |
207 | $totalCountPreMonth_owner = $totalCountMonth_owner = $totalCountYear_owner = $totalCountCurrent_owner = $totalCountTotal_owner = 0; | |
208 | foreach ($membershipSummary as $key => $value) { | |
353ffa53 | 209 | $newCountPreMonth = $newCountPreMonth + $value['premonth']['new']['count']; |
6a488035 TO |
210 | $renewCountPreMonth = $renewCountPreMonth + $value['premonth']['renew']['count']; |
211 | $totalCountPreMonth = $totalCountPreMonth + $value['premonth']['total']['count']; | |
353ffa53 TO |
212 | $newCountMonth = $newCountMonth + $value['month']['new']['count']; |
213 | $renewCountMonth = $renewCountMonth + $value['month']['renew']['count']; | |
214 | $totalCountMonth = $totalCountMonth + $value['month']['total']['count']; | |
215 | $newCountYear = $newCountYear + $value['year']['new']['count']; | |
216 | $renewCountYear = $renewCountYear + $value['year']['renew']['count']; | |
217 | $totalCountYear = $totalCountYear + $value['year']['total']['count']; | |
218 | $totalCountCurrent = $totalCountCurrent + $value['current']['total']['count']; | |
219 | $totalCountTotal = $totalCountTotal + $value['total']['total']['count']; | |
6a488035 TO |
220 | |
221 | //LCD add owner values | |
222 | $totalCountPreMonth_owner = $totalCountPreMonth_owner + $value['premonth_owner']['premonth_owner']['count']; | |
223 | $totalCountMonth_owner = $totalCountMonth_owner + $value['month_owner']['month_owner']['count']; | |
224 | $totalCountYear_owner = $totalCountYear_owner + $value['year_owner']['year_owner']['count']; | |
225 | $totalCountCurrent_owner = $totalCountCurrent_owner + $value['current_owner']['current_owner']['count']; | |
226 | $totalCountTotal_owner = $totalCountTotal_owner + $value['total_owner']['total_owner']['count']; | |
227 | } | |
228 | ||
229 | $totalCount['premonth']['new'] = array( | |
230 | 'count' => $newCountPreMonth, | |
0370ad20 AH |
231 | //'url' => CRM_Utils_System::url('civicrm/activity/search', |
232 | // "reset=1&force=1&signupType=1&dateLow=$preMonth&dateHigh=$preMonthEnd" | |
233 | //), | |
6a488035 TO |
234 | ); |
235 | ||
236 | $totalCount['premonth']['renew'] = array( | |
237 | 'count' => $renewCountPreMonth, | |
0370ad20 AH |
238 | //'url' => CRM_Utils_System::url('civicrm/activity/search', |
239 | // "reset=1&force=1&signupType=2&dateLow=$preMonth&dateHigh=$preMonthEnd" | |
240 | //), | |
6a488035 TO |
241 | ); |
242 | ||
243 | $totalCount['premonth']['total'] = array( | |
244 | 'count' => $totalCountPreMonth, | |
0370ad20 AH |
245 | //'url' => CRM_Utils_System::url('civicrm/activity/search', |
246 | // "reset=1&force=1&signupType=3&dateLow=$preMonth&dateHigh=$preMonthEnd" | |
247 | //), | |
6a488035 TO |
248 | ); |
249 | ||
250 | $totalCount['month']['new'] = array( | |
251 | 'count' => $newCountMonth, | |
0370ad20 AH |
252 | //'url' => CRM_Utils_System::url('civicrm/activity/search', |
253 | // "reset=1&force=1&signupType=1&dateLow=$monthStart&dateHigh=$ymd" | |
254 | //), | |
6a488035 TO |
255 | ); |
256 | ||
257 | $totalCount['month']['renew'] = array( | |
258 | 'count' => $renewCountMonth, | |
0370ad20 AH |
259 | //'url' => CRM_Utils_System::url('civicrm/activity/search', |
260 | // "reset=1&force=1&signupType=2&dateLow=$monthStart&dateHigh=$ymd" | |
261 | //), | |
6a488035 TO |
262 | ); |
263 | ||
264 | $totalCount['month']['total'] = array( | |
265 | 'count' => $totalCountMonth, | |
0370ad20 AH |
266 | //'url' => CRM_Utils_System::url('civicrm/activity/search', |
267 | // "reset=1&force=1&signupType=3&dateLow=$monthStart&dateHigh=$ymd" | |
268 | //), | |
6a488035 TO |
269 | ); |
270 | ||
271 | $totalCount['year']['new'] = array( | |
272 | 'count' => $newCountYear, | |
0370ad20 AH |
273 | //'url' => CRM_Utils_System::url('civicrm/activity/search', |
274 | // "reset=1&force=1&signupType=1&dateLow=$yearStart&dateHigh=$ymd" | |
275 | //), | |
6a488035 TO |
276 | ); |
277 | ||
278 | $totalCount['year']['renew'] = array( | |
279 | 'count' => $renewCountYear, | |
0370ad20 AH |
280 | //'url' => CRM_Utils_System::url('civicrm/activity/search', |
281 | // "reset=1&force=1&signupType=2&dateLow=$yearStart&dateHigh=$ymd" | |
282 | //), | |
6a488035 TO |
283 | ); |
284 | ||
285 | $totalCount['year']['total'] = array( | |
286 | 'count' => $totalCountYear, | |
0370ad20 AH |
287 | //'url' => CRM_Utils_System::url('civicrm/activity/search', |
288 | // "reset=1&force=1&signupType=3&dateLow=$yearStart&dateHigh=$ymd" | |
289 | //), | |
6a488035 TO |
290 | ); |
291 | ||
292 | $totalCount['current']['total'] = array( | |
293 | 'count' => $totalCountCurrent, | |
294 | 'url' => CRM_Utils_System::url('civicrm/member/search', | |
295 | "reset=1&force=1&status=$status" | |
296 | ), | |
297 | ); | |
298 | ||
299 | $totalCount['total']['total'] = array( | |
300 | 'count' => $totalCountTotal, | |
301 | 'url' => CRM_Utils_System::url('civicrm/member/search', | |
302 | "reset=1&force=1&status=$status" | |
303 | ), | |
304 | ); | |
305 | ||
306 | if (!$isCurrentMonth) { | |
307 | $totalCount['total']['total'] = array( | |
308 | 'count' => $totalCountTotal, | |
309 | 'url' => CRM_Utils_System::url('civicrm/member/search', | |
310 | "reset=1&force=1&status=$status&start=&end=$ymd" | |
311 | ), | |
312 | ); | |
313 | } | |
314 | ||
4e636a74 AH |
315 | // Activity search also unable to handle owner vs. inherited |
316 | ||
6a488035 TO |
317 | //LCD add owner values |
318 | $totalCount['premonth_owner']['premonth_owner'] = array( | |
319 | 'count' => $totalCountPreMonth_owner, | |
353ffa53 | 320 | // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$preMonth&end=$preMonthEnd&owner=1"), |
6a488035 TO |
321 | ); |
322 | ||
323 | $totalCount['month_owner']['month_owner'] = array( | |
324 | 'count' => $totalCountMonth_owner, | |
353ffa53 | 325 | // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$monthStart&end=$ymd&owner=1"), |
6a488035 TO |
326 | ); |
327 | ||
328 | $totalCount['year_owner']['year_owner'] = array( | |
329 | 'count' => $totalCountYear_owner, | |
353ffa53 | 330 | // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$yearStart&end=$ymd&owner=1"), |
6a488035 TO |
331 | ); |
332 | ||
333 | $totalCount['current_owner']['current_owner'] = array( | |
334 | 'count' => $totalCountCurrent_owner, | |
353ffa53 | 335 | // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"), |
6a488035 TO |
336 | ); |
337 | ||
338 | $totalCount['total_owner']['total_owner'] = array( | |
339 | 'count' => $totalCountTotal_owner, | |
353ffa53 | 340 | // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"), |
6a488035 TO |
341 | ); |
342 | ||
343 | if (!$isCurrentMonth) { | |
344 | $totalCount['total_owner']['total_owner'] = array( | |
345 | 'count' => $totalCountTotal_owner, | |
353ffa53 | 346 | // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=&end=$ymd&owner=1"), |
6a488035 TO |
347 | ); |
348 | } | |
349 | //LCD end | |
350 | ||
351 | $this->assign('membershipSummary', $membershipSummary); | |
352 | $this->assign('totalCount', $totalCount); | |
d2f262da | 353 | $this->assign('month', CRM_Utils_Date::customFormatTs($monthStartTs, '%B')); |
6a488035 | 354 | $this->assign('year', date('Y', $monthStartTs)); |
74d3ce5e | 355 | $this->assign('premonth', CRM_Utils_Date::customFormat($preMonth, '%B')); |
6a488035 TO |
356 | $this->assign('currentMonth', date('F')); |
357 | $this->assign('currentYear', date('Y')); | |
358 | $this->assign('isCurrent', $isCurrentMonth); | |
359 | $this->assign('preMonth', $isPreviousMonth); | |
360 | } | |
361 | ||
362 | /** | |
dc195289 | 363 | * the main function that is called when the page loads, |
6a488035 TO |
364 | * it decides the which action has to be taken for the page. |
365 | * | |
76e7a76c | 366 | * @return null |
6a488035 | 367 | */ |
00be9182 | 368 | public function run() { |
6a488035 TO |
369 | $this->preProcess(); |
370 | ||
371 | $controller = new CRM_Core_Controller_Simple('CRM_Member_Form_Search', ts('Member'), NULL); | |
372 | $controller->setEmbedded(TRUE); | |
373 | $controller->reset(); | |
374 | $controller->set('limit', 20); | |
375 | $controller->set('force', 1); | |
376 | $controller->set('context', 'dashboard'); | |
377 | $controller->process(); | |
378 | $controller->run(); | |
379 | ||
380 | return parent::run(); | |
381 | } | |
96025800 | 382 | |
6a488035 | 383 | } |