Merge pull request #17583 from civicrm/5.27
[civicrm-core.git] / CRM / Profile / Page / Router.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 *
17 */
18
19 /**
20 * This is some kind of special-purpose router/front-controller for the various profile URLs.
21 */
22 class CRM_Profile_Page_Router extends CRM_Core_Page {
23
24 /**
25 * This is some kind of special-purpose router/front-controller for the various profile URLs.
26 *
27 * @param array $args
28 * this array contains the arguments of the url.
29 *
30 * @return string|void
31 */
32 public function run($args = NULL) {
33 if ($args[1] !== 'profile') {
34 return NULL;
35 }
36
37 $secondArg = CRM_Utils_Array::value(2, $args, '');
38
39 if ($secondArg == 'map') {
40 $controller = new CRM_Core_Controller_Simple(
41 'CRM_Contact_Form_Task_Map',
42 ts('Map Contact'),
43 NULL, FALSE, FALSE, TRUE
44 );
45
46 $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET'));
47
48 if (count($gids) > 1) {
49 foreach ($gids as $pfId) {
50 $profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive');
51 }
52 $controller->set('gid', $profileIds[0]);
53 $profileGID = $profileIds[0];
54 }
55 else {
56 $profileGID = CRM_Utils_Request::retrieve('gid', 'Integer', $controller, TRUE);
57 }
58
59 // make sure that this profile enables mapping
60 // CRM-8609
61 $isMap = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileGID, 'is_map');
62 if (!$isMap) {
63 CRM_Core_Error::statusBounce(ts('This profile does not have the map feature turned on.'));
64 }
65
66 $profileView = CRM_Utils_Request::retrieve('pv', 'Integer', $controller, FALSE);
67
68 // set the userContext stack
69 $session = CRM_Core_Session::singleton();
70 if ($profileView) {
71 $session->pushUserContext(CRM_Utils_System::url('civicrm/profile/view'));
72 }
73 else {
74 $session->pushUserContext(CRM_Utils_System::url('civicrm/profile', 'force=1'));
75 }
76
77 $controller->set('profileGID', $profileGID);
78 $controller->process();
79 return $controller->run();
80 }
81
82 if ($secondArg == 'edit' || $secondArg == 'create') {
83 $allowRemoteSubmit = Civi::settings()->get('remote_profile_submissions');
84 if ($secondArg == 'edit') {
85 $controller = new CRM_Core_Controller_Simple('CRM_Profile_Form_Edit',
86 ts('Create Profile'),
87 CRM_Core_Action::UPDATE,
88 FALSE, FALSE, $allowRemoteSubmit
89 );
90 $controller->set('edit', 1);
91 $controller->process();
92 return $controller->run();
93 }
94 else {
95 $wrapper = new CRM_Utils_Wrapper();
96 return $wrapper->run('CRM_Profile_Form_Edit',
97 ts('Create Profile'),
98 [
99 'mode' => CRM_Core_Action::ADD,
100 'ignoreKey' => $allowRemoteSubmit,
101 ]
102 );
103 }
104 }
105
106 if ($secondArg == 'view' || empty($secondArg)) {
107 $page = new CRM_Profile_Page_Listings();
108 return $page->run();
109 }
110
111 CRM_Utils_System::permissionDenied();
112 }
113
114 }