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_Contact_Page_View_GroupContact
extends CRM_Core_Page
{
38 * This function is called when action is browse
45 $count = CRM_Contact_BAO_GroupContact
::getContactGroup($this->_contactId
, NULL, NULL, TRUE);
47 $in = CRM_Contact_BAO_GroupContact
::getContactGroup($this->_contactId
, 'Added');
48 $pending = CRM_Contact_BAO_GroupContact
::getContactGroup($this->_contactId
, 'Pending');
49 $out = CRM_Contact_BAO_GroupContact
::getContactGroup($this->_contactId
, 'Removed');
51 // keep track of all 'added' contact groups so we can remove them from the smart group
53 $staticGroups = array();
55 foreach ($in as $group) {
56 $staticGroups[$group['group_id']] = 1;
60 $this->assign('groupCount', $count);
61 $this->assign_by_ref('groupIn', $in);
62 $this->assign_by_ref('groupPending', $pending);
63 $this->assign_by_ref('groupOut', $out);
65 $allGroup = CRM_Contact_BAO_GroupContactCache
::contactGroup($this->_contactId
);
66 $this->assign('groupSmart' , null);
67 $this->assign('groupParent', null);
69 if (!empty($allGroup)) {
70 $smart = $parent = array( );
71 foreach ($allGroup['group'] as $group) {
72 // delete all smart groups which are also in static groups
73 if (isset($staticGroups[$group['id']])) {
76 if (empty($group['children'])) {
85 $this->assign_by_ref('groupSmart', $smart);
87 if (!empty($parent)) {
88 $this->assign_by_ref('groupParent', $parent);
94 * This function is called when action is update
96 * @param int $groupID group id
101 function edit($groupId = NULL) {
102 $controller = new CRM_Core_Controller_Simple(
103 'CRM_Contact_Form_GroupContact',
104 ts('Contact\'s Groups'),
107 $controller->setEmbedded(TRUE);
109 // set the userContext stack
110 $session = CRM_Core_Session
::singleton();
112 $session->pushUserContext(
113 CRM_Utils_System
::url(
114 'civicrm/contact/view',
115 "action=browse&selectedChild=group&cid={$this->_contactId}"
119 $controller->reset();
121 $controller->set('contactId', $this->_contactId
);
122 $controller->set('groupId', $groupId);
124 $controller->process();
128 function preProcess() {
129 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
130 $this->assign('contactId', $this->_contactId
);
132 // check logged in url permission
133 CRM_Contact_Page_View
::checkUserPermission($this);
135 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
136 $this->assign('action', $this->_action
);
140 * This function is the main function that is called
141 * when the page loads, it decides the which action has
142 * to be taken for the page.
150 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
151 $this->assign('displayName', $displayName);
153 if ($this->_action
== CRM_Core_Action
::DELETE
) {
154 $groupContactId = CRM_Utils_Request
::retrieve('gcid', 'Positive', CRM_Core_DAO
::$_nullObject, TRUE);
155 $status = CRM_Utils_Request
::retrieve('st', 'String', CRM_Core_DAO
::$_nullObject, TRUE);
156 if (is_numeric($groupContactId) && $status) {
157 $this->del($groupContactId, $status, $this->_contactId
);
159 $session = CRM_Core_Session
::singleton();
160 CRM_Utils_System
::redirect($session->popUserContext());
163 $this->edit(NULL, CRM_Core_Action
::ADD
);
165 return parent
::run();
169 * function to remove/ rejoin the group
171 * @param int $groupContactId id of crm_group_contact
172 * @param string $status this is the status that should be updated.
176 function del($groupContactId, $status, $contactID) {
177 $groupId = CRM_Contact_BAO_GroupContact
::getGroupId($groupContactId);
181 $groupStatus = 'Added';
185 $groupStatus = 'Pending';
189 $groupStatus = 'Removed';
193 $groupStatus = 'Deleted';
197 $groupNum = CRM_Contact_BAO_GroupContact
::getContactGroup($this->_contactId
, 'Added',
200 if ($groupNum == 1 &&
201 $groupStatus == 'Removed' &&
202 CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::MULTISITE_PREFERENCES_NAME
,
206 CRM_Core_Session
::setStatus(ts('Please ensure at least one contact group association is maintained.'), ts('Could Not Remove'));
210 $ids = array($contactID);
213 $session = CRM_Core_Session
::singleton();
214 $userID = $session->get('userID');
216 if ($userID == $contactID) {
220 CRM_Contact_BAO_GroupContact
::removeContactsFromGroup($ids, $groupId, $method, $groupStatus);