3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * This implements the profile page for all contacts. It uses a selector
38 * object to do the actual dispay. The fields displayd are controlled by
41 class CRM_Profile_Page_Listings
extends CRM_Core_Page
{
44 * All the fields that are listings related
51 * The custom fields for this domain
55 protected $_customFields;
58 * The input params from the request
65 * The group id that we are editing
72 * State whether to display search form or not
79 * Should we display a map
86 * Store profile ids if multiple profile ids are passed using comma separated.
87 * Currently lets implement this functionality only for dialog mode
89 protected $_profileIds = array();
92 * Extracts the parameters from the request and constructs information for
93 * the selector object to do a query
97 public function preProcess() {
99 $this->_search
= TRUE;
101 $search = CRM_Utils_Request
::retrieve('search', 'Boolean', $this, FALSE, 0, 'GET');
102 if (isset($search) && $search == 0) {
103 $this->_search
= FALSE;
106 $this->_gid
= $this->get('gid');
107 $this->_profileIds
= $this->get('profileIds');
109 $gids = explode(',', CRM_Utils_Request
::retrieve('gid', 'String', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET'));
111 if ((count($gids) > 1) && !$this->_profileIds
&& empty($this->_profileIds
)) {
113 foreach ($gids as $pfId) {
114 $this->_profileIds
[] = CRM_Utils_Type
::escape($pfId, 'Positive');
118 // check if we are rendering mixed profiles
119 if (CRM_Core_BAO_UFGroup
::checkForMixProfiles($this->_profileIds
)) {
120 CRM_Core_Error
::fatal(ts('You cannot combine profiles of multiple types.'));
123 $this->_gid
= $this->_profileIds
[0];
124 $this->set('profileIds', $this->_profileIds
);
125 $this->set('gid', $this->_gid
);
129 $this->_gid
= CRM_Utils_Request
::retrieve('gid', 'Positive', $this, FALSE, 0, 'GET');
132 if (empty($this->_profileIds
)) {
136 $gids = $this->_profileIds
;
139 $this->_fields
= CRM_Core_BAO_UFGroup
::getListingFields(CRM_Core_Action
::UPDATE
,
140 CRM_Core_BAO_UFGroup
::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup
::LISTINGS_VISIBILITY
,
141 FALSE, $gids, FALSE, 'Profile',
142 CRM_Core_Permission
::SEARCH
145 $this->_customFields
= CRM_Core_BAO_CustomField
::getFieldsForImport(NULL, FALSE, FALSE, FALSE, TRUE, TRUE);
146 $this->_params
= array();
151 'preferred_communication_method',
160 foreach ($this->_fields
as $name => $field) {
161 if ((substr($name, 0, 6) == 'custom') && !empty($field['is_search_range'])) {
162 $from = CRM_Utils_Request
::retrieve($name . '_from', 'String', $this);
163 $to = CRM_Utils_Request
::retrieve($name . '_to', 'String', $this);
166 $value['from'] = $from;
170 $value['from'] = $from;
176 elseif ((substr($name, 0, 7) == 'custom_') &&
177 (CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomField',
178 substr($name, 7), 'html_type'
181 $value = trim(CRM_Utils_Request
::retrieve($name, 'String',
182 $this, FALSE, NULL, 'REQUEST'
184 if (!empty($value) &&
185 !((substr($value, 0, 1) == '%') &&
186 (substr($value, -1, 1) == '%')
189 $value = '%' . $value . '%';
192 elseif (CRM_Utils_Array
::value('html_type', $field) == 'Multi-Select State/Province'
193 || CRM_Utils_Array
::value('html_type', $field) == 'Multi-Select Country'
195 $value = CRM_Utils_Request
::retrieve($name, 'String', $this, FALSE, NULL, 'REQUEST');
196 if (!is_array($value)) {
197 $value = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, substr($value, 1, -1));
200 elseif ($name == 'contact_sub_type') {
201 $v = CRM_Utils_Request
::retrieve($name, 'String', $this, FALSE, NULL, 'REQUEST');
202 if ($v && !is_array($v)) {
203 $v = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, trim($v, CRM_Core_DAO
::VALUE_SEPARATOR
));
206 foreach ($v as $item) {
212 $value = CRM_Utils_Request
::retrieve($name, 'String',
213 $this, FALSE, NULL, 'REQUEST'
217 if (($name == 'group' ||
$name == 'tag') && !empty($value) && !is_array($value)) {
218 $v = explode(',', $value);
220 foreach ($v as $item) {
225 $customField = CRM_Utils_Array
::value($name, $this->_customFields
);
227 if (!empty($_POST) && empty($_POST[$name])) {
229 // reset checkbox/radio because a form does not send null checkbox values
230 if (in_array($customField['html_type'],
231 array('Multi-Select', 'CheckBox', 'Multi-Select State/Province', 'Multi-Select Country', 'Radio')
233 // only reset on a POST submission if we dont see any value
235 $this->set($name, $value);
238 elseif (in_array($name, $resetArray)) {
240 $this->set($name, $value);
244 if (isset($value) && $value != NULL) {
245 if (!is_array($value)) {
246 $value = trim($value);
248 $operator = CRM_Utils_Request
::retrieve($name . '_operator', 'String', $this);
250 $this->_params
[$name . '_operator'] = $operator;
252 $this->_params
[$name] = $this->_fields
[$name]['value'] = $value;
256 // set the prox params
257 // need to ensure proximity searching is enabled
258 $proximityVars = array(
267 foreach ($proximityVars as $var) {
268 $value = CRM_Utils_Request
::retrieve("prox_{$var}",
270 $this, FALSE, NULL, 'REQUEST'
273 $this->_params
["prox_{$var}"] = $value;
277 // set the params in session
278 $session = CRM_Core_Session
::singleton();
279 $session->set('profileParams', $this->_params
);
283 * Run this page (figure out the action needed and perform it).
287 public function run() {
290 $this->assign('recentlyViewed', FALSE);
291 $this->assign('ufGroupName', 'unknown'); // override later (if possible)
294 $ufgroupDAO = new CRM_Core_DAO_UFGroup();
295 $ufgroupDAO->id
= $this->_gid
;
296 if (!$ufgroupDAO->find(TRUE)) {
297 CRM_Core_Error
::fatal();
302 // set the title of the page
303 if ($ufgroupDAO->title
) {
304 CRM_Utils_System
::setTitle($ufgroupDAO->title
);
306 if ($ufgroupDAO->name
) {
307 $this->assign('ufGroupName', $ufgroupDAO->name
);
311 $this->assign('isReset', TRUE);
313 $formController = new CRM_Core_Controller_Simple('CRM_Profile_Form_Search',
314 ts('Search Profile'),
317 $formController->setEmbedded(TRUE);
318 $formController->set('gid', $this->_gid
);
319 $formController->process();
321 $searchError = FALSE;
322 // check if there is a POST
323 if (!empty($_POST)) {
324 if ($formController->validate() !== TRUE) {
329 // also get the search tpl name
330 $this->assign('searchTPL', $formController->getHookedTemplateFileName());
332 $this->assign('search', $this->_search
);
334 // search if search returned a form error?
335 if ((empty($_GET['reset']) ||
!empty($_GET['force'])) &&
338 $this->assign('isReset', FALSE);
340 $gidString = $this->_gid
;
341 if (empty($this->_profileIds
)) {
345 $gids = $this->_profileIds
;
346 $gidString = implode(',', $this->_profileIds
);
353 $map = $ufgroupDAO->is_map
;
354 $linkToUF = $ufgroupDAO->is_uf_link
;
355 $editLink = $ufgroupDAO->is_edit_link
;
359 $this->assign('mapURL',
360 CRM_Utils_System
::url('civicrm/profile/map',
361 "map=1&gid={$gidString}&reset=1"
365 if (!empty($this->_params
['group'])) {
366 foreach ($this->_params
['group'] as $key => $val) {
368 unset($this->_params
['group'][$key]);
373 // the selector will override this if the user does have
374 // edit permissions as determined by the mask, CRM-4341
375 // do not allow edit for anon users in joomla frontend, CRM-4668
376 $config = CRM_Core_Config
::singleton();
377 if (!CRM_Core_Permission
::check('access CiviCRM') ||
378 $config->userFrameworkFrontend
== 1
383 $selector = new CRM_Profile_Selector_Listings($this->_params
, $this->_customFields
, $gids,
384 $map, $editLink, $linkToUF
387 $controller = new CRM_Core_Selector_Controller($selector,
388 $this->get(CRM_Utils_Pager
::PAGE_ID
),
389 $this->get(CRM_Utils_Sort
::SORT_ID
),
390 CRM_Core_Action
::VIEW
,
392 CRM_Core_Selector_Controller
::TEMPLATE
394 $controller->setEmbedded(TRUE);
398 //CRM-6862 -run form cotroller after
399 //selector, since it erase $_POST
400 $formController->run();
402 return parent
::run();
406 * Get the list of contacts for a profile.
412 public function getProfileContact($gid) {
413 $session = CRM_Core_Session
::singleton();
414 $params = $session->get('profileParams');
417 $ufGroupParam = array('id' => $gid);
418 CRM_Core_BAO_UFGroup
::retrieve($ufGroupParam, $details);
420 // make sure this group can be mapped
421 if (!$details['is_map']) {
422 CRM_Core_Error
::statusBounce(ts('This profile does not have the map feature turned on.'));
425 $groupId = CRM_Utils_Array
::value('limit_listings_group_id', $details);
427 // add group id to params if a uf group belong to a any group
429 if (!empty($params['group'])) {
430 $params['group'][$groupId] = 1;
433 $params['group'] = array($groupId => 1);
437 $fields = CRM_Core_BAO_UFGroup
::getListingFields(
438 CRM_Core_Action
::VIEW
,
439 CRM_Core_BAO_UFGroup
::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup
::LISTINGS_VISIBILITY
,
444 $returnProperties = CRM_Contact_BAO_Contact
::makeHierReturnProperties($fields);
445 $returnProperties['contact_type'] = 1;
446 $returnProperties['sort_name'] = 1;
448 $queryParams = CRM_Contact_BAO_Query
::convertFormValues($params, 1);
449 $query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, $fields);
451 $additionalWhereClause = 'contact_a.is_deleted = 0';
453 $ids = $query->searchQuery(0, 0, NULL,
456 $additionalWhereClause
459 $contactIds = explode(',', $ids);
465 * @param string $suffix
467 * @return null|string
469 public function checkTemplateFileExists($suffix = '') {
471 $templateFile = "CRM/Profile/Page/{$this->_gid}/Listings.{$suffix}tpl";
472 $template = CRM_Core_Page
::getTemplate();
473 if ($template->template_exists($templateFile)) {
474 return $templateFile;
477 // lets see if we have customized by name
478 $ufGroupName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid
, 'name');
480 $templateFile = "CRM/Profile/Page/{$ufGroupName}/Listings.{$suffix}tpl";
481 if ($template->template_exists($templateFile)) {
482 return $templateFile;
490 * Use the form name to create the tpl file name.
497 public function getTemplateFileName() {
498 $fileName = $this->checkTemplateFileExists();
499 return $fileName ?
$fileName : parent
::getTemplateFileName();
503 * Default extra tpl file basically just replaces .tpl with .extra.tpl
504 * i.e. we dont override
511 public function overrideExtraTemplateFileName() {
512 $fileName = $this->checkTemplateFileExists('extra.');
513 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();