3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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));
173 //CRM_Core_Error::debug($membershipSummary);
174 $status = CRM_Member_BAO_MembershipStatus
::getMembershipStatusCurrent();
175 $status = implode(',', $status);
177 /* Disabled for lack of appropriate search
179 The Membership search isn't able to properly filter by join or renewal events.
180 Until that works properly, the subtotals shouldn't get links.
182 foreach ($membershipSummary as $typeID => $details) {
183 foreach ($details as $key => $value) {
186 $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");
187 $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");
188 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$preMonth&end=$preMonthEnd");
192 $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");
193 $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");
194 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$monthStart&end=$ymd");
198 $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");
199 $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");
200 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$yearStart&end=$ymd");
204 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID");
208 if (!$isCurrentMonth) {
209 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
210 "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID"
214 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
215 "reset=1&force=1&status=$status"
222 case 'premonth_owner':
223 $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");
227 $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");
231 $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");
234 case 'current_owner':
235 $membershipSummary[$typeID][$key]['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1");
239 if (!$isCurrentMonth) {
240 $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");
243 $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1");
252 // Temporary replacement for current totals column
254 foreach ($membershipSummary as $typeID => $details) {
255 if (!$isCurrentMonth) {
256 $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search',
257 "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID"
259 $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");
262 $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search',
263 "reset=1&force=1&status=$status"
265 $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1");
267 $membershipSummary[$typeID]['current']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID");
268 $membershipSummary[$typeID]['current_owner']['current_owner']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1");
271 $totalCount = array();
273 $newCountPreMonth = $newCountMonth = $newCountYear = 0;
274 $renewCountPreMonth = $renewCountMonth = $renewCountYear = 0;
276 $totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0;
277 $totalCountPreMonth_owner = $totalCountMonth_owner = $totalCountYear_owner = $totalCountCurrent_owner = $totalCountTotal_owner = 0;
278 foreach ($membershipSummary as $key => $value) {
279 $newCountPreMonth = $newCountPreMonth +
$value['premonth']['new']['count'];
280 $renewCountPreMonth = $renewCountPreMonth +
$value['premonth']['renew']['count'];
281 $totalCountPreMonth = $totalCountPreMonth +
$value['premonth']['total']['count'];
282 $newCountMonth = $newCountMonth +
$value['month']['new']['count'];
283 $renewCountMonth = $renewCountMonth +
$value['month']['renew']['count'];
284 $totalCountMonth = $totalCountMonth +
$value['month']['total']['count'];
285 $newCountYear = $newCountYear +
$value['year']['new']['count'];
286 $renewCountYear = $renewCountYear +
$value['year']['renew']['count'];
287 $totalCountYear = $totalCountYear +
$value['year']['total']['count'];
288 $totalCountCurrent = $totalCountCurrent +
$value['current']['total']['count'];
289 $totalCountTotal = $totalCountTotal +
$value['total']['total']['count'];
291 //LCD add owner values
292 $totalCountPreMonth_owner = $totalCountPreMonth_owner +
$value['premonth_owner']['premonth_owner']['count'];
293 $totalCountMonth_owner = $totalCountMonth_owner +
$value['month_owner']['month_owner']['count'];
294 $totalCountYear_owner = $totalCountYear_owner +
$value['year_owner']['year_owner']['count'];
295 $totalCountCurrent_owner = $totalCountCurrent_owner +
$value['current_owner']['current_owner']['count'];
296 $totalCountTotal_owner = $totalCountTotal_owner +
$value['total_owner']['total_owner']['count'];
299 $totalCount['premonth']['new'] = array(
300 'count' => $newCountPreMonth,
301 //'url' => CRM_Utils_System::url('civicrm/activity/search',
302 // "reset=1&force=1&signupType=1&dateLow=$preMonth&dateHigh=$preMonthEnd"
306 $totalCount['premonth']['renew'] = array(
307 'count' => $renewCountPreMonth,
308 //'url' => CRM_Utils_System::url('civicrm/activity/search',
309 // "reset=1&force=1&signupType=2&dateLow=$preMonth&dateHigh=$preMonthEnd"
313 $totalCount['premonth']['total'] = array(
314 'count' => $totalCountPreMonth,
315 //'url' => CRM_Utils_System::url('civicrm/activity/search',
316 // "reset=1&force=1&signupType=3&dateLow=$preMonth&dateHigh=$preMonthEnd"
320 $totalCount['month']['new'] = array(
321 'count' => $newCountMonth,
322 //'url' => CRM_Utils_System::url('civicrm/activity/search',
323 // "reset=1&force=1&signupType=1&dateLow=$monthStart&dateHigh=$ymd"
327 $totalCount['month']['renew'] = array(
328 'count' => $renewCountMonth,
329 //'url' => CRM_Utils_System::url('civicrm/activity/search',
330 // "reset=1&force=1&signupType=2&dateLow=$monthStart&dateHigh=$ymd"
334 $totalCount['month']['total'] = array(
335 'count' => $totalCountMonth,
336 //'url' => CRM_Utils_System::url('civicrm/activity/search',
337 // "reset=1&force=1&signupType=3&dateLow=$monthStart&dateHigh=$ymd"
341 $totalCount['year']['new'] = array(
342 'count' => $newCountYear,
343 //'url' => CRM_Utils_System::url('civicrm/activity/search',
344 // "reset=1&force=1&signupType=1&dateLow=$yearStart&dateHigh=$ymd"
348 $totalCount['year']['renew'] = array(
349 'count' => $renewCountYear,
350 //'url' => CRM_Utils_System::url('civicrm/activity/search',
351 // "reset=1&force=1&signupType=2&dateLow=$yearStart&dateHigh=$ymd"
355 $totalCount['year']['total'] = array(
356 'count' => $totalCountYear,
357 //'url' => CRM_Utils_System::url('civicrm/activity/search',
358 // "reset=1&force=1&signupType=3&dateLow=$yearStart&dateHigh=$ymd"
362 $totalCount['current']['total'] = array(
363 'count' => $totalCountCurrent,
364 'url' => CRM_Utils_System
::url('civicrm/member/search',
365 "reset=1&force=1&status=$status"
369 $totalCount['total']['total'] = array(
370 'count' => $totalCountTotal,
371 'url' => CRM_Utils_System
::url('civicrm/member/search',
372 "reset=1&force=1&status=$status"
376 if (!$isCurrentMonth) {
377 $totalCount['total']['total'] = array(
378 'count' => $totalCountTotal,
379 'url' => CRM_Utils_System
::url('civicrm/member/search',
380 "reset=1&force=1&status=$status&start=&end=$ymd"
385 // Activity search also unable to handle owner vs. inherited
387 //LCD add owner values
388 $totalCount['premonth_owner']['premonth_owner'] = array(
389 'count' => $totalCountPreMonth_owner,
390 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$preMonth&end=$preMonthEnd&owner=1"),
393 $totalCount['month_owner']['month_owner'] = array(
394 'count' => $totalCountMonth_owner,
395 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$monthStart&end=$ymd&owner=1"),
398 $totalCount['year_owner']['year_owner'] = array(
399 'count' => $totalCountYear_owner,
400 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$yearStart&end=$ymd&owner=1"),
403 $totalCount['current_owner']['current_owner'] = array(
404 'count' => $totalCountCurrent_owner,
405 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"),
408 $totalCount['total_owner']['total_owner'] = array(
409 'count' => $totalCountTotal_owner,
410 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"),
413 if (!$isCurrentMonth) {
414 $totalCount['total_owner']['total_owner'] = array(
415 'count' => $totalCountTotal_owner,
416 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=&end=$ymd&owner=1"),
421 $this->assign('membershipSummary', $membershipSummary);
422 $this->assign('totalCount', $totalCount);
423 $this->assign('month', date('F', $monthStartTs));
424 $this->assign('year', date('Y', $monthStartTs));
425 $this->assign('premonth', date('F', strtotime($preMonth)));
426 $this->assign('currentMonth', date('F'));
427 $this->assign('currentYear', date('Y'));
428 $this->assign('isCurrent', $isCurrentMonth);
429 $this->assign('preMonth', $isPreviousMonth);
433 * This function is the main function that is called when the page loads,
434 * it decides the which action has to be taken for the page.
442 $controller = new CRM_Core_Controller_Simple('CRM_Member_Form_Search', ts('Member'), NULL);
443 $controller->setEmbedded(TRUE);
444 $controller->reset();
445 $controller->set('limit', 20);
446 $controller->set('force', 1);
447 $controller->set('context', 'dashboard');
448 $controller->process();
451 return parent
::run();