3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
37 * Create a page for displaying UF Groups.
39 * Heart of this class is the run method which checks
40 * for action type and then displays the appropriate
44 class CRM_UF_Page_Group
extends CRM_Core_Page
{
47 * The action links that we need to display for the browse screen.
51 private static $_actionLinks = NULL;
54 * Get the action links for this page.
60 public function &actionLinks() {
61 // check if variable _actionsLinks is populated
62 if (!self
::$_actionLinks) {
63 // helper variable for nicer formatting
64 $copyExtra = ts('Are you sure you want to make a copy of this Profile?');
65 self
::$_actionLinks = array(
66 CRM_Core_Action
::BROWSE
=> array(
67 'name' => ts('Fields'),
68 'url' => 'civicrm/admin/uf/group/field',
69 'qs' => 'reset=1&action=browse&gid=%%id%%',
70 'title' => ts('View and Edit Fields'),
72 CRM_Core_Action
::UPDATE
=> array(
73 'name' => ts('Settings'),
74 'url' => 'civicrm/admin/uf/group/update',
75 'qs' => 'action=update&id=%%id%%&context=group',
76 'title' => ts('Edit CiviCRM Profile Group'),
78 CRM_Core_Action
::PREVIEW
=> array(
79 'name' => ts('Preview'),
80 'url' => 'civicrm/admin/uf/group',
81 'qs' => 'action=preview&id=%%id%%&field=0&context=group',
82 'title' => ts('Edit CiviCRM Profile Group'),
84 CRM_Core_Action
::ADD
=> array(
85 'name' => ts('Use Profile-Create Mode'),
86 'url' => 'civicrm/profile/create',
87 'qs' => 'gid=%%id%%&reset=1',
88 'title' => ts('Use Profile-Create Mode'),
91 CRM_Core_Action
::BASIC
=> array(
92 'name' => ts('Use Profile-Listings Mode'),
93 'url' => 'civicrm/profile',
94 'qs' => 'gid=%%id%%&reset=1',
95 'title' => ts('Use Profile-Listings Mode'),
98 CRM_Core_Action
::DISABLE
=> array(
99 'name' => ts('Disable'),
100 'ref' => 'crm-enable-disable',
101 'title' => ts('Disable CiviCRM Profile Group'),
103 CRM_Core_Action
::ENABLE
=> array(
104 'name' => ts('Enable'),
105 'ref' => 'crm-enable-disable',
106 'title' => ts('Enable CiviCRM Profile Group'),
108 CRM_Core_Action
::DELETE
=> array(
109 'name' => ts('Delete'),
110 'url' => 'civicrm/admin/uf/group',
111 'qs' => 'action=delete&id=%%id%%',
112 'title' => ts('Delete CiviCRM Profile Group'),
114 CRM_Core_Action
::PROFILE
=> array(
115 'name' => ts('HTML Form Snippet'),
116 'url' => 'civicrm/admin/uf/group',
117 'qs' => 'action=profile&gid=%%id%%',
118 'title' => ts('HTML Form Snippet for this Profile'),
120 CRM_Core_Action
::COPY
=> array(
121 'name' => ts('Copy Profile'),
122 'url' => 'civicrm/admin/uf/group',
123 'qs' => 'action=copy&gid=%%id%%',
124 'title' => ts('Make a Copy of CiviCRM Profile Group'),
125 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
129 return self
::$_actionLinks;
135 * This method is called after the page is created. It checks for the
136 * type of action and executes that action.
137 * Finally it calls the parent's run method.
143 public function run() {
144 // get the requested action
145 $action = CRM_Utils_Request
::retrieve('action', 'String',
147 // default to 'browse'
151 // assign vars to templates
152 $this->assign('action', $action);
153 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
157 //set the context and then start w/ action.
158 $this->setContext($id, $action);
160 // what action to take ?
161 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE | CRM_Core_Action
::DISABLE
)) {
162 $this->edit($id, $action);
165 // if action is enable or disable do the needful.
166 if ($action & CRM_Core_Action
::ENABLE
) {
167 CRM_Core_BAO_UFGroup
::setIsActive($id, 1);
169 // update cms integration with registration / my account
170 CRM_Utils_System
::updateCategories();
172 elseif ($action & CRM_Core_Action
::PROFILE
) {
174 CRM_Utils_System
::setTitle(ts('%1 - HTML Form Snippet', array(1 => $this->_title
)));
176 elseif ($action & CRM_Core_Action
::PREVIEW
) {
177 $this->preview($id, $action);
179 elseif ($action & CRM_Core_Action
::COPY
) {
182 // finally browse the uf groups
186 return parent
::run();
190 * make a copy of a profile, including
191 * all the fields in the profile
195 public function copy() {
196 $gid = CRM_Utils_Request
::retrieve('gid', 'Positive',
197 $this, TRUE, 0, 'GET'
200 CRM_Core_BAO_UFGroup
::copy($gid);
201 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/uf/group', 'reset=1'));
205 * for profile mode (standalone html form ) for uf group
209 public function profile() {
210 $config = CRM_Core_Config
::singleton();
212 // reassign resource base to be the full url, CRM-4660
213 $config->resourceBase
= $config->userFrameworkResourceURL
;
214 $config->useFrameworkRelativeBase
= $config->userFrameworkBaseURL
;
216 $gid = CRM_Utils_Request
::retrieve('gid', 'Positive',
217 $this, FALSE, 0, 'GET'
219 $controller = new CRM_Core_Controller_Simple('CRM_Profile_Form_Edit', ts('Create'), CRM_Core_Action
::ADD
,
222 $controller->reset();
223 $controller->process();
224 $controller->set('gid', $gid);
225 $controller->setEmbedded(TRUE);
227 $template = CRM_Core_Smarty
::singleton();
228 $template->assign('gid', $gid);
229 $template->assign('tplFile', 'CRM/Profile/Form/Edit.tpl');
230 $profile = trim($template->fetch('CRM/Form/default.tpl'));
232 // not sure how to circumvent our own navigation system to generate the right form url
233 $urlReplaceWith = 'civicrm/profile/create&gid=' . $gid . '&reset=1';
234 if ($config->userSystem
->is_drupal
&& $config->cleanURL
) {
235 $urlReplaceWith = 'civicrm/profile/create?gid=' . $gid . '&reset=1';
237 $profile = str_replace('civicrm/admin/uf/group', $urlReplaceWith, $profile);
239 // FIXME: (CRM-3587) hack to make standalone profile work
240 // in wordpress and joomla without administrator login
241 if ($config->userFramework
== 'Joomla') {
242 $profile = str_replace('/administrator/', '/index.php', $profile);
244 elseif ($config->userFramework
== 'WordPress') {
245 //@todo remove this part when it is OK to deprecate CIVICRM_UF_WP_BASEPAGE-CRM-15933
246 if (defined('CIVICRM_UF_WP_BASEPAGE')) {
247 $wpbase = CIVICRM_UF_WP_BASEPAGE
;
249 elseif (!empty($config->wpBasePage
)) {
250 $wpbase = $config->wpBasePage
;
253 $wpbase = 'index.php';
255 $profile = str_replace('/wp-admin/admin.php', '/' . $wpbase . '/', $profile);
259 CRM_Core_Resources
::singleton()->addCoreResources('html-header');
260 $profile = CRM_Core_Region
::instance('html-header')->render('', FALSE) . $profile;
262 $this->assign('profile', htmlentities($profile, ENT_NOQUOTES
, 'UTF-8'));
263 //get the title of uf group
265 $title = CRM_Core_BAO_UFGroup
::getTitle($gid);
266 $this->_title
= $title;
269 $title = 'Profile Form';
272 $this->assign('title', $title);
273 $this->assign('action', CRM_Core_Action
::PROFILE
);
274 $this->assign('isForm', 0);
282 * @param string $action
283 * The action to be invoked.
287 public function edit($id, $action) {
288 // create a simple controller for editing uf data
289 $controller = new CRM_Core_Controller_Simple('CRM_UF_Form_Group', ts('CiviCRM Profile Group'), $action);
290 $this->setContext($id, $action);
291 $controller->set('id', $id);
292 $controller->setEmbedded(TRUE);
293 $controller->process();
298 * Browse all uf data groups.
304 public function browse($action = NULL) {
306 $allUFGroups = array();
307 $allUFGroups = CRM_Core_BAO_UFGroup
::getModuleUFGroup();
308 if (empty($allUFGroups)) {
312 $ufGroups = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_UFField', 'uf_group_id');
313 CRM_Utils_Hook
::aclGroup(CRM_Core_Permission
::ADMIN
, NULL, 'civicrm_uf_group', $ufGroups, $allUFGroups);
315 foreach ($allUFGroups as $id => $value) {
316 $ufGroup[$id] = array();
317 $ufGroup[$id]['id'] = $id;
318 $ufGroup[$id]['title'] = $value['title'];
319 $ufGroup[$id]['created_id'] = $value['created_id'];
320 $ufGroup[$id]['created_by'] = CRM_Contact_BAO_Contact
::displayName($value['created_id']);
321 $ufGroup[$id]['description'] = $value['description'];
322 $ufGroup[$id]['is_active'] = $value['is_active'];
323 $ufGroup[$id]['group_type'] = $value['group_type'];
324 $ufGroup[$id]['is_reserved'] = $value['is_reserved'];
326 // form all action links
327 $action = array_sum(array_keys($this->actionLinks()));
329 // update enable/disable links depending on uf_group properties.
330 if ($value['is_active']) {
331 $action -= CRM_Core_Action
::ENABLE
;
334 $action -= CRM_Core_Action
::DISABLE
;
337 // drop certain actions if the profile is reserved
338 if ($value['is_reserved']) {
339 $action -= CRM_Core_Action
::UPDATE
;
340 $action -= CRM_Core_Action
::DISABLE
;
341 $action -= CRM_Core_Action
::DELETE
;
344 $groupTypes = self
::extractGroupTypes($value['group_type']);
345 $groupComponents = array('Contribution', 'Membership', 'Activity', 'Participant', 'Case');
347 // drop Create, Edit and View mode links if profile group_type is Contribution, Membership, Activities or Participant
348 $componentFound = array_intersect($groupComponents, array_keys($groupTypes));
349 if (!empty($componentFound)) {
350 $action -= CRM_Core_Action
::ADD
;
353 $groupTypesString = '';
354 if (!empty($groupTypes)) {
355 $groupTypesStrings = array();
356 foreach ($groupTypes as $groupType => $typeValues) {
357 if (is_array($typeValues)) {
358 if ($groupType == 'Participant') {
359 foreach ($typeValues as $subType => $subTypeValues) {
360 $groupTypesStrings[] = $subType . '::' . implode(': ', $subTypeValues);
364 $groupTypesStrings[] = $groupType . '::' . implode(': ', current($typeValues));
368 $groupTypesStrings[] = $groupType;
371 $groupTypesString = implode(', ', $groupTypesStrings);
373 $ufGroup[$id]['group_type'] = $groupTypesString;
375 $ufGroup[$id]['action'] = CRM_Core_Action
::formLink(self
::actionLinks(), $action,
379 'ufGroup.row.actions',
383 //get the "Used For" from uf_join
384 $ufGroup[$id]['module'] = implode(', ', CRM_Core_BAO_UFGroup
::getUFJoinRecord($id, TRUE));
387 $this->assign('rows', $ufGroup);
391 * for preview mode for ufoup.
400 public function preview($id, $action) {
401 $controller = new CRM_Core_Controller_Simple('CRM_UF_Form_Preview', ts('CiviCRM Profile Group Preview'), NULL);
402 $controller->set('id', $id);
403 $controller->setEmbedded(TRUE);
404 $controller->process();
412 public function setContext($id, $action) {
413 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
415 //we need to differentiate context for update and preview profile.
416 if (!$context && !($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::PREVIEW
))) {
420 if ($context == 'field') {
421 $url = CRM_Utils_System
::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$id}");
424 $url = CRM_Utils_System
::url('civicrm/admin/uf/group', 'reset=1&action=browse');
427 $session = CRM_Core_Session
::singleton();
428 $session->pushUserContext($url);
436 public static function extractGroupTypes($groupType) {
437 $returnGroupTypes = array();
439 return $returnGroupTypes;
442 $groupTypeParts = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $groupType);
443 foreach (explode(',', $groupTypeParts[0]) as $type) {
444 $returnGroupTypes[$type] = $type;
447 if (!empty($groupTypeParts[1])) {
448 foreach (explode(',', $groupTypeParts[1]) as $typeValue) {
449 $groupTypeValues = $valueLabels = array();
450 $valueParts = explode(':', $typeValue);
452 switch ($valueParts[0]) {
453 case 'ContributionType':
454 $typeName = 'Contribution';
455 $valueLabels = CRM_Contribute_PseudoConstant
::financialType();
458 case 'ParticipantRole':
459 $typeName = 'Participant';
460 $valueLabels = CRM_Event_PseudoConstant
::participantRole();
463 case 'ParticipantEventName':
464 $typeName = 'Participant';
465 $valueLabels = CRM_Event_PseudoConstant
::event();
468 case 'ParticipantEventType':
469 $typeName = 'Participant';
470 $valueLabels = CRM_Event_PseudoConstant
::eventType();
473 case 'MembershipType':
474 $typeName = 'Membership';
475 $valueLabels = CRM_Member_PseudoConstant
::membershipType();
479 $typeName = 'Activity';
480 $valueLabels = CRM_Core_PseudoConstant
::ActivityType(TRUE, TRUE, FALSE, 'label', TRUE);
485 $valueLabels = CRM_Case_PseudoConstant
::caseType();
489 foreach ($valueParts as $val) {
490 if (CRM_Utils_Rule
::integer($val)) {
491 $groupTypeValues[$val] = CRM_Utils_Array
::value($val, $valueLabels);
495 if (!is_array($returnGroupTypes[$typeName])) {
496 $returnGroupTypes[$typeName] = array();
498 $returnGroupTypes[$typeName][$valueParts[0]] = $groupTypeValues;
501 return $returnGroupTypes;