Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-04-04-00-08-28
[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 * @static
47 * @access public
48 */
49 function run($args = NULL) {
50 if ($args[1] !== 'profile') {
51 return;
52 }
53
54 $secondArg = CRM_Utils_Array::value(2, $args, '');
55
56 if ($secondArg == 'map') {
57 $controller = new CRM_Core_Controller_Simple(
58 'CRM_Contact_Form_Task_Map',
59 ts('Map Contact'),
60 NULL, FALSE, FALSE, TRUE
61 );
62
63 $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET'));
64
65 if (count($gids) > 1) {
66 foreach ($gids as $pfId) {
67 $profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive');
68 }
69 $controller->set('gid', $profileIds[0]);
70 $profileGID = $profileIds[0];
71 }
72 else {
73 $profileGID = CRM_Utils_Request::retrieve('gid', 'Integer', $controller, TRUE);
74 }
75
76
77 // make sure that this profile enables mapping
78 // CRM-8609
79 $isMap =
80 CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileGID, 'is_map');
81 if (!$isMap) {
82 CRM_Core_Error::statusBounce(ts('This profile does not have the map feature turned on.'));
83 }
84
85 $profileView = CRM_Utils_Request::retrieve('pv', 'Integer', $controller, FALSE);
86
87 // set the userContext stack
88 $session = CRM_Core_Session::singleton();
89 if ($profileView) {
90 $session->pushUserContext(CRM_Utils_System::url('civicrm/profile/view'));
91 }
92 else {
93 $session->pushUserContext(CRM_Utils_System::url('civicrm/profile', 'force=1'));
94 }
95
96 $controller->set('profileGID', $profileGID);
97 $controller->process();
98 return $controller->run();
99 }
100
101 if ($secondArg == 'edit' || $secondArg == 'create') {
102 $buttonType = CRM_Utils_Array::value('_qf_Edit_cancel', $_POST);
103 // CRM-5849: we should actually check the button *type*, but we get the *value*, potentially translated;
104 // we should keep both English and translated checks just to make sure we also handle untranslated Cancels
105 if ($buttonType == 'Cancel' or $buttonType == ts('Cancel')) {
106 $cancelURL = CRM_Utils_Request::retrieve('cancelURL',
107 'String',
108 CRM_Core_DAO::$_nullObject,
109 FALSE,
110 NULL,
111 $_POST
112 );
113 if ($cancelURL) {
114 CRM_Utils_System::redirect($cancelURL);
115 }
116 }
117
118 if ($secondArg == 'edit') {
119 $controller = new CRM_Core_Controller_Simple('CRM_Profile_Form_Edit',
120 ts('Create Profile'),
121 CRM_Core_Action::UPDATE,
122 FALSE, FALSE, TRUE
123 );
124 $controller->set('edit', 1);
125 $controller->process();
126 return $controller->run();
127 }
128 else {
129 $wrapper = new CRM_Utils_Wrapper();
130 return $wrapper->run('CRM_Profile_Form_Edit',
131 ts('Create Profile'),
132 array(
133 'mode' => CRM_Core_Action::ADD,
134 'ignoreKey' => TRUE,
135 )
136 );
137 }
138 }
139
140 if ($secondArg == 'view' || empty($secondArg)) {
141 $page = new CRM_Profile_Page_Listings();
142 return $page->run();
143 }
144
145 CRM_Utils_System::permissionDenied();
146 return;
147 }
148
149 }