3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * Page for displaying list of Payment-Instrument
39 class CRM_Member_Page_DashBoard
extends CRM_Core_Page
{
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.
49 function preProcess() {
51 //CRM-13901 don't show dashboard to contacts with limited view writes & it does not relect
52 //what they have access to
53 //@todo implement acls on dashboard querys (preferably via api to enhance that at the same time)
54 if(!CRM_Core_Permission
::check(array('view all contacts', 'edit all contacts'))) {
55 $this->showMembershipSummary
= FALSE;
56 $this->assign('membershipSummary', FALSE);
59 $this->assign('membershipSummary', TRUE);
60 CRM_Utils_System
::setTitle(ts('CiviMember'));
61 $membershipSummary = array();
62 $preMonth = date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
63 $preMonthEnd = date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
65 $preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4));
68 $date = CRM_Utils_Date
::getToday();
71 // You can force the dashboard to display based upon a certain date
72 $ym = CRM_Utils_Array
::value('date', $_GET);
75 if (preg_match('/^\d{6}$/', $ym) == 0 ||
76 !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) ||
77 substr($ym, 0, 1) == 0
79 CRM_Core_Error
::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym)));
83 $isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon'];
84 $ymd = date('Y-m-d', mktime(0, 0, -1, substr($ym, 4, 2) +
1, 1, substr($ym, 0, 4)));
85 $monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4));
86 $current = CRM_Utils_Date
::customFormat($date, '%Y-%m-%d');
87 $ym = substr($ym, 0, 4) . '-' . substr($ym, 4, 2);
90 $ym = sprintf("%04d-%02d", $today['year'], $today['mon']);
91 $ymd = sprintf("%04d-%02d-%02d", $today['year'], $today['mon'], $today['mday']);
92 $monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
93 $current = CRM_Utils_Date
::customFormat($date, '%Y-%m-%d');
97 $monthStart = $ym . '-01';
98 $yearStart = substr($ym, 0, 4) . '-01-01';
100 $membershipTypes = CRM_Member_BAO_MembershipType
::getMembershipTypes(FALSE);
102 //$membership = new CRM_Member_BAO_Membership;
104 foreach ($membershipTypes as $key => $value) {
106 $membershipSummary[$key]['premonth']['new'] = array('count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $preMonth, $preMonthEnd),
110 $membershipSummary[$key]['premonth']['renew'] = array('count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $preMonth, $preMonthEnd),
114 $membershipSummary[$key]['premonth']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $preMonth, $preMonthEnd),
119 $membershipSummary[$key]['month']['new'] = array('count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $monthStart, $ymd),
123 $membershipSummary[$key]['month']['renew'] = array('count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $monthStart, $ymd),
127 $membershipSummary[$key]['month']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $monthStart, $ymd),
132 $membershipSummary[$key]['year']['new'] = array('count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $yearStart, $ymd),
136 $membershipSummary[$key]['year']['renew'] = array('count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $yearStart, $ymd),
140 $membershipSummary[$key]['year']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $yearStart, $ymd),
145 $membershipSummary[$key]['current']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $current),
149 $membershipSummary[$key]['total']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $ymd));
151 //LCD also get summary stats for membership owners
152 $membershipSummary[$key]['premonth_owner']['premonth_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $preMonth, $preMonthEnd, 0, 1),
156 $membershipSummary[$key]['month_owner']['month_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $monthStart, $ymd, 0, 1),
160 $membershipSummary[$key]['year_owner']['year_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $yearStart, $ymd, 0, 1),
164 $membershipSummary[$key]['current_owner']['current_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $current, 0, 1),
168 $membershipSummary[$key]['total_owner']['total_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $ymd, 0, 1));
172 $status = CRM_Member_BAO_MembershipStatus
::getMembershipStatusCurrent();
173 $status = implode(',', $status);
175 /* Disabled for lack of appropriate search
177 The Membership search isn't able to properly filter by join or renewal events.
178 Until that works properly, the subtotals shouldn't get links.
180 foreach ($membershipSummary as $typeID => $details) {
181 foreach ($details as $key => $value) {
184 $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$preMonth&joinEnd=$preMonthEnd&start=$preMonth&end=$preMonthEnd");
185 $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$prePreMonthEnd&start=$preMonth&end=$preMonthEnd");
186 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$preMonth&end=$preMonthEnd");
190 $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$monthStart&joinEnd=$ymd&start=$monthStart&end=$ymd");
191 $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$preMonthStart&start=$monthStart&end=$ymd");
192 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$monthStart&end=$ymd");
196 $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$yearStart&joinEnd=$ymd&start=$yearStart&end=$ymd");
197 $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$preYearStart&start=$yearStart&end=$ymd");
198 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$yearStart&end=$ymd");
202 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID");
206 if (!$isCurrentMonth) {
207 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
208 "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID"
212 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
213 "reset=1&force=1&status=$status"
220 case 'premonth_owner':
221 $membershipSummary[$typeID][$key]['premonth_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$preMonth&end=$preMonthEnd&owner=1");
225 $membershipSummary[$typeID][$key]['month_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$monthStart&end=$ymd&owner=1");
229 $membershipSummary[$typeID][$key]['year_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$yearStart&end=$ymd&owner=1");
232 case 'current_owner':
233 $membershipSummary[$typeID][$key]['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1");
237 if (!$isCurrentMonth) {
238 $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID&owner=1");
241 $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1");
250 // Temporary replacement for current totals column
252 foreach ($membershipSummary as $typeID => $details) {
253 if (!$isCurrentMonth) {
254 $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search',
255 "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID"
257 $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");
260 $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search',
261 "reset=1&force=1&status=$status"
263 $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1");
265 $membershipSummary[$typeID]['current']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID");
266 $membershipSummary[$typeID]['current_owner']['current_owner']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1");
269 $totalCount = array();
271 $newCountPreMonth = $newCountMonth = $newCountYear = 0;
272 $renewCountPreMonth = $renewCountMonth = $renewCountYear = 0;
274 $totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0;
275 $totalCountPreMonth_owner = $totalCountMonth_owner = $totalCountYear_owner = $totalCountCurrent_owner = $totalCountTotal_owner = 0;
276 foreach ($membershipSummary as $key => $value) {
277 $newCountPreMonth = $newCountPreMonth +
$value['premonth']['new']['count'];
278 $renewCountPreMonth = $renewCountPreMonth +
$value['premonth']['renew']['count'];
279 $totalCountPreMonth = $totalCountPreMonth +
$value['premonth']['total']['count'];
280 $newCountMonth = $newCountMonth +
$value['month']['new']['count'];
281 $renewCountMonth = $renewCountMonth +
$value['month']['renew']['count'];
282 $totalCountMonth = $totalCountMonth +
$value['month']['total']['count'];
283 $newCountYear = $newCountYear +
$value['year']['new']['count'];
284 $renewCountYear = $renewCountYear +
$value['year']['renew']['count'];
285 $totalCountYear = $totalCountYear +
$value['year']['total']['count'];
286 $totalCountCurrent = $totalCountCurrent +
$value['current']['total']['count'];
287 $totalCountTotal = $totalCountTotal +
$value['total']['total']['count'];
289 //LCD add owner values
290 $totalCountPreMonth_owner = $totalCountPreMonth_owner +
$value['premonth_owner']['premonth_owner']['count'];
291 $totalCountMonth_owner = $totalCountMonth_owner +
$value['month_owner']['month_owner']['count'];
292 $totalCountYear_owner = $totalCountYear_owner +
$value['year_owner']['year_owner']['count'];
293 $totalCountCurrent_owner = $totalCountCurrent_owner +
$value['current_owner']['current_owner']['count'];
294 $totalCountTotal_owner = $totalCountTotal_owner +
$value['total_owner']['total_owner']['count'];
297 $totalCount['premonth']['new'] = array(
298 'count' => $newCountPreMonth,
299 //'url' => CRM_Utils_System::url('civicrm/activity/search',
300 // "reset=1&force=1&signupType=1&dateLow=$preMonth&dateHigh=$preMonthEnd"
304 $totalCount['premonth']['renew'] = array(
305 'count' => $renewCountPreMonth,
306 //'url' => CRM_Utils_System::url('civicrm/activity/search',
307 // "reset=1&force=1&signupType=2&dateLow=$preMonth&dateHigh=$preMonthEnd"
311 $totalCount['premonth']['total'] = array(
312 'count' => $totalCountPreMonth,
313 //'url' => CRM_Utils_System::url('civicrm/activity/search',
314 // "reset=1&force=1&signupType=3&dateLow=$preMonth&dateHigh=$preMonthEnd"
318 $totalCount['month']['new'] = array(
319 'count' => $newCountMonth,
320 //'url' => CRM_Utils_System::url('civicrm/activity/search',
321 // "reset=1&force=1&signupType=1&dateLow=$monthStart&dateHigh=$ymd"
325 $totalCount['month']['renew'] = array(
326 'count' => $renewCountMonth,
327 //'url' => CRM_Utils_System::url('civicrm/activity/search',
328 // "reset=1&force=1&signupType=2&dateLow=$monthStart&dateHigh=$ymd"
332 $totalCount['month']['total'] = array(
333 'count' => $totalCountMonth,
334 //'url' => CRM_Utils_System::url('civicrm/activity/search',
335 // "reset=1&force=1&signupType=3&dateLow=$monthStart&dateHigh=$ymd"
339 $totalCount['year']['new'] = array(
340 'count' => $newCountYear,
341 //'url' => CRM_Utils_System::url('civicrm/activity/search',
342 // "reset=1&force=1&signupType=1&dateLow=$yearStart&dateHigh=$ymd"
346 $totalCount['year']['renew'] = array(
347 'count' => $renewCountYear,
348 //'url' => CRM_Utils_System::url('civicrm/activity/search',
349 // "reset=1&force=1&signupType=2&dateLow=$yearStart&dateHigh=$ymd"
353 $totalCount['year']['total'] = array(
354 'count' => $totalCountYear,
355 //'url' => CRM_Utils_System::url('civicrm/activity/search',
356 // "reset=1&force=1&signupType=3&dateLow=$yearStart&dateHigh=$ymd"
360 $totalCount['current']['total'] = array(
361 'count' => $totalCountCurrent,
362 'url' => CRM_Utils_System
::url('civicrm/member/search',
363 "reset=1&force=1&status=$status"
367 $totalCount['total']['total'] = array(
368 'count' => $totalCountTotal,
369 'url' => CRM_Utils_System
::url('civicrm/member/search',
370 "reset=1&force=1&status=$status"
374 if (!$isCurrentMonth) {
375 $totalCount['total']['total'] = array(
376 'count' => $totalCountTotal,
377 'url' => CRM_Utils_System
::url('civicrm/member/search',
378 "reset=1&force=1&status=$status&start=&end=$ymd"
383 // Activity search also unable to handle owner vs. inherited
385 //LCD add owner values
386 $totalCount['premonth_owner']['premonth_owner'] = array(
387 'count' => $totalCountPreMonth_owner,
388 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$preMonth&end=$preMonthEnd&owner=1"),
391 $totalCount['month_owner']['month_owner'] = array(
392 'count' => $totalCountMonth_owner,
393 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$monthStart&end=$ymd&owner=1"),
396 $totalCount['year_owner']['year_owner'] = array(
397 'count' => $totalCountYear_owner,
398 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$yearStart&end=$ymd&owner=1"),
401 $totalCount['current_owner']['current_owner'] = array(
402 'count' => $totalCountCurrent_owner,
403 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"),
406 $totalCount['total_owner']['total_owner'] = array(
407 'count' => $totalCountTotal_owner,
408 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"),
411 if (!$isCurrentMonth) {
412 $totalCount['total_owner']['total_owner'] = array(
413 'count' => $totalCountTotal_owner,
414 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=&end=$ymd&owner=1"),
419 $this->assign('membershipSummary', $membershipSummary);
420 $this->assign('totalCount', $totalCount);
421 $this->assign('month', date('F', $monthStartTs));
422 $this->assign('year', date('Y', $monthStartTs));
423 $this->assign('premonth', date('F', strtotime($preMonth)));
424 $this->assign('currentMonth', date('F'));
425 $this->assign('currentYear', date('Y'));
426 $this->assign('isCurrent', $isCurrentMonth);
427 $this->assign('preMonth', $isPreviousMonth);
431 * This function is the main function that is called when the page loads,
432 * it decides the which action has to be taken for the page.
440 $controller = new CRM_Core_Controller_Simple('CRM_Member_Form_Search', ts('Member'), NULL);
441 $controller->setEmbedded(TRUE);
442 $controller->reset();
443 $controller->set('limit', 20);
444 $controller->set('force', 1);
445 $controller->set('context', 'dashboard');
446 $controller->process();
449 return parent
::run();