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.
48 public function preProcess() {
50 //CRM-13901 don't show dashboard to contacts with limited view writes & it does not relect
51 //what they have access to
52 //@todo implement acls on dashboard querys (preferably via api to enhance that at the same time)
53 if(!CRM_Core_Permission
::check(array('view all contacts', 'edit all contacts'))) {
54 $this->showMembershipSummary
= FALSE;
55 $this->assign('membershipSummary', FALSE);
58 $this->assign('membershipSummary', TRUE);
59 CRM_Utils_System
::setTitle(ts('CiviMember'));
60 $membershipSummary = array();
61 $preMonth = date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
62 $preMonthEnd = date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
64 $preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4));
67 $date = CRM_Utils_Date
::getToday();
70 // You can force the dashboard to display based upon a certain date
71 $ym = CRM_Utils_Array
::value('date', $_GET);
74 if (preg_match('/^\d{6}$/', $ym) == 0 ||
75 !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) ||
76 substr($ym, 0, 1) == 0
78 CRM_Core_Error
::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym)));
82 $isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon'];
83 $ymd = date('Y-m-d', mktime(0, 0, -1, substr($ym, 4, 2) +
1, 1, substr($ym, 0, 4)));
84 $monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4));
85 $current = CRM_Utils_Date
::customFormat($date, '%Y-%m-%d');
86 $ym = substr($ym, 0, 4) . '-' . substr($ym, 4, 2);
89 $ym = sprintf("%04d-%02d", $today['year'], $today['mon']);
90 $ymd = sprintf("%04d-%02d-%02d", $today['year'], $today['mon'], $today['mday']);
91 $monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
92 $current = CRM_Utils_Date
::customFormat($date, '%Y-%m-%d');
96 $monthStart = $ym . '-01';
97 $yearStart = substr($ym, 0, 4) . '-01-01';
99 $membershipTypes = CRM_Member_BAO_MembershipType
::getMembershipTypes(FALSE);
101 //$membership = new CRM_Member_BAO_Membership;
103 foreach ($membershipTypes as $key => $value) {
105 $membershipSummary[$key]['premonth']['new'] = array('count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $preMonth, $preMonthEnd),
109 $membershipSummary[$key]['premonth']['renew'] = array('count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $preMonth, $preMonthEnd),
113 $membershipSummary[$key]['premonth']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $preMonth, $preMonthEnd),
118 $membershipSummary[$key]['month']['new'] = array('count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $monthStart, $ymd),
122 $membershipSummary[$key]['month']['renew'] = array('count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $monthStart, $ymd),
126 $membershipSummary[$key]['month']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $monthStart, $ymd),
131 $membershipSummary[$key]['year']['new'] = array('count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $yearStart, $ymd),
135 $membershipSummary[$key]['year']['renew'] = array('count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $yearStart, $ymd),
139 $membershipSummary[$key]['year']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $yearStart, $ymd),
144 $membershipSummary[$key]['current']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $current),
148 $membershipSummary[$key]['total']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $ymd));
150 //LCD also get summary stats for membership owners
151 $membershipSummary[$key]['premonth_owner']['premonth_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $preMonth, $preMonthEnd, 0, 1),
155 $membershipSummary[$key]['month_owner']['month_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $monthStart, $ymd, 0, 1),
159 $membershipSummary[$key]['year_owner']['year_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $yearStart, $ymd, 0, 1),
163 $membershipSummary[$key]['current_owner']['current_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $current, 0, 1),
167 $membershipSummary[$key]['total_owner']['total_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $ymd, 0, 1));
171 $status = CRM_Member_BAO_MembershipStatus
::getMembershipStatusCurrent();
172 $status = implode(',', $status);
174 /* Disabled for lack of appropriate search
176 The Membership search isn't able to properly filter by join or renewal events.
177 Until that works properly, the subtotals shouldn't get links.
179 foreach ($membershipSummary as $typeID => $details) {
180 foreach ($details as $key => $value) {
183 $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");
184 $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");
185 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$preMonth&end=$preMonthEnd");
189 $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");
190 $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");
191 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$monthStart&end=$ymd");
195 $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");
196 $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");
197 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$yearStart&end=$ymd");
201 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID");
205 if (!$isCurrentMonth) {
206 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
207 "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID"
211 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
212 "reset=1&force=1&status=$status"
219 case 'premonth_owner':
220 $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");
224 $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");
228 $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");
231 case 'current_owner':
232 $membershipSummary[$typeID][$key]['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1");
236 if (!$isCurrentMonth) {
237 $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");
240 $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1");
249 // Temporary replacement for current totals column
251 foreach ($membershipSummary as $typeID => $details) {
252 if (!$isCurrentMonth) {
253 $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search',
254 "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID"
256 $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");
259 $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search',
260 "reset=1&force=1&status=$status"
262 $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1");
264 $membershipSummary[$typeID]['current']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID");
265 $membershipSummary[$typeID]['current_owner']['current_owner']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1");
268 $totalCount = array();
270 $newCountPreMonth = $newCountMonth = $newCountYear = 0;
271 $renewCountPreMonth = $renewCountMonth = $renewCountYear = 0;
273 $totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0;
274 $totalCountPreMonth_owner = $totalCountMonth_owner = $totalCountYear_owner = $totalCountCurrent_owner = $totalCountTotal_owner = 0;
275 foreach ($membershipSummary as $key => $value) {
276 $newCountPreMonth = $newCountPreMonth +
$value['premonth']['new']['count'];
277 $renewCountPreMonth = $renewCountPreMonth +
$value['premonth']['renew']['count'];
278 $totalCountPreMonth = $totalCountPreMonth +
$value['premonth']['total']['count'];
279 $newCountMonth = $newCountMonth +
$value['month']['new']['count'];
280 $renewCountMonth = $renewCountMonth +
$value['month']['renew']['count'];
281 $totalCountMonth = $totalCountMonth +
$value['month']['total']['count'];
282 $newCountYear = $newCountYear +
$value['year']['new']['count'];
283 $renewCountYear = $renewCountYear +
$value['year']['renew']['count'];
284 $totalCountYear = $totalCountYear +
$value['year']['total']['count'];
285 $totalCountCurrent = $totalCountCurrent +
$value['current']['total']['count'];
286 $totalCountTotal = $totalCountTotal +
$value['total']['total']['count'];
288 //LCD add owner values
289 $totalCountPreMonth_owner = $totalCountPreMonth_owner +
$value['premonth_owner']['premonth_owner']['count'];
290 $totalCountMonth_owner = $totalCountMonth_owner +
$value['month_owner']['month_owner']['count'];
291 $totalCountYear_owner = $totalCountYear_owner +
$value['year_owner']['year_owner']['count'];
292 $totalCountCurrent_owner = $totalCountCurrent_owner +
$value['current_owner']['current_owner']['count'];
293 $totalCountTotal_owner = $totalCountTotal_owner +
$value['total_owner']['total_owner']['count'];
296 $totalCount['premonth']['new'] = array(
297 'count' => $newCountPreMonth,
298 //'url' => CRM_Utils_System::url('civicrm/activity/search',
299 // "reset=1&force=1&signupType=1&dateLow=$preMonth&dateHigh=$preMonthEnd"
303 $totalCount['premonth']['renew'] = array(
304 'count' => $renewCountPreMonth,
305 //'url' => CRM_Utils_System::url('civicrm/activity/search',
306 // "reset=1&force=1&signupType=2&dateLow=$preMonth&dateHigh=$preMonthEnd"
310 $totalCount['premonth']['total'] = array(
311 'count' => $totalCountPreMonth,
312 //'url' => CRM_Utils_System::url('civicrm/activity/search',
313 // "reset=1&force=1&signupType=3&dateLow=$preMonth&dateHigh=$preMonthEnd"
317 $totalCount['month']['new'] = array(
318 'count' => $newCountMonth,
319 //'url' => CRM_Utils_System::url('civicrm/activity/search',
320 // "reset=1&force=1&signupType=1&dateLow=$monthStart&dateHigh=$ymd"
324 $totalCount['month']['renew'] = array(
325 'count' => $renewCountMonth,
326 //'url' => CRM_Utils_System::url('civicrm/activity/search',
327 // "reset=1&force=1&signupType=2&dateLow=$monthStart&dateHigh=$ymd"
331 $totalCount['month']['total'] = array(
332 'count' => $totalCountMonth,
333 //'url' => CRM_Utils_System::url('civicrm/activity/search',
334 // "reset=1&force=1&signupType=3&dateLow=$monthStart&dateHigh=$ymd"
338 $totalCount['year']['new'] = array(
339 'count' => $newCountYear,
340 //'url' => CRM_Utils_System::url('civicrm/activity/search',
341 // "reset=1&force=1&signupType=1&dateLow=$yearStart&dateHigh=$ymd"
345 $totalCount['year']['renew'] = array(
346 'count' => $renewCountYear,
347 //'url' => CRM_Utils_System::url('civicrm/activity/search',
348 // "reset=1&force=1&signupType=2&dateLow=$yearStart&dateHigh=$ymd"
352 $totalCount['year']['total'] = array(
353 'count' => $totalCountYear,
354 //'url' => CRM_Utils_System::url('civicrm/activity/search',
355 // "reset=1&force=1&signupType=3&dateLow=$yearStart&dateHigh=$ymd"
359 $totalCount['current']['total'] = array(
360 'count' => $totalCountCurrent,
361 'url' => CRM_Utils_System
::url('civicrm/member/search',
362 "reset=1&force=1&status=$status"
366 $totalCount['total']['total'] = array(
367 'count' => $totalCountTotal,
368 'url' => CRM_Utils_System
::url('civicrm/member/search',
369 "reset=1&force=1&status=$status"
373 if (!$isCurrentMonth) {
374 $totalCount['total']['total'] = array(
375 'count' => $totalCountTotal,
376 'url' => CRM_Utils_System
::url('civicrm/member/search',
377 "reset=1&force=1&status=$status&start=&end=$ymd"
382 // Activity search also unable to handle owner vs. inherited
384 //LCD add owner values
385 $totalCount['premonth_owner']['premonth_owner'] = array(
386 'count' => $totalCountPreMonth_owner,
387 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$preMonth&end=$preMonthEnd&owner=1"),
390 $totalCount['month_owner']['month_owner'] = array(
391 'count' => $totalCountMonth_owner,
392 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$monthStart&end=$ymd&owner=1"),
395 $totalCount['year_owner']['year_owner'] = array(
396 'count' => $totalCountYear_owner,
397 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$yearStart&end=$ymd&owner=1"),
400 $totalCount['current_owner']['current_owner'] = array(
401 'count' => $totalCountCurrent_owner,
402 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"),
405 $totalCount['total_owner']['total_owner'] = array(
406 'count' => $totalCountTotal_owner,
407 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"),
410 if (!$isCurrentMonth) {
411 $totalCount['total_owner']['total_owner'] = array(
412 'count' => $totalCountTotal_owner,
413 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=&end=$ymd&owner=1"),
418 $this->assign('membershipSummary', $membershipSummary);
419 $this->assign('totalCount', $totalCount);
420 $this->assign('month', date('F', $monthStartTs));
421 $this->assign('year', date('Y', $monthStartTs));
422 $this->assign('premonth', date('F', strtotime($preMonth)));
423 $this->assign('currentMonth', date('F'));
424 $this->assign('currentYear', date('Y'));
425 $this->assign('isCurrent', $isCurrentMonth);
426 $this->assign('preMonth', $isPreviousMonth);
430 * This function is the main function that is called when the page loads,
431 * it decides the which action has to be taken for the page.
435 public function run() {
438 $controller = new CRM_Core_Controller_Simple('CRM_Member_Form_Search', ts('Member'), NULL);
439 $controller->setEmbedded(TRUE);
440 $controller->reset();
441 $controller->set('limit', 20);
442 $controller->set('force', 1);
443 $controller->set('context', 'dashboard');
444 $controller->process();
447 return parent
::run();