Merge pull request #13837 from eileenmcnaughton/event_conf
[civicrm-core.git] / CRM / Profile / Page / Router.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2019
32 *
33 */
34
35 /**
36 * This is some kind of special-purpose router/front-controller for the various profile URLs.
37 */
38 class CRM_Profile_Page_Router extends CRM_Core_Page {
39
40 /**
41 * This is some kind of special-purpose router/front-controller for the various profile URLs.
42 *
43 * @param array $args
44 * this array contains the arguments of the url.
45 *
46 * @return string|void
47 */
48 public function run($args = NULL) {
49 if ($args[1] !== 'profile') {
50 return NULL;
51 }
52
53 $secondArg = CRM_Utils_Array::value(2, $args, '');
54
55 if ($secondArg == 'map') {
56 $controller = new CRM_Core_Controller_Simple(
57 'CRM_Contact_Form_Task_Map',
58 ts('Map Contact'),
59 NULL, FALSE, FALSE, TRUE
60 );
61
62 $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET'));
63
64 if (count($gids) > 1) {
65 foreach ($gids as $pfId) {
66 $profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive');
67 }
68 $controller->set('gid', $profileIds[0]);
69 $profileGID = $profileIds[0];
70 }
71 else {
72 $profileGID = CRM_Utils_Request::retrieve('gid', 'Integer', $controller, TRUE);
73 }
74
75 // make sure that this profile enables mapping
76 // CRM-8609
77 $isMap = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileGID, 'is_map');
78 if (!$isMap) {
79 CRM_Core_Error::statusBounce(ts('This profile does not have the map feature turned on.'));
80 }
81
82 $profileView = CRM_Utils_Request::retrieve('pv', 'Integer', $controller, FALSE);
83
84 // set the userContext stack
85 $session = CRM_Core_Session::singleton();
86 if ($profileView) {
87 $session->pushUserContext(CRM_Utils_System::url('civicrm/profile/view'));
88 }
89 else {
90 $session->pushUserContext(CRM_Utils_System::url('civicrm/profile', 'force=1'));
91 }
92
93 $controller->set('profileGID', $profileGID);
94 $controller->process();
95 return $controller->run();
96 }
97
98 if ($secondArg == 'edit' || $secondArg == 'create') {
99 $allowRemoteSubmit = Civi::settings()->get('remote_profile_submissions');
100 if ($secondArg == 'edit') {
101 $controller = new CRM_Core_Controller_Simple('CRM_Profile_Form_Edit',
102 ts('Create Profile'),
103 CRM_Core_Action::UPDATE,
104 FALSE, FALSE, $allowRemoteSubmit
105 );
106 $controller->set('edit', 1);
107 $controller->process();
108 return $controller->run();
109 }
110 else {
111 $wrapper = new CRM_Utils_Wrapper();
112 return $wrapper->run('CRM_Profile_Form_Edit',
113 ts('Create Profile'),
114 [
115 'mode' => CRM_Core_Action::ADD,
116 'ignoreKey' => $allowRemoteSubmit,
117 ]
118 );
119 }
120 }
121
122 if ($secondArg == 'view' || empty($secondArg)) {
123 $page = new CRM_Profile_Page_Listings();
124 return $page->run();
125 }
126
127 CRM_Utils_System::permissionDenied();
128 }
129
130 }