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 | /** | |
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 | * | |
5a4f6742 CW |
27 | * @param array $args |
28 | * this array contains the arguments of the url. | |
19faccf9 | 29 | * |
77b97be7 | 30 | * @return string|void |
19faccf9 | 31 | */ |
00be9182 | 32 | public function run($args = NULL) { |
19faccf9 | 33 | if ($args[1] !== 'profile') { |
acb1052e | 34 | return NULL; |
19faccf9 TO |
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 | ||
19faccf9 TO |
59 | // make sure that this profile enables mapping |
60 | // CRM-8609 | |
acb1052e | 61 | $isMap = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileGID, 'is_map'); |
19faccf9 TO |
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') { | |
fc5f21f4 | 83 | $allowRemoteSubmit = Civi::settings()->get('remote_profile_submissions'); |
19faccf9 TO |
84 | if ($secondArg == 'edit') { |
85 | $controller = new CRM_Core_Controller_Simple('CRM_Profile_Form_Edit', | |
86 | ts('Create Profile'), | |
87 | CRM_Core_Action::UPDATE, | |
1bfe4abf | 88 | FALSE, FALSE, $allowRemoteSubmit |
19faccf9 TO |
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'), | |
be2fb01f | 98 | [ |
19faccf9 | 99 | 'mode' => CRM_Core_Action::ADD, |
77b09879 | 100 | 'ignoreKey' => $allowRemoteSubmit, |
be2fb01f | 101 | ] |
19faccf9 TO |
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(); | |
19faccf9 TO |
112 | } |
113 | ||
77b97be7 | 114 | } |