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