3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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
);
92 foreach (array('status', 'membership_type') as $fld) {
93 $membership[$dao->id
][$fld] = CRM_Utils_Array
::value($fld, $statusANDType[$dao->id
]);
95 if (CRM_Utils_Array
::value('is_current_member', $statusANDType[$dao->id
])) {
96 $membership[$dao->id
]['active'] = TRUE;
98 if (empty($dao->owner_membership_id
)) {
99 // unset renew and followup link for deceased membership
100 $currentMask = $mask;
101 if ($dao->status_id
== $deceasedStatusId) {
102 $currentMask = $currentMask & ~CRM_Core_Action
::RENEW
& ~CRM_Core_Action
::FOLLOWUP
;
105 $isUpdateBilling = FALSE;
106 $paymentObject = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity(
107 $membership[$dao->id
]['membership_id'], 'membership', 'obj');
108 if (!empty($paymentObject)) {
109 $isUpdateBilling = $paymentObject->isSupported('updateSubscriptionBillingInfo');
112 $isCancelSupported = CRM_Member_BAO_Membership
::isCancelSubscriptionSupported(
113 $membership[$dao->id
]['membership_id']);
115 $membership[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links('all',
124 'cid' => $this->_contactId
,
129 $membership[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links('view'),
133 'cid' => $this->_contactId
,
138 //does membership have auto renew CRM-7137.
139 if (CRM_Utils_Array
::value('contribution_recur_id', $membership[$dao->id
]) &&
140 !CRM_Member_BAO_Membership
::isSubscriptionCancelled($membership[$dao->id
]['membership_id'])
142 $membership[$dao->id
]['auto_renew'] = 1;
145 $membership[$dao->id
]['auto_renew'] = 0;
148 // if relevant, count related memberships
149 if (CRM_Utils_Array
::value('is_current_member', $statusANDType[$dao->id
]) // membership is active
150 && CRM_Utils_Array
::value('relationship_type_id', $statusANDType[$dao->id
]) // membership type allows inheritance
151 && empty($dao->owner_membership_id
)
152 ) { // not an related membership
155 FROM civicrm_membership m
156 LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id
157 LEFT JOIN civicrm_contact ct ON ct.id = m.contact_id
158 WHERE m.owner_membership_id = {$dao->id} AND m.is_test = 0 AND ms.is_current_member = 1 AND ct.is_deleted = 0";
159 $num_related = CRM_Core_DAO
::singleValueQuery($query);
160 $max_related = CRM_Utils_Array
::value('max_related', $membership[$dao->id
]);
161 $membership[$dao->id
]['related_count'] = ($max_related == '' ?
162 ts('%1 created', array(1 => $num_related)) :
163 ts('%1 out of %2', array(1 => $num_related, 2 => $max_related))
167 $membership[$dao->id
]['related_count'] = ts('N/A');
171 //Below code gives list of all Membership Types associated
172 //with an Organization(CRM-2016)
173 $membershipTypes = CRM_Member_BAO_MembershipType
::getMembershipTypesByOrg($this->_contactId
);
174 foreach ($membershipTypes as $key => $value) {
175 $membershipTypes[$key]['action'] = CRM_Core_Action
::formLink(self
::membershipTypeslinks(),
178 'id' => $value['id'],
179 'cid' => $this->_contactId
,
184 $activeMembers = CRM_Member_BAO_Membership
::activeMembers($membership);
185 $inActiveMembers = CRM_Member_BAO_Membership
::activeMembers($membership, 'inactive');
186 $this->assign('activeMembers', $activeMembers);
187 $this->assign('inActiveMembers', $inActiveMembers);
188 $this->assign('membershipTypes', $membershipTypes);
190 if ($this->_contactId
) {
191 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
192 $this->assign('displayName', $displayName);
197 * This function is called when action is view
203 $controller = new CRM_Core_Controller_Simple(
204 'CRM_Member_Form_MembershipView',
205 ts('View Membership'),
208 $controller->setEmbedded(TRUE);
209 $controller->set('id', $this->_id
);
210 $controller->set('cid', $this->_contactId
);
212 return $controller->run();
216 * This function is called when action is update or new
222 // set https for offline cc transaction
223 $mode = CRM_Utils_Request
::retrieve('mode', 'String', $this);
224 if ($mode == 'test' ||
$mode == 'live') {
225 CRM_Utils_System
::redirectToSSL();
228 // build associated contributions ( note: this is called to show associated contributions in edit mode )
229 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
230 $this->assign('accessContribution', FALSE);
231 if (CRM_Core_Permission
::access('CiviContribute')) {
232 $this->assign('accessContribution', TRUE);
233 CRM_Member_Page_Tab
::associatedContribution($this->_contactId
, $this->_id
);
237 if ($this->_action
& CRM_Core_Action
::RENEW
) {
238 $path = 'CRM_Member_Form_MembershipRenewal';
239 $title = ts('Renew Membership');
242 $path = 'CRM_Member_Form_Membership';
243 $title = ts('Create Membership');
246 $controller = new CRM_Core_Controller_Simple($path, $title, $this->_action
);
247 $controller->setEmbedded(TRUE);
248 $controller->set('BAOName', $this->getBAOName());
249 $controller->set('id', $this->_id
);
250 $controller->set('cid', $this->_contactId
);
251 return $controller->run();
254 function preProcess() {
255 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
256 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
257 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
259 if ($context == 'standalone') {
260 $this->_action
= CRM_Core_Action
::ADD
;
263 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
264 $this->assign('contactId', $this->_contactId
);
266 // check logged in url permission
267 CRM_Contact_Page_View
::checkUserPermission($this);
270 CRM_Contact_Page_View
::setTitle($this->_contactId
);
273 $this->assign('action', $this->_action
);
275 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit memberships')) {
276 // demote to view since user does not have edit membership rights
277 $this->_permission
= CRM_Core_Permission
::VIEW
;
278 $this->assign('permission', 'view');
283 * 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.
291 // check if we can process credit card membership
292 $newCredit = CRM_Core_Payment
::allowBackofficeCreditCard($this);
294 $this->_isPaymentProcessor
= TRUE;
297 $this->_isPaymentProcessor
= FALSE;
300 // Only show credit card membership signup if user has CiviContribute permission
301 if (CRM_Core_Permission
::access('CiviContribute')) {
302 $this->_accessContribution
= TRUE;
303 $this->assign('accessContribution', TRUE);
306 $this->_accessContribution
= FALSE;
307 $this->assign('accessContribution', FALSE);
310 if ($this->_action
& CRM_Core_Action
::VIEW
) {
313 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
314 | CRM_Core_Action
::RENEW
)) {
315 self
::setContext($this);
319 self
::setContext($this);
323 return parent
::run();
326 public static function setContext(&$form, $contactId = NULL) {
327 $context = CRM_Utils_Request
::retrieve('context', 'String', $form, FALSE, 'search' );
329 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $form);
331 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
336 $contactId = $form->_contactId
;
341 $url = CRM_Utils_System
::url('civicrm/member', 'reset=1');
345 $url = CRM_Utils_System
::url('civicrm/contact/view', "reset=1&force=1&cid={$contactId}&selectedChild=member");
349 $urlParams = 'force=1';
351 $urlParams .= "&qfKey=$qfKey";
353 $form->assign('searchKey', $qfKey);
355 $url = CRM_Utils_System
::url('civicrm/member/search', $urlParams);
359 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
363 $url = CRM_Utils_System
::url('civicrm/contact/view',
364 "reset=1&force=1&cid={$contactId}&selectedChild=activity"
369 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
373 $action = CRM_Utils_Request
::retrieve('action', 'String', $form);
375 $urlParams = 'force=1';
376 $urlString = 'civicrm/contact/search/custom';
377 if ($action == CRM_Core_Action
::UPDATE
) {
378 if ($form->_contactId
) {
379 $urlParams .= '&cid=' . $this->_contactId
;
382 $urlParams .= '&context=fulltext&action=view';
383 $urlString = 'civicrm/contact/view/membership';
386 $urlParams .= "$keyName=$qfKey";
388 $form->assign('searchKey', $qfKey);
389 $url = CRM_Utils_System
::url($urlString, $urlParams);
395 $cid = '&cid=' . $contactId;
397 $url = CRM_Utils_System
::url('civicrm/member/search', 'force=1' . $cid);
401 $session = CRM_Core_Session
::singleton();
402 $session->pushUserContext($url);
408 * @return array (reference) of action links
411 static function &links($status = 'all',
412 $isPaymentProcessor = NULL,
413 $accessContribution = NULL,
414 $isCancelSupported = FALSE,
415 $isUpdateBilling = FALSE
417 if (!CRM_Utils_Array
::value('view', self
::$_links)) {
418 self
::$_links['view'] = array(
419 CRM_Core_Action
::VIEW
=> array(
420 'name' => ts('View'),
421 'url' => 'civicrm/contact/view/membership',
422 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member',
423 'title' => ts('View Membership'),
428 if (!CRM_Utils_Array
::value('all', self
::$_links)) {
430 CRM_Core_Action
::UPDATE
=> array(
431 'name' => ts('Edit'),
432 'url' => 'civicrm/contact/view/membership',
433 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member',
434 'title' => ts('Edit Membership'),
436 CRM_Core_Action
::RENEW
=> array(
437 'name' => ts('Renew'),
438 'url' => 'civicrm/contact/view/membership',
439 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member',
440 'title' => ts('Renew Membership'),
442 CRM_Core_Action
::FOLLOWUP
=> array(
443 'name' => ts('Renew-Credit Card'),
444 'url' => 'civicrm/contact/view/membership',
445 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member&mode=live',
446 'title' => ts('Renew Membership Using Credit Card'),
448 CRM_Core_Action
::DELETE
=> array(
449 'name' => ts('Delete'),
450 'url' => 'civicrm/contact/view/membership',
451 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member',
452 'title' => ts('Delete Membership'),
455 if (!$isPaymentProcessor ||
!$accessContribution) {
456 //unset the renew with credit card when payment
457 //processor is not available or user is not permitted to create contributions
458 unset($extraLinks[CRM_Core_Action
::FOLLOWUP
]);
460 self
::$_links['all'] = self
::$_links['view'] +
$extraLinks;
464 if ($isCancelSupported) {
465 $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.');
466 self
::$_links['all'][CRM_Core_Action
::DISABLE
] = array(
467 'name' => ts('Cancel Auto-renewal'),
468 'url' => 'civicrm/contribute/unsubscribe',
469 'qs' => 'reset=1&cid=%%cid%%&mid=%%id%%&context=membership&selectedChild=member',
470 'title' => ts('Cancel Auto Renew Subscription'),
471 'extra' => 'onclick = "if (confirm(\'' . $cancelMessage . '\') ) { return true; else return false;}"',
474 elseif (isset(self
::$_links['all'][CRM_Core_Action
::DISABLE
])) {
475 unset(self
::$_links['all'][CRM_Core_Action
::DISABLE
]);
478 if ($isUpdateBilling) {
479 self
::$_links['all'][CRM_Core_Action
::MAP
] = array(
480 'name' => ts('Change Billing Details'),
481 'url' => 'civicrm/contribute/updatebilling',
482 'qs' => 'reset=1&cid=%%cid%%&mid=%%id%%&context=membership&selectedChild=member',
483 'title' => ts('Change Billing Details'),
486 elseif (isset(self
::$_links['all'][CRM_Core_Action
::MAP
])) {
487 unset(self
::$_links['all'][CRM_Core_Action
::MAP
]);
489 return self
::$_links[$status];
493 * Function to define action links for membership types of related organization
495 * @return array self::$_membershipTypesLinks array of action links
498 static function &membershipTypesLinks() {
499 if (!self
::$_membershipTypesLinks) {
500 self
::$_membershipTypesLinks = array(
501 CRM_Core_Action
::VIEW
=> array(
502 'name' => ts('Members'),
503 'url' => 'civicrm/member/search/',
504 'qs' => 'reset=1&force=1&type=%%id%%',
505 'title' => ts('Search'),
507 CRM_Core_Action
::UPDATE
=> array(
508 'name' => ts('Edit'),
509 'url' => 'civicrm/admin/member/membershipType',
510 'qs' => 'action=update&id=%%id%%&reset=1',
511 'title' => ts('Edit Membership Type'),
515 return self
::$_membershipTypesLinks;
519 * This function is used for the to show the associated
520 * contribution for the membership
521 * @form array $form (ref.) an assoc array of name/value pairs
525 public static function associatedContribution($contactId = NULL, $membershipId = NULL) {
526 $controller = new CRM_Core_Controller_Simple(
527 'CRM_Contribute_Form_Search',
532 $controller->setEmbedded(TRUE);
533 $controller->reset();
534 $controller->set('force', 1);
535 $controller->set('cid', $contactId);
536 $controller->set('memberId', $membershipId);
537 $controller->set('context', 'contribution');
538 $controller->process();
545 * @return string Classname of BAO.
547 function getBAOName() {
548 return 'CRM_Member_BAO_Membership';