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