Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Main page for viewing contact. | |
38 | * | |
39 | */ | |
40 | class CRM_Profile_Page_View extends CRM_Core_Page { | |
41 | ||
42 | /** | |
43 | * The id of the contact | |
44 | * | |
45 | * @var int | |
46 | */ | |
47 | protected $_id; | |
48 | ||
49 | /** | |
50 | * The group id that we are editing | |
51 | * | |
52 | * @var int | |
53 | */ | |
54 | protected $_gid; | |
55 | ||
56 | /** | |
57 | * Heart of the viewing process. The runner gets all the meta data for | |
58 | * the contact and calls the appropriate type of page to view. | |
59 | * | |
60 | * @return void | |
61 | * @access public | |
62 | * | |
63 | */ function preProcess() { | |
64 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', | |
65 | $this, FALSE | |
66 | ); | |
67 | if (!$this->_id) { | |
68 | $session = CRM_Core_Session::singleton(); | |
69 | $this->_id = $session->get('userID'); | |
70 | if (!$this->_id) { | |
71 | CRM_Core_Error::fatal(ts('Could not find the required contact id parameter (id=) for viewing a contact record with a Profile.')); | |
72 | } | |
73 | } | |
74 | $this->assign('cid', $this->_id); | |
75 | ||
76 | $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET')); | |
77 | ||
78 | $profileIds = array(); | |
79 | if (count($gids) > 1) { | |
80 | if (!empty($gids)) { | |
81 | foreach ($gids as $pfId) { | |
82 | $profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive'); | |
83 | } | |
84 | } | |
85 | ||
86 | // check if we are rendering mixed profiles | |
87 | if (CRM_Core_BAO_UFGroup::checkForMixProfiles($profileIds)) { | |
88 | CRM_Core_Error::fatal(ts('You cannot combine profiles of multiple types.')); | |
89 | } | |
90 | ||
91 | $this->_gid = $profileIds[0]; | |
92 | } | |
93 | ||
94 | if (!$this->_gid) { | |
95 | $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0, 'GET'); | |
96 | } | |
97 | ||
98 | $anyContent = TRUE; | |
99 | if ($this->_gid) { | |
100 | $page = new CRM_Profile_Page_Dynamic($this->_id, $this->_gid, 'Profile', FALSE, $profileIds); | |
101 | $profileGroup = array(); | |
102 | $profileGroup['title'] = NULL; | |
103 | $profileGroup['content'] = $page->run(); | |
104 | if (empty($profileGroup['content'])) { | |
105 | $anyContent = FALSE; | |
106 | } | |
107 | $profileGroups[] = $profileGroup; | |
108 | ||
109 | $gidString = $this->_gid; | |
110 | if (!empty($profileIds)) { | |
111 | $gidString = implode(',', $profileIds); | |
112 | } | |
113 | ||
114 | $map = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_map'); | |
115 | if ($map) { | |
116 | $this->assign('mapURL', | |
117 | CRM_Utils_System::url("civicrm/profile/map", | |
118 | "reset=1&pv=1&cid={$this->_id}&gid={$gidString}" | |
119 | ) | |
120 | ); | |
121 | } | |
122 | if (CRM_Core_Permission::ufGroupValid($this->_gid, | |
123 | CRM_Core_Permission::SEARCH | |
124 | )) { | |
125 | $this->assign('listingURL', | |
126 | CRM_Utils_System::url("civicrm/profile", | |
127 | "force=1&gid={$gidString}" | |
128 | ) | |
129 | ); | |
130 | } | |
131 | } | |
132 | else { | |
133 | $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Profile'); | |
134 | ||
135 | $profileGroups = array(); | |
136 | foreach ($ufGroups as $groupid => $group) { | |
137 | $page = new CRM_Profile_Page_Dynamic($this->_id, $groupid, 'Profile', FALSE, $profileIds); | |
138 | $profileGroup = array(); | |
139 | $profileGroup['title'] = $group['title']; | |
140 | $profileGroup['content'] = $page->run(); | |
141 | if (empty($profileGroup['content'])) { | |
142 | $anyContent = FALSE; | |
143 | } | |
144 | $profileGroups[] = $profileGroup; | |
145 | } | |
146 | $this->assign('listingURL', | |
147 | CRM_Utils_System::url("civicrm/profile", | |
148 | "force=1" | |
149 | ) | |
150 | ); | |
151 | } | |
152 | ||
153 | $this->assign('groupID', $this->_gid); | |
154 | ||
155 | $this->assign('profileGroups', $profileGroups); | |
156 | $this->assign('recentlyViewed', FALSE); | |
157 | ||
158 | // do not set title if there is no content | |
159 | // CRM-6081 | |
160 | if (!$anyContent) { | |
161 | CRM_Utils_System::setTitle(''); | |
162 | } | |
163 | } | |
164 | ||
165 | /** | |
166 | * build the outcome basing on the CRM_Profile_Page_Dynamic's HTML | |
167 | * | |
168 | * @return void | |
169 | * @access public | |
170 | * | |
171 | */ | |
172 | function run() { | |
173 | $this->preProcess(); | |
174 | return parent::run(); | |
175 | } | |
176 | ||
177 | function checkTemplateFileExists($suffix = '') { | |
178 | if ($this->_gid) { | |
179 | $templateFile = "CRM/Profile/Page/{$this->_gid}/View.{$suffix}tpl"; | |
180 | $template = CRM_Core_Page::getTemplate(); | |
181 | if ($template->template_exists($templateFile)) { | |
182 | return $templateFile; | |
183 | } | |
184 | ||
185 | // lets see if we have customized by name | |
186 | $ufGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'name'); | |
187 | if ($ufGroupName) { | |
188 | $templateFile = "CRM/Profile/Page/{$ufGroupName}/View.{$suffix}tpl"; | |
189 | if ($template->template_exists($templateFile)) { | |
190 | return $templateFile; | |
191 | } | |
192 | } | |
193 | } | |
194 | return NULL; | |
195 | } | |
196 | ||
197 | function getTemplateFileName() { | |
198 | $fileName = $this->checkTemplateFileExists(); | |
199 | return $fileName ? $fileName : parent::getTemplateFileName(); | |
200 | } | |
201 | ||
202 | function overrideExtraTemplateFileName() { | |
203 | $fileName = $this->checkTemplateFileExists('extra.'); | |
204 | return $fileName ? $fileName : parent::overrideExtraTemplateFileName(); | |
205 | } | |
206 | } | |
207 |