4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2014
38 * This implements the profile page for all contacts. It uses a selector
39 * object to do the actual dispay. The fields displayd are controlled by
42 class CRM_Profile_Page_Listings
extends CRM_Core_Page
{
45 * all the fields that are listings related
53 * the custom fields for this domain
58 protected $_customFields;
61 * The input params from the request
69 * The group id that we are editing
76 * state whether to display search form or not
83 * Should we display a map
90 * Store profile ids if multiple profile ids are passed using comma separated.
91 * Currently lets implement this functionality only for dialog mode
93 protected $_profileIds = array();
96 * extracts the parameters from the request and constructs information for
97 * the selector object to do a query
103 function preProcess() {
105 $this->_search
= TRUE;
107 $search = CRM_Utils_Request
::retrieve('search', 'Boolean', $this, FALSE, 0, 'GET');
108 if (isset($search) && $search == 0) {
109 $this->_search
= FALSE;
112 $this->_gid
= $this->get('gid');
113 $this->_profileIds
= $this->get('profileIds');
115 $gids = explode(',', CRM_Utils_Request
::retrieve('gid', 'String', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET'));
117 if ((count($gids) > 1) && !$this->_profileIds
&& empty($this->_profileIds
)) {
119 foreach ($gids as $pfId) {
120 $this->_profileIds
[] = CRM_Utils_Type
::escape($pfId, 'Positive');
124 // check if we are rendering mixed profiles
125 if (CRM_Core_BAO_UFGroup
::checkForMixProfiles($this->_profileIds
)) {
126 CRM_Core_Error
::fatal(ts('You cannot combine profiles of multiple types.'));
129 $this->_gid
= $this->_profileIds
[0];
130 $this->set('profileIds', $this->_profileIds
);
131 $this->set('gid', $this->_gid
);
135 $this->_gid
= CRM_Utils_Request
::retrieve('gid', 'Positive', $this, FALSE, 0, 'GET');
138 if (empty($this->_profileIds
)) {
142 $gids = $this->_profileIds
;
145 $this->_fields
= CRM_Core_BAO_UFGroup
::getListingFields(CRM_Core_Action
::UPDATE
,
146 CRM_Core_BAO_UFGroup
::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup
::LISTINGS_VISIBILITY
,
147 FALSE, $gids, FALSE, 'Profile',
148 CRM_Core_Permission
::SEARCH
151 $this->_customFields
= CRM_Core_BAO_CustomField
::getFieldsForImport(NULL, FALSE, FALSE, FALSE, TRUE, TRUE);
152 $this->_params
= array();
155 'group', 'tag', 'preferred_communication_method', 'do_not_phone',
156 'do_not_email', 'do_not_mail', 'do_not_sms', 'do_not_trade', 'gender',
159 foreach ($this->_fields
as $name => $field) {
160 if ((substr($name, 0, 6) == 'custom') && !empty($field['is_search_range'])) {
161 $from = CRM_Utils_Request
::retrieve($name . '_from', 'String', $this);
162 $to = CRM_Utils_Request
::retrieve($name . '_to', 'String', $this);
165 $value['from'] = $from;
169 $value['from'] = $from;
175 elseif ((substr($name, 0, 7) == 'custom_') &&
176 (CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomField',
177 substr($name, 7), 'html_type'
180 $value = trim(CRM_Utils_Request
::retrieve($name, 'String',
181 $this, FALSE, NULL, 'REQUEST'
183 if (!empty($value) &&
184 !((substr($value, 0, 1) == '%') &&
185 (substr($value, -1, 1) == '%')
188 $value = '%' . $value . '%';
191 elseif (CRM_Utils_Array
::value('html_type', $field) == 'Multi-Select State/Province'
192 || CRM_Utils_Array
::value('html_type', $field) == 'Multi-Select Country'
194 $value = CRM_Utils_Request
::retrieve($name, 'String', $this, FALSE, NULL, 'REQUEST');
195 if (!is_array($value)) {
196 $value = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, substr($value, 1, -1));
199 elseif ($name == 'contact_sub_type') {
200 $v = CRM_Utils_Request
::retrieve($name, 'String', $this, FALSE, NULL, 'REQUEST');
201 if ($v && !is_array($v)) {
202 $v = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, trim($v, CRM_Core_DAO
::VALUE_SEPARATOR
));
205 foreach ($v as $item) {
211 $value = CRM_Utils_Request
::retrieve($name, 'String',
212 $this, FALSE, NULL, 'REQUEST'
216 if (($name == 'group' ||
$name == 'tag') && !empty($value) && !is_array($value)) {
217 $v = explode(',', $value);
219 foreach ($v as $item) {
224 $customField = CRM_Utils_Array
::value($name, $this->_customFields
);
226 if (!empty($_POST) && empty($_POST[$name])) {
228 // reset checkbox/radio because a form does not send null checkbox values
229 if (in_array($customField['html_type'],
230 array('Multi-Select', 'CheckBox', 'Multi-Select State/Province', 'Multi-Select Country', 'Radio')
232 // only reset on a POST submission if we dont see any value
234 $this->set($name, $value);
237 elseif (in_array($name, $resetArray)) {
239 $this->set($name, $value);
243 if (isset($value) && $value != NULL) {
244 if (!is_array($value)) {
245 $value = trim($value);
247 $operator = CRM_Utils_Request
::retrieve($name . '_operator', 'String', $this);
249 $this->_params
[$name . '_operator'] = $operator;
251 $this->_params
[$name] = $this->_fields
[$name]['value'] = $value;
255 // set the prox params
256 // need to ensure proximity searching is enabled
257 $proximityVars = array(
258 'street_address', 'city', 'postal_code', 'state_province_id',
259 'country_id', 'distance', 'distance_unit',
261 foreach ($proximityVars as $var) {
262 $value = CRM_Utils_Request
::retrieve("prox_{$var}",
264 $this, FALSE, NULL, 'REQUEST'
267 $this->_params
["prox_{$var}"] = $value;
272 // set the params in session
273 $session = CRM_Core_Session
::singleton();
274 $session->set('profileParams', $this->_params
);
278 * run this page (figure out the action needed and perform it).
285 $this->assign('recentlyViewed', FALSE);
286 $this->assign('ufGroupName', 'unknown'); // override later (if possible)
289 $ufgroupDAO = new CRM_Core_DAO_UFGroup();
290 $ufgroupDAO->id
= $this->_gid
;
291 if (!$ufgroupDAO->find(TRUE)) {
292 CRM_Core_Error
::fatal();
297 // set the title of the page
298 if ($ufgroupDAO->title
) {
299 CRM_Utils_System
::setTitle($ufgroupDAO->title
);
301 if ($ufgroupDAO->name
) {
302 $this->assign('ufGroupName', $ufgroupDAO->name
);
306 $this->assign('isReset', TRUE);
308 $formController = new CRM_Core_Controller_Simple('CRM_Profile_Form_Search',
309 ts('Search Profile'),
312 $formController->setEmbedded(TRUE);
313 $formController->set('gid', $this->_gid
);
314 $formController->process();
316 $searchError = FALSE;
317 // check if there is a POST
318 if (!empty($_POST)) {
319 if ($formController->validate() !== TRUE) {
324 // also get the search tpl name
325 $this->assign('searchTPL', $formController->getHookedTemplateFileName());
327 $this->assign('search', $this->_search
);
329 // search if search returned a form error?
330 if ((empty($_GET['reset']) ||
!empty($_GET['force'])) &&
333 $this->assign('isReset', FALSE);
335 $gidString = $this->_gid
;
336 if (empty($this->_profileIds
)) {
340 $gids = $this->_profileIds
;
341 $gidString = implode(',', $this->_profileIds
);
348 $map = $ufgroupDAO->is_map
;
349 $linkToUF = $ufgroupDAO->is_uf_link
;
350 $editLink = $ufgroupDAO->is_edit_link
;
354 $this->assign('mapURL',
355 CRM_Utils_System
::url('civicrm/profile/map',
356 "map=1&gid={$gidString}&reset=1"
360 if (!empty($this->_params
['group'])) {
361 foreach ($this->_params
['group'] as $key => $val) {
363 unset($this->_params
['group'][$key]);
368 // the selector will override this if the user does have
369 // edit permissions as determined by the mask, CRM-4341
370 // do not allow edit for anon users in joomla frontend, CRM-4668
371 $config = CRM_Core_Config
::singleton();
372 if (!CRM_Core_Permission
::check('access CiviCRM') ||
373 $config->userFrameworkFrontend
== 1
378 $selector = new CRM_Profile_Selector_Listings($this->_params
, $this->_customFields
, $gids,
379 $map, $editLink, $linkToUF
382 $controller = new CRM_Core_Selector_Controller($selector,
383 $this->get(CRM_Utils_Pager
::PAGE_ID
),
384 $this->get(CRM_Utils_Sort
::SORT_ID
),
385 CRM_Core_Action
::VIEW
,
387 CRM_Core_Selector_Controller
::TEMPLATE
389 $controller->setEmbedded(TRUE);
393 //CRM-6862 -run form cotroller after
394 //selector, since it erase $_POST
395 $formController->run();
397 return parent
::run();
401 * get the list of contacts for a profile
408 function getProfileContact($gid) {
409 $session = CRM_Core_Session
::singleton();
410 $params = $session->get('profileParams');
413 $ufGroupParam = array('id' => $gid);
414 CRM_Core_BAO_UFGroup
::retrieve($ufGroupParam, $details);
416 // make sure this group can be mapped
417 if (!$details['is_map']) {
418 CRM_Core_Error
::statusBounce(ts('This profile does not have the map feature turned on.'));
421 $groupId = CRM_Utils_Array
::value('limit_listings_group_id', $details);
423 // add group id to params if a uf group belong to a any group
425 if (!empty($params['group'])) {
426 $params['group'][$groupId] = 1;
429 $params['group'] = array($groupId => 1);
433 $fields = CRM_Core_BAO_UFGroup
::getListingFields(
434 CRM_Core_Action
::VIEW
,
435 CRM_Core_BAO_UFGroup
::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup
::LISTINGS_VISIBILITY
,
440 $returnProperties = CRM_Contact_BAO_Contact
::makeHierReturnProperties($fields);
441 $returnProperties['contact_type'] = 1;
442 $returnProperties['sort_name'] = 1;
444 $queryParams = CRM_Contact_BAO_Query
::convertFormValues($params, 1);
445 $query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, $fields);
447 $additionalWhereClause = 'contact_a.is_deleted = 0';
449 $ids = $query->searchQuery(0, 0, NULL,
452 $additionalWhereClause
455 $contactIds = explode(',', $ids);
461 * @param string $suffix
463 * @return null|string
465 function checkTemplateFileExists($suffix = '') {
467 $templateFile = "CRM/Profile/Page/{$this->_gid}/Listings.{$suffix}tpl";
468 $template = CRM_Core_Page
::getTemplate();
469 if ($template->template_exists($templateFile)) {
470 return $templateFile;
473 // lets see if we have customized by name
474 $ufGroupName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid
, 'name');
476 $templateFile = "CRM/Profile/Page/{$ufGroupName}/Listings.{$suffix}tpl";
477 if ($template->template_exists($templateFile)) {
478 return $templateFile;
486 * Use the form name to create the tpl file name
494 function getTemplateFileName() {
495 $fileName = $this->checkTemplateFileExists();
496 return $fileName ?
$fileName : parent
::getTemplateFileName();
500 * Default extra tpl file basically just replaces .tpl with .extra.tpl
501 * i.e. we dont override
509 function overrideExtraTemplateFileName() {
510 $fileName = $this->checkTemplateFileExists('extra.');
511 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();