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
35 class CRM_Member_Page_Tab
extends CRM_Core_Page
{
38 * The action links that we need to display for the browse screen
43 static $_links = NULL;
44 static $_membershipTypesLinks = NULL;
46 public $_permission = NULL;
47 public $_contactId = NULL;
50 * This function is called when action is browse
56 $links = self
::links('all', $this->_isPaymentProcessor
, $this->_accessContribution
);
58 $membership = array();
59 $dao = new CRM_Member_DAO_Membership();
60 $dao->contact_id
= $this->_contactId
;
62 //$dao->orderBy('name');
65 //CRM--4418, check for view, edit, delete
66 $permissions = array(CRM_Core_Permission
::VIEW
);
67 if (CRM_Core_Permission
::check('edit memberships')) {
68 $permissions[] = CRM_Core_Permission
::EDIT
;
70 if (CRM_Core_Permission
::check('delete in CiviMember')) {
71 $permissions[] = CRM_Core_Permission
::DELETE
;
73 $mask = CRM_Core_Action
::mask($permissions);
75 // get deceased status id
76 $allStatus = CRM_Member_PseudoConstant
::membershipStatus();
77 $deceasedStatusId = array_search('Deceased', $allStatus);
80 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
82 //checks membership of contact itself
83 while ($dao->fetch()) {
84 $membership[$dao->id
] = array();
85 CRM_Core_DAO
::storeValues($dao, $membership[$dao->id
]);
88 $membership[$dao->id
]['campaign'] = CRM_Utils_Array
::value($dao->campaign_id
, $allCampaigns);
90 //get the membership status and type values.
91 $statusANDType = CRM_Member_BAO_Membership
::getStatusANDTypeValues($dao->id
);
93 'status', 'membership_type') as $fld) {
94 $membership[$dao->id
][$fld] = CRM_Utils_Array
::value($fld, $statusANDType[$dao->id
]);
96 if (CRM_Utils_Array
::value('is_current_member', $statusANDType[$dao->id
])) {
97 $membership[$dao->id
]['active'] = TRUE;
99 if (empty($dao->owner_membership_id
)) {
100 // unset renew and followup link for deceased membership
101 $currentMask = $mask;
102 if ($dao->status_id
== $deceasedStatusId) {
103 $currentMask = $currentMask & ~CRM_Core_Action
::RENEW
& ~CRM_Core_Action
::FOLLOWUP
;
106 $isUpdateBilling = false;
107 $paymentObject = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity($membership[$dao->id
]['membership_id'], 'membership', 'obj');
108 if (!empty($paymentObject)) {
109 $isUpdateBilling = $paymentObject->isSupported('updateSubscriptionBillingInfo');
112 $isCancelSupported = CRM_Member_BAO_Membership
::isCancelSubscriptionSupported($membership[$dao->id
]['membership_id']);
114 $membership[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links('all',
123 'cid' => $this->_contactId
,
128 $membership[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links('view'),
132 'cid' => $this->_contactId
,
137 //does membership have auto renew CRM-7137.
138 if (CRM_Utils_Array
::value('contribution_recur_id', $membership[$dao->id
]) &&
139 !CRM_Member_BAO_Membership
::isSubscriptionCancelled($membership[$dao->id
]['membership_id'])
141 $membership[$dao->id
]['auto_renew'] = 1;
144 $membership[$dao->id
]['auto_renew'] = 0;
147 // if relevant, count related memberships
148 if (CRM_Utils_Array
::value('is_current_member', $statusANDType[$dao->id
]) // membership is active
149 && CRM_Utils_Array
::value('relationship_type_id', $statusANDType[$dao->id
]) // membership type allows inheritance
150 && empty($dao->owner_membership_id
)) { // not an related membership
153 FROM civicrm_membership m
154 LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id
155 LEFT JOIN civicrm_contact ct ON ct.id = m.contact_id
156 WHERE m.owner_membership_id = {$dao->id} AND m.is_test = 0 AND ms.is_current_member = 1 AND ct.is_deleted = 0";
157 $num_related = CRM_Core_DAO
::singleValueQuery($query);
158 $max_related = CRM_Utils_Array
::value('max_related', $membership[$dao->id
]);
159 $membership[$dao->id
]['related_count'] = ($max_related == '' ?
160 ts('%1 created', array(1 => $num_related)) :
161 ts('%1 out of %2', array(1 => $num_related, 2 => $max_related))
164 $membership[$dao->id
]['related_count'] = ts('N/A');
168 //Below code gives list of all Membership Types associated
169 //with an Organization(CRM-2016)
170 $membershipTypes = CRM_Member_BAO_MembershipType
::getMembershipTypesByOrg($this->_contactId
);
171 foreach ($membershipTypes as $key => $value) {
172 $membershipTypes[$key]['action'] = CRM_Core_Action
::formLink(self
::membershipTypeslinks(),
175 'id' => $value['id'],
176 'cid' => $this->_contactId
,
181 $activeMembers = CRM_Member_BAO_Membership
::activeMembers($membership);
182 $inActiveMembers = CRM_Member_BAO_Membership
::activeMembers($membership, 'inactive');
183 $this->assign('activeMembers', $activeMembers);
184 $this->assign('inActiveMembers', $inActiveMembers);
185 $this->assign('membershipTypes', $membershipTypes);
187 if ($this->_contactId
) {
188 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
189 $this->assign('displayName', $displayName);
194 * This function is called when action is view
200 $controller = new CRM_Core_Controller_Simple(
201 'CRM_Member_Form_MembershipView',
202 ts('View Membership'),
205 $controller->setEmbedded(TRUE);
206 $controller->set('id', $this->_id
);
207 $controller->set('cid', $this->_contactId
);
209 return $controller->run();
213 * This function is called when action is update or new
219 // set https for offline cc transaction
220 $mode = CRM_Utils_Request
::retrieve('mode', 'String', $this);
221 if ($mode == 'test' ||
$mode == 'live') {
222 CRM_Utils_System
::redirectToSSL();
225 if ($this->_action
!= CRM_Core_Action
::ADD
) {
226 // get associated contributions only on edit/renew/delete
227 $this->associatedContribution();
230 if ($this->_action
& CRM_Core_Action
::RENEW
) {
231 $path = 'CRM_Member_Form_MembershipRenewal';
232 $title = ts('Renew Membership');
235 $path = 'CRM_Member_Form_Membership';
236 $title = ts('Create Membership');
238 $controller = new CRM_Core_Controller_Simple(
239 $path, $title, $this->_action
241 $controller->setEmbedded(TRUE);
242 $controller->set('BAOName', $this->getBAOName());
243 $controller->set('id', $this->_id
);
244 $controller->set('cid', $this->_contactId
);
245 return $controller->run();
248 function preProcess() {
249 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
250 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
251 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
253 if ($context == 'standalone') {
254 $this->_action
= CRM_Core_Action
::ADD
;
257 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
258 $this->assign('contactId', $this->_contactId
);
260 // check logged in url permission
261 CRM_Contact_Page_View
::checkUserPermission($this);
264 CRM_Contact_Page_View
::setTitle($this->_contactId
);
267 $this->assign('action', $this->_action
);
269 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit memberships')) {
270 // demote to view since user does not have edit membership rights
271 $this->_permission
= CRM_Core_Permission
::VIEW
;
272 $this->assign('permission', 'view');
277 * This function is the main function that is called when the page loads, it decides the which action has to be taken for the page.
285 // check if we can process credit card membership
286 $newCredit = CRM_Core_Payment
::allowBackofficeCreditCard($this);
288 $this->_isPaymentProcessor
= TRUE;
291 $this->_isPaymentProcessor
= FALSE;
294 // Only show credit card membership signup if user has CiviContribute permission
295 if (CRM_Core_Permission
::access('CiviContribute')) {
296 $this->_accessContribution
= TRUE;
297 $this->assign('accessContribution', TRUE);
300 $this->_accessContribution
= FALSE;
301 $this->assign('accessContribution', FALSE);
304 if ($this->_action
& CRM_Core_Action
::VIEW
) {
307 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE | CRM_Core_Action
::RENEW
)) {
316 return parent
::run();
319 function setContext($contactId = NULL) {
320 $context = CRM_Utils_Request
::retrieve('context',
321 'String', $this, FALSE, 'search'
324 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
326 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
331 $contactId = $this->_contactId
;
336 $url = CRM_Utils_System
::url('civicrm/member',
342 $url = CRM_Utils_System
::url('civicrm/contact/view',
343 "reset=1&force=1&cid={$contactId}&selectedChild=member"
348 $urlParams = 'force=1';
350 $urlParams .= "&qfKey=$qfKey";
352 $this->assign('searchKey', $qfKey);
354 $url = CRM_Utils_System
::url('civicrm/member/search', $urlParams);
358 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
362 $url = CRM_Utils_System
::url('civicrm/contact/view',
363 "reset=1&force=1&cid={$contactId}&selectedChild=activity"
368 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
372 $action = CRM_Utils_Request
::retrieve('action', 'String', $this);
374 $urlParams = 'force=1';
375 $urlString = 'civicrm/contact/search/custom';
376 if ($action == CRM_Core_Action
::UPDATE
) {
377 if ($this->_contactId
) {
378 $urlParams .= '&cid=' . $this->_contactId
;
381 $urlParams .= '&context=fulltext&action=view';
382 $urlString = 'civicrm/contact/view/membership';
385 $urlParams .= "$keyName=$qfKey";
387 $this->assign('searchKey', $qfKey);
388 $url = CRM_Utils_System
::url($urlString, $urlParams);
394 $cid = '&cid=' . $contactId;
396 $url = CRM_Utils_System
::url('civicrm/member/search',
402 $session = CRM_Core_Session
::singleton();
403 $session->pushUserContext($url);
409 * @return array (reference) of action links
412 static function &links($status = 'all',
413 $isPaymentProcessor = NULL,
414 $accessContribution = NULL,
415 $isCancelSupported = FALSE,
416 $isUpdateBilling = FALSE
418 if (!CRM_Utils_Array
::value('view', self
::$_links)) {
419 self
::$_links['view'] = array(
420 CRM_Core_Action
::VIEW
=> array(
421 'name' => ts('View'),
422 'url' => 'civicrm/contact/view/membership',
423 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member',
424 'title' => ts('View Membership'),
429 if (!CRM_Utils_Array
::value('all', self
::$_links)) {
431 CRM_Core_Action
::UPDATE
=> array(
432 'name' => ts('Edit'),
433 'url' => 'civicrm/contact/view/membership',
434 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member',
435 'title' => ts('Edit Membership'),
437 CRM_Core_Action
::RENEW
=> array(
438 'name' => ts('Renew'),
439 'url' => 'civicrm/contact/view/membership',
440 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member',
441 'title' => ts('Renew Membership'),
443 CRM_Core_Action
::FOLLOWUP
=> array(
444 'name' => ts('Renew-Credit Card'),
445 'url' => 'civicrm/contact/view/membership',
446 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member&mode=live',
447 'title' => ts('Renew Membership Using Credit Card'),
449 CRM_Core_Action
::DELETE
=> array(
450 'name' => ts('Delete'),
451 'url' => 'civicrm/contact/view/membership',
452 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member',
453 'title' => ts('Delete Membership'),
456 if (!$isPaymentProcessor ||
!$accessContribution) {
457 //unset the renew with credit card when payment
458 //processor is not available or user is not permitted to create contributions
459 unset($extraLinks[CRM_Core_Action
::FOLLOWUP
]);
461 self
::$_links['all'] = self
::$_links['view'] +
$extraLinks;
465 if ($isCancelSupported) {
466 $cancelMessage = ts('WARNING: If you cancel the recurring contribution associated with this membership, the membership will no longer be renewed automatically. However, the current membership status will not be affected.');
467 self
::$_links['all'][CRM_Core_Action
::DISABLE
] = array(
468 'name' => ts('Cancel Auto-renewal'),
469 'url' => 'civicrm/contribute/unsubscribe',
470 'qs' => 'reset=1&cid=%%cid%%&mid=%%id%%&context=membership&selectedChild=member',
471 'title' => ts('Cancel Auto Renew Subscription'),
472 'extra' => 'onclick = "if (confirm(\'' . $cancelMessage . '\') ) { return true; else return false;}"',
475 elseif (isset(self
::$_links['all'][CRM_Core_Action
::DISABLE
])) {
476 unset(self
::$_links['all'][CRM_Core_Action
::DISABLE
]);
479 if ($isUpdateBilling) {
480 self
::$_links['all'][CRM_Core_Action
::MAP
] = array(
481 'name' => ts('Change Billing Details'),
482 'url' => 'civicrm/contribute/updatebilling',
483 'qs' => 'reset=1&cid=%%cid%%&mid=%%id%%&context=membership&selectedChild=member',
484 'title' => ts('Change Billing Details'),
487 elseif (isset(self
::$_links['all'][CRM_Core_Action
::MAP
])) {
488 unset(self
::$_links['all'][CRM_Core_Action
::MAP
]);
490 return self
::$_links[$status];
494 * Function to define action links for membership types of related organization
496 * @return array self::$_membershipTypesLinks array of action links
499 static function &membershipTypesLinks() {
500 if (!self
::$_membershipTypesLinks) {
501 self
::$_membershipTypesLinks = array(
502 CRM_Core_Action
::VIEW
=> array(
503 'name' => ts('Members'),
504 'url' => 'civicrm/member/search/',
505 'qs' => 'reset=1&force=1&type=%%id%%',
506 'title' => ts('Search'),
508 CRM_Core_Action
::UPDATE
=> array(
509 'name' => ts('Edit'),
510 'url' => 'civicrm/admin/member/membershipType',
511 'qs' => 'action=update&id=%%id%%&reset=1',
512 'title' => ts('Edit Membership Type'),
516 return self
::$_membershipTypesLinks;
520 * This function is used for the to show the associated
521 * contribution for the membership
522 * @form array $form (ref.) an assoc array of name/value pairs
526 function associatedContribution($contactId = NULL, $membershipId = NULL) {
528 $contactId = $this->_contactId
;
531 if (!$membershipId) {
532 $membershipId = $this->_id
;
535 // retrieive membership contributions if the $membershipId is set
536 if (CRM_Core_Permission
::access('CiviContribute') && $membershipId) {
537 $this->assign('accessContribution', TRUE);
538 $controller = new CRM_Core_Controller_Simple(
539 'CRM_Contribute_Form_Search',
544 $controller->setEmbedded(TRUE);
545 $controller->reset();
546 $controller->set('force', 1);
547 $controller->set('cid', $contactId);
548 $controller->set('memberId', $membershipId);
549 $controller->set('context', 'contribution');
550 $controller->process();
554 $this->assign('accessContribution', FALSE);
561 * @return string Classname of BAO.
563 function getBAOName() {
564 return 'CRM_Member_BAO_Membership';