3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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() {
50 CRM_Utils_System
::setTitle(ts('CiviMember'));
51 $membershipSummary = array();
52 $preMonth = date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
53 $preMonthEnd = date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
55 $preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4));
58 $date = CRM_Utils_Date
::getToday();
61 // You can force the dashboard to display based upon a certain date
62 $ym = CRM_Utils_Array
::value('date', $_GET);
65 if (preg_match('/^\d{6}$/', $ym) == 0 ||
66 !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) ||
67 substr($ym, 0, 1) == 0
69 CRM_Core_Error
::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym)));
73 $isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon'];
74 $ymd = date('Y-m-d', mktime(0, 0, -1, substr($ym, 4, 2) +
1, 1, substr($ym, 0, 4)));
75 $monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4));
76 $current = CRM_Utils_Date
::customFormat($date, '%Y-%m-%d');
77 $ym = substr($ym, 0, 4) . '-' . substr($ym, 4, 2);
80 $ym = sprintf("%04d-%02d", $today['year'], $today['mon']);
81 $ymd = sprintf("%04d-%02d-%02d", $today['year'], $today['mon'], $today['mday']);
82 $monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
83 $current = CRM_Utils_Date
::customFormat($date, '%Y-%m-%d');
87 $monthStart = $ym . '-01';
88 $yearStart = substr($ym, 0, 4) . '-01-01';
90 $membershipTypes = CRM_Member_BAO_MembershipType
::getMembershipTypes(FALSE);
92 //$membership = new CRM_Member_BAO_Membership;
94 foreach ($membershipTypes as $key => $value) {
96 $membershipSummary[$key]['premonth']['new'] = array('count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $preMonth, $preMonthEnd),
100 $membershipSummary[$key]['premonth']['renew'] = array('count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $preMonth, $preMonthEnd),
104 $membershipSummary[$key]['premonth']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $preMonth, $preMonthEnd),
109 $membershipSummary[$key]['month']['new'] = array('count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $monthStart, $ymd),
113 $membershipSummary[$key]['month']['renew'] = array('count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $monthStart, $ymd),
117 $membershipSummary[$key]['month']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $monthStart, $ymd),
122 $membershipSummary[$key]['year']['new'] = array('count' => CRM_Member_BAO_Membership
::getMembershipJoins($key, $yearStart, $ymd),
126 $membershipSummary[$key]['year']['renew'] = array('count' => CRM_Member_BAO_Membership
::getMembershipRenewals($key, $yearStart, $ymd),
130 $membershipSummary[$key]['year']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $yearStart, $ymd),
135 $membershipSummary[$key]['current']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $current),
139 $membershipSummary[$key]['total']['total'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $ymd));
141 //LCD also get summary stats for membership owners
142 $membershipSummary[$key]['premonth_owner']['premonth_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $preMonth, $preMonthEnd, 0, 1),
146 $membershipSummary[$key]['month_owner']['month_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $monthStart, $ymd, 0, 1),
150 $membershipSummary[$key]['year_owner']['year_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipStarts($key, $yearStart, $ymd, 0, 1),
154 $membershipSummary[$key]['current_owner']['current_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $current, 0, 1),
158 $membershipSummary[$key]['total_owner']['total_owner'] = array('count' => CRM_Member_BAO_Membership
::getMembershipCount($key, $ymd, 0, 1));
163 //CRM_Core_Error::debug($membershipSummary);
164 $status = CRM_Member_BAO_MembershipStatus
::getMembershipStatusCurrent();
165 $status = implode(',', $status);
167 /* Disabled for lack of appropriate search
169 The Membership search isn't able to properly filter by join or renewal events.
170 Until that works properly, the subtotals shouldn't get links.
172 foreach ($membershipSummary as $typeID => $details) {
173 foreach ($details as $key => $value) {
176 $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");
177 $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");
178 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$preMonth&end=$preMonthEnd");
182 $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");
183 $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");
184 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$monthStart&end=$ymd");
188 $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");
189 $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");
190 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$yearStart&end=$ymd");
194 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID");
198 if (!$isCurrentMonth) {
199 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
200 "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID"
204 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
205 "reset=1&force=1&status=$status"
212 case 'premonth_owner':
213 $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");
217 $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");
221 $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");
224 case 'current_owner':
225 $membershipSummary[$typeID][$key]['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1");
229 if (!$isCurrentMonth) {
230 $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");
233 $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1");
242 // Temporary replacement for current totals column
244 foreach ($membershipSummary as $typeID => $details) {
245 if (!$isCurrentMonth) {
246 $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search',
247 "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID"
249 $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");
252 $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search',
253 "reset=1&force=1&status=$status"
255 $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1");
257 $membershipSummary[$typeID]['current']['total']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID");
258 $membershipSummary[$typeID]['current_owner']['current_owner']['url'] = CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1");
261 $totalCount = array();
263 $newCountPreMonth = $newCountMonth = $newCountYear = 0;
264 $renewCountPreMonth = $renewCountMonth = $renewCountYear = 0;
266 $totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0;
267 $totalCountPreMonth_owner = $totalCountMonth_owner = $totalCountYear_owner = $totalCountCurrent_owner = $totalCountTotal_owner = 0;
268 foreach ($membershipSummary as $key => $value) {
269 $newCountPreMonth = $newCountPreMonth +
$value['premonth']['new']['count'];
270 $renewCountPreMonth = $renewCountPreMonth +
$value['premonth']['renew']['count'];
271 $totalCountPreMonth = $totalCountPreMonth +
$value['premonth']['total']['count'];
272 $newCountMonth = $newCountMonth +
$value['month']['new']['count'];
273 $renewCountMonth = $renewCountMonth +
$value['month']['renew']['count'];
274 $totalCountMonth = $totalCountMonth +
$value['month']['total']['count'];
275 $newCountYear = $newCountYear +
$value['year']['new']['count'];
276 $renewCountYear = $renewCountYear +
$value['year']['renew']['count'];
277 $totalCountYear = $totalCountYear +
$value['year']['total']['count'];
278 $totalCountCurrent = $totalCountCurrent +
$value['current']['total']['count'];
279 $totalCountTotal = $totalCountTotal +
$value['total']['total']['count'];
281 //LCD add owner values
282 $totalCountPreMonth_owner = $totalCountPreMonth_owner +
$value['premonth_owner']['premonth_owner']['count'];
283 $totalCountMonth_owner = $totalCountMonth_owner +
$value['month_owner']['month_owner']['count'];
284 $totalCountYear_owner = $totalCountYear_owner +
$value['year_owner']['year_owner']['count'];
285 $totalCountCurrent_owner = $totalCountCurrent_owner +
$value['current_owner']['current_owner']['count'];
286 $totalCountTotal_owner = $totalCountTotal_owner +
$value['total_owner']['total_owner']['count'];
289 $totalCount['premonth']['new'] = array(
290 'count' => $newCountPreMonth,
291 'url' => CRM_Utils_System
::url('civicrm/activity/search',
292 "reset=1&force=1&signupType=1&dateLow=$preMonth&dateHigh=$preMonthEnd"
296 $totalCount['premonth']['renew'] = array(
297 'count' => $renewCountPreMonth,
298 'url' => CRM_Utils_System
::url('civicrm/activity/search',
299 "reset=1&force=1&signupType=2&dateLow=$preMonth&dateHigh=$preMonthEnd"
303 $totalCount['premonth']['total'] = array(
304 'count' => $totalCountPreMonth,
305 'url' => CRM_Utils_System
::url('civicrm/activity/search',
306 "reset=1&force=1&signupType=3&dateLow=$preMonth&dateHigh=$preMonthEnd"
310 $totalCount['month']['new'] = array(
311 'count' => $newCountMonth,
312 'url' => CRM_Utils_System
::url('civicrm/activity/search',
313 "reset=1&force=1&signupType=1&dateLow=$monthStart&dateHigh=$ymd"
317 $totalCount['month']['renew'] = array(
318 'count' => $renewCountMonth,
319 'url' => CRM_Utils_System
::url('civicrm/activity/search',
320 "reset=1&force=1&signupType=2&dateLow=$monthStart&dateHigh=$ymd"
324 $totalCount['month']['total'] = array(
325 'count' => $totalCountMonth,
326 'url' => CRM_Utils_System
::url('civicrm/activity/search',
327 "reset=1&force=1&signupType=3&dateLow=$monthStart&dateHigh=$ymd"
331 $totalCount['year']['new'] = array(
332 'count' => $newCountYear,
333 'url' => CRM_Utils_System
::url('civicrm/activity/search',
334 "reset=1&force=1&signupType=1&dateLow=$yearStart&dateHigh=$ymd"
338 $totalCount['year']['renew'] = array(
339 'count' => $renewCountYear,
340 'url' => CRM_Utils_System
::url('civicrm/activity/search',
341 "reset=1&force=1&signupType=2&dateLow=$yearStart&dateHigh=$ymd"
345 $totalCount['year']['total'] = array(
346 'count' => $totalCountYear,
347 'url' => CRM_Utils_System
::url('civicrm/activity/search',
348 "reset=1&force=1&signupType=3&dateLow=$yearStart&dateHigh=$ymd"
352 $totalCount['current']['total'] = array(
353 'count' => $totalCountCurrent,
354 'url' => CRM_Utils_System
::url('civicrm/member/search',
355 "reset=1&force=1&status=$status"
359 $totalCount['total']['total'] = array(
360 'count' => $totalCountTotal,
361 'url' => CRM_Utils_System
::url('civicrm/member/search',
362 "reset=1&force=1&status=$status"
366 if (!$isCurrentMonth) {
367 $totalCount['total']['total'] = array(
368 'count' => $totalCountTotal,
369 'url' => CRM_Utils_System
::url('civicrm/member/search',
370 "reset=1&force=1&status=$status&start=&end=$ymd"
375 // Activity search also unable to handle owner vs. inherited
377 //LCD add owner values
378 $totalCount['premonth_owner']['premonth_owner'] = array(
379 'count' => $totalCountPreMonth_owner,
380 'url' => CRM_Utils_System
::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$preMonth&end=$preMonthEnd&owner=1"),
383 $totalCount['month_owner']['month_owner'] = array(
384 'count' => $totalCountMonth_owner,
385 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$monthStart&end=$ymd&owner=1"),
388 $totalCount['year_owner']['year_owner'] = array(
389 'count' => $totalCountYear_owner,
390 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=$yearStart&end=$ymd&owner=1"),
393 $totalCount['current_owner']['current_owner'] = array(
394 'count' => $totalCountCurrent_owner,
395 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"),
398 $totalCount['total_owner']['total_owner'] = array(
399 'count' => $totalCountTotal_owner,
400 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"),
403 if (!$isCurrentMonth) {
404 $totalCount['total_owner']['total_owner'] = array(
405 'count' => $totalCountTotal_owner,
406 // 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&start=&end=$ymd&owner=1"),
411 $this->assign('membershipSummary', $membershipSummary);
412 $this->assign('totalCount', $totalCount);
413 $this->assign('month', date('F', $monthStartTs));
414 $this->assign('year', date('Y', $monthStartTs));
415 $this->assign('premonth', date('F', $preMonthYear));
416 $this->assign('currentMonth', date('F'));
417 $this->assign('currentYear', date('Y'));
418 $this->assign('isCurrent', $isCurrentMonth);
419 $this->assign('preMonth', $isPreviousMonth);
423 * This function is the main function that is called when the page loads,
424 * it decides the which action has to be taken for the page.
432 $controller = new CRM_Core_Controller_Simple('CRM_Member_Form_Search', ts('Member'), NULL);
433 $controller->setEmbedded(TRUE);
434 $controller->reset();
435 $controller->set('limit', 20);
436 $controller->set('force', 1);
437 $controller->set('context', 'dashboard');
438 $controller->process();
441 return parent
::run();