First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
1489
sites/all/modules/civicrm/CRM/Contact/Form/Contact.php
Normal file
1489
sites/all/modules/civicrm/CRM/Contact/Form/Contact.php
Normal file
File diff suppressed because it is too large
Load diff
322
sites/all/modules/civicrm/CRM/Contact/Form/CustomData.php
Normal file
322
sites/all/modules/civicrm/CRM/Contact/Form/CustomData.php
Normal file
|
@ -0,0 +1,322 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for custom data.
|
||||
*
|
||||
* It delegates the work to lower level subclasses and integrates the changes
|
||||
* back in. It also uses a lot of functionality with the CRM API's, so any change
|
||||
* made here could potentially affect the API etc. Be careful, be aware, use unit tests.
|
||||
*/
|
||||
class CRM_Contact_Form_CustomData extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The table id, used when editing/creating custom data
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_tableId;
|
||||
|
||||
/**
|
||||
* Entity type of the table id
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_entityType;
|
||||
|
||||
/**
|
||||
* Entity sub type of the table id
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_entitySubType;
|
||||
|
||||
/**
|
||||
* The group tree data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
//protected $_groupTree;
|
||||
|
||||
/**
|
||||
* Which blocks should we show and hide.
|
||||
*
|
||||
* @var CRM_Core_ShowHideBlocks
|
||||
*/
|
||||
protected $_showHide;
|
||||
|
||||
/**
|
||||
* Array group titles.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_groupTitle;
|
||||
|
||||
/**
|
||||
* Array group display status.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_groupCollapseDisplay;
|
||||
|
||||
/**
|
||||
* Custom group id
|
||||
*
|
||||
* @int
|
||||
*/
|
||||
public $_groupID;
|
||||
|
||||
public $_multiRecordDisplay;
|
||||
|
||||
public $_copyValueId;
|
||||
|
||||
/**
|
||||
* Pre processing work done here.
|
||||
*
|
||||
* Gets session variables for table name, id of entity in table, type of entity and stores them.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_cdType = CRM_Utils_Array::value('type', $_GET);
|
||||
$this->assign('cdType', FALSE);
|
||||
$this->_multiRecordDisplay = CRM_Utils_Request::retrieve('multiRecordDisplay', 'String', $this);
|
||||
if ($this->_cdType || $this->_multiRecordDisplay == 'single') {
|
||||
if ($this->_cdType) {
|
||||
$this->assign('cdType', TRUE);
|
||||
}
|
||||
// NOTE : group id is not stored in session from within CRM_Custom_Form_CustomData::preProcess func
|
||||
// this is due to some condition inside it which restricts it from saving in session
|
||||
// so doing this for multi record edit action
|
||||
$entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $this);
|
||||
if (!empty($entityId)) {
|
||||
$subType = CRM_Contact_BAO_Contact::getContactSubType($entityId, ',');
|
||||
}
|
||||
CRM_Custom_Form_CustomData::preProcess($this, NULL, $subType, NULL, NULL, $entityId);
|
||||
if ($this->_multiRecordDisplay) {
|
||||
$this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this);
|
||||
$this->_tableID = $this->_entityId;
|
||||
$this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_tableID);
|
||||
$mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
|
||||
$hasReachedMax = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($this->_groupID, $this->_tableID);
|
||||
if ($hasReachedMax && $mode == 'add') {
|
||||
CRM_Core_Error::statusBounce(ts('The maximum record limit is reached'));
|
||||
}
|
||||
$this->_copyValueId = CRM_Utils_Request::retrieve('copyValueId', 'Positive', $this);
|
||||
|
||||
$groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupID);
|
||||
$mode = CRM_Utils_Request::retrieve('mode', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
|
||||
$mode = ucfirst($mode);
|
||||
CRM_Utils_System::setTitle(ts('%1 %2 Record', array(1 => $mode, 2 => $groupTitle)));
|
||||
|
||||
if (!empty($_POST['hidden_custom'])) {
|
||||
$this->assign('postedInfo', TRUE);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
$this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE);
|
||||
$this->_tableID = CRM_Utils_Request::retrieve('tableId', 'Positive', $this, TRUE);
|
||||
|
||||
$this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_tableID);
|
||||
$this->_contactSubType = CRM_Contact_BAO_Contact::getContactSubType($this->_tableID, ',');
|
||||
$this->assign('contact_type', $this->_contactType);
|
||||
$this->assign('contact_subtype', $this->_contactSubType);
|
||||
list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_tableID);
|
||||
CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName);
|
||||
|
||||
// when custom data is included in this page
|
||||
if (!empty($_POST['hidden_custom'])) {
|
||||
for ($i = 1; $i <= $_POST['hidden_custom_group_count'][$this->_groupID]; $i++) {
|
||||
CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_contactSubType, $i, $this->_contactType, $this->_tableID);
|
||||
CRM_Custom_Form_CustomData::buildQuickForm($this);
|
||||
CRM_Custom_Form_CustomData::setDefaultValues($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
if ($this->_cdType || $this->_multiRecordDisplay == 'single') {
|
||||
// buttons display for multi-valued fields to perform independednt actions
|
||||
if ($this->_multiRecordDisplay) {
|
||||
$isMultiple = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',
|
||||
$this->_groupID,
|
||||
'is_multiple'
|
||||
);
|
||||
if ($isMultiple) {
|
||||
$this->assign('multiRecordDisplay', $this->_multiRecordDisplay);
|
||||
$saveButtonName = $this->_copyValueId ? ts('Save a Copy') : ts('Save');
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => $saveButtonName,
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save and New'),
|
||||
'subName' => 'new',
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
return CRM_Custom_Form_CustomData::buildQuickForm($this);
|
||||
}
|
||||
|
||||
//need to assign custom data type and subtype to the template
|
||||
$this->assign('entityID', $this->_tableID);
|
||||
$this->assign('groupID', $this->_groupID);
|
||||
|
||||
// make this form an upload since we dont know if the custom data injected dynamically
|
||||
// is of type file etc
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default form values.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* the default array reference
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
if ($this->_cdType || $this->_multiRecordDisplay == 'single') {
|
||||
if ($this->_copyValueId) {
|
||||
// cached tree is fetched
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_type,
|
||||
NULL,
|
||||
$this->_entityId,
|
||||
$this->_groupID,
|
||||
array(),
|
||||
NULL,
|
||||
TRUE,
|
||||
NULL,
|
||||
FALSE,
|
||||
TRUE,
|
||||
$this->_copyValueId
|
||||
);
|
||||
$valueIdDefaults = array();
|
||||
$groupTreeValueId = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $this->_copyValueId, $this);
|
||||
CRM_Core_BAO_CustomGroup::setDefaults($groupTreeValueId, $valueIdDefaults, FALSE, FALSE, $this->get('action'));
|
||||
$tableId = $groupTreeValueId[$this->_groupID]['table_id'];
|
||||
foreach ($valueIdDefaults as $valueIdElementName => $value) {
|
||||
// build defaults for COPY action for new record saving
|
||||
$valueIdElementNamePieces = explode('_', $valueIdElementName);
|
||||
$valueIdElementNamePieces[2] = "-{$this->_groupCount}";
|
||||
$elementName = implode('_', $valueIdElementNamePieces);
|
||||
$customDefaultValue[$elementName] = $value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$customDefaultValue = CRM_Custom_Form_CustomData::setDefaultValues($this);
|
||||
}
|
||||
return $customDefaultValue;
|
||||
}
|
||||
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_contactType,
|
||||
NULL,
|
||||
$this->_tableID,
|
||||
$this->_groupID,
|
||||
$this->_contactSubType
|
||||
);
|
||||
|
||||
if (empty($_POST['hidden_custom_group_count'])) {
|
||||
// custom data building in edit mode (required to handle multi-value)
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_contactType, NULL, $this->_tableID,
|
||||
$this->_groupID, $this->_contactSubType
|
||||
);
|
||||
$customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, TRUE, $this->_groupID, NULL, NULL, $this->_tableID);
|
||||
}
|
||||
else {
|
||||
$customValueCount = $_POST['hidden_custom_group_count'][$this->_groupID];
|
||||
}
|
||||
|
||||
$this->assign('customValueCount', $customValueCount);
|
||||
|
||||
$defaults = array();
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the user submitted custom data values.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// Get the form values and groupTree
|
||||
//CRM-18183
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
CRM_Core_BAO_CustomValueTable::postProcess($params,
|
||||
'civicrm_contact',
|
||||
$this->_tableID,
|
||||
$this->_entityType
|
||||
);
|
||||
$table = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupID, 'table_name');
|
||||
$cgcount = CRM_Core_BAO_CustomGroup::customGroupDataExistsForEntity($this->_tableID, $table, TRUE);
|
||||
$cgcount += 1;
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
if ($buttonName == $this->getButtonName('upload', 'new')) {
|
||||
CRM_Core_Session::singleton()
|
||||
->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/cd/edit', "reset=1&type={$this->_contactType}&groupID={$this->_groupID}&entityID={$this->_tableID}&cgcount={$cgcount}&multiRecordDisplay=single&mode=add"));
|
||||
}
|
||||
|
||||
// Add entry in the log table
|
||||
CRM_Core_BAO_Log::register($this->_tableID,
|
||||
'civicrm_contact',
|
||||
$this->_tableID
|
||||
);
|
||||
|
||||
if (CRM_Core_Resources::isAjaxMode()) {
|
||||
$this->ajaxResponse += CRM_Contact_Form_Inline::renderFooter($this->_tableID);
|
||||
}
|
||||
|
||||
CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
|
||||
}
|
||||
|
||||
}
|
106
sites/all/modules/civicrm/CRM/Contact/Form/DedupeFind.php
Normal file
106
sites/all/modules/civicrm/CRM/Contact/Form/DedupeFind.php
Normal file
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for DedupeRules.
|
||||
*/
|
||||
class CRM_Contact_Form_DedupeFind extends CRM_Admin_Form {
|
||||
|
||||
/**
|
||||
* Pre processing.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, FALSE, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
$groupList = array('' => ts('- All Contacts -')) + CRM_Core_PseudoConstant::nestedGroup();
|
||||
|
||||
$this->add('select', 'group_id', ts('Select Group'), $groupList, FALSE, array('class' => 'crm-select2 huge'));
|
||||
if (Civi::settings()->get('dedupe_default_limit')) {
|
||||
$this->add('text', 'limit', ts('No of contacts to find matches for '));
|
||||
}
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Continue'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
//hack to support cancel button functionality
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'class' => 'cancel',
|
||||
'icon' => 'fa-times',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default values for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$this->_defaults['limit'] = Civi::settings()->get('dedupe_default_limit');
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$values = $this->exportValues();
|
||||
if (!empty($_POST['_qf_DedupeFind_submit'])) {
|
||||
//used for cancel button
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/deduperules', 'reset=1'));
|
||||
return;
|
||||
}
|
||||
$url = CRM_Utils_System::url('civicrm/contact/dedupefind', "reset=1&action=update&rgid={$this->rgid}");
|
||||
if ($values['group_id']) {
|
||||
$url .= "&gid={$values['group_id']}";
|
||||
}
|
||||
|
||||
if (!empty($values['limit'])) {
|
||||
$url .= '&limit=' . $values['limit'];
|
||||
}
|
||||
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
|
||||
}
|
323
sites/all/modules/civicrm/CRM/Contact/Form/DedupeRules.php
Normal file
323
sites/all/modules/civicrm/CRM/Contact/Form/DedupeRules.php
Normal file
|
@ -0,0 +1,323 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for DedupeRules.
|
||||
*/
|
||||
class CRM_Contact_Form_DedupeRules extends CRM_Admin_Form {
|
||||
const RULES_COUNT = 5;
|
||||
protected $_contactType;
|
||||
protected $_fields = array();
|
||||
protected $_rgid;
|
||||
|
||||
/**
|
||||
* Explicitly declare the entity api name.
|
||||
*/
|
||||
public function getDefaultEntity() {
|
||||
return 'RuleGroup';
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre processing.
|
||||
*/
|
||||
public function preProcess() {
|
||||
// Ensure user has permission to be here
|
||||
if (!CRM_Core_Permission::check('administer dedupe rules')) {
|
||||
CRM_Utils_System::permissionDenied();
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
$this->_options = CRM_Core_SelectValues::getDedupeRuleTypes();
|
||||
$this->_rgid = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
|
||||
$contactTypes = civicrm_api3('Contact', 'getOptions', array('field' => "contact_type"));
|
||||
$contactType = CRM_Utils_Request::retrieve('contact_type', 'String', $this, FALSE, 0);
|
||||
if (CRM_Utils_Array::value($contactType, $contactTypes['values'])) {
|
||||
$this->_contactType = CRM_Utils_Array::value($contactType, $contactTypes['values']);
|
||||
}
|
||||
elseif (!empty($contactType)) {
|
||||
throw new CRM_Core_Exception('Contact Type is Not valid');
|
||||
}
|
||||
if ($this->_rgid) {
|
||||
$rgDao = new CRM_Dedupe_DAO_RuleGroup();
|
||||
$rgDao->id = $this->_rgid;
|
||||
$rgDao->find(TRUE);
|
||||
|
||||
$this->_defaults['threshold'] = $rgDao->threshold;
|
||||
$this->_contactType = $rgDao->contact_type;
|
||||
$this->_defaults['used'] = $rgDao->used;
|
||||
$this->_defaults['title'] = $rgDao->title;
|
||||
$this->_defaults['name'] = $rgDao->name;
|
||||
$this->_defaults['is_reserved'] = $rgDao->is_reserved;
|
||||
$this->assign('isReserved', $rgDao->is_reserved);
|
||||
$this->assign('ruleName', $rgDao->name);
|
||||
$ruleDao = new CRM_Dedupe_DAO_Rule();
|
||||
$ruleDao->dedupe_rule_group_id = $this->_rgid;
|
||||
$ruleDao->find();
|
||||
$count = 0;
|
||||
while ($ruleDao->fetch()) {
|
||||
$this->_defaults["where_$count"] = "{$ruleDao->rule_table}.{$ruleDao->rule_field}";
|
||||
$this->_defaults["length_$count"] = $ruleDao->rule_length;
|
||||
$this->_defaults["weight_$count"] = $ruleDao->rule_weight;
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
$supported = CRM_Dedupe_BAO_RuleGroup::supportedFields($this->_contactType);
|
||||
if (is_array($supported)) {
|
||||
foreach ($supported as $table => $fields) {
|
||||
foreach ($fields as $field => $title) {
|
||||
$this->_fields["$table.$field"] = $title;
|
||||
}
|
||||
}
|
||||
}
|
||||
asort($this->_fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addField('title', array('label' => ts('Rule Name')), TRUE);
|
||||
$this->addRule('title', ts('A duplicate matching rule with this name already exists. Please select another name.'),
|
||||
'objectExists', array('CRM_Dedupe_DAO_RuleGroup', $this->_rgid, 'title')
|
||||
);
|
||||
|
||||
$this->addField('used', array('label' => ts('Usage')), TRUE);
|
||||
$disabled = array();
|
||||
$reserved = $this->addField('is_reserved', array('label' => ts('Reserved?')));
|
||||
if (!empty($this->_defaults['is_reserved'])) {
|
||||
$reserved->freeze();
|
||||
}
|
||||
|
||||
$attributes = array('class' => 'two');
|
||||
if (!empty($disabled)) {
|
||||
$attributes = array_merge($attributes, $disabled);
|
||||
}
|
||||
|
||||
for ($count = 0; $count < self::RULES_COUNT; $count++) {
|
||||
$this->add('select', "where_$count", ts('Field'),
|
||||
array(
|
||||
NULL => ts('- none -'),
|
||||
) + $this->_fields, FALSE, $disabled
|
||||
);
|
||||
$this->addField("length_$count", array('entity' => 'Rule', 'name' => 'rule_length') + $attributes);
|
||||
$this->addField("weight_$count", array('entity' => 'Rule', 'name' => 'rule_weight') + $attributes);
|
||||
}
|
||||
|
||||
$this->addField('threshold', array('label' => ts("Weight Threshold to Consider Contacts 'Matching':")) + $attributes);
|
||||
|
||||
$this->assign('contact_type', $this->_contactType);
|
||||
|
||||
$this->addFormRule(array('CRM_Contact_Form_DedupeRules', 'formRule'), $this);
|
||||
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @param $files
|
||||
* @param $self
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
$fieldSelected = FALSE;
|
||||
for ($count = 0; $count < self::RULES_COUNT; $count++) {
|
||||
if (!empty($fields["where_$count"]) || (isset($self->_defaults['is_reserved']) && !empty($self->_defaults["where_$count"]))) {
|
||||
$fieldSelected = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (empty($fields['threshold'])) {
|
||||
// CRM-20607 - Don't validate the threshold of hard-coded rules
|
||||
if (!(CRM_Utils_Array::value('is_reserved', $fields) &&
|
||||
CRM_Utils_File::isIncludable("CRM/Dedupe/BAO/QueryBuilder/{$self->_defaultValues['name']}.php"))) {
|
||||
$errors['threshold'] = ts('Threshold weight cannot be empty or zero.');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$fieldSelected) {
|
||||
$errors['_qf_default'] = ts('Please select at least one field.');
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. MobileProvider that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$values = $this->exportValues();
|
||||
|
||||
//FIXME: Handle logic to replace is_default column by usage
|
||||
// reset used column to General (since there can only
|
||||
// be one 'Supervised' or 'Unsupervised' rule)
|
||||
if ($values['used'] != 'General') {
|
||||
$query = "
|
||||
UPDATE civicrm_dedupe_rule_group
|
||||
SET used = 'General'
|
||||
WHERE contact_type = %1
|
||||
AND used = %2";
|
||||
$queryParams = array(
|
||||
1 => array($this->_contactType, 'String'),
|
||||
2 => array($values['used'], 'String'),
|
||||
);
|
||||
|
||||
CRM_Core_DAO::executeQuery($query, $queryParams);
|
||||
}
|
||||
|
||||
$rgDao = new CRM_Dedupe_DAO_RuleGroup();
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$rgDao->id = $this->_rgid;
|
||||
}
|
||||
|
||||
$rgDao->title = $values['title'];
|
||||
$rgDao->is_reserved = CRM_Utils_Array::value('is_reserved', $values, FALSE);
|
||||
$rgDao->used = $values['used'];
|
||||
$rgDao->contact_type = $this->_contactType;
|
||||
$rgDao->threshold = $values['threshold'];
|
||||
$rgDao->save();
|
||||
|
||||
// make sure name is set only during insert
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
// generate name based on title
|
||||
$rgDao->name = CRM_Utils_String::titleToVar($values['title']) . "_{$rgDao->id}";
|
||||
$rgDao->save();
|
||||
}
|
||||
|
||||
// lets skip updating of fields for reserved dedupe group
|
||||
if (CRM_Utils_Array::value('is_reserved', $this->_defaults)) {
|
||||
CRM_Core_Session::setStatus(ts("The rule '%1' has been saved.", array(1 => $rgDao->title)), ts('Saved'), 'success');
|
||||
return;
|
||||
}
|
||||
|
||||
$ruleDao = new CRM_Dedupe_DAO_Rule();
|
||||
$ruleDao->dedupe_rule_group_id = $rgDao->id;
|
||||
$ruleDao->delete();
|
||||
$ruleDao->free();
|
||||
|
||||
$substrLenghts = array();
|
||||
|
||||
$tables = array();
|
||||
$daoObj = new CRM_Core_DAO();
|
||||
$database = $daoObj->database();
|
||||
for ($count = 0; $count < self::RULES_COUNT; $count++) {
|
||||
if (empty($values["where_$count"])) {
|
||||
continue;
|
||||
}
|
||||
list($table, $field) = explode('.', CRM_Utils_Array::value("where_$count", $values));
|
||||
$length = !empty($values["length_$count"]) ? CRM_Utils_Array::value("length_$count", $values) : NULL;
|
||||
$weight = $values["weight_$count"];
|
||||
if ($table and $field) {
|
||||
$ruleDao = new CRM_Dedupe_DAO_Rule();
|
||||
$ruleDao->dedupe_rule_group_id = $rgDao->id;
|
||||
$ruleDao->rule_table = $table;
|
||||
$ruleDao->rule_field = $field;
|
||||
$ruleDao->rule_length = $length;
|
||||
$ruleDao->rule_weight = $weight;
|
||||
$ruleDao->save();
|
||||
$ruleDao->free();
|
||||
|
||||
if (!array_key_exists($table, $tables)) {
|
||||
$tables[$table] = array();
|
||||
}
|
||||
$tables[$table][] = $field;
|
||||
}
|
||||
|
||||
// CRM-6245: we must pass table/field/length triples to the createIndexes() call below
|
||||
if ($length) {
|
||||
if (!isset($substrLenghts[$table])) {
|
||||
$substrLenghts[$table] = array();
|
||||
}
|
||||
|
||||
//CRM-13417 to avoid fatal error "Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys, 1089"
|
||||
$schemaQuery = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = '{$database}' AND
|
||||
TABLE_NAME = '{$table}' AND COLUMN_NAME = '{$field}';";
|
||||
$dao = CRM_Core_DAO::executeQuery($schemaQuery);
|
||||
|
||||
if ($dao->fetch()) {
|
||||
// set the length to null for all the fields where prefix length is not supported. eg. int,tinyint,date,enum etc dataTypes.
|
||||
if ($dao->COLUMN_NAME == $field && !in_array($dao->DATA_TYPE, array(
|
||||
'char',
|
||||
'varchar',
|
||||
'binary',
|
||||
'varbinary',
|
||||
'text',
|
||||
'blob',
|
||||
))
|
||||
) {
|
||||
$length = NULL;
|
||||
}
|
||||
elseif ($dao->COLUMN_NAME == $field && !empty($dao->CHARACTER_MAXIMUM_LENGTH) && ($length > $dao->CHARACTER_MAXIMUM_LENGTH)) {
|
||||
//set the length to CHARACTER_MAXIMUM_LENGTH in case the length provided by the user is greater than the limit
|
||||
$length = $dao->CHARACTER_MAXIMUM_LENGTH;
|
||||
}
|
||||
}
|
||||
$substrLenghts[$table][$field] = $length;
|
||||
}
|
||||
}
|
||||
|
||||
// also create an index for this dedupe rule
|
||||
// CRM-3837
|
||||
CRM_Utils_Hook::dupeQuery($ruleDao, 'dedupeIndexes', $tables);
|
||||
CRM_Core_BAO_SchemaHandler::createIndexes($tables, 'dedupe_index', $substrLenghts);
|
||||
|
||||
//need to clear cache of deduped contacts
|
||||
//based on the previous rule
|
||||
$cacheKey = "merge {$this->_contactType}_{$this->_rgid}_%";
|
||||
|
||||
CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKey);
|
||||
|
||||
CRM_Core_Session::setStatus(ts("The rule '%1' has been saved.", array(1 => $rgDao->title)), ts('Saved'), 'success');
|
||||
}
|
||||
|
||||
}
|
313
sites/all/modules/civicrm/CRM/Contact/Form/Domain.php
Normal file
313
sites/all/modules/civicrm/CRM/Contact/Form/Domain.php
Normal file
|
@ -0,0 +1,313 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is to build the form for adding Group.
|
||||
*/
|
||||
class CRM_Contact_Form_Domain extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The group id, used when editing a group
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* The contact_id of domain.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_contactId;
|
||||
|
||||
/**
|
||||
* Default from email address option value id.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_fromEmailId = NULL;
|
||||
|
||||
/**
|
||||
* Default location type fields.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_locationDefaults = array();
|
||||
|
||||
/**
|
||||
* How many locationBlocks should we display?
|
||||
*
|
||||
* @var int
|
||||
* @const
|
||||
*/
|
||||
const LOCATION_BLOCKS = 1;
|
||||
|
||||
/**
|
||||
* Explicitly declare the entity api name.
|
||||
*/
|
||||
public function getDefaultEntity() {
|
||||
return 'Domain';
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly declare the form context.
|
||||
*/
|
||||
public function getDefaultContext() {
|
||||
return 'create';
|
||||
}
|
||||
|
||||
public function preProcess() {
|
||||
CRM_Utils_System::setTitle(ts('Organization Address and Contact Info'));
|
||||
$breadCrumbPath = CRM_Utils_System::url('civicrm/admin', 'reset=1');
|
||||
CRM_Utils_System::appendBreadCrumb(ts('Administer CiviCRM'), $breadCrumbPath);
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
|
||||
|
||||
$this->_id = CRM_Core_Config::domainID();
|
||||
$this->_action = CRM_Utils_Request::retrieve('action', 'String',
|
||||
$this, FALSE, 'view'
|
||||
);
|
||||
//location blocks.
|
||||
$location = new CRM_Contact_Form_Location();
|
||||
$location->preProcess($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This virtual function is used to set the default values of.
|
||||
* various form elements
|
||||
*
|
||||
* @return array
|
||||
* reference to the array of default values
|
||||
*
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
$params = array();
|
||||
|
||||
if (isset($this->_id)) {
|
||||
$params['id'] = $this->_id;
|
||||
CRM_Core_BAO_Domain::retrieve($params, $domainDefaults);
|
||||
$this->_contactId = $domainDefaults['contact_id'];
|
||||
//get the default domain from email address. fix CRM-3552
|
||||
$optionValues = array();
|
||||
$grpParams['name'] = 'from_email_address';
|
||||
CRM_Core_OptionValue::getValues($grpParams, $optionValues);
|
||||
foreach ($optionValues as $Id => $value) {
|
||||
if ($value['is_default'] && $value['is_active']) {
|
||||
$this->_fromEmailId = $Id;
|
||||
$list = explode('"', $value['label']);
|
||||
$domainDefaults['email_name'] = CRM_Utils_Array::value(1, $list);
|
||||
$domainDefaults['email_address'] = CRM_Utils_Mail::pluckEmailFromHeader($value['label']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unset($params['id']);
|
||||
$locParams = array('contact_id' => $domainDefaults['contact_id']);
|
||||
$this->_locationDefaults = $defaults = CRM_Core_BAO_Location::getValues($locParams);
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
if (!isset($defaults['address'][1]['country_id'])) {
|
||||
$defaults['address'][1]['country_id'] = $config->defaultContactCountry;
|
||||
}
|
||||
|
||||
if (!isset($defaults['address'][1]['state_province_id'])) {
|
||||
$defaults['address'][1]['state_province_id'] = $config->defaultContactStateProvince;
|
||||
}
|
||||
|
||||
}
|
||||
$defaults = array_merge($defaults, $domainDefaults);
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addField('name', array('label' => ts('Organization Name')), TRUE);
|
||||
$this->addField('description', array('label' => ts('Description'), 'size' => 30));
|
||||
$this->add('text', 'email_name', ts('FROM Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email'), TRUE);
|
||||
$this->add('text', 'email_address', ts('FROM Email Address'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email'), TRUE);
|
||||
$this->addRule('email_address', ts('Domain Email Address must use a valid email address format (e.g. \'info@example.org\').'), 'email');
|
||||
|
||||
//build location blocks.
|
||||
CRM_Contact_Form_Location::buildQuickForm($this);
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save'),
|
||||
'subName' => 'view',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
|
||||
if ($this->_action & CRM_Core_Action::VIEW) {
|
||||
$this->freeze();
|
||||
}
|
||||
$this->assign('emailDomain', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add local and global form rules.
|
||||
*/
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Contact_Form_Domain', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($fields) {
|
||||
// check for state/country mapping
|
||||
$errors = CRM_Contact_Form_Edit_Address::formRule($fields, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullObject);
|
||||
// $errors === TRUE means no errors from above formRule excution,
|
||||
// so declaring $errors to array for further processing
|
||||
if ($errors === TRUE) {
|
||||
$errors = array();
|
||||
}
|
||||
|
||||
//fix for CRM-3552,
|
||||
//as we use "fromName"<emailaddresss> format for domain email.
|
||||
if (strpos($fields['email_name'], '"') !== FALSE) {
|
||||
$errors['email_name'] = ts('Double quotes are not allow in from name.');
|
||||
}
|
||||
|
||||
// Check for default from email address and organization (domain) name. Force them to change it.
|
||||
if ($fields['email_address'] == 'info@EXAMPLE.ORG') {
|
||||
$errors['email_address'] = ts('Please enter a valid default FROM email address for system-generated emails.');
|
||||
}
|
||||
if ($fields['name'] == 'Default Domain Name') {
|
||||
$errors['name'] = ts('Please enter the name of the organization or entity which owns this CiviCRM site.');
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form when submitted.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
$params['entity_id'] = $this->_id;
|
||||
$params['entity_table'] = CRM_Core_BAO_Domain::getTableName();
|
||||
$domain = CRM_Core_BAO_Domain::edit($params, $this->_id);
|
||||
|
||||
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
|
||||
|
||||
if (isset($this->_locationDefaults['address'][1]['location_type_id'])) {
|
||||
$params['address'][1]['location_type_id'] = $this->_locationDefaults['address'][1]['location_type_id'];
|
||||
}
|
||||
else {
|
||||
$params['address'][1]['location_type_id'] = $defaultLocationType->id;
|
||||
}
|
||||
|
||||
if (isset($this->_locationDefaults['phone'][1]['location_type_id'])) {
|
||||
$params['phone'][1]['location_type_id'] = $this->_locationDefaults['phone'][1]['location_type_id'];
|
||||
}
|
||||
else {
|
||||
$params['phone'][1]['location_type_id'] = $defaultLocationType->id;
|
||||
}
|
||||
|
||||
if (isset($this->_locationDefaults['email'][1]['location_type_id'])) {
|
||||
$params['email'][1]['location_type_id'] = $this->_locationDefaults['email'][1]['location_type_id'];
|
||||
}
|
||||
else {
|
||||
$params['email'][1]['location_type_id'] = $defaultLocationType->id;
|
||||
}
|
||||
|
||||
$params += array('contact_id' => $this->_contactId);
|
||||
$contactParams = array(
|
||||
'sort_name' => $domain->name,
|
||||
'display_name' => $domain->name,
|
||||
'legal_name' => $domain->name,
|
||||
'organization_name' => $domain->name,
|
||||
'contact_id' => $this->_contactId,
|
||||
'contact_type' => 'Organization',
|
||||
);
|
||||
|
||||
if ($this->_contactId) {
|
||||
$contactParams['contact_sub_type'] = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId);
|
||||
}
|
||||
|
||||
CRM_Contact_BAO_Contact::add($contactParams);
|
||||
CRM_Core_BAO_Location::create($params, TRUE);
|
||||
|
||||
CRM_Core_BAO_Domain::edit($params, $this->_id);
|
||||
|
||||
//set domain from email address, CRM-3552
|
||||
$emailName = '"' . $params['email_name'] . '" <' . $params['email_address'] . '>';
|
||||
|
||||
$emailParams = array(
|
||||
'label' => $emailName,
|
||||
'description' => $params['description'],
|
||||
'is_active' => 1,
|
||||
'is_default' => 1,
|
||||
);
|
||||
|
||||
$groupParams = array('name' => 'from_email_address');
|
||||
|
||||
//get the option value wt.
|
||||
if ($this->_fromEmailId) {
|
||||
$action = $this->_action;
|
||||
$emailParams['weight'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_fromEmailId, 'weight');
|
||||
}
|
||||
else {
|
||||
//add from email address.
|
||||
$action = CRM_Core_Action::ADD;
|
||||
$grpId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'from_email_address', 'id', 'name');
|
||||
$fieldValues = array('option_group_id' => $grpId);
|
||||
$emailParams['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
|
||||
}
|
||||
|
||||
//reset default within domain.
|
||||
$emailParams['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID());
|
||||
|
||||
CRM_Core_OptionValue::addOptionValue($emailParams, $groupParams, $action, $this->_fromEmailId);
|
||||
|
||||
CRM_Core_Session::setStatus(ts("Domain information for '%1' has been saved.", array(1 => $domain->name)), ts('Saved'), 'success');
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
|
||||
}
|
||||
|
||||
}
|
442
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Address.php
Normal file
442
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Address.php
Normal file
|
@ -0,0 +1,442 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is used to build address block.
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_Address {
|
||||
|
||||
/**
|
||||
* Build form for address input fields.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param int $addressBlockCount
|
||||
* The index of the address array (if multiple addresses on a page).
|
||||
* @param bool $sharing
|
||||
* False, if we want to skip the address sharing features.
|
||||
* @param bool $inlineEdit
|
||||
* True when edit used in inline edit.
|
||||
*/
|
||||
public static function buildQuickForm(&$form, $addressBlockCount = NULL, $sharing = TRUE, $inlineEdit = FALSE) {
|
||||
// passing this via the session is AWFUL. we need to fix this
|
||||
if (!$addressBlockCount) {
|
||||
$blockId = ($form->get('Address_Block_Count')) ? $form->get('Address_Block_Count') : 1;
|
||||
}
|
||||
else {
|
||||
$blockId = $addressBlockCount;
|
||||
}
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$countryDefault = $config->defaultContactCountry;
|
||||
|
||||
$form->applyFilter('__ALL__', 'trim');
|
||||
|
||||
$js = array();
|
||||
if (!$inlineEdit) {
|
||||
$js = array('onChange' => 'checkLocation( this.id );', 'placeholder' => NULL);
|
||||
}
|
||||
|
||||
//make location type required for inline edit
|
||||
$form->addField("address[$blockId][location_type_id]", array('entity' => 'address', 'class' => 'eight', 'option_url' => NULL) + $js, $inlineEdit);
|
||||
if (!$inlineEdit) {
|
||||
$js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
|
||||
}
|
||||
|
||||
$form->addField(
|
||||
"address[$blockId][is_primary]", array(
|
||||
'entity' => 'address',
|
||||
'label' => ts('Primary location for this contact'),
|
||||
'text' => ts('Primary location for this contact')) + $js);
|
||||
|
||||
if (!$inlineEdit) {
|
||||
$js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );');
|
||||
}
|
||||
|
||||
$form->addField(
|
||||
"address[$blockId][is_billing]", array(
|
||||
'entity' => 'address',
|
||||
'label' => ts('Billing location for this contact'),
|
||||
'text' => ts('Billing location for this contact')) + $js);
|
||||
|
||||
// hidden element to store master address id
|
||||
$form->addField("address[$blockId][master_id]", array('entity' => 'address', 'type' => 'hidden'));
|
||||
$addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'address_options', TRUE, NULL, TRUE
|
||||
);
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
|
||||
|
||||
$elements = array(
|
||||
'address_name',
|
||||
'street_address',
|
||||
'supplemental_address_1',
|
||||
'supplemental_address_2',
|
||||
'supplemental_address_3',
|
||||
'city',
|
||||
'postal_code',
|
||||
'postal_code_suffix',
|
||||
'country_id',
|
||||
'state_province_id',
|
||||
'county_id',
|
||||
'geo_code_1',
|
||||
'geo_code_2',
|
||||
'street_number',
|
||||
'street_name',
|
||||
'street_unit',
|
||||
);
|
||||
|
||||
foreach ($elements as $name) {
|
||||
//Remove id from name, to allow comparison against enabled addressOtions.
|
||||
$nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name;
|
||||
// Skip fields which are not enabled in the address options.
|
||||
if (empty($addressOptions[$nameWithoutID])) {
|
||||
$continue = TRUE;
|
||||
//Don't skip street parsed fields when parsing is enabled.
|
||||
if (in_array($nameWithoutID, array(
|
||||
'street_number',
|
||||
'street_name',
|
||||
'street_unit',
|
||||
)) && !empty($addressOptions['street_address_parsing'])
|
||||
) {
|
||||
$continue = FALSE;
|
||||
}
|
||||
if ($continue) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ($name == 'address_name') {
|
||||
$name = 'name';
|
||||
}
|
||||
|
||||
$params = array('entity' => 'address');
|
||||
|
||||
if ($name == 'postal_code_suffix') {
|
||||
$params['label'] = ts('Suffix');
|
||||
}
|
||||
|
||||
$form->addField("address[$blockId][$name]", $params);
|
||||
}
|
||||
|
||||
$entityId = NULL;
|
||||
if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) {
|
||||
$entityId = $form->_values['address'][$blockId]['id'];
|
||||
}
|
||||
|
||||
// CRM-11665 geocode override option
|
||||
$geoCode = FALSE;
|
||||
if (!empty($config->geocodeMethod)) {
|
||||
$geoCode = TRUE;
|
||||
$form->addElement('checkbox',
|
||||
"address[$blockId][manual_geo_code]",
|
||||
ts('Override automatic geocoding')
|
||||
);
|
||||
}
|
||||
$form->assign('geoCode', $geoCode);
|
||||
|
||||
// Process any address custom data -
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', NULL, $entityId);
|
||||
|
||||
if (isset($groupTree) && is_array($groupTree)) {
|
||||
// use simplified formatted groupTree
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);
|
||||
|
||||
// make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]'
|
||||
foreach ($groupTree as $id => $group) {
|
||||
foreach ($group['fields'] as $fldId => $field) {
|
||||
$groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
|
||||
$groupTree[$id]['fields'][$fldId]['element_name'] = "address[$blockId][{$field['element_name']}]";
|
||||
}
|
||||
}
|
||||
|
||||
$defaults = array();
|
||||
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
|
||||
|
||||
// since we change element name for address custom data, we need to format the setdefault values
|
||||
$addressDefaults = array();
|
||||
foreach ($defaults as $key => $val) {
|
||||
if (empty($val)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// inorder to set correct defaults for checkbox custom data, we need to converted flat key to array
|
||||
// this works for all types custom data
|
||||
$keyValues = explode('[', str_replace(']', '', $key));
|
||||
$addressDefaults[$keyValues[0]][$keyValues[1]][$keyValues[2]] = $val;
|
||||
}
|
||||
|
||||
$form->setDefaults($addressDefaults);
|
||||
|
||||
// we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var.
|
||||
// And we can't set it to 'address_' because we want to set it in a slightly different format.
|
||||
CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_');
|
||||
|
||||
// during contact editing : if no address is filled
|
||||
// required custom data must not produce 'required' form rule error
|
||||
// more handling done in formRule func
|
||||
CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree);
|
||||
|
||||
$template = CRM_Core_Smarty::singleton();
|
||||
$tplGroupTree = $template->get_template_vars('address_groupTree');
|
||||
$tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree;
|
||||
|
||||
$form->assign('address_groupTree', $tplGroupTree + array($blockId => $groupTree));
|
||||
// unset the temp smarty var that got created
|
||||
$form->assign('dnc_groupTree', NULL);
|
||||
}
|
||||
// address custom data processing ends ..
|
||||
|
||||
if ($sharing) {
|
||||
// shared address
|
||||
$form->addElement('checkbox', "address[$blockId][use_shared_address]", NULL, ts('Use another contact\'s address'));
|
||||
|
||||
// Override the default profile links to add address form
|
||||
$profileLinks = CRM_Core_BAO_UFGroup::getCreateLinks(array(
|
||||
'new_individual',
|
||||
'new_organization',
|
||||
'new_household',
|
||||
), 'shared_address');
|
||||
$form->addEntityRef("address[$blockId][master_contact_id]", ts('Share With'), array('create' => $profileLinks));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for correct state / country mapping.
|
||||
*
|
||||
* @param array $fields
|
||||
* @param array $files
|
||||
* @param CRM_Core_Form $self
|
||||
*
|
||||
* @return array|bool
|
||||
* if no errors
|
||||
*/
|
||||
public static function formRule($fields, $files = array(), $self = NULL) {
|
||||
$errors = array();
|
||||
|
||||
$customDataRequiredFields = array();
|
||||
if ($self && property_exists($self, '_addressRequireOmission')) {
|
||||
$customDataRequiredFields = explode(',', $self->_addressRequireOmission);
|
||||
}
|
||||
|
||||
if (!empty($fields['address']) && is_array($fields['address'])) {
|
||||
foreach ($fields['address'] as $instance => $addressValues) {
|
||||
|
||||
if (CRM_Utils_System::isNull($addressValues)) {
|
||||
// DETACH 'required' form rule error to
|
||||
// custom data only if address data not exists upon submission
|
||||
if (!empty($customDataRequiredFields)) {
|
||||
foreach ($customDataRequiredFields as $customElementName) {
|
||||
$elementName = "address[$instance][$customElementName]";
|
||||
if ($self->getElementError($elementName)) {
|
||||
// set element error to none
|
||||
$self->setElementError($elementName, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// DETACH 'required' form rule error to
|
||||
// custom data if address data not exists upon submission
|
||||
// or if master address is selected
|
||||
if (!empty($customDataRequiredFields) && (!CRM_Core_BAO_Address::dataExists($addressValues) || !empty($addressValues['master_id']))) {
|
||||
foreach ($customDataRequiredFields as $customElementName) {
|
||||
$elementName = "address[$instance][$customElementName]";
|
||||
if ($self->getElementError($elementName)) {
|
||||
// set element error to none
|
||||
$self->setElementError($elementName, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($addressValues['use_shared_address']) && empty($addressValues['master_id'])) {
|
||||
$errors["address[$instance][use_shared_address]"] = ts('Please select valid shared contact or a contact with valid address.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for address block.
|
||||
*
|
||||
* @param array $defaults
|
||||
* Defaults associated array.
|
||||
* @param CRM_Core_Form $form
|
||||
* Form object.
|
||||
*/
|
||||
public static function setDefaultValues(&$defaults, &$form) {
|
||||
$addressValues = array();
|
||||
if (isset($defaults['address']) && is_array($defaults['address']) &&
|
||||
!CRM_Utils_System::isNull($defaults['address'])
|
||||
) {
|
||||
|
||||
// start of contact shared adddress defaults
|
||||
$sharedAddresses = array();
|
||||
$masterAddress = array();
|
||||
|
||||
// get contact name of shared contact names
|
||||
$shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']);
|
||||
|
||||
foreach ($defaults['address'] as $key => $addressValue) {
|
||||
if (!empty($addressValue['master_id']) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
|
||||
$master_cid = $shareAddressContactNames[$addressValue['master_id']]['contact_id'];
|
||||
$sharedAddresses[$key]['shared_address_display'] = array(
|
||||
'address' => $addressValue['display'],
|
||||
'name' => $shareAddressContactNames[$addressValue['master_id']]['name'],
|
||||
'options' => CRM_Core_BAO_Address::getValues(array(
|
||||
'entity_id' => $master_cid,
|
||||
'contact_id' => $master_cid,
|
||||
)),
|
||||
'master_id' => $addressValue['master_id'],
|
||||
);
|
||||
$defaults['address'][$key]['master_contact_id'] = $master_cid;
|
||||
}
|
||||
else {
|
||||
$defaults['address'][$key]['use_shared_address'] = 0;
|
||||
}
|
||||
|
||||
//check if any address is shared by any other contacts
|
||||
$masterAddress[$key] = CRM_Core_BAO_Address::checkContactSharedAddress($addressValue['id']);
|
||||
}
|
||||
|
||||
$form->assign('sharedAddresses', $sharedAddresses);
|
||||
$form->assign('masterAddress', $masterAddress);
|
||||
// end of shared address defaults
|
||||
|
||||
// start of parse address functionality
|
||||
// build street address, CRM-5450.
|
||||
if ($form->_parseStreetAddress) {
|
||||
$parseFields = array('street_address', 'street_number', 'street_name', 'street_unit');
|
||||
foreach ($defaults['address'] as $cnt => & $address) {
|
||||
$streetAddress = NULL;
|
||||
foreach (array(
|
||||
'street_number',
|
||||
'street_number_suffix',
|
||||
'street_name',
|
||||
'street_unit',
|
||||
) as $fld) {
|
||||
if (in_array($fld, array(
|
||||
'street_name',
|
||||
'street_unit',
|
||||
))) {
|
||||
$streetAddress .= ' ';
|
||||
}
|
||||
// CRM-17619 - if the street number suffix begins with a number, add a space
|
||||
$numsuffix = CRM_Utils_Array::value($fld, $address);
|
||||
if ($fld === 'street_number_suffix' && !empty($numsuffix)) {
|
||||
if (ctype_digit(substr($numsuffix, 0, 1))) {
|
||||
$streetAddress .= ' ';
|
||||
}
|
||||
}
|
||||
$streetAddress .= CRM_Utils_Array::value($fld, $address);
|
||||
}
|
||||
$streetAddress = trim($streetAddress);
|
||||
if (!empty($streetAddress)) {
|
||||
$address['street_address'] = $streetAddress;
|
||||
}
|
||||
if (isset($address['street_number'])) {
|
||||
// CRM-17619 - if the street number suffix begins with a number, add a space
|
||||
$thesuffix = CRM_Utils_Array::value('street_number_suffix', $address);
|
||||
if ($thesuffix) {
|
||||
if (ctype_digit(substr($thesuffix, 0, 1))) {
|
||||
$address['street_number'] .= " ";
|
||||
}
|
||||
}
|
||||
$address['street_number'] .= $thesuffix;
|
||||
}
|
||||
// build array for set default.
|
||||
foreach ($parseFields as $field) {
|
||||
$addressValues["{$field}_{$cnt}"] = CRM_Utils_Array::value($field, $address);
|
||||
}
|
||||
// don't load fields, use js to populate.
|
||||
foreach (array('street_number', 'street_name', 'street_unit') as $f) {
|
||||
if (isset($address[$f])) {
|
||||
unset($address[$f]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$form->assign('allAddressFieldValues', json_encode($addressValues));
|
||||
|
||||
//hack to handle show/hide address fields.
|
||||
$parsedAddress = array();
|
||||
if ($form->_contactId && !empty($_POST['address']) && is_array($_POST['address'])
|
||||
) {
|
||||
foreach ($_POST['address'] as $cnt => $values) {
|
||||
$showField = 'streetAddress';
|
||||
foreach (array('street_number', 'street_name', 'street_unit') as $fld) {
|
||||
if (!empty($values[$fld])) {
|
||||
$showField = 'addressElements';
|
||||
break;
|
||||
}
|
||||
}
|
||||
$parsedAddress[$cnt] = $showField;
|
||||
}
|
||||
}
|
||||
$form->assign('showHideAddressFields', $parsedAddress);
|
||||
$form->assign('loadShowHideAddressFields', empty($parsedAddress) ? FALSE : TRUE);
|
||||
}
|
||||
// end of parse address functionality
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store required custom data info.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $groupTree
|
||||
*/
|
||||
public static function storeRequiredCustomDataInfo(&$form, $groupTree) {
|
||||
if (in_array(CRM_Utils_System::getClassName($form), array('CRM_Contact_Form_Contact', 'CRM_Contact_Form_Inline_Address'))) {
|
||||
$requireOmission = NULL;
|
||||
foreach ($groupTree as $csId => $csVal) {
|
||||
// only process Address entity fields
|
||||
if ($csVal['extends'] != 'Address') {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($csVal['fields'] as $cdId => $cdVal) {
|
||||
if ($cdVal['is_required']) {
|
||||
$elementName = $cdVal['element_name'];
|
||||
if (in_array($elementName, $form->_required)) {
|
||||
// store the omitted rule for a element, to be used later on
|
||||
$requireOmission .= $cdVal['element_custom_name'] . ',';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form->_addressRequireOmission = rtrim($requireOmission, ',');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,240 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an Communication Preferences object.
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_CommunicationPreferences {
|
||||
|
||||
/**
|
||||
* Greetings.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $greetings = array();
|
||||
|
||||
/**
|
||||
* Build the form object elements for Communication Preferences object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Reference to the form object.
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
// since the pcm - preferred communication method is logically
|
||||
// grouped hence we'll use groups of HTML_QuickForm
|
||||
|
||||
// checkboxes for DO NOT phone, email, mail
|
||||
// we take labels from SelectValues
|
||||
$privacy = $commPreff = $commPreference = array();
|
||||
$privacyOptions = CRM_Core_SelectValues::privacy();
|
||||
|
||||
// we add is_opt_out as a separate checkbox below for display and help purposes so remove it here
|
||||
unset($privacyOptions['is_opt_out']);
|
||||
|
||||
foreach ($privacyOptions as $name => $label) {
|
||||
$privacy[] = $form->createElement('advcheckbox', $name, NULL, $label);
|
||||
}
|
||||
$form->addGroup($privacy, 'privacy', ts('Privacy'), ' <br/>');
|
||||
|
||||
// preferred communication method
|
||||
$comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method', array('loclize' => TRUE));
|
||||
foreach ($comm as $value => $title) {
|
||||
$commPreff[] = $form->createElement('advcheckbox', $value, NULL, $title);
|
||||
}
|
||||
$form->addField('preferred_communication_method', array('entity' => 'contact', 'type' => 'CheckBoxGroup'));
|
||||
$form->addField('preferred_language', array('entity' => 'contact'));
|
||||
|
||||
if (!empty($privacyOptions)) {
|
||||
$commPreference['privacy'] = $privacyOptions;
|
||||
}
|
||||
if (!empty($comm)) {
|
||||
$commPreference['preferred_communication_method'] = $comm;
|
||||
}
|
||||
|
||||
//using for display purpose.
|
||||
$form->assign('commPreference', $commPreference);
|
||||
|
||||
$form->addField('preferred_mail_format', array('entity' => 'contact', 'label' => ts('Email Format')));
|
||||
|
||||
$form->addField('is_opt_out', array('entity' => 'contact', 'label' => ts('NO BULK EMAILS (User Opt Out)')));
|
||||
|
||||
$form->addField('communication_style_id', array('entity' => 'contact', 'type' => 'RadioGroup'));
|
||||
//check contact type and build filter clause accordingly for greeting types, CRM-4575
|
||||
$greetings = self::getGreetingFields($form->_contactType);
|
||||
|
||||
foreach ($greetings as $greeting => $fields) {
|
||||
$filter = array(
|
||||
'contact_type' => $form->_contactType,
|
||||
'greeting_type' => $greeting,
|
||||
);
|
||||
|
||||
//add addressee in Contact form
|
||||
$greetingTokens = CRM_Core_PseudoConstant::greeting($filter);
|
||||
if (!empty($greetingTokens)) {
|
||||
$form->addElement('select', $fields['field'], $fields['label'],
|
||||
array(
|
||||
'' => ts('- select -'),
|
||||
) + $greetingTokens
|
||||
);
|
||||
//custom addressee
|
||||
$form->addElement('text', $fields['customField'], $fields['customLabel'],
|
||||
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', $fields['customField']), $fields['js']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Global form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param CRM_Contact_Form_Edit_CommunicationPreferences $self
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
//CRM-4575
|
||||
|
||||
$greetings = self::getGreetingFields($self->_contactType);
|
||||
foreach ($greetings as $greeting => $details) {
|
||||
$customizedValue = CRM_Core_PseudoConstant::getKey('CRM_Contact_BAO_Contact', $details['field'], 'Customized');
|
||||
if (CRM_Utils_Array::value($details['field'], $fields) == $customizedValue && empty($fields[$details['customField']])) {
|
||||
$errors[$details['customField']] = ts('Custom %1 is a required field if %1 is of type Customized.',
|
||||
array(1 => $details['label'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('preferred_mail_format', $fields) && empty($fields['preferred_mail_format'])) {
|
||||
$errors['preferred_mail_format'] = ts('Please select an email format preferred by this contact.');
|
||||
}
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $defaults
|
||||
*/
|
||||
public static function setDefaultValues(&$form, &$defaults) {
|
||||
|
||||
if (!empty($defaults['preferred_language'])) {
|
||||
$languages = CRM_Contact_BAO_Contact::buildOptions('preferred_language');
|
||||
$defaults['preferred_language'] = CRM_Utils_Array::key($defaults['preferred_language'], $languages);
|
||||
}
|
||||
|
||||
// CRM-7119: set preferred_language to default if unset
|
||||
if (empty($defaults['preferred_language'])) {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$defaults['preferred_language'] = $config->lcMessages;
|
||||
}
|
||||
|
||||
if (empty($defaults['communication_style_id'])) {
|
||||
$defaults['communication_style_id'] = array_pop(CRM_Core_OptionGroup::values('communication_style', TRUE, NULL, NULL, 'AND is_default = 1'));
|
||||
}
|
||||
|
||||
// CRM-17778 -- set preferred_mail_format to default if unset
|
||||
if (empty($defaults['preferred_mail_format'])) {
|
||||
$defaults['preferred_mail_format'] = 'Both';
|
||||
}
|
||||
else {
|
||||
$defaults['preferred_mail_format'] = array_search($defaults['preferred_mail_format'], CRM_Core_SelectValues::pmf());
|
||||
}
|
||||
|
||||
//set default from greeting types CRM-4575, CRM-9739
|
||||
if ($form->_action & CRM_Core_Action::ADD) {
|
||||
foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
|
||||
if (empty($defaults[$greeting . '_id'])) {
|
||||
if ($defaultGreetingTypeId = CRM_Contact_BAO_Contact_Utils::defaultGreeting($form->_contactType, $greeting)
|
||||
) {
|
||||
$defaults[$greeting . '_id'] = $defaultGreetingTypeId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
|
||||
$name = "{$greeting}_display";
|
||||
$form->assign($name, CRM_Utils_Array::value($name, $defaults));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set array of greeting fields.
|
||||
*
|
||||
* @param string $contactType
|
||||
*/
|
||||
public static function getGreetingFields($contactType) {
|
||||
if (empty(self::$greetings[$contactType])) {
|
||||
self::$greetings[$contactType] = array();
|
||||
|
||||
$js = array(
|
||||
'onfocus' => "if (!this.value) { this.value='Dear ';} else return false",
|
||||
'onblur' => "if ( this.value == 'Dear') { this.value='';} else return false",
|
||||
);
|
||||
|
||||
self::$greetings[$contactType] = array(
|
||||
'addressee' => array(
|
||||
'field' => 'addressee_id',
|
||||
'customField' => 'addressee_custom',
|
||||
'label' => ts('Addressee'),
|
||||
'customLabel' => ts('Custom Addressee'),
|
||||
'js' => NULL,
|
||||
),
|
||||
'email_greeting' => array(
|
||||
'field' => 'email_greeting_id',
|
||||
'customField' => 'email_greeting_custom',
|
||||
'label' => ts('Email Greeting'),
|
||||
'customLabel' => ts('Custom Email Greeting'),
|
||||
'js' => $js,
|
||||
),
|
||||
'postal_greeting' => array(
|
||||
'field' => 'postal_greeting_id',
|
||||
'customField' => 'postal_greeting_custom',
|
||||
'label' => ts('Postal Greeting'),
|
||||
'customLabel' => ts('Custom Postal Greeting'),
|
||||
'js' => $js,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return self::$greetings[$contactType];
|
||||
}
|
||||
|
||||
}
|
108
sites/all/modules/civicrm/CRM/Contact/Form/Edit/CustomData.php
Normal file
108
sites/all/modules/civicrm/CRM/Contact/Form/Edit/CustomData.php
Normal file
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an Demographics object.
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_CustomData {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function preProcess(&$form) {
|
||||
$form->_type = CRM_Utils_Request::retrieve('type', 'String');
|
||||
$form->_subType = CRM_Utils_Request::retrieve('subType', 'String');
|
||||
|
||||
//build the custom data as other blocks.
|
||||
//$form->assign( "addBlock", false );
|
||||
if ($form->_type) {
|
||||
$form->_addBlockName = 'CustomData';
|
||||
$form->assign("addBlock", TRUE);
|
||||
$form->assign("blockName", $form->_addBlockName);
|
||||
}
|
||||
|
||||
CRM_Custom_Form_CustomData::preProcess($form, NULL, $form->_subType, NULL,
|
||||
($form->_type) ? $form->_type : $form->_contactType
|
||||
);
|
||||
|
||||
//assign group tree after build.
|
||||
$form->assign('groupTree', $form->_groupTree);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for CustomData object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Reference to the form object.
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
if (!empty($form->_submitValues)) {
|
||||
if ($customValueCount = CRM_Utils_Array::value('hidden_custom_group_count', $form->_submitValues)) {
|
||||
if (is_array($customValueCount)) {
|
||||
if (array_key_exists(0, $customValueCount)) {
|
||||
unset($customValueCount[0]);
|
||||
}
|
||||
$form->_customValueCount = $customValueCount;
|
||||
$form->assign('customValueCount', $customValueCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
CRM_Custom_Form_CustomData::buildQuickForm($form);
|
||||
|
||||
//build custom data.
|
||||
$contactSubType = NULL;
|
||||
if (!empty($_POST["hidden_custom"]) && !empty($_POST['contact_sub_type'])) {
|
||||
$contactSubType = $_POST['contact_sub_type'];
|
||||
}
|
||||
else {
|
||||
$contactSubType = CRM_Utils_Array::value('contact_sub_type', $form->_values);
|
||||
}
|
||||
$form->assign('contactType', $form->_contactType);
|
||||
$form->assign('contactSubType', $contactSubType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. Note that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $defaults
|
||||
*/
|
||||
public static function setDefaultValues(&$form, &$defaults) {
|
||||
$defaults += CRM_Custom_Form_CustomData::setDefaultValues($form);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an Demographics object.
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_Demographics {
|
||||
|
||||
/**
|
||||
* Build the form object elements for Demographics object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Reference to the form object.
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
$form->addField('gender_id', array('entity' => 'contact', 'type' => 'Radio', 'allowClear' => TRUE));
|
||||
|
||||
$form->addField('birth_date', array('entity' => 'contact'), FALSE, FALSE);
|
||||
|
||||
$form->addField('is_deceased', array('entity' => 'contact', 'label' => ts('Contact is Deceased'), 'onclick' => "showDeceasedDate()"));
|
||||
$form->addField('deceased_date', array('entity' => 'contact'), FALSE, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. Note that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $defaults
|
||||
*/
|
||||
public static function setDefaultValues(&$form, &$defaults) {
|
||||
}
|
||||
|
||||
}
|
118
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Email.php
Normal file
118
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Email.php
Normal file
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an Email object.
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_Email {
|
||||
|
||||
/**
|
||||
* Build the form object elements for an email object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Reference to the form object.
|
||||
* @param int $blockCount
|
||||
* Block number to build.
|
||||
* @param bool $blockEdit
|
||||
* Is it block edit.
|
||||
*/
|
||||
public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) {
|
||||
// passing this via the session is AWFUL. we need to fix this
|
||||
if (!$blockCount) {
|
||||
$blockId = ($form->get('Email_Block_Count')) ? $form->get('Email_Block_Count') : 1;
|
||||
}
|
||||
else {
|
||||
$blockId = $blockCount;
|
||||
}
|
||||
|
||||
$form->applyFilter('__ALL__', 'trim');
|
||||
|
||||
//Email box
|
||||
$form->addField("email[$blockId][email]", array('entity' => 'email'));
|
||||
$form->addRule("email[$blockId][email]", ts('Email is not valid.'), 'email');
|
||||
if (isset($form->_contactType) || $blockEdit) {
|
||||
//Block type
|
||||
$form->addField("email[$blockId][location_type_id]", array('entity' => 'email', 'placeholder' => NULL, 'class' => 'eight', 'option_url' => NULL));
|
||||
|
||||
//TODO: Refactor on_hold field to select.
|
||||
$multipleBulk = CRM_Core_BAO_Email::isMultipleBulkMail();
|
||||
|
||||
//On-hold select
|
||||
if ($multipleBulk) {
|
||||
$holdOptions = array(
|
||||
0 => ts('- select -'),
|
||||
1 => ts('On Hold Bounce'),
|
||||
2 => ts('On Hold Opt Out'),
|
||||
);
|
||||
$form->addElement('select', "email[$blockId][on_hold]", '', $holdOptions);
|
||||
}
|
||||
else {
|
||||
$form->addField("email[$blockId][on_hold]", array('entity' => 'email', 'type' => 'advcheckbox'));
|
||||
}
|
||||
|
||||
//Bulkmail checkbox
|
||||
$form->assign('multipleBulk', $multipleBulk);
|
||||
if ($multipleBulk) {
|
||||
$js = array('id' => "Email_" . $blockId . "_IsBulkmail");
|
||||
$form->addElement('advcheckbox', "email[$blockId][is_bulkmail]", NULL, '', $js);
|
||||
}
|
||||
else {
|
||||
$js = array('id' => "Email_" . $blockId . "_IsBulkmail");
|
||||
if (!$blockEdit) {
|
||||
$js['onClick'] = 'singleSelect( this.id );';
|
||||
}
|
||||
$form->addElement('radio', "email[$blockId][is_bulkmail]", '', '', '1', $js);
|
||||
}
|
||||
|
||||
//is_Primary radio
|
||||
$js = array('id' => "Email_" . $blockId . "_IsPrimary");
|
||||
if (!$blockEdit) {
|
||||
$js['onClick'] = 'singleSelect( this.id );';
|
||||
}
|
||||
|
||||
$form->addElement('radio', "email[$blockId][is_primary]", '', '', '1', $js);
|
||||
|
||||
if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') {
|
||||
|
||||
$form->add('textarea', "email[$blockId][signature_text]", ts('Signature (Text)'),
|
||||
array('rows' => 2, 'cols' => 40)
|
||||
);
|
||||
|
||||
$form->add('wysiwyg', "email[$blockId][signature_html]", ts('Signature (HTML)'),
|
||||
array('rows' => 2, 'cols' => 40)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
101
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Household.php
Normal file
101
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Household.php
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auxiliary class to provide support to the Contact Form class.
|
||||
*
|
||||
* Does this by implementing a small set of static methods.
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_Household {
|
||||
|
||||
/**
|
||||
* This function provides the HTML form elements that are specific to the Household Contact Type.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Form object.
|
||||
* @param int $inlineEditMode
|
||||
* ( 1 for contact summary.
|
||||
* top bar form and 2 for display name edit )
|
||||
*/
|
||||
public static function buildQuickForm(&$form, $inlineEditMode = NULL) {
|
||||
$form->applyFilter('__ALL__', 'trim');
|
||||
|
||||
if (!$inlineEditMode || $inlineEditMode == 1) {
|
||||
// household_name
|
||||
$form->addField('household_name');
|
||||
}
|
||||
|
||||
if (!$inlineEditMode || $inlineEditMode == 2) {
|
||||
// nick_name
|
||||
$form->addField('nick_name');
|
||||
$form->addField('contact_source', array('label' => ts('Source')));
|
||||
}
|
||||
|
||||
if (!$inlineEditMode) {
|
||||
$form->addField('external_identifier', array('label' => ts('External ID')));
|
||||
$form->addRule('external_identifier',
|
||||
ts('External ID already exists in Database.'),
|
||||
'objectExists',
|
||||
array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add rule for household.
|
||||
*
|
||||
* @param array $fields
|
||||
* Array of form values.
|
||||
* @param array $files
|
||||
* Unused.
|
||||
* @param int $contactID
|
||||
*
|
||||
* @return array|bool
|
||||
* $error
|
||||
*/
|
||||
public static function formRule($fields, $files, $contactID = NULL) {
|
||||
$errors = array();
|
||||
$primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
|
||||
|
||||
// make sure that household name is set
|
||||
if (empty($fields['household_name'])) {
|
||||
$errors['household_name'] = 'Household Name should be set.';
|
||||
}
|
||||
|
||||
//check for duplicate - dedupe rules
|
||||
CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Household');
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
}
|
74
sites/all/modules/civicrm/CRM/Contact/Form/Edit/IM.php
Normal file
74
sites/all/modules/civicrm/CRM/Contact/Form/Edit/IM.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an IM object.
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_IM {
|
||||
|
||||
/**
|
||||
* Build the form object elements for an IM object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Reference to the form object.
|
||||
* @param int $blockCount
|
||||
* Block number to build.
|
||||
* @param bool $blockEdit
|
||||
* Is it block edit.
|
||||
*/
|
||||
public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) {
|
||||
if (!$blockCount) {
|
||||
$blockId = ($form->get('IM_Block_Count')) ? $form->get('IM_Block_Count') : 1;
|
||||
}
|
||||
else {
|
||||
$blockId = $blockCount;
|
||||
}
|
||||
$form->applyFilter('__ALL__', 'trim');
|
||||
|
||||
//IM provider select
|
||||
$form->addField("im[$blockId][provider_id]", array('entity' => 'im', 'class' => 'eight', 'placeholder' => NULL));
|
||||
//Block type select
|
||||
$form->addField("im[$blockId][location_type_id]", array('entity' => 'im', 'class' => 'eight', 'placeholder' => NULL, 'option_url' => NULL));
|
||||
|
||||
//IM box
|
||||
$form->addField("im[$blockId][name]", array('entity' => 'im'));
|
||||
//is_Primary radio
|
||||
$js = array('id' => 'IM_' . $blockId . '_IsPrimary');
|
||||
if (!$blockEdit) {
|
||||
$js['onClick'] = 'singleSelect( this.id );';
|
||||
}
|
||||
|
||||
$form->addElement('radio', "im[$blockId][is_primary]", '', '', '1', $js);
|
||||
}
|
||||
|
||||
}
|
145
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Individual.php
Normal file
145
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Individual.php
Normal file
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auxiliary class to provide support to the Contact Form class.
|
||||
*
|
||||
* Does this by implementing a small set of static methods.
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_Individual {
|
||||
|
||||
/**
|
||||
* This function provides the HTML form elements that are specific to the Individual Contact Type.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Form object.
|
||||
* @param int $inlineEditMode
|
||||
* ( 1 for contact summary.
|
||||
* top bar form and 2 for display name edit )
|
||||
*/
|
||||
public static function buildQuickForm(&$form, $inlineEditMode = NULL) {
|
||||
$form->applyFilter('__ALL__', 'trim');
|
||||
|
||||
if (!$inlineEditMode || $inlineEditMode == 1) {
|
||||
$nameFields = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'contact_edit_options', TRUE, NULL,
|
||||
FALSE, 'name', TRUE, 'AND v.filter = 2'
|
||||
);
|
||||
|
||||
// Use names instead of labels to build form.
|
||||
$nameFields = array_keys($nameFields);
|
||||
|
||||
// Fixme: dear god why? these come out in a format that is NOT the name of the fields.
|
||||
foreach ($nameFields as &$fix) {
|
||||
$fix = str_replace(' ', '_', strtolower($fix));
|
||||
if ($fix == 'prefix' || $fix == 'suffix') {
|
||||
// God, why god?
|
||||
$fix .= '_id';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($nameFields as $name) {
|
||||
$props = array();
|
||||
if ($name == 'prefix_id' || $name == 'suffix_id') {
|
||||
//override prefix/suffix label name as Prefix/Suffix respectively and adjust select size
|
||||
$props = array('class' => 'eight', 'placeholder' => ' ', 'label' => $name == 'prefix_id' ? ts('Prefix') : ts('Suffix'));
|
||||
}
|
||||
$form->addField($name, $props);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$inlineEditMode || $inlineEditMode == 2) {
|
||||
// nick_name
|
||||
$form->addField('nick_name');
|
||||
|
||||
// job title
|
||||
// override the size for UI to look better
|
||||
$form->addField('job_title', array('size' => '30'));
|
||||
|
||||
//Current Employer Element
|
||||
$props = array(
|
||||
'api' => array('params' => array('contact_type' => 'Organization')),
|
||||
'create' => TRUE,
|
||||
);
|
||||
$form->addField('employer_id', $props);
|
||||
$form->addField('contact_source', array('class' => 'big'));
|
||||
}
|
||||
|
||||
if (!$inlineEditMode) {
|
||||
$checkSimilar = Civi::settings()->get('contact_ajax_check_similar');
|
||||
|
||||
if ($checkSimilar == NULL) {
|
||||
$checkSimilar = 0;
|
||||
}
|
||||
$form->assign('checkSimilar', $checkSimilar);
|
||||
|
||||
//External Identifier Element
|
||||
$form->addField('external_identifier', array('label' => 'External ID'));
|
||||
|
||||
$form->addRule('external_identifier',
|
||||
ts('External ID already exists in Database.'),
|
||||
'objectExists',
|
||||
array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier')
|
||||
);
|
||||
CRM_Core_ShowHideBlocks::links($form, 'demographics', '', '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Global form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param int $contactID
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if no errors, else array of errors.
|
||||
*/
|
||||
public static function formRule($fields, $files, $contactID = NULL) {
|
||||
$errors = array();
|
||||
$primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
|
||||
|
||||
// make sure that firstName and lastName or a primary OpenID is set
|
||||
if (!$primaryID && (empty($fields['first_name']) || empty($fields['last_name']))) {
|
||||
$errors['_qf_default'] = ts('First Name and Last Name OR an email OR an OpenID in the Primary Location should be set.');
|
||||
}
|
||||
|
||||
//check for duplicate - dedupe rules
|
||||
CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Individual');
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
}
|
75
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Lock.php
Normal file
75
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Lock.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auxiliary class to provide support for locking (and ignoring locks on) contact records.
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_Lock {
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Form object.
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
$form->addField('modified_date', array('type' => 'hidden', 'id' => 'modified_date', 'label' => ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that modified_date has not changed in the underlying DB.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param int $contactID
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $contactID = NULL) {
|
||||
$errors = array();
|
||||
|
||||
$timestamps = CRM_Contact_BAO_Contact::getTimestamps($contactID);
|
||||
if ($fields['modified_date'] != $timestamps['modified_date']) {
|
||||
// Inline buttons generated via JS
|
||||
$open = sprintf("<span id='update_modified_date' data:latest_modified_date='%s'>", $timestamps['modified_date']);
|
||||
$close = "</span>";
|
||||
$errors['modified_date'] = $open . ts('This record was modified by another user!') . $close;
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
}
|
46
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Notes.php
Normal file
46
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Notes.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_Notes {
|
||||
|
||||
/**
|
||||
* Build form elements.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
$form->applyFilter('__ALL__', 'trim');
|
||||
$form->addField('subject', array('entity' => 'note', 'size' => '60'));
|
||||
$form->addField('note', array('entity' => 'note', 'rows' => 3));
|
||||
}
|
||||
|
||||
}
|
75
sites/all/modules/civicrm/CRM/Contact/Form/Edit/OpenID.php
Normal file
75
sites/all/modules/civicrm/CRM/Contact/Form/Edit/OpenID.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an OpenID object.
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_OpenID {
|
||||
|
||||
/**
|
||||
* Build the form object elements for an open id object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Reference to the form object.
|
||||
* @param int $blockCount
|
||||
* Block number to build.
|
||||
* @param bool $blockEdit
|
||||
* Is it block edit.
|
||||
*/
|
||||
public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) {
|
||||
if (!$blockCount) {
|
||||
$blockId = ($form->get('OpenID_Block_Count')) ? $form->get('OpenID_Block_Count') : 1;
|
||||
}
|
||||
else {
|
||||
$blockId = $blockCount;
|
||||
}
|
||||
$form->applyFilter('__ALL__', 'trim');
|
||||
|
||||
$form->addElement('text', "openid[$blockId][openid]", ts('OpenID'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Core_DAO_OpenID', 'openid')
|
||||
);
|
||||
$form->addRule("openid[$blockId][openid]", ts('OpenID is not a valid URL.'), 'url');
|
||||
|
||||
//Block type
|
||||
$form->addElement('select', "openid[$blockId][location_type_id]", '', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'));
|
||||
|
||||
//is_Primary radio
|
||||
$js = array('id' => "OpenID_" . $blockId . "_IsPrimary");
|
||||
if (!$blockEdit) {
|
||||
$js['onClick'] = 'singleSelect( this.id );';
|
||||
}
|
||||
|
||||
$form->addElement('radio', "openid[$blockId][is_primary]", '', '', '1', $js);
|
||||
}
|
||||
|
||||
}
|
103
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Organization.php
Normal file
103
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Organization.php
Normal file
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auxiliary class to provide support to the Contact Form class.
|
||||
*
|
||||
* Does this by implementing a small set of static methods.
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_Organization {
|
||||
|
||||
/**
|
||||
* This function provides the HTML form elements that are specific to the Organization Contact Type.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Form object.
|
||||
* @param int $inlineEditMode
|
||||
* ( 1 for contact summary.
|
||||
* top bar form and 2 for display name edit )
|
||||
*/
|
||||
public static function buildQuickForm(&$form, $inlineEditMode = NULL) {
|
||||
$form->applyFilter('__ALL__', 'trim');
|
||||
|
||||
if (!$inlineEditMode || $inlineEditMode == 1) {
|
||||
// Organization_name
|
||||
$form->addField('organization_name');
|
||||
}
|
||||
|
||||
if (!$inlineEditMode || $inlineEditMode == 2) {
|
||||
// legal_name
|
||||
$form->addField('legal_name');
|
||||
|
||||
// nick_name
|
||||
$form->addField('nick_name');
|
||||
|
||||
// sic_code
|
||||
$form->addField('sic_code');
|
||||
$form->addField('contact_source');
|
||||
}
|
||||
|
||||
if (!$inlineEditMode) {
|
||||
$form->addField('external_identifier', array('label' => ts('External ID')));
|
||||
$form->addRule('external_identifier',
|
||||
ts('External ID already exists in Database.'),
|
||||
'objectExists',
|
||||
array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fields
|
||||
* @param $files
|
||||
* @param int $contactID
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function formRule($fields, $files, $contactID = NULL) {
|
||||
$errors = array();
|
||||
$primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
|
||||
|
||||
// make sure that organization name is set
|
||||
if (empty($fields['organization_name'])) {
|
||||
$errors['organization_name'] = 'Organization Name should be set.';
|
||||
}
|
||||
|
||||
//check for duplicate - dedupe rules
|
||||
CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Organization');
|
||||
|
||||
// add code to make sure that the uniqueness criteria is satisfied
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
}
|
86
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Phone.php
Normal file
86
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Phone.php
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for a phone object.
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_Phone {
|
||||
|
||||
/**
|
||||
* Build the form object elements for a phone object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Reference to the form object.
|
||||
* @param int $addressBlockCount
|
||||
* Block number to build.
|
||||
* @param bool $blockEdit
|
||||
* Is it block edit.
|
||||
*/
|
||||
public static function buildQuickForm(&$form, $addressBlockCount = NULL, $blockEdit = FALSE) {
|
||||
// passing this via the session is AWFUL. we need to fix this
|
||||
if (!$addressBlockCount) {
|
||||
$blockId = ($form->get('Phone_Block_Count')) ? $form->get('Phone_Block_Count') : 1;
|
||||
}
|
||||
else {
|
||||
$blockId = $addressBlockCount;
|
||||
}
|
||||
|
||||
$form->applyFilter('__ALL__', 'trim');
|
||||
|
||||
//phone type select
|
||||
$form->addField("phone[$blockId][phone_type_id]", array(
|
||||
'entity' => 'phone',
|
||||
'class' => 'eight',
|
||||
'placeholder' => NULL,
|
||||
));
|
||||
//main phone number with crm_phone class
|
||||
$form->addField("phone[$blockId][phone]", array('entity' => 'phone', 'class' => 'crm_phone twelve'));
|
||||
$form->addField("phone[$blockId][phone_ext]", array('entity' => 'phone'));
|
||||
if (isset($form->_contactType) || $blockEdit) {
|
||||
//Block type select
|
||||
$form->addField("phone[$blockId][location_type_id]", array(
|
||||
'entity' => 'phone',
|
||||
'class' => 'eight',
|
||||
'placeholder' => NULL,
|
||||
'option_url' => NULL,
|
||||
));
|
||||
|
||||
//is_Primary radio
|
||||
$js = array('id' => 'Phone_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
|
||||
$form->addElement('radio', "phone[$blockId][is_primary]", '', '', '1', $js);
|
||||
}
|
||||
// TODO: set this up as a group, we need a valid phone_type_id if we have a phone number
|
||||
// $form->addRule( "location[$locationId][phone][$locationId][phone]", ts('Phone number is not valid.'), 'phone' );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,235 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_TagsAndGroups {
|
||||
|
||||
/**
|
||||
* Constant to determine which forms we are generating.
|
||||
*
|
||||
* Used by both profile and edit contact
|
||||
*/
|
||||
const GROUP = 1, TAG = 2, ALL = 3;
|
||||
|
||||
/**
|
||||
* Build form elements.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* The form object that we are operating on.
|
||||
* @param int $contactId
|
||||
* Contact id.
|
||||
* @param int $type
|
||||
* What components are we interested in.
|
||||
* @param bool $visibility
|
||||
* Visibility of the field.
|
||||
* @param null $isRequired
|
||||
* @param string $groupName
|
||||
* If used for building group block.
|
||||
* @param string $tagName
|
||||
* If used for building tag block.
|
||||
* @param string $fieldName
|
||||
* This is used in batch profile(i.e to build multiple blocks).
|
||||
*
|
||||
* @param string $groupElementType
|
||||
*
|
||||
*/
|
||||
public static function buildQuickForm(
|
||||
&$form,
|
||||
$contactId = 0,
|
||||
$type = self::ALL,
|
||||
$visibility = FALSE,
|
||||
$isRequired = NULL,
|
||||
$groupName = 'Group(s)',
|
||||
$tagName = 'Tag(s)',
|
||||
$fieldName = NULL,
|
||||
$groupElementType = 'checkbox'
|
||||
) {
|
||||
if (!isset($form->_tagGroup)) {
|
||||
$form->_tagGroup = array();
|
||||
}
|
||||
|
||||
// NYSS 5670
|
||||
if (!$contactId && !empty($form->_contactId)) {
|
||||
$contactId = $form->_contactId;
|
||||
}
|
||||
|
||||
$type = (int) $type;
|
||||
if ($type & self::GROUP) {
|
||||
|
||||
$fName = 'group';
|
||||
if ($fieldName) {
|
||||
$fName = $fieldName;
|
||||
}
|
||||
|
||||
$groupID = isset($form->_grid) ? $form->_grid : NULL;
|
||||
if ($groupID && $visibility) {
|
||||
$ids = array($groupID => $groupID);
|
||||
}
|
||||
else {
|
||||
if ($visibility) {
|
||||
$group = CRM_Core_PseudoConstant::allGroup();
|
||||
}
|
||||
else {
|
||||
$group = CRM_Core_PseudoConstant::group();
|
||||
}
|
||||
$ids = $group;
|
||||
}
|
||||
|
||||
if ($groupID || !empty($group)) {
|
||||
$groups = CRM_Contact_BAO_Group::getGroupsHierarchy($ids);
|
||||
|
||||
$attributes['skiplabel'] = TRUE;
|
||||
$elements = array();
|
||||
$groupsOptions = array();
|
||||
foreach ($groups as $id => $group) {
|
||||
// make sure that this group has public visibility
|
||||
if ($visibility &&
|
||||
$group['visibility'] == 'User and User Admin Only'
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($groupElementType == 'select') {
|
||||
$groupsOptions[$id] = $group['title'];
|
||||
}
|
||||
else {
|
||||
$form->_tagGroup[$fName][$id]['description'] = $group['description'];
|
||||
$elements[] = &$form->addElement('advcheckbox', $id, NULL, $group['title'], $attributes);
|
||||
}
|
||||
}
|
||||
|
||||
if ($groupElementType == 'select' && !empty($groupsOptions)) {
|
||||
$form->add('select', $fName, $groupName, $groupsOptions, FALSE,
|
||||
array('id' => $fName, 'multiple' => 'multiple', 'class' => 'crm-select2 twenty')
|
||||
);
|
||||
$form->assign('groupCount', count($groupsOptions));
|
||||
}
|
||||
|
||||
if ($groupElementType == 'checkbox' && !empty($elements)) {
|
||||
$form->addGroup($elements, $fName, $groupName, ' <br />');
|
||||
$form->assign('groupCount', count($elements));
|
||||
if ($isRequired) {
|
||||
$form->addRule($fName, ts('%1 is a required field.', array(1 => $groupName)), 'required');
|
||||
}
|
||||
}
|
||||
$form->assign('groupElementType', $groupElementType);
|
||||
}
|
||||
}
|
||||
|
||||
if ($type & self::TAG) {
|
||||
$tags = CRM_Core_BAO_Tag::getColorTags('civicrm_contact');
|
||||
|
||||
if (!empty($tags)) {
|
||||
$form->add('select2', 'tag', ts('Tag(s)'), $tags, FALSE, array('class' => 'huge', 'placeholder' => ts('- select -'), 'multiple' => TRUE));
|
||||
}
|
||||
|
||||
// build tag widget
|
||||
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
|
||||
CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', $contactId, FALSE, TRUE);
|
||||
}
|
||||
$form->assign('tagGroup', $form->_tagGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for relevant form elements.
|
||||
*
|
||||
* @param int $id
|
||||
* The contact id.
|
||||
* @param array $defaults
|
||||
* The defaults array to store the values in.
|
||||
* @param int $type
|
||||
* What components are we interested in.
|
||||
* @param string $fieldName
|
||||
* This is used in batch profile(i.e to build multiple blocks).
|
||||
*
|
||||
* @param string $groupElementType
|
||||
*/
|
||||
public static function setDefaults($id, &$defaults, $type = self::ALL, $fieldName = NULL, $groupElementType = 'checkbox') {
|
||||
$type = (int ) $type;
|
||||
if ($type & self::GROUP) {
|
||||
$fName = 'group';
|
||||
if ($fieldName) {
|
||||
$fName = $fieldName;
|
||||
}
|
||||
|
||||
$contactGroup = CRM_Contact_BAO_GroupContact::getContactGroup($id, 'Added', NULL, FALSE, TRUE);
|
||||
if ($contactGroup) {
|
||||
foreach ($contactGroup as $group) {
|
||||
if ($groupElementType == 'select') {
|
||||
$defaults[$fName][] = $group['group_id'];
|
||||
}
|
||||
else {
|
||||
$defaults[$fName . '[' . $group['group_id'] . ']'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($type & self::TAG) {
|
||||
$defaults['tag'] = implode(',', CRM_Core_BAO_EntityTag::getTag($id, 'civicrm_contact'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. Note that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $defaults
|
||||
*/
|
||||
public static function setDefaultValues(&$form, &$defaults) {
|
||||
$contactEditOptions = $form->get('contactEditOptions');
|
||||
|
||||
if ($form->_action & CRM_Core_Action::ADD) {
|
||||
if (array_key_exists('TagsAndGroups', $contactEditOptions)) {
|
||||
// set group and tag defaults if any
|
||||
if ($form->_gid) {
|
||||
$defaults['group'][$form->_gid] = 1;
|
||||
}
|
||||
if ($form->_tid) {
|
||||
$defaults['tag'][$form->_tid] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (array_key_exists('TagsAndGroups', $contactEditOptions)) {
|
||||
// set the group and tag ids
|
||||
$groupElementType = 'checkbox';
|
||||
if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') {
|
||||
$groupElementType = 'select';
|
||||
}
|
||||
self::setDefaults($form->_contactId, $defaults, self::ALL, NULL, $groupElementType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
66
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Website.php
Normal file
66
sites/all/modules/civicrm/CRM/Contact/Form/Edit/Website.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an Website object.
|
||||
*/
|
||||
class CRM_Contact_Form_Edit_Website {
|
||||
|
||||
/**
|
||||
* Build the form object elements for an Website object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Reference to the form object.
|
||||
* @param int $blockCount
|
||||
* Block number to build.
|
||||
*/
|
||||
public static function buildQuickForm(&$form, $blockCount = NULL) {
|
||||
if (!$blockCount) {
|
||||
$blockId = ($form->get('Website_Block_Count')) ? $form->get('Website_Block_Count') : 1;
|
||||
}
|
||||
else {
|
||||
$blockId = $blockCount;
|
||||
}
|
||||
|
||||
$form->applyFilter('__ALL__', 'trim');
|
||||
|
||||
//Website type select
|
||||
$form->addField("website[$blockId][website_type_id]", array('entity' => 'website', 'class' => 'eight'));
|
||||
|
||||
//Website box
|
||||
$form->addField("website[$blockId][url]", array('entity' => 'website'));
|
||||
$form->addRule("website[$blockId][url]", ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'url');
|
||||
|
||||
}
|
||||
|
||||
}
|
161
sites/all/modules/civicrm/CRM/Contact/Form/GroupContact.php
Normal file
161
sites/all/modules/civicrm/CRM/Contact/Form/GroupContact.php
Normal file
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for groupContact.
|
||||
*/
|
||||
class CRM_Contact_Form_GroupContact extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The groupContact id, used when editing the groupContact
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_groupContactId;
|
||||
|
||||
/**
|
||||
* The contact id, used when add/edit groupContact
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_contactId;
|
||||
|
||||
/**
|
||||
* Explicitly declare the entity api name.
|
||||
*/
|
||||
public function getDefaultEntity() {
|
||||
return 'GroupContact';
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly declare the form context.
|
||||
*/
|
||||
public function getDefaultContext() {
|
||||
return 'create';
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre process form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_contactId = $this->get('contactId');
|
||||
$this->_groupContactId = $this->get('groupContactId');
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
// get the list of all the groups
|
||||
if ($this->_context == 'user') {
|
||||
$onlyPublicGroups = CRM_Utils_Request::retrieve('onlyPublicGroups', 'Boolean', $this, FALSE);
|
||||
$ids = CRM_Core_PseudoConstant::allGroup();
|
||||
$heirGroups = CRM_Contact_BAO_Group::getGroupsHierarchy($ids);
|
||||
|
||||
$allGroups = array();
|
||||
foreach ($heirGroups as $id => $group) {
|
||||
// make sure that this group has public visibility
|
||||
if ($onlyPublicGroups && $group['visibility'] == 'User and User Admin Only') {
|
||||
continue;
|
||||
}
|
||||
$allGroups[$id] = $group;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$allGroups = CRM_Core_PseudoConstant::group();
|
||||
}
|
||||
|
||||
// Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title)
|
||||
$groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($allGroups, NULL, ' ', TRUE);
|
||||
|
||||
// get the list of groups contact is currently in ("Added") or unsubscribed ("Removed").
|
||||
$currentGroups = CRM_Contact_BAO_GroupContact::getGroupList($this->_contactId);
|
||||
|
||||
// Remove current groups from drowdown options ($groupSelect)
|
||||
if (is_array($currentGroups)) {
|
||||
// Compare array keys, since the array values (group title) in $groupList may have extra spaces for indenting child groups
|
||||
$groupSelect = array_diff_key($groupHierarchy, $currentGroups);
|
||||
}
|
||||
else {
|
||||
$groupSelect = $groupHierarchy;
|
||||
}
|
||||
|
||||
$groupSelect = array('' => ts('- select group -')) + $groupSelect;
|
||||
|
||||
if (count($groupSelect) > 1) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
// user dashboard
|
||||
if (strstr($session->readUserContext(), 'user')) {
|
||||
$msg = ts('Join a Group');
|
||||
}
|
||||
else {
|
||||
$msg = ts('Add to a group');
|
||||
}
|
||||
|
||||
$this->addField('group_id', array('class' => 'crm-action-menu fa-plus', 'placeholder' => $msg, 'options' => $groupSelect));
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Add'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Post process form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$contactID = array($this->_contactId);
|
||||
$groupId = $this->controller->exportValue('GroupContact', 'group_id');
|
||||
$method = ($this->_context == 'user') ? 'Web' : 'Admin';
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$userID = $session->get('userID');
|
||||
|
||||
if ($userID == $this->_contactId) {
|
||||
$method = 'Web';
|
||||
}
|
||||
$groupContact = CRM_Contact_BAO_GroupContact::addContactsToGroup($contactID, $groupId, $method);
|
||||
|
||||
if ($groupContact && $this->_context != 'user') {
|
||||
$groups = CRM_Core_PseudoConstant::group();
|
||||
CRM_Core_Session::setStatus(ts("Contact has been added to '%1'.", array(1 => $groups[$groupId])), ts('Added to Group'), 'success');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
185
sites/all/modules/civicrm/CRM/Contact/Form/Inline.php
Normal file
185
sites/all/modules/civicrm/CRM/Contact/Form/Inline.php
Normal file
|
@ -0,0 +1,185 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parent class for inline contact forms.
|
||||
*/
|
||||
abstract class CRM_Contact_Form_Inline extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* Id of the contact that is being edited
|
||||
*/
|
||||
public $_contactId;
|
||||
|
||||
/**
|
||||
* Type of contact being edited
|
||||
*/
|
||||
public $_contactType;
|
||||
|
||||
/**
|
||||
* Sub type of contact being edited
|
||||
*/
|
||||
public $_contactSubType;
|
||||
|
||||
/**
|
||||
* Explicitly declare the form context.
|
||||
*/
|
||||
public function getDefaultContext() {
|
||||
return 'create';
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly declare the entity api name.
|
||||
*/
|
||||
public function getDefaultEntity() {
|
||||
return 'Contact';
|
||||
}
|
||||
|
||||
/**
|
||||
* Common preprocess: fetch contact ID and contact type
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE, NULL, $_REQUEST);
|
||||
$this->assign('contactId', $this->_contactId);
|
||||
|
||||
// get contact type and subtype
|
||||
if (empty($this->_contactType)) {
|
||||
$contactTypeInfo = CRM_Contact_BAO_Contact::getContactTypes($this->_contactId);
|
||||
$this->_contactType = $contactTypeInfo[0];
|
||||
|
||||
// check if subtype is set
|
||||
if (isset($contactTypeInfo[1])) {
|
||||
// unset contact type which is 0th element
|
||||
unset($contactTypeInfo[0]);
|
||||
$this->_contactSubType = $contactTypeInfo;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('contactType', $this->_contactType);
|
||||
|
||||
$this->setAction(CRM_Core_Action::UPDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common form elements.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
CRM_Contact_Form_Inline_Lock::buildQuickForm($this, $this->_contactId);
|
||||
|
||||
$buttons = array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
);
|
||||
$this->addButtons($buttons);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override default cancel action.
|
||||
*/
|
||||
public function cancelAction() {
|
||||
$response = array('status' => 'cancel');
|
||||
CRM_Utils_JSON::output($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = $params = array();
|
||||
$params['id'] = $this->_contactId;
|
||||
|
||||
CRM_Contact_BAO_Contact::getValues($params, $defaults);
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add entry to log table.
|
||||
*/
|
||||
protected function log() {
|
||||
CRM_Core_BAO_Log::register($this->_contactId,
|
||||
'civicrm_contact',
|
||||
$this->_contactId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common function for all inline contact edit forms.
|
||||
*
|
||||
* Prepares ajaxResponse
|
||||
*/
|
||||
protected function response() {
|
||||
$this->ajaxResponse = array_merge(
|
||||
self::renderFooter($this->_contactId),
|
||||
$this->ajaxResponse,
|
||||
CRM_Contact_Form_Inline_Lock::getResponse($this->_contactId)
|
||||
);
|
||||
// Note: Post hooks will be called by CRM_Core_Form::mainProcess
|
||||
}
|
||||
|
||||
/**
|
||||
* Render change log footer markup for a contact and supply count.
|
||||
*
|
||||
* Needed for refreshing the contact summary screen
|
||||
*
|
||||
* @param int $cid
|
||||
* @param bool $includeCount
|
||||
* @return array
|
||||
*/
|
||||
public static function renderFooter($cid, $includeCount = TRUE) {
|
||||
// Load change log footer from template.
|
||||
$smarty = CRM_Core_Smarty::singleton();
|
||||
$smarty->assign('contactId', $cid);
|
||||
$smarty->assign('external_identifier', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'external_identifier'));
|
||||
$smarty->assign('lastModified', CRM_Core_BAO_Log::lastModified($cid, 'civicrm_contact'));
|
||||
$viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'contact_view_options', TRUE
|
||||
);
|
||||
$smarty->assign('changeLog', $viewOptions['log']);
|
||||
$ret = array('markup' => $smarty->fetch('CRM/common/contactFooter.tpl'));
|
||||
if ($includeCount) {
|
||||
$ret['count'] = CRM_Contact_BAO_Contact::getCountComponent('log', $cid);
|
||||
}
|
||||
return array('changeLog' => $ret);
|
||||
}
|
||||
|
||||
}
|
190
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Address.php
Normal file
190
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Address.php
Normal file
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for address section.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_Address extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Location block no
|
||||
*/
|
||||
private $_locBlockNo;
|
||||
|
||||
/**
|
||||
* Do we want to parse street address.
|
||||
*/
|
||||
public $_parseStreetAddress;
|
||||
|
||||
/**
|
||||
* Store address values
|
||||
*/
|
||||
public $_values;
|
||||
|
||||
/**
|
||||
* Form action
|
||||
*/
|
||||
public $_action;
|
||||
|
||||
/**
|
||||
* Address id
|
||||
*/
|
||||
public $_addressId;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* Since we are using same class / code to generate multiple instances
|
||||
* of address block, we need to generate unique form name for each,
|
||||
* hence calling parent constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$locBlockNo = CRM_Utils_Request::retrieve('locno', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
|
||||
$name = "Address_{$locBlockNo}";
|
||||
|
||||
parent::__construct(NULL, CRM_Core_Action::NONE, 'post', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call preprocess.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
$this->_locBlockNo = CRM_Utils_Request::retrieve('locno', 'Positive', $this, TRUE, NULL, $_REQUEST);
|
||||
$this->assign('blockId', $this->_locBlockNo);
|
||||
|
||||
$addressSequence = CRM_Core_BAO_Address::addressSequence();
|
||||
$this->assign('addressSequence', $addressSequence);
|
||||
|
||||
$this->_values = array();
|
||||
$this->_addressId = CRM_Utils_Request::retrieve('aid', 'Positive', $this, FALSE, NULL, $_REQUEST);
|
||||
|
||||
$this->_action = CRM_Core_Action::ADD;
|
||||
if ($this->_addressId) {
|
||||
$params = array('id' => $this->_addressId);
|
||||
$address = CRM_Core_BAO_Address::getValues($params, FALSE, 'id');
|
||||
$this->_values['address'][$this->_locBlockNo] = array_pop($address);
|
||||
$this->_action = CRM_Core_Action::UPDATE;
|
||||
}
|
||||
else {
|
||||
$this->_addressId = 0;
|
||||
}
|
||||
|
||||
$this->assign('action', $this->_action);
|
||||
$this->assign('addressId', $this->_addressId);
|
||||
|
||||
// parse street address, CRM-5450
|
||||
$this->_parseStreetAddress = $this->get('parseStreetAddress');
|
||||
if (!isset($this->_parseStreetAddress)) {
|
||||
$addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'address_options'
|
||||
);
|
||||
$this->_parseStreetAddress = FALSE;
|
||||
if (!empty($addressOptions['street_address']) && !empty($addressOptions['street_address_parsing'])) {
|
||||
$this->_parseStreetAddress = TRUE;
|
||||
}
|
||||
$this->set('parseStreetAddress', $this->_parseStreetAddress);
|
||||
}
|
||||
$this->assign('parseStreetAddress', $this->_parseStreetAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for an address object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
CRM_Contact_Form_Edit_Address::buildQuickForm($this, $this->_locBlockNo, TRUE, TRUE);
|
||||
$this->addFormRule(array('CRM_Contact_Form_Edit_Address', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = $this->_values;
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
//set address block defaults
|
||||
if (!empty($defaults['address'])) {
|
||||
CRM_Contact_Form_Edit_Address::setDefaultValues($defaults, $this);
|
||||
}
|
||||
else {
|
||||
// get the default location type
|
||||
$locationType = CRM_Core_BAO_LocationType::getDefault();
|
||||
|
||||
if ($this->_locBlockNo == 1) {
|
||||
$address['is_primary'] = TRUE;
|
||||
$address['location_type_id'] = $locationType->id;
|
||||
}
|
||||
|
||||
$address['country_id'] = $config->defaultContactCountry;
|
||||
$address['state_province_id'] = $config->defaultContactStateProvince;
|
||||
$defaults['address'][$this->_locBlockNo] = $address;
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save address
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
$params['updateBlankLocInfo'] = TRUE;
|
||||
|
||||
// process shared contact address.
|
||||
CRM_Contact_BAO_Contact_Utils::processSharedAddress($params['address']);
|
||||
|
||||
if ($this->_parseStreetAddress) {
|
||||
CRM_Contact_Form_Contact::parseAddress($params);
|
||||
}
|
||||
|
||||
if ($this->_addressId > 0) {
|
||||
$params['address'][$this->_locBlockNo]['id'] = $this->_addressId;
|
||||
}
|
||||
|
||||
// save address changes
|
||||
$address = CRM_Core_BAO_Address::create($params, TRUE);
|
||||
|
||||
$this->log();
|
||||
$this->ajaxResponse['addressId'] = $address[0]->id;
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for communication preferences inline edit section.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_CommunicationPreferences extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Build the form object elements for communication preferences.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
CRM_Contact_Form_Edit_CommunicationPreferences::buildQuickForm($this);
|
||||
$this->addFormRule(array('CRM_Contact_Form_Edit_CommunicationPreferences', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = parent::setDefaultValues();
|
||||
|
||||
if (!empty($defaults['preferred_language'])) {
|
||||
$languages = CRM_Contact_BAO_Contact::buildOptions('preferred_language');
|
||||
$defaults['preferred_language'] = CRM_Utils_Array::key($defaults['preferred_language'], $languages);
|
||||
}
|
||||
|
||||
// CRM-7119: set preferred_language to default if unset
|
||||
if (empty($defaults['preferred_language'])) {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$defaults['preferred_language'] = $config->lcMessages;
|
||||
}
|
||||
|
||||
// CRM-19135: where CRM_Core_BAO_Contact::getValues() set label as a default value instead of reserved 'value',
|
||||
// the code is to ensure we always set default to value instead of label
|
||||
if (!empty($defaults['preferred_mail_format'])) {
|
||||
$defaults['preferred_mail_format'] = array_search($defaults['preferred_mail_format'], CRM_Core_SelectValues::pmf());
|
||||
}
|
||||
|
||||
if (empty($defaults['communication_style_id'])) {
|
||||
$defaults['communication_style_id'] = array_pop(CRM_Core_OptionGroup::values('communication_style', TRUE, NULL, NULL, 'AND is_default = 1'));
|
||||
}
|
||||
|
||||
foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
|
||||
$name = "{$greeting}_display";
|
||||
$this->assign($name, CRM_Utils_Array::value($name, $defaults));
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save communication preferences
|
||||
|
||||
// this is a chekbox, so mark false if we dont get a POST value
|
||||
$params['is_opt_out'] = CRM_Utils_Array::value('is_opt_out', $params, FALSE);
|
||||
$params['contact_type'] = $this->_contactType;
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
|
||||
if (!empty($this->_contactSubType)) {
|
||||
$params['contact_sub_type'] = $this->_contactSubType;
|
||||
}
|
||||
|
||||
if (!isset($params['preferred_communication_method'])) {
|
||||
$params['preferred_communication_method'] = 'null';
|
||||
}
|
||||
CRM_Contact_BAO_Contact::create($params);
|
||||
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for contact info section.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_ContactInfo extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Build the form object elements.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
// Build contact type specific fields
|
||||
$class = 'CRM_Contact_Form_Edit_' . $this->_contactType;
|
||||
$class::buildQuickForm($this, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return parent::setDefaultValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save contact info
|
||||
$params['contact_type'] = $this->_contactType;
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
|
||||
if (!empty($this->_contactSubType)) {
|
||||
$params['contact_sub_type'] = $this->_contactSubType;
|
||||
}
|
||||
|
||||
CRM_Contact_BAO_Contact::create($params);
|
||||
|
||||
// Saving current employer affects relationship tab, and possibly related memberships and contributions
|
||||
$this->ajaxResponse['updateTabs'] = array(
|
||||
'#tab_rel' => CRM_Contact_BAO_Contact::getCountComponent('rel', $this->_contactId),
|
||||
);
|
||||
if (CRM_Core_Permission::access('CiviContribute')) {
|
||||
$this->ajaxResponse['updateTabs']['#tab_contribute'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId);
|
||||
}
|
||||
if (CRM_Core_Permission::access('CiviMember')) {
|
||||
$this->ajaxResponse['updateTabs']['#tab_member'] = CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId);
|
||||
}
|
||||
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for contact name section.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_ContactName extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Build the form object elements.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
// Build contact type specific fields
|
||||
$class = 'CRM_Contact_Form_Edit_' . $this->_contactType;
|
||||
$class::buildQuickForm($this, 1);
|
||||
$this->addFormRule(array('CRM_Contact_Form_Inline_ContactName', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
* @param array $errors
|
||||
* List of errors to be posted back to the form.
|
||||
* @param CRM_Contact_Form_Inline_ContactName $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($fields, $errors, $form) {
|
||||
if (empty($fields['first_name']) && empty($fields['last_name'])
|
||||
&& empty($fields['organization_name'])
|
||||
&& empty($fields['household_name'])) {
|
||||
$emails = civicrm_api3('Email', 'getcount', array('contact_id' => $form->_contactId));
|
||||
if (!$emails) {
|
||||
$errorField = $form->_contactType == 'Individual' ? 'last' : strtolower($form->_contactType);
|
||||
$errors[$errorField . '_name'] = ts('Contact with no email must have a name.');
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save contact info
|
||||
$params['contact_type'] = $this->_contactType;
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
|
||||
if (!empty($this->_contactSubType)) {
|
||||
$params['contact_sub_type'] = $this->_contactSubType;
|
||||
}
|
||||
|
||||
CRM_Contact_BAO_Contact::create($params);
|
||||
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
105
sites/all/modules/civicrm/CRM/Contact/Form/Inline/CustomData.php
Normal file
105
sites/all/modules/civicrm/CRM/Contact/Form/Inline/CustomData.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for custom data section.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_CustomData extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Custom group id.
|
||||
*
|
||||
* @int
|
||||
*/
|
||||
public $_groupID;
|
||||
|
||||
/**
|
||||
* Entity type of the table id.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_entityType;
|
||||
|
||||
/**
|
||||
* Call preprocess.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
$this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE, NULL, $_REQUEST);
|
||||
$this->assign('customGroupId', $this->_groupID);
|
||||
$customRecId = CRM_Utils_Request::retrieve('customRecId', 'Positive', $this, FALSE, 1, $_REQUEST);
|
||||
$cgcount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $this, FALSE, 1, $_REQUEST);
|
||||
$subType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ',');
|
||||
CRM_Custom_Form_CustomData::preProcess($this, NULL, $subType, $cgcount,
|
||||
$this->_contactType, $this->_contactId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for custom data.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
CRM_Custom_Form_CustomData::buildQuickForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return CRM_Custom_Form_CustomData::setDefaultValues($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// Process / save custom data
|
||||
// Get the form values and groupTree
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
CRM_Core_BAO_CustomValueTable::postProcess($params,
|
||||
'civicrm_contact',
|
||||
$this->_contactId,
|
||||
$this->_entityType
|
||||
);
|
||||
|
||||
$this->log();
|
||||
|
||||
CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
|
||||
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for demographics section.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_Demographics extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Build the form object elements.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
CRM_Contact_Form_Edit_Demographics::buildQuickForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save demographics
|
||||
if (empty($params['is_deceased'])) {
|
||||
$params['is_deceased'] = FALSE;
|
||||
$params['deceased_date'] = NULL;
|
||||
}
|
||||
|
||||
$params['contact_type'] = 'Individual';
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
|
||||
if (!empty($this->_contactSubType)) {
|
||||
$params['contact_sub_type'] = $this->_contactSubType;
|
||||
}
|
||||
|
||||
CRM_Contact_BAO_Contact::create($params);
|
||||
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
204
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Email.php
Normal file
204
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Email.php
Normal file
|
@ -0,0 +1,204 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an Email object.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_Email extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Email addresses of the contact that is been viewed.
|
||||
*/
|
||||
private $_emails = array();
|
||||
|
||||
/**
|
||||
* No of email blocks for inline edit.
|
||||
*/
|
||||
private $_blockCount = 6;
|
||||
|
||||
/**
|
||||
* Whether this contact has a first/last/organization/household name
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $contactHasName;
|
||||
|
||||
/**
|
||||
* Call preprocess.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
//get all the existing email addresses
|
||||
$email = new CRM_Core_BAO_Email();
|
||||
$email->contact_id = $this->_contactId;
|
||||
|
||||
$this->_emails = CRM_Core_BAO_Block::retrieveBlock($email, NULL);
|
||||
|
||||
// Check if this contact has a first/last/organization/household name
|
||||
if ($this->_contactType == 'Individual') {
|
||||
$this->contactHasName = (bool) (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'last_name')
|
||||
|| CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'first_name'));
|
||||
}
|
||||
else {
|
||||
$this->contactHasName = (bool) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, strtolower($this->_contactType) . '_name');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for an email object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
$totalBlocks = $this->_blockCount;
|
||||
$actualBlockCount = 1;
|
||||
if (count($this->_emails) > 1) {
|
||||
$actualBlockCount = $totalBlocks = count($this->_emails);
|
||||
if ($totalBlocks < $this->_blockCount) {
|
||||
$additionalBlocks = $this->_blockCount - $totalBlocks;
|
||||
$totalBlocks += $additionalBlocks;
|
||||
}
|
||||
else {
|
||||
$actualBlockCount++;
|
||||
$totalBlocks++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('actualBlockCount', $actualBlockCount);
|
||||
$this->assign('totalBlocks', $totalBlocks);
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
for ($blockId = 1; $blockId < $totalBlocks; $blockId++) {
|
||||
CRM_Contact_Form_Edit_Email::buildQuickForm($this, $blockId, TRUE);
|
||||
}
|
||||
|
||||
$this->addFormRule(array('CRM_Contact_Form_Inline_Email', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
* @param array $errors
|
||||
* List of errors to be posted back to the form.
|
||||
* @param CRM_Contact_Form_Inline_Email $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($fields, $errors, $form) {
|
||||
$hasData = $hasPrimary = $errors = array();
|
||||
if (!empty($fields['email']) && is_array($fields['email'])) {
|
||||
foreach ($fields['email'] as $instance => $blockValues) {
|
||||
$dataExists = CRM_Contact_Form_Contact::blockDataExists($blockValues);
|
||||
|
||||
if ($dataExists) {
|
||||
$hasData[] = $instance;
|
||||
if (!empty($blockValues['is_primary'])) {
|
||||
$hasPrimary[] = $instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($hasPrimary) && !empty($hasData)) {
|
||||
$errors["email[1][is_primary]"] = ts('One email should be marked as primary.');
|
||||
}
|
||||
|
||||
if (count($hasPrimary) > 1) {
|
||||
$errors["email[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one email can be marked as primary.');
|
||||
}
|
||||
}
|
||||
if (!$hasData && !$form->contactHasName) {
|
||||
$errors["email[1][email]"] = ts('Contact with no name must have an email.');
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (!empty($this->_emails)) {
|
||||
foreach ($this->_emails as $id => $value) {
|
||||
$defaults['email'][$id] = $value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// get the default location type
|
||||
$locationType = CRM_Core_BAO_LocationType::getDefault();
|
||||
$defaults['email'][1]['location_type_id'] = $locationType->id;
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save emails
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
$params['updateBlankLocInfo'] = TRUE;
|
||||
$params['email']['isIdSet'] = TRUE;
|
||||
foreach ($this->_emails as $count => $value) {
|
||||
if (!empty($value['id']) && isset($params['email'][$count])) {
|
||||
$params['email'][$count]['id'] = $value['id'];
|
||||
}
|
||||
}
|
||||
CRM_Core_BAO_Block::create('email', $params);
|
||||
|
||||
// If contact has no name, set primary email as display name
|
||||
// TODO: This should be handled in the BAO for the benefit of the api, etc.
|
||||
if (!$this->contactHasName) {
|
||||
foreach ($params['email'] as $email) {
|
||||
if ($email['is_primary']) {
|
||||
CRM_Core_DAO::setFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'display_name', $email['email']);
|
||||
CRM_Core_DAO::setFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'sort_name', $email['email']);
|
||||
$this->ajaxResponse['reloadBlocks'] = array('#crm-contactname-content');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->log();
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
173
sites/all/modules/civicrm/CRM/Contact/Form/Inline/IM.php
Normal file
173
sites/all/modules/civicrm/CRM/Contact/Form/Inline/IM.php
Normal file
|
@ -0,0 +1,173 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an IM object.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_IM extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Ims of the contact that is been viewed.
|
||||
*/
|
||||
private $_ims = array();
|
||||
|
||||
/**
|
||||
* No of im blocks for inline edit.
|
||||
*/
|
||||
private $_blockCount = 6;
|
||||
|
||||
/**
|
||||
* Call preprocess.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
//get all the existing ims
|
||||
$im = new CRM_Core_BAO_IM();
|
||||
$im->contact_id = $this->_contactId;
|
||||
|
||||
$this->_ims = CRM_Core_BAO_Block::retrieveBlock($im, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for im object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
$totalBlocks = $this->_blockCount;
|
||||
$actualBlockCount = 1;
|
||||
if (count($this->_ims) > 1) {
|
||||
$actualBlockCount = $totalBlocks = count($this->_ims);
|
||||
if ($totalBlocks < $this->_blockCount) {
|
||||
$additionalBlocks = $this->_blockCount - $totalBlocks;
|
||||
$totalBlocks += $additionalBlocks;
|
||||
}
|
||||
else {
|
||||
$actualBlockCount++;
|
||||
$totalBlocks++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('actualBlockCount', $actualBlockCount);
|
||||
$this->assign('totalBlocks', $totalBlocks);
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
for ($blockId = 1; $blockId < $totalBlocks; $blockId++) {
|
||||
CRM_Contact_Form_Edit_IM::buildQuickForm($this, $blockId, TRUE);
|
||||
}
|
||||
|
||||
$this->addFormRule(array('CRM_Contact_Form_Inline_IM', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
* @param array $errors
|
||||
* List of errors to be posted back to the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($fields, $errors) {
|
||||
$hasData = $hasPrimary = $errors = array();
|
||||
if (!empty($fields['im']) && is_array($fields['im'])) {
|
||||
foreach ($fields['im'] as $instance => $blockValues) {
|
||||
$dataExists = CRM_Contact_Form_Contact::blockDataExists($blockValues);
|
||||
|
||||
if ($dataExists) {
|
||||
$hasData[] = $instance;
|
||||
if (!empty($blockValues['is_primary'])) {
|
||||
$hasPrimary[] = $instance;
|
||||
if (!$primaryID && !empty($blockValues['im'])) {
|
||||
$primaryID = $blockValues['im'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($hasPrimary) && !empty($hasData)) {
|
||||
$errors["im[1][is_primary]"] = ts('One IM should be marked as primary.');
|
||||
}
|
||||
|
||||
if (count($hasPrimary) > 1) {
|
||||
$errors["im[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one IM can be marked as primary.');
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (!empty($this->_ims)) {
|
||||
foreach ($this->_ims as $id => $value) {
|
||||
$defaults['im'][$id] = $value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// get the default location type
|
||||
$locationType = CRM_Core_BAO_LocationType::getDefault();
|
||||
$defaults['im'][1]['location_type_id'] = $locationType->id;
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save IMs
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
$params['updateBlankLocInfo'] = TRUE;
|
||||
$params['im']['isIdSet'] = TRUE;
|
||||
foreach ($this->_ims as $count => $value) {
|
||||
if (!empty($value['id']) && isset($params['im'][$count])) {
|
||||
$params['im'][$count]['id'] = $value['id'];
|
||||
}
|
||||
}
|
||||
CRM_Core_BAO_Block::create('im', $params);
|
||||
|
||||
$this->log();
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
99
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Lock.php
Normal file
99
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Lock.php
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auxiliary class to provide support for locking (and ignoring locks on) contact records.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_Lock {
|
||||
|
||||
/**
|
||||
* This function provides the HTML form elements.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Form object.
|
||||
* @param int $contactID
|
||||
*/
|
||||
public static function buildQuickForm(&$form, $contactID) {
|
||||
// We provide a value for oplock_ts to client, but JS uses it carefully
|
||||
// -- i.e. when loading the first inline form, JS copies oplock_ts to a
|
||||
// global value, and that global value is used for future form submissions.
|
||||
// Any time a form is submitted, the value will be updated. This
|
||||
// handles cases like:
|
||||
// - V1:open V1.phone:open V1.email:open V1.email:submit V1.phone:submit
|
||||
// - V1:open E1:open E1:submit V1.email:open V1.email:submit
|
||||
// - V1:open V1.email:open E1:open E1:submit V1.email:submit V1:lock
|
||||
$timestamps = CRM_Contact_BAO_Contact::getTimestamps($contactID);
|
||||
$form->addElement('hidden', 'oplock_ts', $timestamps['modified_date'], array('id' => 'oplock_ts'));
|
||||
$form->addFormRule(array('CRM_Contact_Form_Inline_Lock', 'formRule'), $contactID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that oplock_ts hasn't changed in the underlying DB.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param int $contactID
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $contactID = NULL) {
|
||||
$errors = array();
|
||||
|
||||
$timestamps = CRM_Contact_BAO_Contact::getTimestamps($contactID);
|
||||
if ($fields['oplock_ts'] != $timestamps['modified_date']) {
|
||||
// Inline buttons generated via JS
|
||||
$open = sprintf("<div class='update_oplock_ts' data:update_oplock_ts='%s'>", $timestamps['modified_date']);
|
||||
$close = "</div>";
|
||||
$errors['oplock_ts'] = $open . ts('This record was modified by another user!') . $close;
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return any post-save data.
|
||||
*
|
||||
* @param int $contactID
|
||||
*
|
||||
* @return array
|
||||
* extra options to return in JSON
|
||||
*/
|
||||
public static function getResponse($contactID) {
|
||||
$timestamps = CRM_Contact_BAO_Contact::getTimestamps($contactID);
|
||||
return array('oplock_ts' => $timestamps['modified_date']);
|
||||
}
|
||||
|
||||
}
|
173
sites/all/modules/civicrm/CRM/Contact/Form/Inline/OpenID.php
Normal file
173
sites/all/modules/civicrm/CRM/Contact/Form/Inline/OpenID.php
Normal file
|
@ -0,0 +1,173 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an OpenID object.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_OpenID extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Ims of the contact that is been viewed.
|
||||
*/
|
||||
private $_openids = array();
|
||||
|
||||
/**
|
||||
* No of openid blocks for inline edit.
|
||||
*/
|
||||
private $_blockCount = 6;
|
||||
|
||||
/**
|
||||
* Call preprocess.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
//get all the existing openids
|
||||
$openid = new CRM_Core_BAO_OpenID();
|
||||
$openid->contact_id = $this->_contactId;
|
||||
|
||||
$this->_openids = CRM_Core_BAO_Block::retrieveBlock($openid, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for openID object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
$totalBlocks = $this->_blockCount;
|
||||
$actualBlockCount = 1;
|
||||
if (count($this->_openids) > 1) {
|
||||
$actualBlockCount = $totalBlocks = count($this->_openids);
|
||||
if ($totalBlocks < $this->_blockCount) {
|
||||
$additionalBlocks = $this->_blockCount - $totalBlocks;
|
||||
$totalBlocks += $additionalBlocks;
|
||||
}
|
||||
else {
|
||||
$actualBlockCount++;
|
||||
$totalBlocks++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('actualBlockCount', $actualBlockCount);
|
||||
$this->assign('totalBlocks', $totalBlocks);
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
for ($blockId = 1; $blockId < $totalBlocks; $blockId++) {
|
||||
CRM_Contact_Form_Edit_OpenID::buildQuickForm($this, $blockId, TRUE);
|
||||
}
|
||||
|
||||
$this->addFormRule(array('CRM_Contact_Form_Inline_OpenID', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
* @param array $errors
|
||||
* List of errors to be posted back to the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($fields, $errors) {
|
||||
$hasData = $hasPrimary = $errors = array();
|
||||
if (!empty($fields['openid']) && is_array($fields['openid'])) {
|
||||
foreach ($fields['openid'] as $instance => $blockValues) {
|
||||
$dataExists = CRM_Contact_Form_Contact::blockDataExists($blockValues);
|
||||
|
||||
if ($dataExists) {
|
||||
$hasData[] = $instance;
|
||||
if (!empty($blockValues['is_primary'])) {
|
||||
$hasPrimary[] = $instance;
|
||||
if (!$primaryID && !empty($blockValues['openid'])) {
|
||||
$primaryID = $blockValues['openid'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($hasPrimary) && !empty($hasData)) {
|
||||
$errors["openid[1][is_primary]"] = ts('One OpenID should be marked as primary.');
|
||||
}
|
||||
|
||||
if (count($hasPrimary) > 1) {
|
||||
$errors["openid[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one OpenID can be marked as primary.');
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (!empty($this->_openids)) {
|
||||
foreach ($this->_openids as $id => $value) {
|
||||
$defaults['openid'][$id] = $value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// get the default location type
|
||||
$locationType = CRM_Core_BAO_LocationType::getDefault();
|
||||
$defaults['openid'][1]['location_type_id'] = $locationType->id;
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save openID
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
$params['updateBlankLocInfo'] = TRUE;
|
||||
$params['openid']['isIdSet'] = TRUE;
|
||||
foreach ($this->_openids as $count => $value) {
|
||||
if (!empty($value['id']) && isset($params['openid'][$count])) {
|
||||
$params['openid'][$count]['id'] = $value['id'];
|
||||
}
|
||||
}
|
||||
CRM_Core_BAO_Block::create('openid', $params);
|
||||
|
||||
$this->log();
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
174
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Phone.php
Normal file
174
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Phone.php
Normal file
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an Phone object.
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_Phone extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Phones of the contact that is been viewed
|
||||
*/
|
||||
private $_phones = array();
|
||||
|
||||
/**
|
||||
* No of phone blocks for inline edit
|
||||
*/
|
||||
private $_blockCount = 6;
|
||||
|
||||
/**
|
||||
* Call preprocess.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
//get all the existing phones
|
||||
$phone = new CRM_Core_BAO_Phone();
|
||||
$phone->contact_id = $this->_contactId;
|
||||
|
||||
$this->_phones = CRM_Core_BAO_Block::retrieveBlock($phone, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for phone object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
$totalBlocks = $this->_blockCount;
|
||||
$actualBlockCount = 1;
|
||||
if (count($this->_phones) > 1) {
|
||||
$actualBlockCount = $totalBlocks = count($this->_phones);
|
||||
if ($totalBlocks < $this->_blockCount) {
|
||||
$additionalBlocks = $this->_blockCount - $totalBlocks;
|
||||
$totalBlocks += $additionalBlocks;
|
||||
}
|
||||
else {
|
||||
$actualBlockCount++;
|
||||
$totalBlocks++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('actualBlockCount', $actualBlockCount);
|
||||
$this->assign('totalBlocks', $totalBlocks);
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
for ($blockId = 1; $blockId < $totalBlocks; $blockId++) {
|
||||
CRM_Contact_Form_Edit_Phone::buildQuickForm($this, $blockId, TRUE);
|
||||
}
|
||||
|
||||
$this->addFormRule(array('CRM_Contact_Form_Inline_Phone', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
* @param array $errors
|
||||
* List of errors to be posted back to the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($fields, $errors) {
|
||||
$hasData = $hasPrimary = $errors = array();
|
||||
if (!empty($fields['phone']) && is_array($fields['phone'])) {
|
||||
$primaryID = NULL;
|
||||
foreach ($fields['phone'] as $instance => $blockValues) {
|
||||
$dataExists = CRM_Contact_Form_Contact::blockDataExists($blockValues);
|
||||
|
||||
if ($dataExists) {
|
||||
$hasData[] = $instance;
|
||||
if (!empty($blockValues['is_primary'])) {
|
||||
$hasPrimary[] = $instance;
|
||||
if (!$primaryID && !empty($blockValues['phone'])) {
|
||||
$primaryID = $blockValues['phone'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($hasPrimary) && !empty($hasData)) {
|
||||
$errors["phone[1][is_primary]"] = ts('One phone should be marked as primary.');
|
||||
}
|
||||
|
||||
if (count($hasPrimary) > 1) {
|
||||
$errors["phone[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one phone can be marked as primary.');
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (!empty($this->_phones)) {
|
||||
foreach ($this->_phones as $id => $value) {
|
||||
$defaults['phone'][$id] = $value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// get the default location type
|
||||
$locationType = CRM_Core_BAO_LocationType::getDefault();
|
||||
$defaults['phone'][1]['location_type_id'] = $locationType->id;
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
// Process / save phones
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
$params['updateBlankLocInfo'] = TRUE;
|
||||
$params['phone']['isIdSet'] = TRUE;
|
||||
foreach ($this->_phones as $count => $value) {
|
||||
if (!empty($value['id']) && isset($params['phone'][$count])) {
|
||||
$params['phone'][$count]['id'] = $value['id'];
|
||||
}
|
||||
}
|
||||
CRM_Core_BAO_Block::create('phone', $params);
|
||||
|
||||
$this->log();
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
131
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Website.php
Normal file
131
sites/all/modules/civicrm/CRM/Contact/Form/Inline/Website.php
Normal file
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form helper class for an Website object,
|
||||
*/
|
||||
class CRM_Contact_Form_Inline_Website extends CRM_Contact_Form_Inline {
|
||||
|
||||
/**
|
||||
* Websitess of the contact that is been viewed.
|
||||
*/
|
||||
private $_websites = array();
|
||||
|
||||
/**
|
||||
* No of website blocks for inline edit.
|
||||
*/
|
||||
private $_blockCount = 6;
|
||||
|
||||
/**
|
||||
* Call preprocess.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
//get all the existing websites
|
||||
$params = array('contact_id' => $this->_contactId);
|
||||
$values = array();
|
||||
$this->_websites = CRM_Core_BAO_Website::getValues($params, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object elements for website object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
|
||||
$totalBlocks = $this->_blockCount;
|
||||
$actualBlockCount = 1;
|
||||
if (count($this->_websites) > 1) {
|
||||
$actualBlockCount = $totalBlocks = count($this->_websites);
|
||||
if ($totalBlocks < $this->_blockCount) {
|
||||
$additionalBlocks = $this->_blockCount - $totalBlocks;
|
||||
$totalBlocks += $additionalBlocks;
|
||||
}
|
||||
else {
|
||||
$actualBlockCount++;
|
||||
$totalBlocks++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('actualBlockCount', $actualBlockCount);
|
||||
$this->assign('totalBlocks', $totalBlocks);
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
for ($blockId = 1; $blockId < $totalBlocks; $blockId++) {
|
||||
CRM_Contact_Form_Edit_Website::buildQuickForm($this, $blockId, TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (!empty($this->_websites)) {
|
||||
foreach ($this->_websites as $id => $value) {
|
||||
$defaults['website'][$id] = $value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// set the default website type
|
||||
$defaults['website'][1]['website_type_id'] = key(CRM_Core_OptionGroup::values('website_type',
|
||||
FALSE, FALSE, FALSE, ' AND is_default = 1'
|
||||
));
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
foreach ($this->_websites as $count => $value) {
|
||||
if (!empty($value['id']) && isset($params['website'][$count])) {
|
||||
$params['website'][$count]['id'] = $value['id'];
|
||||
}
|
||||
}
|
||||
// Process / save websites
|
||||
CRM_Core_BAO_Website::create($params['website'], $this->_contactId, TRUE);
|
||||
|
||||
$this->log();
|
||||
$this->response();
|
||||
}
|
||||
|
||||
}
|
117
sites/all/modules/civicrm/CRM/Contact/Form/Location.php
Normal file
117
sites/all/modules/civicrm/CRM/Contact/Form/Location.php
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Location {
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function preProcess(&$form) {
|
||||
$form->_addBlockName = CRM_Utils_Request::retrieve('block', 'String');
|
||||
$additionalblockCount = CRM_Utils_Request::retrieve('count', 'Positive');
|
||||
|
||||
$form->assign('addBlock', FALSE);
|
||||
if ($form->_addBlockName && $additionalblockCount) {
|
||||
$form->assign('addBlock', TRUE);
|
||||
$form->assign('blockName', $form->_addBlockName);
|
||||
$form->assign('blockId', $additionalblockCount);
|
||||
$form->set($form->_addBlockName . '_Block_Count', $additionalblockCount);
|
||||
}
|
||||
|
||||
if (is_a($form, 'CRM_Event_Form_ManageEvent_Location')
|
||||
|| is_a($form, 'CRM_Contact_Form_Domain')) {
|
||||
$form->_blocks = array(
|
||||
'Address' => ts('Address'),
|
||||
'Email' => ts('Email'),
|
||||
'Phone' => ts('Phone'),
|
||||
);
|
||||
}
|
||||
|
||||
$form->assign('blocks', $form->_blocks);
|
||||
$form->assign('className', CRM_Utils_System::getClassName($form));
|
||||
|
||||
// get address sequence.
|
||||
if (!$addressSequence = $form->get('addressSequence')) {
|
||||
$addressSequence = CRM_Core_BAO_Address::addressSequence();
|
||||
$form->set('addressSequence', $addressSequence);
|
||||
}
|
||||
$form->assign('addressSequence', $addressSequence);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
// required for subsequent AJAX requests.
|
||||
$ajaxRequestBlocks = array();
|
||||
$generateAjaxRequest = 0;
|
||||
|
||||
//build 1 instance of all blocks, without using ajax ...
|
||||
foreach ($form->_blocks as $blockName => $label) {
|
||||
require_once str_replace('_', DIRECTORY_SEPARATOR, 'CRM_Contact_Form_Edit_' . $blockName) . '.php';
|
||||
$name = strtolower($blockName);
|
||||
|
||||
$instances = array(1);
|
||||
if (!empty($_POST[$name]) && is_array($_POST[$name])) {
|
||||
$instances = array_keys($_POST[$name]);
|
||||
}
|
||||
elseif (property_exists($form, '_values') && !empty($form->_values[$name]) && is_array($form->_values[$name])) {
|
||||
$instances = array_keys($form->_values[$name]);
|
||||
}
|
||||
|
||||
foreach ($instances as $instance) {
|
||||
if ($instance == 1) {
|
||||
$form->assign('addBlock', FALSE);
|
||||
$form->assign('blockId', $instance);
|
||||
}
|
||||
else {
|
||||
//we are going to build other block instances w/ AJAX
|
||||
$generateAjaxRequest++;
|
||||
$ajaxRequestBlocks[$blockName][$instance] = TRUE;
|
||||
}
|
||||
|
||||
$form->set($blockName . '_Block_Count', $instance);
|
||||
$formName = 'CRM_Contact_Form_Edit_' . $blockName;
|
||||
$formName::buildQuickForm($form);
|
||||
}
|
||||
}
|
||||
|
||||
//assign to generate AJAX request for building extra blocks.
|
||||
$form->assign('generateAjaxRequest', $generateAjaxRequest);
|
||||
$form->assign('ajaxRequestBlocks', $ajaxRequestBlocks);
|
||||
}
|
||||
|
||||
}
|
366
sites/all/modules/civicrm/CRM/Contact/Form/Merge.php
Normal file
366
sites/all/modules/civicrm/CRM/Contact/Form/Merge.php
Normal file
|
@ -0,0 +1,366 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class CRM_Contact_Form_Merge.
|
||||
*/
|
||||
class CRM_Contact_Form_Merge extends CRM_Core_Form {
|
||||
// The id of the contact that there's a duplicate for; this one will
|
||||
// possibly inherit some of $_oid's properties and remain in the system.
|
||||
var $_cid = NULL;
|
||||
|
||||
// The id of the other contact - the duplicate one that will get deleted.
|
||||
var $_oid = NULL;
|
||||
|
||||
var $_contactType = NULL;
|
||||
|
||||
/**
|
||||
* Query limit to be retained in the urls.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $limit;
|
||||
|
||||
/**
|
||||
* String for quickform bug handling.
|
||||
*
|
||||
* FIXME: QuickForm can't create advcheckboxes with value set to 0 or '0' :(
|
||||
* see HTML_QuickForm_advcheckbox::setValues() - but patching that doesn't
|
||||
* help, as QF doesn't put the 0-value elements in exportValues() anyway...
|
||||
* to side-step this, we use the below UUID as a (re)placeholder
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_qfZeroBug = 'e8cddb72-a257-11dc-b9cc-0016d3330ee9';
|
||||
|
||||
public function preProcess() {
|
||||
try {
|
||||
|
||||
$this->_cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
|
||||
$this->_oid = CRM_Utils_Request::retrieve('oid', 'Positive', $this, TRUE);
|
||||
$flip = CRM_Utils_Request::retrieve('flip', 'Positive', $this, FALSE);
|
||||
|
||||
$this->_rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, FALSE);
|
||||
$this->_gid = $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE);
|
||||
$this->_mergeId = CRM_Utils_Request::retrieve('mergeId', 'Positive', $this, FALSE);
|
||||
$this->limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this, FALSE);
|
||||
$urlParams = "reset=1&rgid={$this->_rgid}&gid={$this->_gid}&limit=" . $this->limit;
|
||||
|
||||
$this->bounceIfInvalid($this->_cid, $this->_oid);
|
||||
|
||||
$this->_contactType = civicrm_api3('Contact', 'getvalue', array(
|
||||
'id' => $this->_cid,
|
||||
'return' => 'contact_type',
|
||||
));
|
||||
|
||||
$browseUrl = CRM_Utils_System::url('civicrm/contact/dedupefind', $urlParams . '&action=browse');
|
||||
|
||||
if (!$this->_rgid) {
|
||||
// Unset browse URL as we have come from the search screen.
|
||||
$browseUrl = '';
|
||||
$this->_rgid = civicrm_api3('RuleGroup', 'getvalue', array(
|
||||
'contact_type' => $this->_contactType,
|
||||
'used' => 'Supervised',
|
||||
'return' => 'id',
|
||||
));
|
||||
}
|
||||
$this->assign('browseUrl', $browseUrl);
|
||||
if ($browseUrl) {
|
||||
CRM_Core_Session::singleton()->pushUserContext($browseUrl);
|
||||
}
|
||||
|
||||
$cacheKey = CRM_Dedupe_Merger::getMergeCacheKeyString($this->_rgid, $gid);
|
||||
|
||||
$join = CRM_Dedupe_Merger::getJoinOnDedupeTable();
|
||||
$where = "de.id IS NULL";
|
||||
|
||||
$pos = CRM_Core_BAO_PrevNextCache::getPositions($cacheKey, $this->_cid, $this->_oid, $this->_mergeId, $join, $where, $flip);
|
||||
|
||||
// get user info of main contact.
|
||||
$config = CRM_Core_Config::singleton();
|
||||
CRM_Core_Config::setPermitCacheFlushMode(FALSE);
|
||||
|
||||
$mainUfId = CRM_Core_BAO_UFMatch::getUFId($this->_cid);
|
||||
$mainUser = NULL;
|
||||
if ($mainUfId) {
|
||||
// d6 compatible
|
||||
if ($config->userSystem->is_drupal == '1') {
|
||||
$mainUser = user_load($mainUfId);
|
||||
}
|
||||
elseif ($config->userFramework == 'Joomla') {
|
||||
$mainUser = JFactory::getUser($mainUfId);
|
||||
}
|
||||
|
||||
$this->assign('mainUfId', $mainUfId);
|
||||
$this->assign('mainUfName', $mainUser ? $mainUser->name : NULL);
|
||||
}
|
||||
|
||||
$flipUrl = CRM_Utils_System::url('civicrm/contact/merge',
|
||||
"reset=1&action=update&cid={$this->_oid}&oid={$this->_cid}&rgid={$this->_rgid}&gid={$gid}"
|
||||
);
|
||||
if (!$flip) {
|
||||
$flipUrl .= '&flip=1';
|
||||
}
|
||||
$this->assign('flip', $flipUrl);
|
||||
|
||||
$this->prev = $this->next = NULL;
|
||||
foreach (array(
|
||||
'prev',
|
||||
'next',
|
||||
) as $position) {
|
||||
if (!empty($pos[$position])) {
|
||||
if ($pos[$position]['id1'] && $pos[$position]['id2']) {
|
||||
$urlParams .= "&cid={$pos[$position]['id1']}&oid={$pos[$position]['id2']}&mergeId={$pos[$position]['mergeId']}&action=update";
|
||||
$this->$position = CRM_Utils_System::url('civicrm/contact/merge', $urlParams);
|
||||
$this->assign($position, $this->$position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get user info of other contact.
|
||||
$otherUfId = CRM_Core_BAO_UFMatch::getUFId($this->_oid);
|
||||
$otherUser = NULL;
|
||||
|
||||
if ($otherUfId) {
|
||||
// d6 compatible
|
||||
if ($config->userSystem->is_drupal == '1') {
|
||||
$otherUser = user_load($otherUfId);
|
||||
}
|
||||
elseif ($config->userFramework == 'Joomla') {
|
||||
$otherUser = JFactory::getUser($otherUfId);
|
||||
}
|
||||
|
||||
$this->assign('otherUfId', $otherUfId);
|
||||
$this->assign('otherUfName', $otherUser ? $otherUser->name : NULL);
|
||||
}
|
||||
|
||||
$cmsUser = ($mainUfId && $otherUfId) ? TRUE : FALSE;
|
||||
$this->assign('user', $cmsUser);
|
||||
|
||||
$rowsElementsAndInfo = CRM_Dedupe_Merger::getRowsElementsAndInfo($this->_cid, $this->_oid);
|
||||
$main = $this->_mainDetails = $rowsElementsAndInfo['main_details'];
|
||||
$other = $this->_otherDetails = $rowsElementsAndInfo['other_details'];
|
||||
|
||||
$this->assign('contact_type', $main['contact_type']);
|
||||
$this->assign('main_name', $main['display_name']);
|
||||
$this->assign('other_name', $other['display_name']);
|
||||
$this->assign('main_cid', $main['contact_id']);
|
||||
$this->assign('other_cid', $other['contact_id']);
|
||||
$this->assign('rgid', $this->_rgid);
|
||||
|
||||
$this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows'));
|
||||
|
||||
$this->assign('mainLocBlock', json_encode($rowsElementsAndInfo['main_details']['location_blocks']));
|
||||
$this->assign('locationBlockInfo', json_encode(CRM_Dedupe_Merger::getLocationBlockInfo()));
|
||||
$this->assign('rows', $rowsElementsAndInfo['rows']);
|
||||
|
||||
// add elements
|
||||
foreach ($rowsElementsAndInfo['elements'] as $element) {
|
||||
// We could push this down to the getRowsElementsAndInfo function but it's
|
||||
// already so overloaded - let's start moving towards doing form-things
|
||||
// on the form.
|
||||
if (substr($element[1], 0, 13) === 'move_location') {
|
||||
$element[4] = array_merge(
|
||||
(array) CRM_Utils_Array::value(4, $element, array()),
|
||||
array(
|
||||
'data-location' => substr($element[1], 14),
|
||||
'data-is_location' => TRUE,
|
||||
));
|
||||
}
|
||||
if (substr($element[1], 0, 15) === 'location_blocks') {
|
||||
// @todo We could add some data elements here to make jquery manipulation more straight-forward
|
||||
// @todo consider enabling if it is an add & defaulting to true.
|
||||
$element[4] = array_merge((array) CRM_Utils_Array::value(4, $element, array()), array('disabled' => TRUE));
|
||||
}
|
||||
$this->addElement($element[0],
|
||||
$element[1],
|
||||
array_key_exists('2', $element) ? $element[2] : NULL,
|
||||
array_key_exists('3', $element) ? $element[3] : NULL,
|
||||
array_key_exists('4', $element) ? $element[4] : NULL,
|
||||
array_key_exists('5', $element) ? $element[5] : NULL
|
||||
);
|
||||
}
|
||||
|
||||
// add related table elements
|
||||
foreach ($rowsElementsAndInfo['rel_table_elements'] as $relTableElement) {
|
||||
$element = $this->addElement($relTableElement[0], $relTableElement[1]);
|
||||
$element->setChecked(TRUE);
|
||||
}
|
||||
|
||||
$this->assign('rel_tables', $rowsElementsAndInfo['rel_tables']);
|
||||
$this->assign('userContextURL', CRM_Core_Session::singleton()
|
||||
->readUserContext());
|
||||
}
|
||||
catch (CRM_Core_Exception $e) {
|
||||
CRM_Core_Error::statusBounce(ts($e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public function addRules() {
|
||||
}
|
||||
|
||||
public function buildQuickForm() {
|
||||
CRM_Utils_System::setTitle(ts('Merge %1 contacts', array(1 => $this->_contactType)));
|
||||
$buttons = array();
|
||||
|
||||
$buttons[] = array(
|
||||
'type' => 'next',
|
||||
'name' => $this->next ? ts('Merge and go to Next Pair') : ts('Merge'),
|
||||
'isDefault' => TRUE,
|
||||
'icon' => $this->next ? 'circle-triangle-e' : 'check',
|
||||
);
|
||||
|
||||
if ($this->next || $this->prev) {
|
||||
$buttons[] = array(
|
||||
'type' => 'submit',
|
||||
'name' => ts('Merge and go to Listing'),
|
||||
);
|
||||
$buttons[] = array(
|
||||
'type' => 'done',
|
||||
'name' => ts('Merge and View Result'),
|
||||
'icon' => 'fa-check-circle',
|
||||
);
|
||||
}
|
||||
|
||||
$buttons[] = array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
);
|
||||
|
||||
$this->addButtons($buttons);
|
||||
$this->addFormRule(array('CRM_Contact_Form_Merge', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fields
|
||||
* @param $files
|
||||
* @param $self
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
$link = CRM_Utils_System::href(ts('Flip between the original and duplicate contacts.'),
|
||||
'civicrm/contact/merge',
|
||||
'reset=1&action=update&cid=' . $self->_oid . '&oid=' . $self->_cid . '&rgid=' . $self->_rgid . '&flip=1'
|
||||
);
|
||||
if (CRM_Contact_BAO_Contact::checkDomainContact($self->_oid)) {
|
||||
$errors['_qf_default'] = ts("The Default Organization contact cannot be merged into another contact record. It is associated with the CiviCRM installation for this domain and contains information used for system functions. If you want to merge these records, you can: %1", array(1 => $link));
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
public function postProcess() {
|
||||
$formValues = $this->exportValues();
|
||||
|
||||
$formValues['main_details'] = $this->_mainDetails;
|
||||
$formValues['other_details'] = $this->_otherDetails;
|
||||
$migrationData = array('migration_info' => $formValues);
|
||||
CRM_Utils_Hook::merge('form', $migrationData, $this->_cid, $this->_oid);
|
||||
CRM_Dedupe_Merger::moveAllBelongings($this->_cid, $this->_oid, $migrationData['migration_info']);
|
||||
|
||||
$name = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_cid, 'display_name');
|
||||
$message = '<ul><li>' . ts('%1 has been updated.', array(1 => $name)) . '</li><li>' . ts('Contact ID %1 has been deleted.', array(1 => $this->_oid)) . '</li></ul>';
|
||||
CRM_Core_Session::setStatus($message, ts('Contacts Merged'), 'success');
|
||||
|
||||
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_cid}");
|
||||
$urlParams = "reset=1&gid={$this->_gid}&rgid={$this->_rgid}&limit={$this->limit}";
|
||||
|
||||
if (!empty($formValues['_qf_Merge_submit'])) {
|
||||
$urlParams .= "&action=update";
|
||||
$lisitingURL = CRM_Utils_System::url('civicrm/contact/dedupefind',
|
||||
$urlParams
|
||||
);
|
||||
CRM_Utils_System::redirect($lisitingURL);
|
||||
}
|
||||
if (!empty($formValues['_qf_Merge_done'])) {
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
|
||||
if ($this->next && $this->_mergeId) {
|
||||
$cacheKey = CRM_Dedupe_Merger::getMergeCacheKeyString($this->_rgid, $this->_gid);
|
||||
|
||||
$join = CRM_Dedupe_Merger::getJoinOnDedupeTable();
|
||||
$where = "de.id IS NULL";
|
||||
|
||||
$pos = CRM_Core_BAO_PrevNextCache::getPositions($cacheKey, NULL, NULL, $this->_mergeId, $join, $where);
|
||||
|
||||
if (!empty($pos) &&
|
||||
$pos['next']['id1'] &&
|
||||
$pos['next']['id2']
|
||||
) {
|
||||
|
||||
$urlParams .= "&cid={$pos['next']['id1']}&oid={$pos['next']['id2']}&mergeId={$pos['next']['mergeId']}&action=update";
|
||||
$url = CRM_Utils_System::url('civicrm/contact/merge', $urlParams);
|
||||
}
|
||||
}
|
||||
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bounce if the merge action is invalid.
|
||||
*
|
||||
* We don't allow the merge if it is nonsensical, marked as a duplicate
|
||||
* or outside the user's permission.
|
||||
*
|
||||
* @param int $cid
|
||||
* Contact ID to retain
|
||||
* @param int $oid
|
||||
* Contact ID to delete.
|
||||
*/
|
||||
public function bounceIfInvalid($cid, $oid) {
|
||||
if ($cid == $oid) {
|
||||
CRM_Core_Error::statusBounce(ts('Cannot merge a contact with itself.'));
|
||||
}
|
||||
|
||||
if (!CRM_Dedupe_BAO_Rule::validateContacts($cid, $oid)) {
|
||||
CRM_Core_Error::statusBounce(ts('The selected pair of contacts are marked as non duplicates. If these records should be merged, you can remove this exception on the <a href="%1">Dedupe Exceptions</a> page.', array(1 => CRM_Utils_System::url('civicrm/dedupe/exception', 'reset=1'))));
|
||||
}
|
||||
|
||||
if (!(CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::EDIT) &&
|
||||
CRM_Contact_BAO_Contact_Permission::allow($oid, CRM_Core_Permission::EDIT)
|
||||
)
|
||||
) {
|
||||
CRM_Utils_System::permissionDenied();
|
||||
}
|
||||
// ensure that oid is not the current user, if so refuse to do the merge
|
||||
if (CRM_Core_Session::singleton()->getLoggedInContactID() == $oid) {
|
||||
$message = ts('The contact record which is linked to the currently logged in user account - \'%1\' - cannot be deleted.',
|
||||
array(1 => CRM_Core_Session::singleton()->getLoggedInContactDisplayName())
|
||||
);
|
||||
CRM_Core_Error::statusBounce($message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
190
sites/all/modules/civicrm/CRM/Contact/Form/RelatedContact.php
Normal file
190
sites/all/modules/civicrm/CRM/Contact/Form/RelatedContact.php
Normal file
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components generic to all the contact types.
|
||||
*
|
||||
* It delegates the work to lower level subclasses and integrates the changes
|
||||
* back in. It also uses a lot of functionality with the CRM API's, so any change
|
||||
* made here could potentially affect the API etc. Be careful, be aware, use unit tests.
|
||||
*/
|
||||
class CRM_Contact_Form_RelatedContact extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The contact type of the form.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_contactType;
|
||||
|
||||
/**
|
||||
* The contact id, used when editing the form
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_contactId;
|
||||
|
||||
/**
|
||||
* Explicitly declare the form context.
|
||||
*/
|
||||
public function getDefaultContext() {
|
||||
return 'create';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
// reset action from the session
|
||||
$this->_action = CRM_Utils_Request::retrieve('action', 'String',
|
||||
$this, FALSE, 'update'
|
||||
);
|
||||
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
|
||||
|
||||
$rcid = CRM_Utils_Request::retrieve('rcid', 'Positive', $this);
|
||||
$rcid = $rcid ? "&id={$rcid}" : '';
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->pushUserContext(CRM_Utils_System::url('civicrm/user', "reset=1{$rcid}"));
|
||||
|
||||
if ($this->_contactId) {
|
||||
$contact = new CRM_Contact_DAO_Contact();
|
||||
$contact->id = $this->_contactId;
|
||||
if (!$contact->find(TRUE)) {
|
||||
CRM_Core_Error::statusBounce(ts('contact does not exist: %1', array(1 => $this->_contactId)));
|
||||
}
|
||||
$this->_contactType = $contact->contact_type;
|
||||
|
||||
// check for permissions
|
||||
if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
|
||||
CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.'));
|
||||
}
|
||||
|
||||
list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId);
|
||||
CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName);
|
||||
}
|
||||
else {
|
||||
CRM_Core_Error::statusBounce(ts('Could not get a contact_id and/or contact_type'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* Note that in edit/view mode the default values are retrieved from the
|
||||
* database
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$params = array();
|
||||
$params['id'] = $params['contact_id'] = $this->_contactId;
|
||||
$contact = CRM_Contact_BAO_Contact::retrieve($params, $this->_defaults);
|
||||
|
||||
$countryID = '';
|
||||
$stateID = '';
|
||||
if (!empty($this->_defaults['address'][1])) {
|
||||
$countryID = CRM_Utils_Array::value('country_id',
|
||||
$this->_defaults['address'][1]
|
||||
);
|
||||
$stateID = CRM_Utils_Array::value('state_province_id',
|
||||
$this->_defaults['address'][1]
|
||||
);
|
||||
}
|
||||
CRM_Contact_BAO_Contact_Utils::buildOnBehalfForm($this,
|
||||
$this->_contactType,
|
||||
$countryID,
|
||||
$stateID,
|
||||
ts('Contact Information')
|
||||
);
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submission of new/edit contact is processed.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// store the submitted values in an array
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
$locType = CRM_Core_BAO_LocationType::getDefault();
|
||||
foreach (array(
|
||||
'phone',
|
||||
'email',
|
||||
'address',
|
||||
) as $locFld) {
|
||||
if (!empty($this->_defaults[$locFld]) && $this->_defaults[$locFld][1]['location_type_id']) {
|
||||
$params[$locFld][1]['is_primary'] = $this->_defaults[$locFld][1]['is_primary'];
|
||||
$params[$locFld][1]['location_type_id'] = $this->_defaults[$locFld][1]['location_type_id'];
|
||||
}
|
||||
else {
|
||||
$params[$locFld][1]['is_primary'] = 1;
|
||||
$params[$locFld][1]['location_type_id'] = $locType->id;
|
||||
}
|
||||
}
|
||||
|
||||
$params['contact_type'] = $this->_contactType;
|
||||
//CRM-14904
|
||||
if (isset($this->_defaults['contact_sub_type'])) {
|
||||
$params['contact_sub_type'] = $this->_defaults['contact_sub_type'];
|
||||
}
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
|
||||
$contact = CRM_Contact_BAO_Contact::create($params, TRUE);
|
||||
|
||||
// set status message.
|
||||
if ($this->_contactId) {
|
||||
$message = ts('%1 has been updated.', array(1 => $contact->display_name));
|
||||
}
|
||||
else {
|
||||
$message = ts('%1 has been created.', array(1 => $contact->display_name));
|
||||
}
|
||||
CRM_Core_Session::setStatus($message, ts('Contact Saved'), 'success');
|
||||
}
|
||||
|
||||
}
|
672
sites/all/modules/civicrm/CRM/Contact/Form/Relationship.php
Normal file
672
sites/all/modules/civicrm/CRM/Contact/Form/Relationship.php
Normal file
|
@ -0,0 +1,672 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for relationship.
|
||||
*/
|
||||
class CRM_Contact_Form_Relationship extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The relationship id, used when editing the relationship
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_relationshipId;
|
||||
|
||||
/**
|
||||
* The contact id, used when add/edit relationship
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_contactId;
|
||||
|
||||
/**
|
||||
* This is a string which is either a_b or b_a used to determine the relationship between to contacts
|
||||
*/
|
||||
public $_rtype;
|
||||
|
||||
/**
|
||||
* This is a string which is used to determine the relationship between to contacts
|
||||
*/
|
||||
public $_rtypeId;
|
||||
|
||||
/**
|
||||
* Display name of contact a
|
||||
*/
|
||||
public $_display_name_a;
|
||||
|
||||
/**
|
||||
* Display name of contact b
|
||||
*/
|
||||
public $_display_name_b;
|
||||
|
||||
/**
|
||||
* The relationship type id
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_relationshipTypeId;
|
||||
|
||||
/**
|
||||
* An array of all relationship names
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_allRelationshipNames;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $_enabled;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $_isCurrentEmployer;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $_contactType;
|
||||
|
||||
/**
|
||||
* The relationship values if Updating relationship
|
||||
*/
|
||||
public $_values;
|
||||
|
||||
/**
|
||||
* Case id if it called from case context
|
||||
*/
|
||||
public $_caseId;
|
||||
|
||||
/**
|
||||
* Explicitly declare the form context.
|
||||
*/
|
||||
public function getDefaultContext() {
|
||||
return 'create';
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly declare the entity api name.
|
||||
*/
|
||||
public function getDefaultEntity() {
|
||||
return 'Relationship';
|
||||
}
|
||||
|
||||
public function preProcess() {
|
||||
$this->_contactId = $this->get('contactId');
|
||||
|
||||
$this->_contactType = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'contact_type');
|
||||
|
||||
$this->_relationshipId = $this->get('id');
|
||||
|
||||
$this->_rtype = CRM_Utils_Request::retrieve('rtype', 'String', $this);
|
||||
|
||||
$this->_rtypeId = CRM_Utils_Request::retrieve('relTypeId', 'String', $this);
|
||||
|
||||
$this->_display_name_a = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'display_name');
|
||||
|
||||
$this->assign('display_name_a', $this->_display_name_a);
|
||||
//get the relationship values.
|
||||
$this->_values = array();
|
||||
if ($this->_relationshipId) {
|
||||
$params = array('id' => $this->_relationshipId);
|
||||
CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_Relationship', $params, $this->_values);
|
||||
}
|
||||
|
||||
// Check for permissions
|
||||
if (in_array($this->_action, array(CRM_Core_Action::ADD, CRM_Core_Action::UPDATE, CRM_Core_Action::DELETE))) {
|
||||
if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)
|
||||
&& !CRM_Contact_BAO_Contact_Permission::allow($this->_values['contact_id_b'], CRM_Core_Permission::EDIT)) {
|
||||
CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.'));
|
||||
}
|
||||
}
|
||||
|
||||
// Set page title based on action
|
||||
switch ($this->_action) {
|
||||
case CRM_Core_Action::VIEW:
|
||||
CRM_Utils_System::setTitle(ts('View Relationship for %1', array(1 => $this->_display_name_a)));
|
||||
break;
|
||||
|
||||
case CRM_Core_Action::ADD:
|
||||
CRM_Utils_System::setTitle(ts('Add Relationship for %1', array(1 => $this->_display_name_a)));
|
||||
break;
|
||||
|
||||
case CRM_Core_Action::UPDATE:
|
||||
CRM_Utils_System::setTitle(ts('Edit Relationship for %1', array(1 => $this->_display_name_a)));
|
||||
break;
|
||||
|
||||
case CRM_Core_Action::DELETE:
|
||||
CRM_Utils_System::setTitle(ts('Delete Relationship for %1', array(1 => $this->_display_name_a)));
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_caseId = CRM_Utils_Request::retrieve('caseID', 'Integer', $this);
|
||||
|
||||
if (!$this->_rtypeId) {
|
||||
$params = CRM_Utils_Request::exportValues();
|
||||
if (isset($params['relationship_type_id'])) {
|
||||
$this->_rtypeId = $params['relationship_type_id'];
|
||||
}
|
||||
elseif (!empty($this->_values)) {
|
||||
$this->_rtypeId = $this->_values['relationship_type_id'] . '_' . $this->_rtype;
|
||||
}
|
||||
}
|
||||
|
||||
//get the relationship type id
|
||||
$this->_relationshipTypeId = str_replace(array('_a_b', '_b_a'), array('', ''), $this->_rtypeId);
|
||||
|
||||
//get the relationship type
|
||||
if (!$this->_rtype) {
|
||||
$this->_rtype = str_replace($this->_relationshipTypeId . '_', '', $this->_rtypeId);
|
||||
}
|
||||
|
||||
//need to assign custom data type and subtype to the template - FIXME: explain why
|
||||
$this->assign('customDataType', 'Relationship');
|
||||
$this->assign('customDataSubType', $this->_relationshipTypeId);
|
||||
$this->assign('entityID', $this->_relationshipId);
|
||||
|
||||
//use name as it remain constant, CRM-3336
|
||||
$this->_allRelationshipNames = CRM_Core_PseudoConstant::relationshipType('name');
|
||||
|
||||
// Current employer?
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
if ($this->_allRelationshipNames[$this->_relationshipTypeId]["name_a_b"] == 'Employee of') {
|
||||
$this->_isCurrentEmployer = $this->_values['contact_id_b'] == CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_values['contact_id_a'], 'employer_id');
|
||||
}
|
||||
}
|
||||
|
||||
// when custom data is included in this page
|
||||
if (!empty($_POST['hidden_custom'])) {
|
||||
CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_relationshipTypeId, 1, 'Relationship', $this->_relationshipId);
|
||||
CRM_Custom_Form_CustomData::buildQuickForm($this);
|
||||
CRM_Custom_Form_CustomData::setDefaultValues($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
|
||||
$defaults = array();
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
if (!empty($this->_values)) {
|
||||
$defaults['relationship_type_id'] = $this->_rtypeId;
|
||||
if (!empty($this->_values['start_date'])) {
|
||||
list($defaults['start_date']) = CRM_Utils_Date::setDateDefaults($this->_values['start_date']);
|
||||
}
|
||||
if (!empty($this->_values['end_date'])) {
|
||||
list($defaults['end_date']) = CRM_Utils_Date::setDateDefaults($this->_values['end_date']);
|
||||
}
|
||||
$defaults['description'] = CRM_Utils_Array::value('description', $this->_values);
|
||||
$defaults['is_active'] = CRM_Utils_Array::value('is_active', $this->_values);
|
||||
|
||||
// The javascript on the form will swap these fields if it is a b_a relationship, so we compensate here
|
||||
$defaults['is_permission_a_b'] = CRM_Utils_Array::value('is_permission_' . $this->_rtype, $this->_values);
|
||||
$defaults['is_permission_b_a'] = CRM_Utils_Array::value('is_permission_' . strrev($this->_rtype), $this->_values);
|
||||
|
||||
$defaults['is_current_employer'] = $this->_isCurrentEmployer;
|
||||
|
||||
// Load info about the related contact
|
||||
$contact = new CRM_Contact_DAO_Contact();
|
||||
if ($this->_rtype == 'a_b' && $this->_values['contact_id_a'] == $this->_contactId) {
|
||||
$contact->id = $this->_values['contact_id_b'];
|
||||
}
|
||||
else {
|
||||
$contact->id = $this->_values['contact_id_a'];
|
||||
}
|
||||
if ($contact->find(TRUE)) {
|
||||
$defaults['related_contact_id'] = $contact->id;
|
||||
$this->_display_name_b = $contact->display_name;
|
||||
$this->assign('display_name_b', $this->_display_name_b);
|
||||
}
|
||||
|
||||
$noteParams = array(
|
||||
'entity_id' => $this->_relationshipId,
|
||||
'entity_table' => 'civicrm_relationship',
|
||||
'limit' => 1,
|
||||
'version' => 3,
|
||||
);
|
||||
$note = civicrm_api('Note', 'getsingle', $noteParams);
|
||||
$defaults['note'] = CRM_Utils_Array::value('note', $note);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$defaults['is_active'] = $defaults['is_current_employer'] = 1;
|
||||
$defaults['relationship_type_id'] = $this->_rtypeId;
|
||||
}
|
||||
|
||||
$this->_enabled = $defaults['is_active'];
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the rules for form.
|
||||
*/
|
||||
public function addRules() {
|
||||
|
||||
if (!($this->_action & CRM_Core_Action::DELETE)) {
|
||||
$this->addFormRule(array('CRM_Contact_Form_Relationship', 'dateRule'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Delete'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Select list
|
||||
$relationshipList = CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactId, $this->_rtype, $this->_relationshipId);
|
||||
|
||||
// Metadata needed on clientside
|
||||
$this->assign('relationshipData', self::getRelationshipTypeMetadata($relationshipList));
|
||||
|
||||
foreach ($this->_allRelationshipNames as $id => $vals) {
|
||||
if ($vals['name_a_b'] === 'Employee of') {
|
||||
$this->assign('employmentRelationship', $id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->addField('relationship_type_id', array('options' => array('' => ts('- select -')) + $relationshipList, 'class' => 'huge', 'placeholder' => '- select -'), TRUE);
|
||||
|
||||
$label = $this->_action & CRM_Core_Action::ADD ? ts('Contact(s)') : ts('Contact');
|
||||
$contactField = $this->addField('related_contact_id', array('label' => $label, 'name' => 'contact_id_b', 'multiple' => TRUE, 'create' => TRUE), TRUE);
|
||||
// This field cannot be updated
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$contactField->freeze();
|
||||
}
|
||||
|
||||
$this->add('advcheckbox', 'is_current_employer', $this->_contactType == 'Organization' ? ts('Current Employee') : ts('Current Employer'));
|
||||
|
||||
$this->addField('start_date', array('label' => ts('Start Date'), 'formatType' => 'searchDate'));
|
||||
$this->addField('end_date', array('label' => ts('End Date'), 'formatType' => 'searchDate'));
|
||||
|
||||
$this->addField('is_active', array('label' => ts('Enabled?'), 'type' => 'advcheckbox'));
|
||||
|
||||
$this->addField('is_permission_a_b');
|
||||
$this->addField('is_permission_b_a');
|
||||
|
||||
$this->addField('description', array('label' => ts('Description')));
|
||||
|
||||
CRM_Contact_Form_Edit_Notes::buildQuickForm($this);
|
||||
|
||||
if ($this->_action & CRM_Core_Action::VIEW) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Done'),
|
||||
),
|
||||
));
|
||||
}
|
||||
else {
|
||||
// make this form an upload since we don't know if the custom data injected dynamically is of type file etc.
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save Relationship'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called when the form is submitted and also from unit test.
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function submit($params) {
|
||||
switch ($this->getAction()) {
|
||||
case CRM_Core_Action::DELETE:
|
||||
$this->deleteAction($this->_relationshipId);
|
||||
return array();
|
||||
|
||||
case CRM_Core_Action::UPDATE:
|
||||
return $this->updateAction($params);
|
||||
|
||||
default:
|
||||
return $this->createAction($params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called when the form is submitted.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// Store the submitted values in an array.
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
$values = $this->submit($params);
|
||||
if (empty($values)) {
|
||||
return;
|
||||
}
|
||||
list ($params, $relationshipIds) = $values;
|
||||
|
||||
// if this is called from case view,
|
||||
//create an activity for case role removal.CRM-4480
|
||||
// @todo this belongs in the BAO.
|
||||
if ($this->_caseId) {
|
||||
CRM_Case_BAO_Case::createCaseRoleActivity($this->_caseId, $relationshipIds, $params['contact_check'], $this->_contactId);
|
||||
}
|
||||
|
||||
// @todo this belongs in the BAO.
|
||||
$note = !empty($params['note']) ? $params['note'] : '';
|
||||
$this->saveRelationshipNotes($relationshipIds, $note);
|
||||
|
||||
$this->setEmploymentRelationship($params, $relationshipIds);
|
||||
|
||||
// Refresh contact tabs which might have been affected
|
||||
$this->ajaxResponse['updateTabs'] = array(
|
||||
'#tab_member' => CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId),
|
||||
'#tab_contribute' => CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Date validation.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
*
|
||||
* @return bool|array
|
||||
* mixed true or array of errors
|
||||
*/
|
||||
public static function dateRule($params) {
|
||||
$errors = array();
|
||||
|
||||
// check start and end date
|
||||
if (!empty($params['start_date']) && !empty($params['end_date'])) {
|
||||
$start_date = CRM_Utils_Date::format(CRM_Utils_Array::value('start_date', $params));
|
||||
$end_date = CRM_Utils_Date::format(CRM_Utils_Array::value('end_date', $params));
|
||||
if ($start_date && $end_date && (int ) $end_date < (int ) $start_date) {
|
||||
$errors['end_date'] = ts('The relationship end date cannot be prior to the start date.');
|
||||
}
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Status message to reflect outcome of the update action.
|
||||
*
|
||||
* @param array $outcome
|
||||
* Outcome of save action - including
|
||||
* - 'valid' : Number of valid relationships attempted.
|
||||
* - 'invalid' : Number of invalid relationships attempted.
|
||||
* - 'duplicate' : Number of duplicate relationships attempted.
|
||||
* - 'saved' : boolean of whether save was successful
|
||||
*/
|
||||
protected function setMessage($outcome) {
|
||||
if (!empty($outcome['valid']) && empty($outcome['saved'])) {
|
||||
CRM_Core_Session::setStatus(ts('Relationship created.', array(
|
||||
'count' => $outcome['valid'],
|
||||
'plural' => '%count relationships created.',
|
||||
)), ts('Saved'), 'success');
|
||||
}
|
||||
if (!empty($outcome['invalid'])) {
|
||||
CRM_Core_Session::setStatus(ts('%count relationship record was not created due to an invalid contact type.', array(
|
||||
'count' => $outcome['invalid'],
|
||||
'plural' => '%count relationship records were not created due to invalid contact types.',
|
||||
)), ts('%count invalid relationship record', array(
|
||||
'count' => $outcome['invalid'],
|
||||
'plural' => '%count invalid relationship records',
|
||||
)));
|
||||
}
|
||||
if (!empty($outcome['duplicate'])) {
|
||||
CRM_Core_Session::setStatus(ts('One relationship was not created because it already exists.', array(
|
||||
'count' => $outcome['duplicate'],
|
||||
'plural' => '%count relationships were not created because they already exist.',
|
||||
)), ts('%count duplicate relationship', array(
|
||||
'count' => $outcome['duplicate'],
|
||||
'plural' => '%count duplicate relationships',
|
||||
)));
|
||||
}
|
||||
if (!empty($outcome['saved'])) {
|
||||
CRM_Core_Session::setStatus(ts('Relationship record has been updated.'), ts('Saved'), 'success');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $relationshipList
|
||||
* @return array
|
||||
*/
|
||||
public static function getRelationshipTypeMetadata($relationshipList) {
|
||||
$contactTypes = CRM_Contact_BAO_ContactType::contactTypeInfo(TRUE);
|
||||
$allRelationshipNames = CRM_Core_PseudoConstant::relationshipType('name');
|
||||
$jsData = array();
|
||||
// Get just what we need to keep the dom small
|
||||
$whatWeWant = array_flip(array(
|
||||
'contact_type_a',
|
||||
'contact_type_b',
|
||||
'contact_sub_type_a',
|
||||
'contact_sub_type_b',
|
||||
));
|
||||
foreach ($allRelationshipNames as $id => $vals) {
|
||||
if (isset($relationshipList["{$id}_a_b"]) || isset($relationshipList["{$id}_b_a"])) {
|
||||
$jsData[$id] = array_filter(array_intersect_key($allRelationshipNames[$id], $whatWeWant));
|
||||
// Add user-friendly placeholder
|
||||
foreach (array('a', 'b') as $x) {
|
||||
$type = !empty($jsData[$id]["contact_sub_type_$x"]) ? $jsData[$id]["contact_sub_type_$x"] : CRM_Utils_Array::value("contact_type_$x", $jsData[$id]);
|
||||
$jsData[$id]["placeholder_$x"] = $type ? ts('- select %1 -', array(strtolower($contactTypes[$type]['label']))) : ts('- select contact -');
|
||||
}
|
||||
}
|
||||
}
|
||||
return $jsData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handling 'delete relationship' action
|
||||
*
|
||||
* @param int $id
|
||||
* Relationship ID
|
||||
*/
|
||||
private function deleteAction($id) {
|
||||
CRM_Contact_BAO_Relationship::del($id);
|
||||
|
||||
// reload all blocks to reflect this change on the user interface.
|
||||
$this->ajaxResponse['reloadBlocks'] = array('#crm-contactinfo-content');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handling updating relationship action
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function updateAction($params) {
|
||||
$params = $this->preparePostProcessParameters($params);
|
||||
$params = $params[0];
|
||||
|
||||
try {
|
||||
civicrm_api3('relationship', 'create', $params);
|
||||
}
|
||||
catch (CiviCRM_API3_Exception $e) {
|
||||
throw new CRM_Core_Exception('Relationship create error ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$this->clearCurrentEmployer($params);
|
||||
|
||||
$this->setMessage(array('saved' => TRUE));
|
||||
|
||||
return array($params, array($this->_relationshipId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handling creating relationship action
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function createAction($params) {
|
||||
list($params, $primaryContactLetter) = $this->preparePostProcessParameters($params);
|
||||
|
||||
$outcome = CRM_Contact_BAO_Relationship::createMultiple($params, $primaryContactLetter);
|
||||
|
||||
$relationshipIds = $outcome['relationship_ids'];
|
||||
|
||||
$this->setMessage($outcome);
|
||||
|
||||
return array($params, $relationshipIds);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepares parameters to be used for create/update actions
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function preparePostProcessParameters($params) {
|
||||
$relationshipTypeParts = explode('_', $params['relationship_type_id']);
|
||||
|
||||
$params['relationship_type_id'] = $relationshipTypeParts[0];
|
||||
$params['contact_id_' . $relationshipTypeParts[1]] = $this->_contactId;
|
||||
|
||||
if (empty($this->_relationshipId)) {
|
||||
$params['contact_id_' . $relationshipTypeParts[2]] = explode(',', $params['related_contact_id']);
|
||||
}
|
||||
else {
|
||||
$params['id'] = $this->_relationshipId;
|
||||
$params['contact_id_' . $relationshipTypeParts[2]] = $params['related_contact_id'];
|
||||
|
||||
foreach (array('start_date', 'end_date') as $dateParam) {
|
||||
if (!empty($params[$dateParam])) {
|
||||
$params[$dateParam] = CRM_Utils_Date::processDate($params[$dateParam]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CRM-14612 - Don't use adv-checkbox as it interferes with the form js
|
||||
$params['is_permission_a_b'] = CRM_Utils_Array::value('is_permission_a_b', $params, 0);
|
||||
$params['is_permission_b_a'] = CRM_Utils_Array::value('is_permission_b_a', $params, 0);
|
||||
|
||||
return array($params, $relationshipTypeParts[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates/Creates relationship notes
|
||||
*
|
||||
* @param array $relationshipIds
|
||||
* @param string $note
|
||||
*/
|
||||
private function saveRelationshipNotes($relationshipIds, $note) {
|
||||
foreach ($relationshipIds as $id) {
|
||||
$noteParams = array(
|
||||
'entity_id' => $id,
|
||||
'entity_table' => 'civicrm_relationship',
|
||||
);
|
||||
|
||||
$existing = civicrm_api3('note', 'get', $noteParams);
|
||||
if (!empty($existing['id'])) {
|
||||
$noteParams['id'] = $existing['id'];
|
||||
}
|
||||
|
||||
$action = NULL;
|
||||
if (!empty($note)) {
|
||||
$action = 'create';
|
||||
$noteParams['note'] = $note;
|
||||
$noteParams['contact_id'] = $this->_contactId;
|
||||
}
|
||||
elseif (!empty($noteParams['id'])) {
|
||||
$action = 'delete';
|
||||
}
|
||||
|
||||
if (!empty($action)) {
|
||||
civicrm_api3('note', $action, $noteParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current employee/employer relationship
|
||||
*
|
||||
* @param $params
|
||||
* @param array $relationshipIds
|
||||
*/
|
||||
private function setEmploymentRelationship($params, $relationshipIds) {
|
||||
if (
|
||||
!empty($params['is_current_employer']) &&
|
||||
$this->_allRelationshipNames[$params['relationship_type_id']]["name_a_b"] == 'Employee of') {
|
||||
$employerParams = array();
|
||||
foreach ($relationshipIds as $id) {
|
||||
// Fixme this is dumb why do we have to look this up again?
|
||||
$rel = CRM_Contact_BAO_Relationship::getRelationshipByID($id);
|
||||
$employerParams[$rel->contact_id_a] = $rel->contact_id_b;
|
||||
}
|
||||
// @todo this belongs in the BAO.
|
||||
CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($employerParams);
|
||||
// Refresh contact summary if in ajax mode
|
||||
$this->ajaxResponse['reloadBlocks'] = array('#crm-contactinfo-content');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the current employer if the relationship type
|
||||
* get changed, disabled or 'current employer' checkbox get unchecked.
|
||||
*
|
||||
* @param $params
|
||||
*/
|
||||
private function clearCurrentEmployer($params) {
|
||||
// @todo this belongs in the BAO.
|
||||
if ($this->_isCurrentEmployer) {
|
||||
$relChanged = $params['relationship_type_id'] != $this->_values['relationship_type_id'];
|
||||
if (!$params['is_active'] || !$params['is_current_employer'] || $relChanged) {
|
||||
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_values['contact_id_a']);
|
||||
|
||||
// Refresh contact summary if in ajax mode
|
||||
$this->ajaxResponse['reloadBlocks'] = array('#crm-contactinfo-content');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
890
sites/all/modules/civicrm/CRM/Contact/Form/Search.php
Normal file
890
sites/all/modules/civicrm/CRM/Contact/Form/Search.php
Normal file
|
@ -0,0 +1,890 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base Search / View form for *all* listing of multiple
|
||||
* contacts
|
||||
*/
|
||||
class CRM_Contact_Form_Search extends CRM_Core_Form_Search {
|
||||
|
||||
/**
|
||||
* list of valid contexts.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_validContext = NULL;
|
||||
|
||||
/**
|
||||
* List of values used when we want to display other objects.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_modeValues = NULL;
|
||||
|
||||
/**
|
||||
* The contextMenu.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_contextMenu;
|
||||
|
||||
/**
|
||||
* The groupId retrieved from the GET vars.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_groupID;
|
||||
|
||||
/**
|
||||
* The Group ID belonging to Add Member to group ID.
|
||||
* retrieved from the GET vars
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_amtgID;
|
||||
|
||||
/**
|
||||
* The saved search ID retrieved from the GET vars.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_ssID;
|
||||
|
||||
/**
|
||||
* The group elements.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_group;
|
||||
public $_groupElement;
|
||||
|
||||
/**
|
||||
* The tag elements.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_tag;
|
||||
public $_tagElement;
|
||||
|
||||
/**
|
||||
* The params used for search.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_params;
|
||||
|
||||
/**
|
||||
* The return properties used for search.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_returnProperties;
|
||||
|
||||
/**
|
||||
* The sort by character.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_sortByCharacter;
|
||||
|
||||
/**
|
||||
* The profile group id used for display.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_ufGroupID;
|
||||
|
||||
/**
|
||||
* Csv - common search values
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $csv = array('contact_type', 'group', 'tag');
|
||||
|
||||
/**
|
||||
* @var string how to display the results. Should we display as
|
||||
* contributons, members, cases etc
|
||||
*/
|
||||
protected $_componentMode;
|
||||
|
||||
/**
|
||||
* @var string what operator should we use, AND or OR
|
||||
*/
|
||||
protected $_operator;
|
||||
|
||||
protected $_modeValue;
|
||||
|
||||
/**
|
||||
* Declare entity reference fields as they will need to be converted to using 'IN'.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $entityReferenceFields = array('event_id', 'membership_type_id');
|
||||
|
||||
/**
|
||||
* Name of the selector to use.
|
||||
*/
|
||||
static $_selectorName = 'CRM_Contact_Selector';
|
||||
protected $_customSearchID = NULL;
|
||||
protected $_customSearchClass = NULL;
|
||||
|
||||
protected $_openedPanes = array();
|
||||
|
||||
/**
|
||||
* Explicitly declare the entity api name.
|
||||
*/
|
||||
public function getDefaultEntity() {
|
||||
return 'Contact';
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the set of valid contexts that the search form operates on.
|
||||
*
|
||||
* @return array
|
||||
* the valid context set and the titles
|
||||
*/
|
||||
public static function &validContext() {
|
||||
if (!(self::$_validContext)) {
|
||||
self::$_validContext = array(
|
||||
'smog' => 'Show members of group',
|
||||
'amtg' => 'Add members to group',
|
||||
'basic' => 'Basic Search',
|
||||
'search' => 'Search',
|
||||
'builder' => 'Search Builder',
|
||||
'advanced' => 'Advanced Search',
|
||||
'custom' => 'Custom Search',
|
||||
);
|
||||
}
|
||||
return self::$_validContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $context
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSearchContext($context) {
|
||||
$searchContext = CRM_Utils_Array::value($context, self::validContext());
|
||||
return $searchContext ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
public static function setModeValues() {
|
||||
if (!self::$_modeValues) {
|
||||
self::$_modeValues = array(
|
||||
1 => array(
|
||||
'selectorName' => self::$_selectorName,
|
||||
'selectorLabel' => ts('Contacts'),
|
||||
'taskFile' => 'CRM/Contact/Form/Search/ResultTasks.tpl',
|
||||
'taskContext' => NULL,
|
||||
'resultFile' => 'CRM/Contact/Form/Selector.tpl',
|
||||
'resultContext' => NULL,
|
||||
'taskClassName' => 'CRM_Contact_Task',
|
||||
),
|
||||
2 => array(
|
||||
'selectorName' => 'CRM_Contribute_Selector_Search',
|
||||
'selectorLabel' => ts('Contributions'),
|
||||
'taskFile' => 'CRM/common/searchResultTasks.tpl',
|
||||
'taskContext' => 'Contribution',
|
||||
'resultFile' => 'CRM/Contribute/Form/Selector.tpl',
|
||||
'resultContext' => 'Search',
|
||||
'taskClassName' => 'CRM_Contribute_Task',
|
||||
),
|
||||
3 => array(
|
||||
'selectorName' => 'CRM_Event_Selector_Search',
|
||||
'selectorLabel' => ts('Event Participants'),
|
||||
'taskFile' => 'CRM/common/searchResultTasks.tpl',
|
||||
'taskContext' => NULL,
|
||||
'resultFile' => 'CRM/Event/Form/Selector.tpl',
|
||||
'resultContext' => 'Search',
|
||||
'taskClassName' => 'CRM_Event_Task',
|
||||
),
|
||||
4 => array(
|
||||
'selectorName' => 'CRM_Activity_Selector_Search',
|
||||
'selectorLabel' => ts('Activities'),
|
||||
'taskFile' => 'CRM/common/searchResultTasks.tpl',
|
||||
'taskContext' => NULL,
|
||||
'resultFile' => 'CRM/Activity/Form/Selector.tpl',
|
||||
'resultContext' => 'Search',
|
||||
'taskClassName' => 'CRM_Activity_Task',
|
||||
),
|
||||
5 => array(
|
||||
'selectorName' => 'CRM_Member_Selector_Search',
|
||||
'selectorLabel' => ts('Memberships'),
|
||||
'taskFile' => "CRM/common/searchResultTasks.tpl",
|
||||
'taskContext' => NULL,
|
||||
'resultFile' => 'CRM/Member/Form/Selector.tpl',
|
||||
'resultContext' => 'Search',
|
||||
'taskClassName' => 'CRM_Member_Task',
|
||||
),
|
||||
6 => array(
|
||||
'selectorName' => 'CRM_Case_Selector_Search',
|
||||
'selectorLabel' => ts('Cases'),
|
||||
'taskFile' => "CRM/common/searchResultTasks.tpl",
|
||||
'taskContext' => NULL,
|
||||
'resultFile' => 'CRM/Case/Form/Selector.tpl',
|
||||
'resultContext' => 'Search',
|
||||
'taskClassName' => 'CRM_Case_Task',
|
||||
),
|
||||
7 => array(
|
||||
'selectorName' => self::$_selectorName,
|
||||
'selectorLabel' => ts('Related Contacts'),
|
||||
'taskFile' => 'CRM/Contact/Form/Search/ResultTasks.tpl',
|
||||
'taskContext' => NULL,
|
||||
'resultFile' => 'CRM/Contact/Form/Selector.tpl',
|
||||
'resultContext' => NULL,
|
||||
'taskClassName' => 'CRM_Contact_Task',
|
||||
),
|
||||
8 => array(
|
||||
'selectorName' => 'CRM_Mailing_Selector_Search',
|
||||
'selectorLabel' => ts('Mailings'),
|
||||
'taskFile' => "CRM/common/searchResultTasks.tpl",
|
||||
'taskContext' => NULL,
|
||||
'resultFile' => 'CRM/Mailing/Form/Selector.tpl',
|
||||
'resultContext' => 'Search',
|
||||
'taskClassName' => 'CRM_Mailing_Task',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $mode
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getModeValue($mode = 1) {
|
||||
self::setModeValues();
|
||||
|
||||
if (!array_key_exists($mode, self::$_modeValues)) {
|
||||
$mode = 1;
|
||||
}
|
||||
|
||||
return self::$_modeValues[$mode];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function getModeSelect() {
|
||||
self::setModeValues();
|
||||
|
||||
$select = array();
|
||||
foreach (self::$_modeValues as $id => & $value) {
|
||||
$select[$id] = $value['selectorLabel'];
|
||||
}
|
||||
|
||||
// unset contributions or participants if user does not have
|
||||
// permission on them
|
||||
if (!CRM_Core_Permission::access('CiviContribute')) {
|
||||
unset($select['2']);
|
||||
}
|
||||
|
||||
if (!CRM_Core_Permission::access('CiviEvent')) {
|
||||
unset($select['3']);
|
||||
}
|
||||
|
||||
if (!CRM_Core_Permission::check('view all activities')) {
|
||||
unset($select['4']);
|
||||
}
|
||||
return $select;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the list of tasks or actions that a searcher can perform on a result set.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function buildTaskList() {
|
||||
if ($this->_context !== 'amtg') {
|
||||
$permission = CRM_Core_Permission::getPermission();
|
||||
|
||||
if ($this->_componentMode == 1 || $this->_componentMode == 7) {
|
||||
$this->_taskList += CRM_Contact_Task::permissionedTaskTitles($permission,
|
||||
CRM_Utils_Array::value('deleted_contacts', $this->_formValues)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$className = $this->_modeValue['taskClassName'];
|
||||
$this->_taskList += $className::permissionedTaskTitles($permission, FALSE);
|
||||
}
|
||||
|
||||
// Only offer the "Update Smart Group" task if a smart group/saved search is already in play
|
||||
if (isset($this->_ssID) && $permission == CRM_Core_Permission::EDIT) {
|
||||
$this->_taskList += CRM_Contact_Task::optionalTaskTitle();
|
||||
}
|
||||
}
|
||||
|
||||
asort($this->_taskList);
|
||||
return $this->_taskList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the common elements between the search/advanced form.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
CRM_Core_Resources::singleton()
|
||||
// jsTree is needed for tags popup
|
||||
->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)
|
||||
->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
|
||||
$permission = CRM_Core_Permission::getPermission();
|
||||
// some tasks.. what do we want to do with the selected contacts ?
|
||||
$tasks = array();
|
||||
if ($this->_componentMode == 1 || $this->_componentMode == 7) {
|
||||
$tasks += CRM_Contact_Task::permissionedTaskTitles($permission,
|
||||
CRM_Utils_Array::value('deleted_contacts', $this->_formValues)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$className = $this->_modeValue['taskClassName'];
|
||||
$tasks += $className::permissionedTaskTitles($permission, FALSE);
|
||||
}
|
||||
|
||||
if (isset($this->_ssID)) {
|
||||
if ($permission == CRM_Core_Permission::EDIT) {
|
||||
$tasks = $tasks + CRM_Contact_Task::optionalTaskTitle();
|
||||
}
|
||||
|
||||
$search_custom_id
|
||||
= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'search_custom_id');
|
||||
|
||||
$savedSearchValues = array(
|
||||
'id' => $this->_ssID,
|
||||
'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'),
|
||||
'search_custom_id' => $search_custom_id,
|
||||
);
|
||||
$this->assign_by_ref('savedSearch', $savedSearchValues);
|
||||
$this->assign('ssID', $this->_ssID);
|
||||
}
|
||||
|
||||
if ($this->_context === 'smog') {
|
||||
// CRM-11788, we might want to do this for all of search where force=1
|
||||
$formQFKey = CRM_Utils_Array::value('qfKey', $this->_formValues);
|
||||
$getQFKey = CRM_Utils_Array::value('qfKey', $_GET);
|
||||
$postQFKey = CRM_Utils_Array::value('qfKey', $_POST);
|
||||
if ($formQFKey && empty($getQFKey) && empty($postQFKey)) {
|
||||
$url = CRM_Utils_System::makeURL('qfKey') . $formQFKey;
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
$permissionForGroup = FALSE;
|
||||
|
||||
if (!empty($this->_groupID)) {
|
||||
// check if user has permission to edit members of this group
|
||||
$permission = CRM_Contact_BAO_Group::checkPermission($this->_groupID);
|
||||
if ($permission && in_array(CRM_Core_Permission::EDIT, $permission)) {
|
||||
$permissionForGroup = TRUE;
|
||||
}
|
||||
|
||||
// check if _groupID exists, it might not if
|
||||
// we are displaying a hidden group
|
||||
if (!isset($this->_group[$this->_groupID])) {
|
||||
$this->_group[$this->_groupID]
|
||||
= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'title');
|
||||
}
|
||||
|
||||
// set the group title
|
||||
$groupValues = array('id' => $this->_groupID, 'title' => $this->_group[$this->_groupID]);
|
||||
$this->assign_by_ref('group', $groupValues);
|
||||
|
||||
// also set ssID if this is a saved search
|
||||
$ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id');
|
||||
$this->assign('ssID', $ssID);
|
||||
|
||||
//get the saved search mapping id
|
||||
if ($ssID) {
|
||||
$this->_ssID = $ssID;
|
||||
$ssMappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id');
|
||||
$this->assign('ssMappingID', $ssMappingId);
|
||||
}
|
||||
|
||||
// Set dynamic page title for 'Show Members of Group'
|
||||
CRM_Utils_System::setTitle(ts('Contacts in Group: %1', array(1 => $this->_group[$this->_groupID])));
|
||||
}
|
||||
|
||||
$group_contact_status = array();
|
||||
foreach (CRM_Core_SelectValues::groupContactStatus() as $k => $v) {
|
||||
if (!empty($k)) {
|
||||
$group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v);
|
||||
}
|
||||
}
|
||||
$this->addGroup($group_contact_status,
|
||||
'group_contact_status', ts('Group Status')
|
||||
);
|
||||
|
||||
$this->assign('permissionedForGroup', $permissionForGroup);
|
||||
}
|
||||
|
||||
// add the go button for the action form, note it is of type 'next' rather than of type 'submit'
|
||||
if ($this->_context === 'amtg') {
|
||||
// check if _groupID exists, it might not if
|
||||
// we are displaying a hidden group
|
||||
if (!isset($this->_group[$this->_amtgID])) {
|
||||
$this->assign('permissionedForGroup', FALSE);
|
||||
$this->_group[$this->_amtgID]
|
||||
= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_amtgID, 'title');
|
||||
}
|
||||
|
||||
// Set dynamic page title for 'Add Members Group'
|
||||
CRM_Utils_System::setTitle(ts('Add to Group: %1', array(1 => $this->_group[$this->_amtgID])));
|
||||
// also set the group title and freeze the action task with Add Members to Group
|
||||
$groupValues = array('id' => $this->_amtgID, 'title' => $this->_group[$this->_amtgID]);
|
||||
$this->assign_by_ref('group', $groupValues);
|
||||
$this->add('submit', $this->_actionButtonName, ts('Add Contacts to %1', array(1 => $this->_group[$this->_amtgID])),
|
||||
array(
|
||||
'class' => 'crm-form-submit',
|
||||
)
|
||||
);
|
||||
$this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS);
|
||||
$selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
|
||||
$allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all');
|
||||
$this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']);
|
||||
$this->assign('ts_all_id', $allRowsRadio->_attributes['id']);
|
||||
}
|
||||
|
||||
$selectedContactIds = array();
|
||||
$qfKeyParam = CRM_Utils_Array::value('qfKey', $this->_formValues);
|
||||
// We use ajax to handle selections only if the search results component_mode is set to "contacts"
|
||||
if ($qfKeyParam && ($this->get('component_mode') <= 1 || $this->get('component_mode') == 7)) {
|
||||
$this->addClass('crm-ajax-selection-form');
|
||||
$qfKeyParam = "civicrm search {$qfKeyParam}";
|
||||
$selectedContactIdsArr = CRM_Core_BAO_PrevNextCache::getSelection($qfKeyParam);
|
||||
$selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]);
|
||||
}
|
||||
|
||||
$this->assign_by_ref('selectedContactIds', $selectedContactIds);
|
||||
|
||||
$rows = $this->get('rows');
|
||||
|
||||
if (is_array($rows)) {
|
||||
$this->addRowSelectors($rows);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Processing needed for buildForm and later.
|
||||
*/
|
||||
public function preProcess() {
|
||||
// set the various class variables
|
||||
|
||||
$this->_group = CRM_Core_PseudoConstant::group();
|
||||
|
||||
$this->_tag = CRM_Core_BAO_Tag::getTags();
|
||||
$this->_done = FALSE;
|
||||
|
||||
/*
|
||||
* we allow the controller to set force/reset externally, useful when we are being
|
||||
* driven by the wizard framework
|
||||
*/
|
||||
|
||||
$this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean');
|
||||
|
||||
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean');
|
||||
$this->_groupID = CRM_Utils_Request::retrieve('gid', 'Positive', $this);
|
||||
$this->_amtgID = CRM_Utils_Request::retrieve('amtgID', 'Positive', $this);
|
||||
$this->_ssID = CRM_Utils_Request::retrieve('ssID', 'Positive', $this);
|
||||
$this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this);
|
||||
$this->_ufGroupID = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
$this->_componentMode = CRM_Utils_Request::retrieve('component_mode', 'Positive', $this, FALSE, 1, $_REQUEST);
|
||||
$this->_operator = CRM_Utils_Request::retrieve('operator', 'String', $this, FALSE, 1, $_REQUEST, 'AND');
|
||||
|
||||
/**
|
||||
* set the button names
|
||||
*/
|
||||
$this->_searchButtonName = $this->getButtonName('refresh');
|
||||
$this->_actionButtonName = $this->getButtonName('next', 'action');
|
||||
|
||||
$this->assign('actionButtonName', $this->_actionButtonName);
|
||||
|
||||
// if we dont get this from the url, use default if one exsts
|
||||
$config = CRM_Core_Config::singleton();
|
||||
if ($this->_ufGroupID == NULL &&
|
||||
$config->defaultSearchProfileID != NULL
|
||||
) {
|
||||
$this->_ufGroupID = $config->defaultSearchProfileID;
|
||||
}
|
||||
|
||||
// assign context to drive the template display, make sure context is valid
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'search');
|
||||
if (!CRM_Utils_Array::value($this->_context, self::validContext())) {
|
||||
$this->_context = 'search';
|
||||
}
|
||||
$this->set('context', $this->_context);
|
||||
$this->assign('context', $this->_context);
|
||||
|
||||
$this->_modeValue = self::getModeValue($this->_componentMode);
|
||||
$this->assign($this->_modeValue);
|
||||
|
||||
$this->set('selectorName', self::$_selectorName);
|
||||
|
||||
// get user submitted values
|
||||
// get it from controller only if form has been submitted, else preProcess has set this
|
||||
// $this->controller->isModal( ) returns TRUE if page is
|
||||
// valid, i.e all the validations are TRUE
|
||||
|
||||
if (!empty($_POST) && !$this->controller->isModal()) {
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
|
||||
$this->normalizeFormValues();
|
||||
$this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields);
|
||||
$this->_returnProperties = &$this->returnProperties();
|
||||
|
||||
// also get the uf group id directly from the post value
|
||||
$this->_ufGroupID = CRM_Utils_Array::value('uf_group_id', $_POST, $this->_ufGroupID);
|
||||
$this->_formValues['uf_group_id'] = $this->_ufGroupID;
|
||||
$this->set('id', $this->_ufGroupID);
|
||||
|
||||
// also get the object mode directly from the post value
|
||||
$this->_componentMode = CRM_Utils_Array::value('component_mode', $_POST, $this->_componentMode);
|
||||
|
||||
// also get the operator from the post value if set
|
||||
$this->_operator = CRM_Utils_Array::value('operator', $_POST, $this->_operator);
|
||||
$this->_formValues['operator'] = $this->_operator;
|
||||
$this->set('operator', $this->_operator);
|
||||
}
|
||||
else {
|
||||
$this->_formValues = $this->get('formValues');
|
||||
$this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields);
|
||||
$this->_returnProperties = &$this->returnProperties();
|
||||
if (!empty($this->_ufGroupID)) {
|
||||
$this->set('id', $this->_ufGroupID);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->_formValues)) {
|
||||
//check if group is a smart group (fix for CRM-1255)
|
||||
if ($this->_groupID) {
|
||||
if ($ssId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id')) {
|
||||
$this->_ssID = $ssId;
|
||||
}
|
||||
}
|
||||
|
||||
// fix for CRM-1907
|
||||
if (isset($this->_ssID) && $this->_context != 'smog') {
|
||||
// we only retrieve the saved search values if out current values are null
|
||||
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
|
||||
|
||||
//fix for CRM-1505
|
||||
if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'mapping_id')) {
|
||||
$this->_params = CRM_Contact_BAO_SavedSearch::getSearchParams($this->_ssID);
|
||||
}
|
||||
else {
|
||||
$this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
|
||||
}
|
||||
$this->_returnProperties = &$this->returnProperties();
|
||||
}
|
||||
else {
|
||||
if (isset($this->_ufGroupID)) {
|
||||
// also set the uf group id if not already present
|
||||
$this->_formValues['uf_group_id'] = $this->_ufGroupID;
|
||||
}
|
||||
if (isset($this->_componentMode)) {
|
||||
$this->_formValues['component_mode'] = $this->_componentMode;
|
||||
}
|
||||
if (isset($this->_operator)) {
|
||||
$this->_formValues['operator'] = $this->_operator;
|
||||
}
|
||||
|
||||
// FIXME: we should generalise in a way that components could inject url-filters
|
||||
// just like they build their own form elements
|
||||
foreach (array(
|
||||
'mailing_id',
|
||||
'mailing_delivery_status',
|
||||
'mailing_open_status',
|
||||
'mailing_click_status',
|
||||
'mailing_reply_status',
|
||||
'mailing_optout',
|
||||
'mailing_forward',
|
||||
'mailing_unsubscribe',
|
||||
'mailing_date_low',
|
||||
'mailing_date_high',
|
||||
) as $mailingFilter) {
|
||||
$type = 'String';
|
||||
if ($mailingFilter == 'mailing_id' &&
|
||||
$filterVal = CRM_Utils_Request::retrieve('mailing_id', 'Positive', $this)
|
||||
) {
|
||||
$this->_formValues[$mailingFilter] = array($filterVal);
|
||||
}
|
||||
elseif ($filterVal = CRM_Utils_Request::retrieve($mailingFilter, $type, $this)) {
|
||||
$this->_formValues[$mailingFilter] = $filterVal;
|
||||
}
|
||||
if ($filterVal) {
|
||||
$this->_openedPanes['Mailings'] = 1;
|
||||
$this->_formValues['hidden_CiviMail'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assign('id',
|
||||
CRM_Utils_Array::value('uf_group_id', $this->_formValues)
|
||||
);
|
||||
$operator = CRM_Utils_Array::value('operator', $this->_formValues, 'AND');
|
||||
$this->set('queryOperator', $operator);
|
||||
if ($operator == 'OR') {
|
||||
$this->assign('operator', ts('OR'));
|
||||
}
|
||||
else {
|
||||
$this->assign('operator', ts('AND'));
|
||||
}
|
||||
|
||||
// show the context menu only when we’re not searching for deleted contacts; CRM-5673
|
||||
if (empty($this->_formValues['deleted_contacts'])) {
|
||||
$menuItems = CRM_Contact_BAO_Contact::contextMenu();
|
||||
$primaryActions = CRM_Utils_Array::value('primaryActions', $menuItems, array());
|
||||
$this->_contextMenu = CRM_Utils_Array::value('moreActions', $menuItems, array());
|
||||
$this->assign('contextMenu', $primaryActions + $this->_contextMenu);
|
||||
}
|
||||
|
||||
if (!isset($this->_componentMode)) {
|
||||
$this->_componentMode = CRM_Contact_BAO_Query::MODE_CONTACTS;
|
||||
}
|
||||
self::setModeValues();
|
||||
|
||||
self::$_selectorName = $this->_modeValue['selectorName'];
|
||||
|
||||
$setDynamic = FALSE;
|
||||
if (strpos(self::$_selectorName, 'CRM_Contact_Selector') !== FALSE) {
|
||||
$selector = new self::$_selectorName(
|
||||
$this->_customSearchClass,
|
||||
$this->_formValues,
|
||||
$this->_params,
|
||||
$this->_returnProperties,
|
||||
$this->_action,
|
||||
FALSE, TRUE,
|
||||
$this->_context,
|
||||
$this->_contextMenu
|
||||
);
|
||||
$setDynamic = TRUE;
|
||||
}
|
||||
else {
|
||||
$selector = new self::$_selectorName(
|
||||
$this->_params,
|
||||
$this->_action,
|
||||
NULL, FALSE, NULL,
|
||||
"search", "advanced"
|
||||
);
|
||||
}
|
||||
|
||||
$selector->setKey($this->controller->_key);
|
||||
|
||||
$controller = new CRM_Contact_Selector_Controller($selector,
|
||||
$this->get(CRM_Utils_Pager::PAGE_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_ID),
|
||||
CRM_Core_Action::VIEW,
|
||||
$this,
|
||||
CRM_Core_Selector_Controller::TRANSFER
|
||||
);
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->setDynamicAction($setDynamic);
|
||||
|
||||
if ($this->_force) {
|
||||
|
||||
$this->postProcess();
|
||||
|
||||
/*
|
||||
* Note that we repeat this, since the search creates and stores
|
||||
* values that potentially change the controller behavior. i.e. things
|
||||
* like totalCount etc
|
||||
*/
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
$controller = new CRM_Contact_Selector_Controller($selector,
|
||||
$this->get(CRM_Utils_Pager::PAGE_ID),
|
||||
$sortID,
|
||||
CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER
|
||||
);
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->setDynamicAction($setDynamic);
|
||||
}
|
||||
|
||||
$controller->moveFromSessionToTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function &getFormValues() {
|
||||
return $this->_formValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Common post processing.
|
||||
*/
|
||||
public function postProcess() {
|
||||
/*
|
||||
* sometime we do a postProcess early on, so we dont need to repeat it
|
||||
* this will most likely introduce some more bugs :(
|
||||
*/
|
||||
|
||||
if ($this->_done) {
|
||||
return;
|
||||
}
|
||||
$this->_done = TRUE;
|
||||
|
||||
//for prev/next pagination
|
||||
$crmPID = CRM_Utils_Request::retrieve('crmPID', 'Integer');
|
||||
|
||||
if (array_key_exists($this->_searchButtonName, $_POST) ||
|
||||
($this->_force && !$crmPID)
|
||||
) {
|
||||
//reset the cache table for new search
|
||||
$cacheKey = "civicrm search {$this->controller->_key}";
|
||||
CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKey);
|
||||
}
|
||||
|
||||
//get the button name
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
|
||||
if (isset($this->_ufGroupID) && empty($this->_formValues['uf_group_id'])) {
|
||||
$this->_formValues['uf_group_id'] = $this->_ufGroupID;
|
||||
}
|
||||
|
||||
if (isset($this->_componentMode) && empty($this->_formValues['component_mode'])) {
|
||||
$this->_formValues['component_mode'] = $this->_componentMode;
|
||||
}
|
||||
|
||||
if (isset($this->_operator) && empty($this->_formValues['operator'])) {
|
||||
$this->_formValues['operator'] = $this->_operator;
|
||||
}
|
||||
|
||||
if (empty($this->_formValues['qfKey'])) {
|
||||
$this->_formValues['qfKey'] = $this->controller->_key;
|
||||
}
|
||||
|
||||
if (!CRM_Core_Permission::check('access deleted contacts')) {
|
||||
unset($this->_formValues['deleted_contacts']);
|
||||
}
|
||||
|
||||
$this->set('type', $this->_action);
|
||||
$this->set('formValues', $this->_formValues);
|
||||
$this->set('queryParams', $this->_params);
|
||||
$this->set('returnProperties', $this->_returnProperties);
|
||||
|
||||
if ($buttonName == $this->_actionButtonName) {
|
||||
// check actionName and if next, then do not repeat a search, since we are going to the next page
|
||||
// hack, make sure we reset the task values
|
||||
$stateMachine = $this->controller->getStateMachine();
|
||||
$formName = $stateMachine->getTaskFormName();
|
||||
$this->controller->resetPage($formName);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$output = CRM_Core_Selector_Controller::SESSION;
|
||||
|
||||
// create the selector, controller and run - store results in session
|
||||
$searchChildGroups = TRUE;
|
||||
if ($this->get('isAdvanced')) {
|
||||
$searchChildGroups = FALSE;
|
||||
}
|
||||
|
||||
$setDynamic = FALSE;
|
||||
|
||||
if (strpos(self::$_selectorName, 'CRM_Contact_Selector') !== FALSE) {
|
||||
$selector = new self::$_selectorName(
|
||||
$this->_customSearchClass,
|
||||
$this->_formValues,
|
||||
$this->_params,
|
||||
$this->_returnProperties,
|
||||
$this->_action,
|
||||
FALSE,
|
||||
$searchChildGroups,
|
||||
$this->_context,
|
||||
$this->_contextMenu
|
||||
);
|
||||
$setDynamic = TRUE;
|
||||
}
|
||||
else {
|
||||
$selector = new self::$_selectorName(
|
||||
$this->_params,
|
||||
$this->_action,
|
||||
NULL,
|
||||
FALSE,
|
||||
NULL,
|
||||
"search",
|
||||
"advanced"
|
||||
);
|
||||
}
|
||||
|
||||
$selector->setKey($this->controller->_key);
|
||||
|
||||
// added the sorting character to the form array
|
||||
$config = CRM_Core_Config::singleton();
|
||||
// do this only for contact search
|
||||
if ($setDynamic && $config->includeAlphabeticalPager) {
|
||||
// Don't recompute if we are just paging/sorting
|
||||
if ($this->_reset || (empty($_GET['crmPID']) && empty($_GET['crmSID']) && !$this->_sortByCharacter)) {
|
||||
$aToZBar = CRM_Utils_PagerAToZ::getAToZBar($selector, $this->_sortByCharacter);
|
||||
$this->set('AToZBar', $aToZBar);
|
||||
}
|
||||
}
|
||||
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
$controller = new CRM_Contact_Selector_Controller($selector,
|
||||
$this->get(CRM_Utils_Pager::PAGE_ID),
|
||||
$sortID,
|
||||
CRM_Core_Action::VIEW,
|
||||
$this,
|
||||
$output
|
||||
);
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->setDynamicAction($setDynamic);
|
||||
$controller->run();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return NULL
|
||||
*/
|
||||
public function &returnProperties() {
|
||||
return CRM_Core_DAO::$_nullObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Search');
|
||||
}
|
||||
|
||||
}
|
446
sites/all/modules/civicrm/CRM/Contact/Form/Search/Advanced.php
Normal file
446
sites/all/modules/civicrm/CRM/Contact/Form/Search/Advanced.php
Normal file
|
@ -0,0 +1,446 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Advanced search, extends basic search.
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
|
||||
|
||||
/**
|
||||
* Processing needed for buildForm and later.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->set('searchFormName', 'Advanced');
|
||||
|
||||
parent::preProcess();
|
||||
$openedPanes = CRM_Contact_BAO_Query::$_openedPanes;
|
||||
$openedPanes = array_merge($openedPanes, $this->_openedPanes);
|
||||
$this->assign('openedPanes', $openedPanes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->set('context', 'advanced');
|
||||
|
||||
$this->_searchPane = CRM_Utils_Array::value('searchPane', $_GET);
|
||||
|
||||
$this->_searchOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'advanced_search_options'
|
||||
);
|
||||
|
||||
if (!$this->_searchPane || $this->_searchPane == 'basic') {
|
||||
CRM_Contact_Form_Search_Criteria::basic($this);
|
||||
}
|
||||
|
||||
$allPanes = array();
|
||||
$paneNames = array(
|
||||
ts('Address Fields') => 'location',
|
||||
ts('Custom Fields') => 'custom',
|
||||
ts('Activities') => 'activity',
|
||||
ts('Relationships') => 'relationship',
|
||||
ts('Demographics') => 'demographics',
|
||||
ts('Notes') => 'notes',
|
||||
ts('Change Log') => 'changeLog',
|
||||
);
|
||||
|
||||
//check if there are any custom data searchable fields
|
||||
$extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'),
|
||||
CRM_Contact_BAO_ContactType::subTypes()
|
||||
);
|
||||
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE,
|
||||
$extends
|
||||
);
|
||||
// if no searchable fields unset panel
|
||||
if (empty($groupDetails)) {
|
||||
unset($paneNames[ts('Custom Fields')]);
|
||||
}
|
||||
|
||||
foreach ($paneNames as $name => $type) {
|
||||
if (!$this->_searchOptions[$type]) {
|
||||
unset($paneNames[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
$components = CRM_Core_Component::getEnabledComponents();
|
||||
|
||||
$componentPanes = array();
|
||||
foreach ($components as $name => $component) {
|
||||
if (in_array($name, array_keys($this->_searchOptions)) &&
|
||||
$this->_searchOptions[$name] &&
|
||||
CRM_Core_Permission::access($component->name)
|
||||
) {
|
||||
$componentPanes[$name] = $component->registerAdvancedSearchPane();
|
||||
$componentPanes[$name]['name'] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
usort($componentPanes, array('CRM_Utils_Sort', 'cmpFunc'));
|
||||
foreach ($componentPanes as $name => $pane) {
|
||||
// FIXME: we should change the use of $name here to keyword
|
||||
$paneNames[$pane['title']] = $pane['name'];
|
||||
}
|
||||
|
||||
$hookPanes = array();
|
||||
CRM_Contact_BAO_Query_Hook::singleton()->registerAdvancedSearchPane($hookPanes);
|
||||
$paneNames = array_merge($paneNames, $hookPanes);
|
||||
|
||||
$this->_paneTemplatePath = array();
|
||||
foreach ($paneNames as $name => $type) {
|
||||
if (!array_key_exists($type, $this->_searchOptions) && !in_array($type, $hookPanes)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$allPanes[$name] = array(
|
||||
'url' => CRM_Utils_System::url('civicrm/contact/search/advanced',
|
||||
"snippet=1&searchPane=$type&qfKey={$this->controller->_key}"
|
||||
),
|
||||
'open' => 'false',
|
||||
'id' => $type,
|
||||
);
|
||||
|
||||
// see if we need to include this paneName in the current form
|
||||
if ($this->_searchPane == $type || !empty($_POST["hidden_{$type}"]) ||
|
||||
CRM_Utils_Array::value("hidden_{$type}", $this->_formValues)
|
||||
) {
|
||||
$allPanes[$name]['open'] = 'true';
|
||||
|
||||
if (!empty($components[$type])) {
|
||||
$c = $components[$type];
|
||||
$this->add('hidden', "hidden_$type", 1);
|
||||
$c->buildAdvancedSearchPaneForm($this);
|
||||
$this->_paneTemplatePath[$type] = $c->getAdvancedSearchPaneTemplatePath();
|
||||
}
|
||||
elseif (in_array($type, $hookPanes)) {
|
||||
CRM_Contact_BAO_Query_Hook::singleton()->buildAdvancedSearchPaneForm($this, $type);
|
||||
CRM_Contact_BAO_Query_Hook::singleton()->setAdvancedSearchPaneTemplatePath($this->_paneTemplatePath, $type);
|
||||
}
|
||||
else {
|
||||
CRM_Contact_Form_Search_Criteria::$type($this);
|
||||
$template = ucfirst($type);
|
||||
$this->_paneTemplatePath[$type] = "CRM/Contact/Form/Search/Criteria/{$template}.tpl";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('allPanes', $allPanes);
|
||||
if (!$this->_searchPane) {
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
else {
|
||||
$this->assign('suppressForm', TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the form name to create the tpl file name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplateFileName() {
|
||||
if (!$this->_searchPane) {
|
||||
return parent::getTemplateFileName();
|
||||
}
|
||||
else {
|
||||
if (isset($this->_paneTemplatePath[$this->_searchPane])) {
|
||||
return $this->_paneTemplatePath[$this->_searchPane];
|
||||
}
|
||||
else {
|
||||
$name = ucfirst($this->_searchPane);
|
||||
return "CRM/Contact/Form/Search/Criteria/{$name}.tpl";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default form values.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* the default array reference
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
// Set ssID for unit tests.
|
||||
if (empty($this->_ssID)) {
|
||||
$this->_ssID = $this->get('ssID');
|
||||
}
|
||||
|
||||
$defaults = array_merge($this->_formValues, array(
|
||||
'privacy_toggle' => 1,
|
||||
'operator' => 'AND',
|
||||
));
|
||||
$this->normalizeDefaultValues($defaults);
|
||||
|
||||
if ($this->_context === 'amtg') {
|
||||
$defaults['task'] = CRM_Contact_Task::GROUP_CONTACTS;
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* The post processing of the form gets done here.
|
||||
*
|
||||
* Key things done during post processing are
|
||||
* - check for reset or next request. if present, skip post processing.
|
||||
* - now check if user requested running a saved search, if so, then
|
||||
* the form values associated with the saved search are used for searching.
|
||||
* - if user has done a submit with new values the regular post submitting is
|
||||
* done.
|
||||
* The processing consists of using a Selector / Controller framework for getting the
|
||||
* search results.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$this->set('isAdvanced', '1');
|
||||
|
||||
// get user submitted values
|
||||
// get it from controller only if form has been submitted, else preProcess has set this
|
||||
if (!empty($_POST)) {
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
$this->normalizeFormValues();
|
||||
// FIXME: couldn't figure out a good place to do this,
|
||||
// FIXME: so leaving this as a dependency for now
|
||||
if (array_key_exists('contribution_amount_low', $this->_formValues)) {
|
||||
foreach (array(
|
||||
'contribution_amount_low',
|
||||
'contribution_amount_high',
|
||||
) as $f) {
|
||||
$this->_formValues[$f] = CRM_Utils_Rule::cleanMoney($this->_formValues[$f]);
|
||||
}
|
||||
}
|
||||
|
||||
// set the group if group is submitted
|
||||
if (!empty($this->_formValues['uf_group_id'])) {
|
||||
$this->set('id', $this->_formValues['uf_group_id']);
|
||||
}
|
||||
else {
|
||||
$this->set('id', '');
|
||||
}
|
||||
}
|
||||
|
||||
// retrieve ssID values only if formValues is null, i.e. form has never been posted
|
||||
if (empty($this->_formValues) && isset($this->_ssID)) {
|
||||
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
|
||||
}
|
||||
|
||||
if (isset($this->_groupID) && empty($this->_formValues['group'])) {
|
||||
$this->_formValues['group'] = array($this->_groupID => 1);
|
||||
}
|
||||
|
||||
//search for civicase
|
||||
if (is_array($this->_formValues)) {
|
||||
$allCases = FALSE;
|
||||
if (array_key_exists('case_owner', $this->_formValues) &&
|
||||
!$this->_formValues['case_owner'] &&
|
||||
!$this->_force
|
||||
) {
|
||||
foreach (array(
|
||||
'case_type_id',
|
||||
'case_status_id',
|
||||
'case_deleted',
|
||||
'case_tags',
|
||||
) as $caseCriteria) {
|
||||
if (!empty($this->_formValues[$caseCriteria])) {
|
||||
$allCases = TRUE;
|
||||
$this->_formValues['case_owner'] = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ($allCases) {
|
||||
if (CRM_Core_Permission::check('access all cases and activities')) {
|
||||
$this->_formValues['case_owner'] = 1;
|
||||
}
|
||||
else {
|
||||
$this->_formValues['case_owner'] = 2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->_formValues['case_owner'] = 0;
|
||||
}
|
||||
}
|
||||
if (array_key_exists('case_owner', $this->_formValues) && empty($this->_formValues['case_deleted'])) {
|
||||
$this->_formValues['case_deleted'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// we dont want to store the sortByCharacter in the formValue, it is more like
|
||||
// a filter on the result set
|
||||
// this filter is reset if we click on the search button
|
||||
if ($this->_sortByCharacter !== NULL && empty($_POST)) {
|
||||
if (strtolower($this->_sortByCharacter) == 'all') {
|
||||
$this->_formValues['sortByCharacter'] = NULL;
|
||||
}
|
||||
else {
|
||||
$this->_formValues['sortByCharacter'] = $this->_sortByCharacter;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->_sortByCharacter = NULL;
|
||||
}
|
||||
|
||||
CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);
|
||||
|
||||
$this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields);
|
||||
$this->_returnProperties = &$this->returnProperties();
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize the form values to make it look similar to the advanced form values.
|
||||
*
|
||||
* This prevents a ton of work downstream and allows us to use the same code for
|
||||
* multiple purposes (queries, save/edit etc)
|
||||
*/
|
||||
public function normalizeFormValues() {
|
||||
$contactType = CRM_Utils_Array::value('contact_type', $this->_formValues);
|
||||
|
||||
if ($contactType && is_array($contactType)) {
|
||||
unset($this->_formValues['contact_type']);
|
||||
foreach ($contactType as $key => $value) {
|
||||
$this->_formValues['contact_type'][$value] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$specialParams = array(
|
||||
'financial_type_id',
|
||||
'contribution_soft_credit_type_id',
|
||||
'contribution_status',
|
||||
'contribution_status_id',
|
||||
'contribution_source',
|
||||
'membership_status_id',
|
||||
'participant_status_id',
|
||||
'contribution_trxn_id',
|
||||
'activity_type_id',
|
||||
'status_id',
|
||||
'priority_id',
|
||||
'activity_subject',
|
||||
'activity_details',
|
||||
'contribution_page_id',
|
||||
'contribution_product_id',
|
||||
'payment_instrument_id',
|
||||
'group',
|
||||
'contact_tags',
|
||||
'preferred_communication_method',
|
||||
);
|
||||
$changeNames = array(
|
||||
'status_id' => 'activity_status_id',
|
||||
'priority_id' => 'activity_priority_id',
|
||||
);
|
||||
CRM_Contact_BAO_Query::processSpecialFormValue($this->_formValues, $specialParams, $changeNames);
|
||||
|
||||
$taglist = CRM_Utils_Array::value('contact_taglist', $this->_formValues);
|
||||
|
||||
if ($taglist && is_array($taglist)) {
|
||||
unset($this->_formValues['contact_taglist']);
|
||||
foreach ($taglist as $value) {
|
||||
if ($value) {
|
||||
$value = explode(',', $value);
|
||||
foreach ($value as $tId) {
|
||||
if (is_numeric($tId)) {
|
||||
$this->_formValues['contact_tags'][] = $tId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize default values for multiselect plugins.
|
||||
*
|
||||
* @param array $defaults
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function normalizeDefaultValues(&$defaults) {
|
||||
if (!is_array($defaults)) {
|
||||
$defaults = array();
|
||||
}
|
||||
$this->loadDefaultCountryBasedOnState($defaults);
|
||||
if ($this->_ssID && empty($_POST)) {
|
||||
$defaults = array_merge($defaults, CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID));
|
||||
}
|
||||
|
||||
/*
|
||||
* CRM-18656 - reverse the normalisation of 'contact_taglist' done in
|
||||
* self::normalizeFormValues(). Remove tagset tags from the default
|
||||
* 'contact_tags' and put them in 'contact_taglist[N]' where N is the
|
||||
* id of the tagset.
|
||||
*/
|
||||
if (isset($defaults['contact_tags'])) {
|
||||
foreach ($defaults['contact_tags'] as $key => $tagId) {
|
||||
if (!is_array($tagId)) {
|
||||
$parentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $tagId, 'parent_id');
|
||||
$element = "contact_taglist[$parentId]";
|
||||
if ($this->elementExists($element)) {
|
||||
// This tag is a tagset
|
||||
unset($defaults['contact_tags'][$key]);
|
||||
if (!isset($defaults[$element])) {
|
||||
$defaults[$element] = array();
|
||||
}
|
||||
$defaults[$element][] = $tagId;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($defaults['contact_tags'])) {
|
||||
unset($defaults['contact_tags']);
|
||||
}
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default country for the form.
|
||||
*
|
||||
* For performance reasons country might be removed from the form CRM-18125
|
||||
* but we need to include it in our defaults or the state will not be visible.
|
||||
*
|
||||
* @param array $defaults
|
||||
*/
|
||||
public function loadDefaultCountryBasedOnState(&$defaults) {
|
||||
if (!empty($defaults['state_province'])) {
|
||||
$defaults['country'] = CRM_Core_DAO::singleValueQuery(
|
||||
"SELECT country_id FROM civicrm_state_province
|
||||
WHERE id = %1",
|
||||
array(1 => array($defaults['state_province'][0], 'Integer'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
242
sites/all/modules/civicrm/CRM/Contact/Form/Search/Basic.php
Normal file
242
sites/all/modules/civicrm/CRM/Contact/Form/Search/Basic.php
Normal file
|
@ -0,0 +1,242 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base Search / View form for *all* listing of multiple contacts.
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Basic extends CRM_Contact_Form_Search {
|
||||
|
||||
/**
|
||||
* csv - common search values
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $csv = array('contact_type', 'group', 'tag');
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addSortNameField();
|
||||
|
||||
$searchOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'advanced_search_options'
|
||||
);
|
||||
|
||||
if (!empty($searchOptions['contactType'])) {
|
||||
$contactTypes = array('' => ts('- any contact type -')) + CRM_Contact_BAO_ContactType::getSelectElements();
|
||||
$this->add('select', 'contact_type',
|
||||
ts('is...'),
|
||||
$contactTypes,
|
||||
FALSE,
|
||||
array('class' => 'crm-select2')
|
||||
);
|
||||
}
|
||||
|
||||
// add select for groups
|
||||
// Get hierarchical listing of groups, respecting ACLs for CRM-16836.
|
||||
$groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($this->_group, NULL, ' ', TRUE);
|
||||
if (!empty($searchOptions['groups'])) {
|
||||
$this->addField('group', array(
|
||||
'entity' => 'group_contact',
|
||||
'label' => ts('in'),
|
||||
'placeholder' => ts('- any group -'),
|
||||
'options' => $groupHierarchy,
|
||||
));
|
||||
}
|
||||
|
||||
if (!empty($searchOptions['tags'])) {
|
||||
// tag criteria
|
||||
if (!empty($this->_tag)) {
|
||||
$this->addField('tag', array(
|
||||
'entity' => 'entity_tag',
|
||||
'label' => ts('with'),
|
||||
'placeholder' => ts('- any tag -'),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default form values.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* the default array reference
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
$defaults['sort_name'] = CRM_Utils_Array::value('sort_name', $this->_formValues);
|
||||
foreach (self::$csv as $v) {
|
||||
if (!empty($this->_formValues[$v]) && is_array($this->_formValues[$v])) {
|
||||
$tmpArray = array_keys($this->_formValues[$v]);
|
||||
$defaults[$v] = array_pop($tmpArray);
|
||||
}
|
||||
else {
|
||||
$defaults[$v] = '';
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_context === 'amtg') {
|
||||
$defaults['task'] = CRM_Contact_Task::GROUP_CONTACTS;
|
||||
}
|
||||
|
||||
if ($this->_context === 'smog') {
|
||||
$defaults['group_contact_status[Added]'] = TRUE;
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add local and global form rules.
|
||||
*/
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Contact_Form_Search_Basic', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Processing needed for buildForm and later.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->set('searchFormName', 'Basic');
|
||||
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function &getFormValues() {
|
||||
return $this->_formValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called for processing a submitted search form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$this->set('isAdvanced', '0');
|
||||
$this->set('isSearchBuilder', '0');
|
||||
|
||||
// get user submitted values
|
||||
// get it from controller only if form has been submitted, else preProcess has set this
|
||||
if (!empty($_POST)) {
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
}
|
||||
|
||||
if (isset($this->_groupID) && empty($this->_formValues['group'])) {
|
||||
$this->_formValues['group'] = $this->_groupID;
|
||||
}
|
||||
elseif (isset($this->_ssID) && empty($_POST)) {
|
||||
// if we are editing / running a saved search and the form has not been posted
|
||||
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
|
||||
|
||||
//fix for CRM-1505
|
||||
if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'mapping_id')) {
|
||||
$this->_params = CRM_Contact_BAO_SavedSearch::getSearchParams($this->_ssID);
|
||||
}
|
||||
}
|
||||
|
||||
// we dont want to store the sortByCharacter in the formValue, it is more like
|
||||
// a filter on the result set
|
||||
// this filter is reset if we click on the search button
|
||||
if ($this->_sortByCharacter !== NULL && empty($_POST)) {
|
||||
if (strtolower($this->_sortByCharacter) == 'all') {
|
||||
$this->_formValues['sortByCharacter'] = NULL;
|
||||
}
|
||||
else {
|
||||
$this->_formValues['sortByCharacter'] = $this->_sortByCharacter;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->_sortByCharacter = NULL;
|
||||
}
|
||||
|
||||
$this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
|
||||
$this->_returnProperties = &$this->returnProperties();
|
||||
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a form rule for this form.
|
||||
*
|
||||
* If Go is pressed then we must select some checkboxes and an action.
|
||||
*
|
||||
* @param array $fields
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function formRule($fields) {
|
||||
// check actionName and if next, then do not repeat a search, since we are going to the next page
|
||||
if (array_key_exists('_qf_Search_next', $fields)) {
|
||||
if (empty($fields['task'])) {
|
||||
return array('task' => 'Please select a valid action.');
|
||||
}
|
||||
|
||||
if (CRM_Utils_Array::value('task', $fields) == CRM_Contact_Task::SAVE_SEARCH) {
|
||||
// dont need to check for selection of contacts for saving search
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// if the all contact option is selected, ignore the contact checkbox validation
|
||||
if ($fields['radio_ts'] == 'ts_all') {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
foreach ($fields as $name => $dontCare) {
|
||||
if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return array('task' => 'Please select one or more checkboxes to perform the action on.');
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Find Contacts');
|
||||
}
|
||||
|
||||
}
|
524
sites/all/modules/civicrm/CRM/Contact/Form/Search/Builder.php
Normal file
524
sites/all/modules/civicrm/CRM/Contact/Form/Search/Builder.php
Normal file
|
@ -0,0 +1,524 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is for search builder processing.
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Builder extends CRM_Contact_Form_Search {
|
||||
|
||||
/**
|
||||
* Number of columns in where.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_columnCount;
|
||||
|
||||
/**
|
||||
* Number of blocks to be shown.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_blockCount;
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->set('searchFormName', 'Builder');
|
||||
|
||||
$this->set('context', 'builder');
|
||||
parent::preProcess();
|
||||
|
||||
// Get the block count
|
||||
$this->_blockCount = $this->get('blockCount');
|
||||
// Initialize new form
|
||||
if (!$this->_blockCount) {
|
||||
$this->_blockCount = 4;
|
||||
$this->set('newBlock', 1);
|
||||
}
|
||||
|
||||
//get the column count
|
||||
$this->_columnCount = $this->get('columnCount');
|
||||
|
||||
for ($i = 1; $i < $this->_blockCount; $i++) {
|
||||
if (empty($this->_columnCount[$i])) {
|
||||
$this->_columnCount[$i] = 5;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_loadedMappingId = $this->get('savedMapping');
|
||||
|
||||
if ($this->get('showSearchForm')) {
|
||||
$this->assign('showSearchForm', TRUE);
|
||||
}
|
||||
else {
|
||||
$this->assign('showSearchForm', FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build quick form.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$fields = self::fields();
|
||||
// Get fields of type date
|
||||
// FIXME: This is a hack until our fields contain this meta-data
|
||||
$dateFields = array();
|
||||
$stringFields = array();
|
||||
$searchByLabelFields = array();
|
||||
foreach ($fields as $name => $field) {
|
||||
if (strpos($name, '_date') || CRM_Utils_Array::value('data_type', $field) == 'Date') {
|
||||
$dateFields[] = $name;
|
||||
}
|
||||
// it's necessary to know which of the fields are from string data type
|
||||
if (isset($field['type']) && $field['type'] === CRM_Utils_Type::T_STRING) {
|
||||
$stringFields[] = $name;
|
||||
}
|
||||
// it's necessary to know which of the fields are searchable by label
|
||||
if (isset($field['searchByLabel']) && $field['searchByLabel']) {
|
||||
$searchByLabelFields[] = $name;
|
||||
}
|
||||
}
|
||||
// Add javascript
|
||||
CRM_Core_Resources::singleton()
|
||||
->addScriptFile('civicrm', 'templates/CRM/Contact/Form/Search/Builder.js', 1, 'html-header')
|
||||
->addSetting(array(
|
||||
'searchBuilder' => array(
|
||||
// Index of newly added/expanded block (1-based index)
|
||||
'newBlock' => $this->get('newBlock'),
|
||||
'dateFields' => $dateFields,
|
||||
'fieldOptions' => self::fieldOptions(),
|
||||
'stringFields' => $stringFields,
|
||||
'searchByLabelFields' => $searchByLabelFields,
|
||||
'generalOperators' => array('' => ts('-operator-')) + CRM_Core_SelectValues::getSearchBuilderOperators(),
|
||||
'stringOperators' => array('' => ts('-operator-')) + CRM_Core_SelectValues::getSearchBuilderOperators(CRM_Utils_Type::T_STRING),
|
||||
),
|
||||
));
|
||||
//get the saved search mapping id
|
||||
$mappingId = NULL;
|
||||
if ($this->_ssID) {
|
||||
$mappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'mapping_id');
|
||||
}
|
||||
|
||||
CRM_Core_BAO_Mapping::buildMappingForm($this, 'Search Builder', $mappingId, $this->_columnCount, $this->_blockCount);
|
||||
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add local and global form rules.
|
||||
*/
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Contact_Form_Search_Builder', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $values
|
||||
* @param array $files
|
||||
* @param CRM_Core_Form $self
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($values, $files, $self) {
|
||||
if (!empty($values['addMore']) || !empty($values['addBlock'])) {
|
||||
return TRUE;
|
||||
}
|
||||
$fields = self::fields();
|
||||
$fld = CRM_Core_BAO_Mapping::formattedFields($values, TRUE);
|
||||
|
||||
$errorMsg = array();
|
||||
foreach ($fld as $k => $v) {
|
||||
if (!$v[1]) {
|
||||
$errorMsg["operator[$v[3]][$v[4]]"] = ts("Please enter the operator.");
|
||||
}
|
||||
else {
|
||||
// CRM-10338
|
||||
$v[2] = self::checkArrayKeyEmpty($v[2]);
|
||||
|
||||
if (in_array($v[1], array(
|
||||
'IS NULL',
|
||||
'IS NOT NULL',
|
||||
'IS EMPTY',
|
||||
'IS NOT EMPTY',
|
||||
)) &&
|
||||
!empty($v[2])
|
||||
) {
|
||||
$errorMsg["value[$v[3]][$v[4]]"] = ts('Please clear your value if you want to use %1 operator.', array(1 => $v[1]));
|
||||
}
|
||||
elseif (substr($v[0], 0, 7) === 'do_not_' or substr($v[0], 0, 3) === 'is_') {
|
||||
if (isset($v[2])) {
|
||||
$v2 = array($v[2]);
|
||||
if (!isset($v[2])) {
|
||||
$errorMsg["value[$v[3]][$v[4]]"] = ts("Please enter a value.");
|
||||
}
|
||||
|
||||
$error = CRM_Utils_Type::validate($v2[0], 'Integer', FALSE);
|
||||
if ($error != $v2[0]) {
|
||||
$errorMsg["value[$v[3]][$v[4]]"] = ts("Please enter a valid value.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
$errorMsg["value[$v[3]][$v[4]]"] = ts("Please enter a value.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (substr($v[0], 0, 7) == 'custom_') {
|
||||
// Get rid of appended location type id
|
||||
list($fieldKey) = explode('-', $v[0]);
|
||||
$type = $fields[$fieldKey]['data_type'];
|
||||
|
||||
// hack to handle custom data of type state and country
|
||||
if (in_array($type, array(
|
||||
'Country',
|
||||
'StateProvince',
|
||||
))) {
|
||||
$type = "Integer";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$fldName = $v[0];
|
||||
// FIXME: no idea at this point what to do with this,
|
||||
// FIXME: but definitely needs fixing.
|
||||
if (substr($v[0], 0, 13) == 'contribution_') {
|
||||
$fldName = substr($v[0], 13);
|
||||
}
|
||||
|
||||
$fldValue = CRM_Utils_Array::value($fldName, $fields);
|
||||
$fldType = CRM_Utils_Array::value('type', $fldValue);
|
||||
$type = CRM_Utils_Type::typeToString($fldType);
|
||||
|
||||
if (strstr($v[1], 'IN')) {
|
||||
if (empty($v[2])) {
|
||||
$errorMsg["value[$v[3]][$v[4]]"] = ts("Please enter a value.");
|
||||
}
|
||||
}
|
||||
// Check Empty values for Integer Or Boolean Or Date type For operators other than IS NULL and IS NOT NULL.
|
||||
elseif (!in_array($v[1],
|
||||
array('IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY'))
|
||||
) {
|
||||
if ((($type == 'Int' || $type == 'Boolean') && !is_array($v[2]) && !trim($v[2])) && $v[2] != '0') {
|
||||
$errorMsg["value[$v[3]][$v[4]]"] = ts("Please enter a value.");
|
||||
}
|
||||
elseif ($type == 'Date' && !trim($v[2])) {
|
||||
$errorMsg["value[$v[3]][$v[4]]"] = ts("Please enter a value.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($type && empty($errorMsg)) {
|
||||
// check for valid format while using IN Operator
|
||||
if (strstr($v[1], 'IN')) {
|
||||
if (!is_array($v[2])) {
|
||||
$inVal = trim($v[2]);
|
||||
//checking for format to avoid db errors
|
||||
if ($type == 'Int') {
|
||||
if (!preg_match('/^[A-Za-z0-9\,]+$/', $inVal)) {
|
||||
$errorMsg["value[$v[3]][$v[4]]"] = ts("Please enter correct Data (in valid format).");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!preg_match('/^[A-Za-z0-9åäöÅÄÖüÜœŒæÆøØ()\,\s]+$/', $inVal)) {
|
||||
$errorMsg["value[$v[3]][$v[4]]"] = ts("Please enter correct Data (in valid format).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Validate each value in parenthesis to avoid db errors
|
||||
if (empty($errorMsg)) {
|
||||
$parenValues = array();
|
||||
$parenValues = is_array($v[2]) ? (array_key_exists($v[1], $v[2])) ? $v[2][$v[1]] : $v[2] : explode(',', trim($inVal, "(..)"));
|
||||
foreach ($parenValues as $val) {
|
||||
if ($type == 'Date' || $type == 'Timestamp') {
|
||||
$val = CRM_Utils_Date::processDate($val);
|
||||
if ($type == 'Date') {
|
||||
$val = substr($val, 0, 8);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$val = trim($val);
|
||||
}
|
||||
if (!$val && $val != '0') {
|
||||
$errorMsg["value[$v[3]][$v[4]]"] = ts("Please enter the values correctly.");
|
||||
}
|
||||
if (empty($errorMsg)) {
|
||||
$error = CRM_Utils_Type::validate($val, $type, FALSE);
|
||||
if ($error != $val) {
|
||||
$errorMsg["value[$v[3]][$v[4]]"] = ts("Please enter a valid value.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (trim($v[2])) {
|
||||
//else check value for rest of the Operators
|
||||
$error = CRM_Utils_Type::validate($v[2], $type, FALSE);
|
||||
if ($error != $v[2]) {
|
||||
$errorMsg["value[$v[3]][$v[4]]"] = ts("Please enter a valid value.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($errorMsg)) {
|
||||
$self->set('showSearchForm', TRUE);
|
||||
$self->assign('rows', NULL);
|
||||
return $errorMsg;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise form values.
|
||||
*/
|
||||
public function normalizeFormValues() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert form values.
|
||||
*
|
||||
* @param array $formValues
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function convertFormValues(&$formValues) {
|
||||
return CRM_Core_BAO_Mapping::formattedFields($formValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get return properties.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function &returnProperties() {
|
||||
return CRM_Core_BAO_Mapping::returnProperties($this->_formValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the uploaded file.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$this->set('isAdvanced', '2');
|
||||
$this->set('isSearchBuilder', '1');
|
||||
$this->set('showSearchForm', FALSE);
|
||||
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
if (!empty($params)) {
|
||||
// Add another block
|
||||
if (!empty($params['addBlock'])) {
|
||||
$this->set('newBlock', $this->_blockCount);
|
||||
$this->_blockCount += 3;
|
||||
$this->set('blockCount', $this->_blockCount);
|
||||
$this->set('showSearchForm', TRUE);
|
||||
return;
|
||||
}
|
||||
// Add another field
|
||||
$addMore = CRM_Utils_Array::value('addMore', $params);
|
||||
for ($x = 1; $x <= $this->_blockCount; $x++) {
|
||||
if (!empty($addMore[$x])) {
|
||||
$this->set('newBlock', $x);
|
||||
$this->_columnCount[$x] = $this->_columnCount[$x] + 5;
|
||||
$this->set('columnCount', $this->_columnCount);
|
||||
$this->set('showSearchForm', TRUE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->set('newBlock', NULL);
|
||||
$checkEmpty = NULL;
|
||||
foreach ($params['mapper'] as $key => $value) {
|
||||
foreach ($value as $k => $v) {
|
||||
if ($v[0]) {
|
||||
$checkEmpty++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$checkEmpty) {
|
||||
$this->set('newBlock', 1);
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/search/builder', '_qf_Builder_display=true'));
|
||||
}
|
||||
}
|
||||
|
||||
// get user submitted values
|
||||
// get it from controller only if form has been submitted, else preProcess has set this
|
||||
if (!empty($_POST)) {
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
|
||||
// set the group if group is submitted
|
||||
if (!empty($this->_formValues['uf_group_id'])) {
|
||||
$this->set('id', $this->_formValues['uf_group_id']);
|
||||
}
|
||||
else {
|
||||
$this->set('id', '');
|
||||
}
|
||||
}
|
||||
|
||||
// we dont want to store the sortByCharacter in the formValue, it is more like
|
||||
// a filter on the result set
|
||||
// this filter is reset if we click on the search button
|
||||
if ($this->_sortByCharacter !== NULL && empty($_POST)) {
|
||||
if (strtolower($this->_sortByCharacter) == 'all') {
|
||||
$this->_formValues['sortByCharacter'] = NULL;
|
||||
}
|
||||
else {
|
||||
$this->_formValues['sortByCharacter'] = $this->_sortByCharacter;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->_sortByCharacter = NULL;
|
||||
}
|
||||
|
||||
$this->_params = $this->convertFormValues($this->_formValues);
|
||||
$this->_returnProperties = &$this->returnProperties();
|
||||
|
||||
// CRM-10338 check if value is empty array
|
||||
foreach ($this->_params as $k => $v) {
|
||||
$this->_params[$k][2] = self::checkArrayKeyEmpty($v[2]);
|
||||
}
|
||||
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fields.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function fields() {
|
||||
$fields = array_merge(
|
||||
CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE),
|
||||
CRM_Core_Component::getQueryFields(),
|
||||
CRM_Contact_BAO_Query_Hook::singleton()->getFields(),
|
||||
CRM_Activity_BAO_Activity::exportableFields()
|
||||
);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* CRM-9434 Hackish function to fetch fields with options.
|
||||
*
|
||||
* FIXME: When our core fields contain reliable metadata this will be much simpler.
|
||||
* @return array
|
||||
* (string => string) key: field_name value: api entity name
|
||||
* Note: options are fetched via ajax using the api "getoptions" method
|
||||
*/
|
||||
public static function fieldOptions() {
|
||||
// Hack to add options not retrieved by getfields
|
||||
// This list could go on and on, but it would be better to fix getfields
|
||||
$options = array(
|
||||
'group' => 'group_contact',
|
||||
'tag' => 'entity_tag',
|
||||
'on_hold' => 'yesno',
|
||||
'is_bulkmail' => 'yesno',
|
||||
'payment_instrument' => 'contribution',
|
||||
'membership_status' => 'membership',
|
||||
'membership_type' => 'membership',
|
||||
'member_campaign_id' => 'membership',
|
||||
'member_is_test' => 'yesno',
|
||||
'member_is_pay_later' => 'yesno',
|
||||
'is_override' => 'yesno',
|
||||
);
|
||||
$entities = array(
|
||||
'contact',
|
||||
'address',
|
||||
'activity',
|
||||
'participant',
|
||||
'pledge',
|
||||
'member',
|
||||
'contribution',
|
||||
'case',
|
||||
'grant',
|
||||
);
|
||||
CRM_Contact_BAO_Query_Hook::singleton()->alterSearchBuilderOptions($entities, $options);
|
||||
foreach ($entities as $entity) {
|
||||
$fields = civicrm_api3($entity, 'getfields');
|
||||
foreach ($fields['values'] as $field => $info) {
|
||||
if (!empty($info['options']) || !empty($info['pseudoconstant']) || !empty($info['option_group_id'])) {
|
||||
$options[$field] = $entity;
|
||||
// Hack for when search field doesn't match db field - e.g. "country" instead of "country_id"
|
||||
if (substr($field, -3) == '_id') {
|
||||
$options[substr($field, 0, -3)] = $entity;
|
||||
}
|
||||
}
|
||||
elseif (!empty($info['data_type']) && in_array($info['data_type'], array('StateProvince', 'Country'))) {
|
||||
$options[$field] = $entity;
|
||||
}
|
||||
elseif (in_array(substr($field, 0, 3), array(
|
||||
'is_',
|
||||
'do_',
|
||||
)) || CRM_Utils_Array::value('data_type', $info) == 'Boolean'
|
||||
) {
|
||||
$options[$field] = 'yesno';
|
||||
if ($entity != 'contact') {
|
||||
$options[$entity . '_' . $field] = 'yesno';
|
||||
}
|
||||
}
|
||||
elseif (strpos($field, '_is_')) {
|
||||
$options[$field] = 'yesno';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* CRM-10338 tags and groups use array keys for selection list.
|
||||
*
|
||||
* if using IS NULL/NOT NULL, an array with no array key is created
|
||||
* convert that to simple NULL so processing can proceed
|
||||
*
|
||||
* @param string $val
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public static function checkArrayKeyEmpty($val) {
|
||||
if (is_array($val)) {
|
||||
$v2empty = TRUE;
|
||||
foreach ($val as $vk => $vv) {
|
||||
if (!empty($vk)) {
|
||||
$v2empty = FALSE;
|
||||
}
|
||||
}
|
||||
if ($v2empty) {
|
||||
$val = NULL;
|
||||
}
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
}
|
538
sites/all/modules/civicrm/CRM/Contact/Form/Search/Criteria.php
Normal file
538
sites/all/modules/civicrm/CRM/Contact/Form/Search/Criteria.php
Normal file
|
@ -0,0 +1,538 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Criteria {
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function basic(&$form) {
|
||||
$form->addElement('hidden', 'hidden_basic', 1);
|
||||
|
||||
if ($form->_searchOptions['contactType']) {
|
||||
$contactTypes = CRM_Contact_BAO_ContactType::getSelectElements();
|
||||
|
||||
if ($contactTypes) {
|
||||
$form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE,
|
||||
array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($form->_searchOptions['groups']) {
|
||||
// multiselect for groups
|
||||
if ($form->_group) {
|
||||
// Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title)
|
||||
$groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($form->_group, NULL, ' ', TRUE);
|
||||
|
||||
$form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE,
|
||||
array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2')
|
||||
);
|
||||
$groupOptions = CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('group_type');
|
||||
$form->add('select', 'group_type', ts('Group Types'), $groupOptions, FALSE,
|
||||
array('id' => 'group_type', 'multiple' => 'multiple', 'class' => 'crm-select2')
|
||||
);
|
||||
$form->add('hidden', 'group_search_selected', 'group');
|
||||
}
|
||||
}
|
||||
|
||||
if ($form->_searchOptions['tags']) {
|
||||
// multiselect for categories
|
||||
$contactTags = CRM_Core_BAO_Tag::getTags();
|
||||
|
||||
if ($contactTags) {
|
||||
$form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE,
|
||||
array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;')
|
||||
);
|
||||
}
|
||||
|
||||
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
|
||||
CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE);
|
||||
|
||||
$used_for = CRM_Core_OptionGroup::values('tag_used_for');
|
||||
$tagsTypes = array();
|
||||
$showAllTagTypes = FALSE;
|
||||
foreach ($used_for as $key => $value) {
|
||||
//check tags for every type and find if there are any defined
|
||||
$tags = CRM_Core_BAO_Tag::getTagsUsedFor($key, FALSE, TRUE, NULL);
|
||||
// check if there are tags other than contact type, if no - keep checkbox hidden on adv search
|
||||
// we will hide searching contact by attachments tags until it will be implemented in core
|
||||
if (count($tags) && $key != 'civicrm_file' && $key != 'civicrm_contact') {
|
||||
//if tags exists then add type to display in adv search form help text
|
||||
$tagsTypes[] = ts($value);
|
||||
$showAllTagTypes = TRUE;
|
||||
}
|
||||
}
|
||||
$tagTypesText = implode(" or ", $tagsTypes);
|
||||
if ($showAllTagTypes) {
|
||||
$form->add('checkbox', 'all_tag_types', ts('Include tags used for %1', array(1 => $tagTypesText)));
|
||||
$form->add('hidden', 'tag_types_text', $tagTypesText);
|
||||
}
|
||||
}
|
||||
|
||||
// add text box for last name, first name, street name, city
|
||||
$form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
|
||||
|
||||
// add text box for last name, first name, street name, city
|
||||
$form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
|
||||
|
||||
//added contact source
|
||||
$form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'contact_source'));
|
||||
|
||||
//added job title
|
||||
$form->addElement('text', 'job_title', ts('Job Title'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'job_title'));
|
||||
|
||||
//added internal ID
|
||||
$form->add('number', 'contact_id', ts('Contact ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'id') + array('min' => 1));
|
||||
$form->addRule('contact_id', ts('Please enter valid Contact ID'), 'positiveInteger');
|
||||
|
||||
//added external ID
|
||||
$form->addElement('text', 'external_identifier', ts('External ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'));
|
||||
|
||||
if (CRM_Core_Permission::check('access deleted contacts') and Civi::settings()->get('contact_undelete')) {
|
||||
$form->add('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)'));
|
||||
}
|
||||
|
||||
// add checkbox for cms users only
|
||||
$form->addYesNo('uf_user', ts('CMS User?'), TRUE);
|
||||
|
||||
// tag all search
|
||||
$form->add('text', 'tag_search', ts('All Tags'));
|
||||
|
||||
// add search profiles
|
||||
|
||||
// FIXME: This is probably a part of profiles - need to be
|
||||
// FIXME: eradicated from here when profiles are reworked.
|
||||
$types = array('Participant', 'Contribution', 'Membership');
|
||||
|
||||
// get component profiles
|
||||
$componentProfiles = array();
|
||||
$componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types);
|
||||
|
||||
$ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1);
|
||||
$accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW);
|
||||
|
||||
$searchProfiles = array();
|
||||
foreach ($ufGroups as $key => $var) {
|
||||
if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) {
|
||||
$searchProfiles[$key] = $var['title'];
|
||||
}
|
||||
}
|
||||
|
||||
$form->add('select',
|
||||
'uf_group_id',
|
||||
ts('Views For Display Contacts'),
|
||||
array(
|
||||
'0' => ts('- default view -'),
|
||||
) + $searchProfiles,
|
||||
FALSE,
|
||||
array('class' => 'crm-select2')
|
||||
);
|
||||
|
||||
$componentModes = CRM_Contact_Form_Search::getModeSelect();
|
||||
$enabledComponents = CRM_Core_Component::getEnabledComponents();
|
||||
|
||||
// unset disabled components that must should have been enabled
|
||||
// to the option be viable
|
||||
if (!array_key_exists('CiviMail', $enabledComponents)) {
|
||||
unset($componentModes['8']);
|
||||
}
|
||||
|
||||
// unset contributions or participants if user does not have
|
||||
// permission on them
|
||||
if (!CRM_Core_Permission::access('CiviContribute')) {
|
||||
unset($componentModes['2']);
|
||||
}
|
||||
|
||||
if (!CRM_Core_Permission::access('CiviEvent')) {
|
||||
unset($componentModes['3']);
|
||||
}
|
||||
|
||||
if (!CRM_Core_Permission::access('CiviMember')) {
|
||||
unset($componentModes['5']);
|
||||
}
|
||||
|
||||
if (!CRM_Core_Permission::check('view all activities')) {
|
||||
unset($componentModes['4']);
|
||||
}
|
||||
|
||||
if (count($componentModes) > 1) {
|
||||
$form->add('select',
|
||||
'component_mode',
|
||||
ts('Display Results As'),
|
||||
$componentModes,
|
||||
FALSE,
|
||||
array('class' => 'crm-select2')
|
||||
);
|
||||
}
|
||||
|
||||
$form->addRadio(
|
||||
'operator',
|
||||
ts('Search Operator'),
|
||||
array(
|
||||
'AND' => ts('AND'),
|
||||
'OR' => ts('OR'),
|
||||
),
|
||||
array('allowClear' => FALSE)
|
||||
);
|
||||
|
||||
// add the option to display relationships
|
||||
$rTypes = CRM_Core_PseudoConstant::relationshipType();
|
||||
$rSelect = array('' => ts('- Select Relationship Type-'));
|
||||
foreach ($rTypes as $rid => $rValue) {
|
||||
if ($rValue['label_a_b'] == $rValue['label_b_a']) {
|
||||
$rSelect[$rid] = $rValue['label_a_b'];
|
||||
}
|
||||
else {
|
||||
$rSelect["{$rid}_a_b"] = $rValue['label_a_b'];
|
||||
$rSelect["{$rid}_b_a"] = $rValue['label_b_a'];
|
||||
}
|
||||
}
|
||||
|
||||
$form->addElement('select',
|
||||
'display_relationship_type',
|
||||
ts('Display Results as Relationship'),
|
||||
$rSelect,
|
||||
array('class' => 'crm-select2')
|
||||
);
|
||||
|
||||
// checkboxes for DO NOT phone, email, mail
|
||||
// we take labels from SelectValues
|
||||
$t = CRM_Core_SelectValues::privacy();
|
||||
$form->add('select',
|
||||
'privacy_options',
|
||||
ts('Privacy'),
|
||||
$t,
|
||||
FALSE,
|
||||
array(
|
||||
'id' => 'privacy_options',
|
||||
'multiple' => 'multiple',
|
||||
'class' => 'crm-select2',
|
||||
)
|
||||
);
|
||||
|
||||
$form->addElement('select',
|
||||
'privacy_operator',
|
||||
ts('Operator'),
|
||||
array(
|
||||
'OR' => ts('OR'),
|
||||
'AND' => ts('AND'),
|
||||
)
|
||||
);
|
||||
|
||||
$options = array(
|
||||
1 => ts('Exclude'),
|
||||
2 => ts('Include by Privacy Option(s)'),
|
||||
);
|
||||
$form->addRadio('privacy_toggle', ts('Privacy Options'), $options, array('allowClear' => FALSE));
|
||||
|
||||
// preferred communication method
|
||||
|
||||
$onHold[] = $form->createElement('advcheckbox', 'on_hold', NULL, '');
|
||||
$form->addGroup($onHold, 'email_on_hold', ts('Email On Hold'));
|
||||
|
||||
$form->addSelect('preferred_communication_method',
|
||||
array('entity' => 'contact', 'multiple' => 'multiple', 'label' => ts('Preferred Communication Method'), 'option_url' => NULL, 'placeholder' => ts('- any -')));
|
||||
|
||||
//CRM-6138 Preferred Language
|
||||
$form->addSelect('preferred_language', array('class' => 'twenty', 'context' => 'search'));
|
||||
|
||||
// Phone search
|
||||
$form->addElement('text', 'phone_numeric', ts('Phone'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'));
|
||||
$locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
|
||||
$phoneType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
|
||||
$form->add('select', 'phone_location_type_id', ts('Phone Location'), array('' => ts('- any -')) + $locationType, FALSE, array('class' => 'crm-select2'));
|
||||
$form->add('select', 'phone_phone_type_id', ts('Phone Type'), array('' => ts('- any -')) + $phoneType, FALSE, array('class' => 'crm-select2'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function location(&$form) {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
// Build location criteria based on _submitValues if
|
||||
// available; otherwise, use $form->_formValues.
|
||||
$formValues = $form->_submitValues;
|
||||
|
||||
if (empty($formValues) && !empty($form->_formValues)) {
|
||||
$formValues = $form->_formValues;
|
||||
}
|
||||
|
||||
$form->addElement('hidden', 'hidden_location', 1);
|
||||
|
||||
$addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'address_options', TRUE, NULL, TRUE
|
||||
);
|
||||
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
|
||||
|
||||
$elements = array(
|
||||
'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL, NULL),
|
||||
'supplemental_address_1' => array(ts('Supplemental Address 1'), $attributes['supplemental_address_1'], NULL, NULL),
|
||||
'supplemental_address_2' => array(ts('Supplemental Address 2'), $attributes['supplemental_address_2'], NULL, NULL),
|
||||
'supplemental_address_3' => array(ts('Supplemental Address 3'), $attributes['supplemental_address_3'], NULL, NULL),
|
||||
'city' => array(ts('City'), $attributes['city'], NULL, NULL),
|
||||
'postal_code' => array(ts('Postal Code'), $attributes['postal_code'], NULL, NULL),
|
||||
'country' => array(ts('Country'), $attributes['country_id'], 'country', FALSE),
|
||||
'state_province' => array(ts('State/Province'), $attributes['state_province_id'], 'stateProvince', TRUE),
|
||||
'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE),
|
||||
'address_name' => array(ts('Address Name'), $attributes['address_name'], NULL, NULL),
|
||||
'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL, NULL),
|
||||
'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL, NULL),
|
||||
'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL, NULL),
|
||||
);
|
||||
|
||||
$parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', $addressOptions, 0);
|
||||
$form->assign('parseStreetAddress', $parseStreetAddress);
|
||||
foreach ($elements as $name => $v) {
|
||||
list($title, $attributes, $select, $multiSelect) = $v;
|
||||
|
||||
if (in_array($name,
|
||||
array('street_number', 'street_name', 'street_unit')
|
||||
)) {
|
||||
if (!$parseStreetAddress) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
elseif (!$addressOptions[$name]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$attributes) {
|
||||
$attributes = $attributes[$name];
|
||||
}
|
||||
|
||||
if ($select) {
|
||||
if ($select == 'stateProvince' || $select == 'county') {
|
||||
$element = $form->addChainSelect($name);
|
||||
}
|
||||
else {
|
||||
$selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::$select();
|
||||
$element = $form->add('select', $name, $title, $selectElements, FALSE, array('class' => 'crm-select2'));
|
||||
}
|
||||
if ($multiSelect) {
|
||||
$element->setMultiple(TRUE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$form->addElement('text', $name, $title, $attributes);
|
||||
}
|
||||
|
||||
if ($addressOptions['postal_code']) {
|
||||
$attr = array('class' => 'six') + (array) CRM_Utils_Array::value('postal_code', $attributes);
|
||||
$form->addElement('text', 'postal_code_low', NULL, $attr + array('placeholder' => ts('From')));
|
||||
$form->addElement('text', 'postal_code_high', NULL, $attr + array('placeholder' => ts('To')));
|
||||
}
|
||||
}
|
||||
|
||||
// extend addresses with proximity search
|
||||
if (!empty($config->geocodeMethod)) {
|
||||
$form->addElement('text', 'prox_distance', ts('Find contacts within'), array('class' => 'six'));
|
||||
$form->addElement('select', 'prox_distance_unit', NULL, array(
|
||||
'miles' => ts('Miles'),
|
||||
'kilos' => ts('Kilometers'),
|
||||
));
|
||||
$form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric');
|
||||
}
|
||||
|
||||
$form->addSelect('world_region', array('entity' => 'address', 'context' => 'search'));
|
||||
|
||||
// select for location type
|
||||
$locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
|
||||
$form->add('select', 'location_type', ts('Address Location'), $locationType, FALSE, array(
|
||||
'multiple' => TRUE,
|
||||
'class' => 'crm-select2',
|
||||
'placeholder' => ts('Primary'),
|
||||
));
|
||||
|
||||
// custom data extending addresses
|
||||
CRM_Core_BAO_Query::addCustomFormFields($form, array('Address'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function activity(&$form) {
|
||||
$form->add('hidden', 'hidden_activity', 1);
|
||||
CRM_Activity_BAO_Query::buildSearchForm($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function changeLog(&$form) {
|
||||
$form->add('hidden', 'hidden_changeLog', 1);
|
||||
|
||||
// block for change log
|
||||
$form->addElement('text', 'changed_by', ts('Modified By'), NULL);
|
||||
|
||||
$dates = array(1 => ts('Added'), 2 => ts('Modified'));
|
||||
$form->addRadio('log_date', NULL, $dates, array('allowClear' => TRUE), '<br />');
|
||||
|
||||
CRM_Core_Form_Date::buildDateRange($form, 'log_date', 1, '_low', '_high', ts('From'), FALSE, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function task(&$form) {
|
||||
$form->add('hidden', 'hidden_task', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $form
|
||||
*/
|
||||
public static function relationship(&$form) {
|
||||
$form->add('hidden', 'hidden_relationship', 1);
|
||||
|
||||
$allRelationshipType = array();
|
||||
$allRelationshipType = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE);
|
||||
$form->add('select', 'relation_type_id', ts('Relationship Type'), array('' => ts('- select -')) + $allRelationshipType, FALSE, array('class' => 'crm-select2'));
|
||||
$form->addElement('text', 'relation_target_name', ts('Target Contact'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
|
||||
// relation status
|
||||
$relStatusOption = array(ts('Active'), ts('Inactive'), ts('All'));
|
||||
$form->addRadio('relation_status', ts('Relationship Status'), $relStatusOption);
|
||||
$form->setDefaults(array('relation_status' => 0));
|
||||
// relation permission
|
||||
$relPermissionOption = array(ts('Any'), ts('Yes'), ts('No'));
|
||||
$form->addRadio('relation_permission', ts('Permissioned Relationship?'), $relPermissionOption);
|
||||
$form->setDefaults(array('relation_permission' => 0));
|
||||
|
||||
//add the target group
|
||||
if ($form->_group) {
|
||||
$form->add('select', 'relation_target_group', ts('Target Contact(s) in Group'), $form->_group, FALSE,
|
||||
array('id' => 'relation_target_group', 'multiple' => 'multiple', 'class' => 'crm-select2')
|
||||
);
|
||||
}
|
||||
CRM_Core_Form_Date::buildDateRange($form, 'relation_start_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
|
||||
CRM_Core_Form_Date::buildDateRange($form, 'relation_end_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
|
||||
|
||||
CRM_Core_Form_Date::buildDateRange($form, 'relation_active_period_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
|
||||
|
||||
// Add reltionship dates
|
||||
CRM_Core_Form_Date::buildDateRange($form, 'relation_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
|
||||
|
||||
// add all the custom searchable fields
|
||||
CRM_Core_BAO_Query::addCustomFormFields($form, array('Relationship'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $form
|
||||
*/
|
||||
public static function demographics(&$form) {
|
||||
$form->add('hidden', 'hidden_demographics', 1);
|
||||
// radio button for gender
|
||||
$genderOptions = array();
|
||||
$gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
|
||||
foreach ($gender as $key => $var) {
|
||||
$genderOptions[$key] = $form->createElement('radio', NULL,
|
||||
ts('Gender'), $var, $key,
|
||||
array('id' => "civicrm_gender_{$var}_{$key}")
|
||||
);
|
||||
}
|
||||
$form->addGroup($genderOptions, 'gender_id', ts('Gender'))->setAttribute('allowClear', TRUE);
|
||||
|
||||
$form->add('text', 'age_low', ts('Min Age'), array('size' => 6));
|
||||
$form->addRule('age_low', ts('Please enter a positive integer'), 'positiveInteger');
|
||||
$form->add('text', 'age_high', ts('Max Age'), array('size' => 6));
|
||||
$form->addRule('age_high', ts('Please enter a positive integer'), 'positiveInteger');
|
||||
$form->addDate('age_asof_date', ts('Age as of Date'), FALSE, array('formatType' => 'searchDate'));
|
||||
|
||||
CRM_Core_Form_Date::buildDateRange($form, 'birth_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');
|
||||
|
||||
CRM_Core_Form_Date::buildDateRange($form, 'deceased_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');
|
||||
|
||||
// radio button for is_deceased
|
||||
$form->addYesNo('is_deceased', ts('Deceased'), TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $form
|
||||
*/
|
||||
public static function notes(&$form) {
|
||||
$form->add('hidden', 'hidden_notes', 1);
|
||||
|
||||
$options = array(
|
||||
2 => ts('Body Only'),
|
||||
3 => ts('Subject Only'),
|
||||
6 => ts('Both'),
|
||||
);
|
||||
$form->addRadio('note_option', '', $options);
|
||||
|
||||
$form->addElement('text', 'note', ts('Note Text'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
|
||||
|
||||
$form->setDefaults(array('note_option' => 6));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the custom Data Fields based for those with is_searchable = 1.
|
||||
*
|
||||
* @param CRM_Contact_Form_Search $form
|
||||
*/
|
||||
public static function custom(&$form) {
|
||||
$form->add('hidden', 'hidden_custom', 1);
|
||||
$extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'),
|
||||
CRM_Contact_BAO_ContactType::subTypes()
|
||||
);
|
||||
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE,
|
||||
$extends
|
||||
);
|
||||
|
||||
$form->assign('groupTree', $groupDetails);
|
||||
|
||||
foreach ($groupDetails as $key => $group) {
|
||||
$_groupTitle[$key] = $group['name'];
|
||||
CRM_Core_ShowHideBlocks::links($form, $group['name'], '', '');
|
||||
|
||||
foreach ($group['fields'] as $field) {
|
||||
$fieldId = $field['id'];
|
||||
$elementName = 'custom_' . $fieldId;
|
||||
if ($field['data_type'] == 'Date' && $field['is_search_range']) {
|
||||
CRM_Core_Form_Date::buildDateRange($form, $elementName, 1, '_from', '_to', ts('From:'), FALSE);
|
||||
}
|
||||
else {
|
||||
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $form
|
||||
*/
|
||||
public static function CiviCase(&$form) {
|
||||
//Looks like obsolete code, since CiviCase is a component, but might be used by HRD
|
||||
$form->add('hidden', 'hidden_CiviCase', 1);
|
||||
CRM_Case_BAO_Query::buildSearchForm($form);
|
||||
}
|
||||
|
||||
}
|
199
sites/all/modules/civicrm/CRM/Contact/Form/Search/Custom.php
Normal file
199
sites/all/modules/civicrm/CRM/Contact/Form/Search/Custom.php
Normal file
|
@ -0,0 +1,199 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom extends CRM_Contact_Form_Search {
|
||||
|
||||
protected $_customClass = NULL;
|
||||
|
||||
public function preProcess() {
|
||||
$this->set('searchFormName', 'Custom');
|
||||
|
||||
$this->set('context', 'custom');
|
||||
|
||||
$csID = CRM_Utils_Request::retrieve('csid', 'Integer', $this);
|
||||
$ssID = CRM_Utils_Request::retrieve('ssID', 'Integer', $this);
|
||||
$gID = CRM_Utils_Request::retrieve('gid', 'Integer', $this);
|
||||
|
||||
list(
|
||||
$this->_customSearchID,
|
||||
$this->_customSearchClass,
|
||||
$formValues
|
||||
) = CRM_Contact_BAO_SearchCustom::details($csID, $ssID, $gID);
|
||||
|
||||
if (!$this->_customSearchID) {
|
||||
CRM_Core_Error::fatal('Could not get details for custom search.');
|
||||
}
|
||||
|
||||
// stash this as a hidden element so we can potentially go there if the session
|
||||
// is reset but this is available in the POST
|
||||
$this->addElement('hidden', 'csid', $csID);
|
||||
|
||||
if (!empty($formValues)) {
|
||||
$this->_formValues = $formValues;
|
||||
}
|
||||
|
||||
// set breadcrumb to return to Custom Search listings page
|
||||
$breadCrumb = array(
|
||||
array(
|
||||
'title' => ts('Custom Searches'),
|
||||
'url' => CRM_Utils_System::url('civicrm/contact/search/custom/list',
|
||||
'reset=1'
|
||||
),
|
||||
),
|
||||
);
|
||||
CRM_Utils_System::appendBreadCrumb($breadCrumb);
|
||||
|
||||
// use the custom selector
|
||||
self::$_selectorName = 'CRM_Contact_Selector_Custom';
|
||||
|
||||
$this->set('customSearchID', $this->_customSearchID);
|
||||
$this->set('customSearchClass', $this->_customSearchClass);
|
||||
|
||||
parent::preProcess();
|
||||
|
||||
// instantiate the new class
|
||||
$this->_customClass = new $this->_customSearchClass($this->_formValues);
|
||||
|
||||
// CRM-12747
|
||||
if (isset($this->_customClass->_permissionedComponent) &&
|
||||
!self::isPermissioned($this->_customClass->_permissionedComponent)
|
||||
) {
|
||||
CRM_Utils_System::permissionDenied();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default values of various form elements.
|
||||
*
|
||||
* @return array
|
||||
* reference to the array of default values
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
if (method_exists($this->_customSearchClass, 'setDefaultValues')) {
|
||||
return $this->_customClass->setDefaultValues();
|
||||
}
|
||||
return $this->_formValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the list of tasks or actions that a searcher can perform on a result set.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function buildTaskList() {
|
||||
// call the parent method to populate $this->_taskList for the custom search
|
||||
parent::buildTaskList();
|
||||
|
||||
return $this->_customClass->buildTaskList($this);
|
||||
}
|
||||
|
||||
public function buildQuickForm() {
|
||||
$this->_customClass->buildForm($this);
|
||||
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the form name to create the tpl file name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplateFileName() {
|
||||
|
||||
$ext = CRM_Extension_System::singleton()->getMapper();
|
||||
|
||||
if ($ext->isExtensionClass(CRM_Utils_System::getClassName($this->_customClass))) {
|
||||
$fileName = $ext->getTemplatePath(CRM_Utils_System::getClassName($this->_customClass)) . '/' . $ext->getTemplateName(CRM_Utils_System::getClassName($this->_customClass));
|
||||
}
|
||||
else {
|
||||
$fileName = $this->_customClass->templateFile();
|
||||
}
|
||||
|
||||
return $fileName ? $fileName : parent::getTemplateFileName();
|
||||
}
|
||||
|
||||
public function postProcess() {
|
||||
$this->set('isAdvanced', '3');
|
||||
$this->set('isCustom', '1');
|
||||
|
||||
// get user submitted values
|
||||
// get it from controller only if form has been submitted, else preProcess has set this
|
||||
if (!empty($_POST)) {
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
|
||||
$this->_formValues['customSearchID'] = $this->_customSearchID;
|
||||
$this->_formValues['customSearchClass'] = $this->_customSearchClass;
|
||||
}
|
||||
|
||||
//use the custom selector
|
||||
self::$_selectorName = 'CRM_Contact_Selector_Custom';
|
||||
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Custom Search');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $components
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPermissioned($components) {
|
||||
if (empty($components)) {
|
||||
return TRUE;
|
||||
}
|
||||
if (is_array($components)) {
|
||||
foreach ($components as $component) {
|
||||
if (!CRM_Core_Permission::access($component)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!CRM_Core_Permission::access($components)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,432 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_ActivitySearch extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
|
||||
protected $_formValues;
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
$this->_formValues = $formValues;
|
||||
|
||||
/**
|
||||
* Define the columns for search result rows
|
||||
*/
|
||||
$this->_columns = array(
|
||||
ts('Name') => 'sort_name',
|
||||
ts('Status') => 'activity_status',
|
||||
ts('Activity Type') => 'activity_type',
|
||||
ts('Activity Subject') => 'activity_subject',
|
||||
ts('Scheduled By') => 'source_contact',
|
||||
ts('Scheduled Date') => 'activity_date',
|
||||
' ' => 'activity_id',
|
||||
' ' => 'activity_type_id',
|
||||
' ' => 'case_id',
|
||||
ts('Location') => 'location',
|
||||
ts('Duration') => 'duration',
|
||||
ts('Details') => 'details',
|
||||
ts('Assignee') => 'assignee',
|
||||
);
|
||||
|
||||
$this->_groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup',
|
||||
'activity_status',
|
||||
'id',
|
||||
'name'
|
||||
);
|
||||
|
||||
//Add custom fields to columns array for inclusion in export
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity');
|
||||
|
||||
//use simplified formatted groupTree
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree);
|
||||
|
||||
//cycle through custom fields and assign to _columns array
|
||||
foreach ($groupTree as $key) {
|
||||
foreach ($key['fields'] as $field) {
|
||||
$fieldlabel = $key['title'] . ": " . $field['label'];
|
||||
$this->_columns[$fieldlabel] = $field['column_name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
|
||||
/**
|
||||
* You can define a custom title for the search form
|
||||
*/
|
||||
$this->setTitle('Find Latest Activities');
|
||||
|
||||
/**
|
||||
* Define the search form fields here
|
||||
*/
|
||||
// Allow user to choose which type of contact to limit search on
|
||||
$form->add('select', 'contact_type', ts('Find...'), CRM_Core_SelectValues::contactType());
|
||||
|
||||
// Text box for Activity Subject
|
||||
$form->add('text',
|
||||
'activity_subject',
|
||||
ts('Activity Subject')
|
||||
);
|
||||
|
||||
// Select box for Activity Type
|
||||
$activityType = array('' => ' - select activity - ') + CRM_Core_PseudoConstant::activityType();
|
||||
|
||||
$form->add('select', 'activity_type_id', ts('Activity Type'),
|
||||
$activityType,
|
||||
FALSE
|
||||
);
|
||||
|
||||
// textbox for Activity Status
|
||||
$activityStatus = array('' => ' - select status - ') + CRM_Core_PseudoConstant::activityStatus();
|
||||
|
||||
$form->add('select', 'activity_status_id', ts('Activity Status'),
|
||||
$activityStatus,
|
||||
FALSE
|
||||
);
|
||||
|
||||
// Activity Date range
|
||||
$form->addDate('start_date', ts('Activity Date From'), FALSE, array('formatType' => 'custom'));
|
||||
$form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom'));
|
||||
|
||||
// Contact Name field
|
||||
$form->add('text', 'sort_name', ts('Contact Name'));
|
||||
|
||||
/**
|
||||
* If you are using the sample template, this array tells the template fields to render
|
||||
* for the search form.
|
||||
*/
|
||||
$form->assign('elements', array(
|
||||
'contact_type',
|
||||
'activity_subject',
|
||||
'activity_type_id',
|
||||
'activity_status_id',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'sort_name',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the smarty template used to layout the search form and results listings.
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom/ActivitySearch.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the search query.
|
||||
*
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all(
|
||||
$offset = 0, $rowcount = 0, $sort = NULL,
|
||||
$includeContactIDs = FALSE, $justIDs = FALSE
|
||||
) {
|
||||
|
||||
// SELECT clause must include contact_id as an alias for civicrm_contact.id
|
||||
if ($justIDs) {
|
||||
$select = 'contact_a.id as contact_id';
|
||||
}
|
||||
else {
|
||||
$select = '
|
||||
contact_a.id as contact_id,
|
||||
contact_a.sort_name as sort_name,
|
||||
contact_a.contact_type as contact_type,
|
||||
activity.id as activity_id,
|
||||
activity.activity_type_id as activity_type_id,
|
||||
contact_b.sort_name as source_contact,
|
||||
ov1.label as activity_type,
|
||||
activity.subject as activity_subject,
|
||||
activity.activity_date_time as activity_date,
|
||||
ov2.label as activity_status,
|
||||
cca.case_id as case_id,
|
||||
activity.location as location,
|
||||
activity.duration as duration,
|
||||
activity.details as details,
|
||||
assignment.activity_id as assignment_activity,
|
||||
contact_c.display_name as assignee
|
||||
';
|
||||
}
|
||||
|
||||
$from = $this->from();
|
||||
|
||||
$where = $this->where($includeContactIDs);
|
||||
|
||||
if (!empty($where)) {
|
||||
$where = "WHERE $where";
|
||||
}
|
||||
|
||||
// add custom group fields to SELECT and FROM clause
|
||||
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity');
|
||||
|
||||
foreach ($groupTree as $key) {
|
||||
if (!empty($key['extends']) && $key['extends'] == 'Activity') {
|
||||
$select .= ", " . $key['table_name'] . ".*";
|
||||
$from .= " LEFT JOIN " . $key['table_name'] . " ON " . $key['table_name'] . ".entity_id = activity.id";
|
||||
}
|
||||
}
|
||||
// end custom groups add
|
||||
|
||||
$sql = " SELECT $select FROM $from $where ";
|
||||
|
||||
//no need to add order when only contact Ids.
|
||||
if (!$justIDs) {
|
||||
// Define ORDER BY for query in $sort, with default value
|
||||
if (!empty($sort)) {
|
||||
if (is_string($sort)) {
|
||||
$sort = CRM_Utils_Type::escape($sort, 'String');
|
||||
$sql .= " ORDER BY $sort ";
|
||||
}
|
||||
else {
|
||||
$sql .= ' ORDER BY ' . trim($sort->orderBy());
|
||||
}
|
||||
}
|
||||
else {
|
||||
$sql .= 'ORDER BY contact_a.sort_name, activity.activity_date_time DESC, activity.activity_type_id, activity.status_id, activity.subject';
|
||||
}
|
||||
}
|
||||
else {
|
||||
//CRM-14107, since there could be multiple activities against same contact,
|
||||
//we need to provide GROUP BY on contact id to prevent duplicacy on prev/next entries
|
||||
$sql .= 'GROUP BY contact_a.id
|
||||
ORDER BY contact_a.sort_name';
|
||||
}
|
||||
|
||||
if ($rowcount > 0 && $offset >= 0) {
|
||||
$offset = CRM_Utils_Type::escape($offset, 'Int');
|
||||
$rowcount = CRM_Utils_Type::escape($rowcount, 'Int');
|
||||
$sql .= " LIMIT $offset, $rowcount ";
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alters the date display in the Activity Date Column. We do this after we already have
|
||||
* the result so that sorting on the date column stays pertinent to the numeric date value
|
||||
* @param $row
|
||||
*/
|
||||
public function alterRow(&$row) {
|
||||
$row['activity_date'] = CRM_Utils_Date::customFormat($row['activity_date'], '%B %E%f, %Y %l:%M %P');
|
||||
}
|
||||
|
||||
/**
|
||||
* Regular JOIN statements here to limit results to contacts who have activities.
|
||||
* @return string
|
||||
*/
|
||||
public function from() {
|
||||
$this->buildACLClause('contact_a');
|
||||
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
|
||||
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
|
||||
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
|
||||
$sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
|
||||
|
||||
$from = "
|
||||
civicrm_activity activity
|
||||
LEFT JOIN civicrm_activity_contact target
|
||||
ON activity.id = target.activity_id AND target.record_type_id = {$targetID}
|
||||
JOIN civicrm_contact contact_a
|
||||
ON contact_a.id = target.contact_id
|
||||
JOIN civicrm_option_value ov1
|
||||
ON activity.activity_type_id = ov1.value AND ov1.option_group_id = 2
|
||||
JOIN civicrm_option_value ov2
|
||||
ON activity.status_id = ov2.value AND ov2.option_group_id = {$this->_groupId}
|
||||
LEFT JOIN civicrm_activity_contact sourceContact
|
||||
ON activity.id = sourceContact.activity_id AND sourceContact.record_type_id = {$sourceID}
|
||||
JOIN civicrm_contact contact_b
|
||||
ON sourceContact.contact_id = contact_b.id
|
||||
LEFT JOIN civicrm_case_activity cca
|
||||
ON activity.id = cca.activity_id
|
||||
LEFT JOIN civicrm_activity_contact assignment
|
||||
ON activity.id = assignment.activity_id AND assignment.record_type_id = {$assigneeID}
|
||||
LEFT JOIN civicrm_contact contact_c
|
||||
ON assignment.contact_id = contact_c.id {$this->_aclFrom}";
|
||||
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* WHERE clause is an array built from any required JOINS plus conditional filters based on search criteria field values.
|
||||
*
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
$clauses = array();
|
||||
|
||||
// add contact name search; search on primary name, source contact, assignee
|
||||
$contactname = $this->_formValues['sort_name'];
|
||||
if (!empty($contactname)) {
|
||||
$dao = new CRM_Core_DAO();
|
||||
$contactname = $dao->escape($contactname);
|
||||
$clauses[] = "(contact_a.sort_name LIKE '%{$contactname}%' OR
|
||||
contact_b.sort_name LIKE '%{$contactname}%' OR
|
||||
contact_c.display_name LIKE '%{$contactname}%')";
|
||||
}
|
||||
|
||||
$subject = $this->_formValues['activity_subject'];
|
||||
|
||||
if (!empty($this->_formValues['contact_type'])) {
|
||||
$clauses[] = "contact_a.contact_type LIKE '%{$this->_formValues['contact_type']}%'";
|
||||
}
|
||||
|
||||
if (!empty($subject)) {
|
||||
$dao = new CRM_Core_DAO();
|
||||
$subject = $dao->escape($subject);
|
||||
$clauses[] = "activity.subject LIKE '%{$subject}%'";
|
||||
}
|
||||
|
||||
if (!empty($this->_formValues['activity_status_id'])) {
|
||||
$clauses[] = "activity.status_id = {$this->_formValues['activity_status_id']}";
|
||||
}
|
||||
|
||||
if (!empty($this->_formValues['activity_type_id'])) {
|
||||
$clauses[] = "activity.activity_type_id = {$this->_formValues['activity_type_id']}";
|
||||
}
|
||||
|
||||
$startDate = $this->_formValues['start_date'];
|
||||
if (!empty($startDate)) {
|
||||
$startDate .= '00:00:00';
|
||||
$startDateFormatted = CRM_Utils_Date::processDate($startDate);
|
||||
if ($startDateFormatted) {
|
||||
$clauses[] = "activity.activity_date_time >= $startDateFormatted";
|
||||
}
|
||||
}
|
||||
|
||||
$endDate = $this->_formValues['end_date'];
|
||||
if (!empty($endDate)) {
|
||||
$endDate .= '23:59:59';
|
||||
$endDateFormatted = CRM_Utils_Date::processDate($endDate);
|
||||
if ($endDateFormatted) {
|
||||
$clauses[] = "activity.activity_date_time <= $endDateFormatted";
|
||||
}
|
||||
}
|
||||
|
||||
if ($includeContactIDs) {
|
||||
$contactIDs = array();
|
||||
foreach ($this->_formValues as $id => $value) {
|
||||
if ($value &&
|
||||
substr($id, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX
|
||||
) {
|
||||
$contactIDs[] = substr($id, CRM_Core_Form::CB_PREFIX_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($contactIDs)) {
|
||||
$contactIDs = implode(', ', $contactIDs);
|
||||
$clauses[] = "contact_a.id IN ( $contactIDs )";
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_aclWhere) {
|
||||
$clauses[] = " {$this->_aclWhere} ";
|
||||
}
|
||||
return implode(' AND ', $clauses);
|
||||
}
|
||||
|
||||
/*
|
||||
* Functions below generally don't need to be modified
|
||||
*/
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function count() {
|
||||
$sql = $this->all();
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql,
|
||||
CRM_Core_DAO::$_nullArray
|
||||
);
|
||||
return $dao->N;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $returnSQL Not used; included for consistency with parent; SQL is always returned
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = TRUE) {
|
||||
return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function &columns() {
|
||||
return $this->_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Search'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function summary() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,260 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_Base {
|
||||
|
||||
protected $_formValues;
|
||||
|
||||
protected $_columns;
|
||||
|
||||
protected $_stateID;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
$this->_formValues = &$formValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the list of tasks or actions that a searcher can perform on a result set.
|
||||
*
|
||||
* The returned array completely replaces the task list, so a child class that
|
||||
* wants to modify the existing list should manipulate the result of this method.
|
||||
*
|
||||
* @param CRM_Core_Form_Search $form
|
||||
* @return array
|
||||
*/
|
||||
public function buildTaskList(CRM_Core_Form_Search $form) {
|
||||
return $form->getVar('_taskList');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function count() {
|
||||
return CRM_Core_DAO::singleValueQuery($this->sql('count(distinct contact_a.id) as total'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function summary() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $returnSQL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
|
||||
$sql = $this->sql(
|
||||
'contact_a.id as contact_id',
|
||||
$offset,
|
||||
$rowcount,
|
||||
$sort
|
||||
);
|
||||
$this->validateUserSQL($sql);
|
||||
|
||||
if ($returnSQL) {
|
||||
return $sql;
|
||||
}
|
||||
|
||||
return CRM_Core_DAO::composeQuery($sql, CRM_Core_DAO::$_nullArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $selectClause
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param null $groupBy
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sql(
|
||||
$selectClause,
|
||||
$offset = 0,
|
||||
$rowcount = 0,
|
||||
$sort = NULL,
|
||||
$includeContactIDs = FALSE,
|
||||
$groupBy = NULL
|
||||
) {
|
||||
|
||||
$sql = "SELECT $selectClause " . $this->from();
|
||||
$where = $this->where();
|
||||
if (!empty($where)) {
|
||||
$sql .= " WHERE " . $where;
|
||||
}
|
||||
|
||||
if ($includeContactIDs) {
|
||||
$this->includeContactIDs($sql,
|
||||
$this->_formValues
|
||||
);
|
||||
}
|
||||
|
||||
if ($groupBy) {
|
||||
$sql .= " $groupBy ";
|
||||
}
|
||||
|
||||
$this->addSortOffset($sql, $offset, $rowcount, $sort);
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function templateFile() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function &columns() {
|
||||
return $this->_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sql
|
||||
* @param $formValues
|
||||
*/
|
||||
public static function includeContactIDs(&$sql, &$formValues) {
|
||||
$contactIDs = array();
|
||||
foreach ($formValues as $id => $value) {
|
||||
if ($value &&
|
||||
substr($id, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX
|
||||
) {
|
||||
$contactIDs[] = substr($id, CRM_Core_Form::CB_PREFIX_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($contactIDs)) {
|
||||
$contactIDs = implode(', ', $contactIDs);
|
||||
$sql .= " AND contact_a.id IN ( $contactIDs )";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sql
|
||||
* @param $offset
|
||||
* @param $rowcount
|
||||
* @param $sort
|
||||
*/
|
||||
public function addSortOffset(&$sql, $offset, $rowcount, $sort) {
|
||||
if (!empty($sort)) {
|
||||
if (is_string($sort)) {
|
||||
$sort = CRM_Utils_Type::escape($sort, 'String');
|
||||
$sql .= " ORDER BY $sort ";
|
||||
}
|
||||
else {
|
||||
$sql .= " ORDER BY " . trim($sort->orderBy());
|
||||
}
|
||||
}
|
||||
|
||||
if ($rowcount > 0 && $offset >= 0) {
|
||||
$offset = CRM_Utils_Type::escape($offset, 'Int');
|
||||
$rowcount = CRM_Utils_Type::escape($rowcount, 'Int');
|
||||
|
||||
$sql .= " LIMIT $offset, $rowcount ";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sql
|
||||
* @param bool $onlyWhere
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function validateUserSQL(&$sql, $onlyWhere = FALSE) {
|
||||
$includeStrings = array('contact_a');
|
||||
$excludeStrings = array('insert', 'delete', 'update');
|
||||
|
||||
if (!$onlyWhere) {
|
||||
$includeStrings += array('select', 'from', 'where', 'civicrm_contact');
|
||||
}
|
||||
|
||||
foreach ($includeStrings as $string) {
|
||||
if (stripos($sql, $string) === FALSE) {
|
||||
CRM_Core_Error::fatal(ts('Could not find \'%1\' string in SQL clause.',
|
||||
array(1 => $string)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($excludeStrings as $string) {
|
||||
if (preg_match('/(\s' . $string . ')|(' . $string . '\s)/i', $sql)) {
|
||||
CRM_Core_Error::fatal(ts('Found illegal \'%1\' string in SQL clause.',
|
||||
array(1 => $string)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @param array $params
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function whereClause(&$where, &$params) {
|
||||
return CRM_Core_DAO::composeQuery($where, $params, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* override this method to define the contact query object
|
||||
* used for creating $sql
|
||||
* @return null
|
||||
*/
|
||||
public function getQueryObj() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title.
|
||||
*
|
||||
* @param string $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Search'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_Basic extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
|
||||
protected $_query;
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
parent::__construct($formValues);
|
||||
|
||||
$this->_columns = array(
|
||||
'' => 'contact_type',
|
||||
ts('Name') => 'sort_name',
|
||||
ts('Address') => 'street_address',
|
||||
ts('City') => 'city',
|
||||
ts('State') => 'state_province',
|
||||
ts('Postal') => 'postal_code',
|
||||
ts('Country') => 'country',
|
||||
ts('Email') => 'email',
|
||||
ts('Phone') => 'phone',
|
||||
);
|
||||
|
||||
$params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
|
||||
$returnProperties = array();
|
||||
$returnProperties['contact_sub_type'] = 1;
|
||||
|
||||
$addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'address_options', TRUE, NULL, TRUE
|
||||
);
|
||||
|
||||
foreach ($this->_columns as $name => $field) {
|
||||
if (in_array($field, array(
|
||||
'street_address',
|
||||
'city',
|
||||
'state_province',
|
||||
'postal_code',
|
||||
'country',
|
||||
)) && empty($addressOptions[$field])
|
||||
) {
|
||||
unset($this->_columns[$name]);
|
||||
continue;
|
||||
}
|
||||
$returnProperties[$field] = 1;
|
||||
}
|
||||
|
||||
$this->_query = new CRM_Contact_BAO_Query($params, $returnProperties, NULL,
|
||||
FALSE, FALSE, 1, FALSE, FALSE
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
$contactTypes = array('' => ts('- any contact type -')) + CRM_Contact_BAO_ContactType::getSelectElements();
|
||||
$form->add('select', 'contact_type', ts('Find...'), $contactTypes, FALSE, array('class' => 'crm-select2 huge'));
|
||||
|
||||
// add select for groups
|
||||
$group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::nestedGroup();
|
||||
$form->addElement('select', 'group', ts('in'), $group, array('class' => 'crm-select2 huge'));
|
||||
|
||||
// add select for categories
|
||||
$tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
|
||||
$form->addElement('select', 'tag', ts('Tagged'), $tag, array('class' => 'crm-select2 huge'));
|
||||
|
||||
// text for sort_name
|
||||
$form->add('text', 'sort_name', ts('Name'));
|
||||
|
||||
$form->assign('elements', array('sort_name', 'contact_type', 'group', 'tag'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CRM_Contact_DAO_Contact
|
||||
*/
|
||||
public function count() {
|
||||
return $this->_query->searchQuery(0, 0, NULL, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowCount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return CRM_Contact_DAO_Contact
|
||||
*/
|
||||
public function all(
|
||||
$offset = 0,
|
||||
$rowCount = 0,
|
||||
$sort = NULL,
|
||||
$includeContactIDs = FALSE,
|
||||
$justIDs = FALSE
|
||||
) {
|
||||
return $this->_query->searchQuery(
|
||||
$offset,
|
||||
$rowCount,
|
||||
$sort,
|
||||
FALSE,
|
||||
$includeContactIDs,
|
||||
FALSE,
|
||||
$justIDs,
|
||||
TRUE
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function from() {
|
||||
$this->buildACLClause('contact_a');
|
||||
$from = $this->_query->_fromClause;
|
||||
$from .= "{$this->_aclFrom}";
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
if ($whereClause = $this->_query->whereClause()) {
|
||||
if ($this->_aclWhere) {
|
||||
$whereClause .= " AND {$this->_aclWhere}";
|
||||
}
|
||||
return $whereClause;
|
||||
}
|
||||
return ' (1) ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Basic.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CRM_Contact_BAO_Query
|
||||
*/
|
||||
public function getQueryObj() {
|
||||
return $this->_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,425 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_ContribSYBNT extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
|
||||
protected $_formValues;
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
public $_permissionedComponent;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
$this->_formValues = self::formatSavedSearchFields($formValues);
|
||||
$this->_permissionedComponent = 'CiviContribute';
|
||||
|
||||
$this->_columns = array(
|
||||
ts('Contact ID') => 'contact_id',
|
||||
ts('Name') => 'display_name',
|
||||
ts('Contribution Count') => 'donation_count',
|
||||
ts('Contribution Amount') => 'donation_amount',
|
||||
);
|
||||
|
||||
$this->_amounts = array(
|
||||
'min_amount_1' => ts('Min Amount One'),
|
||||
'max_amount_1' => ts('Max Amount One'),
|
||||
'min_amount_2' => ts('Min Amount Two'),
|
||||
'max_amount_2' => ts('Max Amount Two'),
|
||||
'exclude_min_amount' => ts('Exclusion Min Amount'),
|
||||
'exclude_max_amount' => ts('Exclusion Max Amount'),
|
||||
);
|
||||
|
||||
$this->_dates = array(
|
||||
'start_date_1' => ts('Start Date One'),
|
||||
'end_date_1' => ts('End Date One'),
|
||||
'start_date_2' => ts('Start Date Two'),
|
||||
'end_date_2' => ts('End Date Two'),
|
||||
'exclude_start_date' => ts('Exclusion Start Date'),
|
||||
'exclude_end_date' => ts('Exclusion End Date'),
|
||||
);
|
||||
|
||||
$this->_checkboxes = array('is_first_amount' => ts('First Donation?'));
|
||||
|
||||
foreach ($this->_amounts as $name => $title) {
|
||||
$this->{$name} = CRM_Utils_Array::value($name, $this->_formValues);
|
||||
}
|
||||
|
||||
foreach ($this->_checkboxes as $name => $title) {
|
||||
$this->{$name} = CRM_Utils_Array::value($name, $this->_formValues, FALSE);
|
||||
}
|
||||
|
||||
foreach ($this->_dates as $name => $title) {
|
||||
if (!empty($this->_formValues[$name])) {
|
||||
$this->{$name} = $this->_formValues[$name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
|
||||
foreach ($this->_amounts as $name => $title) {
|
||||
$form->add('text',
|
||||
$name,
|
||||
$title
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($this->_dates as $name => $title) {
|
||||
$form->add('datepicker', $name, $title, array(), FALSE, array('time' => FALSE));
|
||||
}
|
||||
|
||||
foreach ($this->_checkboxes as $name => $title) {
|
||||
$form->add('checkbox',
|
||||
$name,
|
||||
$title
|
||||
);
|
||||
}
|
||||
|
||||
$this->setTitle('Contributions made in Year X and not Year Y');
|
||||
// @TODO: Decide on better names for "Exclusion"
|
||||
// @TODO: Add rule to ensure that exclusion dates are not in the inclusion range
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function count() {
|
||||
$sql = $this->all();
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
return $dao->N;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $returnSQL Not used; included for consistency with parent; SQL is always returned
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = TRUE) {
|
||||
return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all(
|
||||
$offset = 0,
|
||||
$rowcount = 0,
|
||||
$sort = NULL,
|
||||
$includeContactIDs = FALSE,
|
||||
$justIDs = FALSE
|
||||
) {
|
||||
|
||||
$where = $this->where();
|
||||
if (!empty($where)) {
|
||||
$where = " AND $where";
|
||||
}
|
||||
|
||||
$having = $this->having();
|
||||
if ($having) {
|
||||
$having = " HAVING $having ";
|
||||
}
|
||||
|
||||
$from = $this->from();
|
||||
|
||||
$select = $this->select();
|
||||
if ($justIDs) {
|
||||
$select .= ', contact_a.id, display_name';
|
||||
}
|
||||
else {
|
||||
$select = "
|
||||
DISTINCT contact_a.id as contact_id,
|
||||
contact_a.display_name as display_name,
|
||||
$select ";
|
||||
}
|
||||
$this->buildACLClause('contact_a');
|
||||
$sql = "
|
||||
SELECT $select
|
||||
FROM civicrm_contact AS contact_a {$this->_aclFrom}
|
||||
LEFT JOIN civicrm_contribution contrib_1 ON contrib_1.contact_id = contact_a.id
|
||||
$from
|
||||
WHERE contrib_1.contact_id = contact_a.id
|
||||
AND contrib_1.is_test = 0
|
||||
$where
|
||||
GROUP BY contact_a.id
|
||||
$having
|
||||
ORDER BY donation_amount desc
|
||||
";
|
||||
|
||||
if ($justIDs) {
|
||||
CRM_Core_DAO::executeQuery("DROP TEMPORARY TABLE IF EXISTS CustomSearch_SYBNT_temp");
|
||||
$query = "CREATE TEMPORARY TABLE CustomSearch_SYBNT_temp AS ({$sql})";
|
||||
CRM_Core_DAO::executeQuery($query);
|
||||
$sql = "SELECT contact_a.id as contact_id FROM CustomSearch_SYBNT_temp as contact_a";
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function select() {
|
||||
if (!empty($this->start_date_2) || !empty($this->end_date_2)) {
|
||||
return "
|
||||
sum(contrib_1.total_amount) + sum(contrib_2.total_amount) AS donation_amount,
|
||||
count(contrib_1.id) + count(contrib_1.id) AS donation_count
|
||||
";
|
||||
}
|
||||
else {
|
||||
return "
|
||||
sum(contrib_1.total_amount) AS donation_amount,
|
||||
count(contrib_1.id) AS donation_count
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function from() {
|
||||
$from = NULL;
|
||||
if (!empty($this->start_date_2) || !empty($this->end_date_2)) {
|
||||
$from .= " LEFT JOIN civicrm_contribution contrib_2 ON contrib_2.contact_id = contact_a.id ";
|
||||
}
|
||||
|
||||
if (!empty($this->exclude_start_date) ||
|
||||
!empty($this->exclude_end_date) ||
|
||||
!empty($this->is_first_amount)
|
||||
) {
|
||||
$from .= " LEFT JOIN XG_CustomSearch_SYBNT xg ON xg.contact_id = contact_a.id ";
|
||||
}
|
||||
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
$clauses = array();
|
||||
|
||||
if (!empty($this->start_date_1)) {
|
||||
$clauses[] = CRM_Core_DAO::composeQuery('contrib_1.receive_date >= %1', array(1 => array($this->start_date_1, 'String')));
|
||||
}
|
||||
|
||||
if (!empty($this->end_date_1)) {
|
||||
$clauses[] = CRM_Core_DAO::composeQuery('contrib_1.receive_date <= %1', array(1 => array($this->end_date_1, 'String')));
|
||||
}
|
||||
|
||||
if (!empty($this->start_date_2) || !empty($this->end_date_2)) {
|
||||
$clauses[] = "contrib_2.is_test = 0";
|
||||
|
||||
if (!empty($this->start_date_2)) {
|
||||
$clauses[] = CRM_Core_DAO::composeQuery('contrib_2.receive_date >= %1', array(1 => array($this->start_date_2, 'String')));
|
||||
}
|
||||
|
||||
if (!empty($this->end_date_2)) {
|
||||
$clauses[] = CRM_Core_DAO::composeQuery('contrib_2.receive_date <= %1', array(1 => array($this->end_date_2, 'String')));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->exclude_start_date) ||
|
||||
!empty($this->exclude_end_date) ||
|
||||
!empty($this->is_first_amount)
|
||||
) {
|
||||
|
||||
// first create temp table to store contact ids
|
||||
$sql = "DROP TEMPORARY TABLE IF EXISTS XG_CustomSearch_SYBNT";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
$sql = "CREATE TEMPORARY TABLE XG_CustomSearch_SYBNT ( contact_id int primary key) ENGINE=HEAP";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
$excludeClauses = array();
|
||||
if ($this->exclude_start_date) {
|
||||
$excludeClauses[] = CRM_Core_DAO::composeQuery('c.receive_date >= %1', array(1 => array($this->exclude_start_date, 'String')));
|
||||
}
|
||||
|
||||
if ($this->exclude_end_date) {
|
||||
$excludeClauses[] = CRM_Core_DAO::composeQuery('c.receive_date <= %1', array(1 => array($this->exclude_end_date, 'String')));
|
||||
}
|
||||
|
||||
$excludeClause = NULL;
|
||||
if ($excludeClauses) {
|
||||
$excludeClause = ' AND ' . implode(' AND ', $excludeClauses);
|
||||
}
|
||||
|
||||
$having = array();
|
||||
if ($this->exclude_min_amount) {
|
||||
$having[] = "sum(c.total_amount) >= {$this->exclude_min_amount}";
|
||||
}
|
||||
|
||||
if ($this->exclude_max_amount) {
|
||||
$having[] = "sum(c.total_amount) <= {$this->exclude_max_amount}";
|
||||
}
|
||||
|
||||
$havingClause = NULL;
|
||||
if (!empty($having)) {
|
||||
$havingClause = "HAVING " . implode(' AND ', $having);
|
||||
}
|
||||
|
||||
if ($excludeClause || $havingClause) {
|
||||
// Run subquery
|
||||
$query = "
|
||||
REPLACE INTO XG_CustomSearch_SYBNT
|
||||
SELECT DISTINCT contact_id AS contact_id
|
||||
FROM civicrm_contribution c
|
||||
WHERE c.is_test = 0
|
||||
$excludeClause
|
||||
GROUP BY c.contact_id
|
||||
$havingClause
|
||||
";
|
||||
|
||||
CRM_Core_DAO::executeQuery($query);
|
||||
}
|
||||
|
||||
// now ensure we dont consider donors that are not first time
|
||||
if ($this->is_first_amount) {
|
||||
$query = "
|
||||
REPLACE INTO XG_CustomSearch_SYBNT
|
||||
SELECT DISTINCT contact_id AS contact_id
|
||||
FROM civicrm_contribution c
|
||||
WHERE c.is_test = 0
|
||||
AND c.receive_date < {$this->start_date_1}
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($query);
|
||||
}
|
||||
|
||||
$clauses[] = " xg.contact_id IS NULL ";
|
||||
}
|
||||
if ($this->_aclWhere) {
|
||||
$clauses[] .= " {$this->_aclWhere} ";
|
||||
}
|
||||
return implode(' AND ', $clauses);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function having($includeContactIDs = FALSE) {
|
||||
$clauses = array();
|
||||
$min = CRM_Utils_Array::value('min_amount', $this->_formValues);
|
||||
if ($min) {
|
||||
$clauses[] = "sum(contrib_1.total_amount) >= $min";
|
||||
}
|
||||
|
||||
$max = CRM_Utils_Array::value('max_amount', $this->_formValues);
|
||||
if ($max) {
|
||||
$clauses[] = "sum(contrib_1.total_amount) <= $max";
|
||||
}
|
||||
|
||||
return implode(' AND ', $clauses);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function &columns() {
|
||||
return $this->_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom/ContribSYBNT.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function summary() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Search'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format saved search fields for this custom group
|
||||
*
|
||||
* @param array $formValues
|
||||
*
|
||||
*/
|
||||
public static function formatSavedSearchFields(&$formValues) {
|
||||
$dateFields = array(
|
||||
'start_date_1',
|
||||
'end_date_1',
|
||||
'start_date_2',
|
||||
'end_date_2',
|
||||
'exclude_start_date',
|
||||
'exclude_end_date',
|
||||
);
|
||||
foreach ($formValues as $element => $value) {
|
||||
if (in_array($element, $dateFields) && !empty($value)) {
|
||||
$formValues[$element] = date('Y-m-d', strtotime($value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,328 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_ContributionAggregate extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
|
||||
protected $_formValues;
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
public $_permissionedComponent;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
$this->_formValues = $formValues;
|
||||
|
||||
// Define the columns for search result rows
|
||||
$this->_columns = array(
|
||||
ts('Contact ID') => 'contact_id',
|
||||
ts('Name') => 'sort_name',
|
||||
ts('Contribution Count') => 'donation_count',
|
||||
ts('Contribution Amount') => 'donation_amount',
|
||||
);
|
||||
|
||||
// define component access permission needed
|
||||
$this->_permissionedComponent = 'CiviContribute';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build form.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
|
||||
/**
|
||||
* You can define a custom title for the search form
|
||||
*/
|
||||
$this->setTitle('Find Contributors by Aggregate Totals');
|
||||
|
||||
/**
|
||||
* Define the search form fields here
|
||||
*/
|
||||
$form->add('text',
|
||||
'min_amount',
|
||||
ts('Aggregate Total Between $')
|
||||
);
|
||||
$form->addRule('min_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
|
||||
|
||||
$form->add('text',
|
||||
'max_amount',
|
||||
ts('...and $')
|
||||
);
|
||||
$form->addRule('max_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
|
||||
CRM_Core_Form_Date::buildDateRange($form, 'contribution_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
|
||||
|
||||
$form->addSelect('financial_type_id',
|
||||
array('entity' => 'contribution', 'multiple' => 'multiple', 'context' => 'search')
|
||||
);
|
||||
|
||||
/**
|
||||
* If you are using the sample template, this array tells the template fields to render
|
||||
* for the search form.
|
||||
*/
|
||||
$form->assign('elements', array('min_amount', 'max_amount'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the smarty template used to layout the search form and results listings.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom/ContributionAggregate.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the search query.
|
||||
*
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param string|object $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all(
|
||||
$offset = 0, $rowcount = 0, $sort = NULL,
|
||||
$includeContactIDs = FALSE, $justIDs = FALSE
|
||||
) {
|
||||
|
||||
// SELECT clause must include contact_id as an alias for civicrm_contact.id
|
||||
if ($justIDs) {
|
||||
$select = "contact_a.id as contact_id";
|
||||
}
|
||||
else {
|
||||
$select = "
|
||||
DISTINCT contact_a.id as contact_id,
|
||||
contact_a.sort_name as sort_name,
|
||||
sum(contrib.total_amount) AS donation_amount,
|
||||
count(contrib.id) AS donation_count
|
||||
";
|
||||
}
|
||||
$from = $this->from();
|
||||
|
||||
$where = $this->where($includeContactIDs);
|
||||
|
||||
$having = $this->having();
|
||||
if ($having) {
|
||||
$having = " HAVING $having ";
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT $select
|
||||
FROM $from
|
||||
WHERE $where
|
||||
GROUP BY contact_a.id
|
||||
$having
|
||||
";
|
||||
//for only contact ids ignore order.
|
||||
if (!$justIDs) {
|
||||
// Define ORDER BY for query in $sort, with default value
|
||||
if (!empty($sort)) {
|
||||
if (is_string($sort)) {
|
||||
$sort = CRM_Utils_Type::escape($sort, 'String');
|
||||
$sql .= " ORDER BY $sort ";
|
||||
}
|
||||
else {
|
||||
$sql .= " ORDER BY " . trim($sort->orderBy());
|
||||
}
|
||||
}
|
||||
else {
|
||||
$sql .= "ORDER BY donation_amount desc";
|
||||
}
|
||||
}
|
||||
|
||||
if ($rowcount > 0 && $offset >= 0) {
|
||||
$offset = CRM_Utils_Type::escape($offset, 'Int');
|
||||
$rowcount = CRM_Utils_Type::escape($rowcount, 'Int');
|
||||
$sql .= " LIMIT $offset, $rowcount ";
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function from() {
|
||||
$this->buildACLClause('contact_a');
|
||||
$from = "
|
||||
civicrm_contribution AS contrib,
|
||||
civicrm_contact AS contact_a {$this->_aclFrom}
|
||||
";
|
||||
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* WHERE clause is an array built from any required JOINS plus conditional filters based on search criteria field values.
|
||||
*
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
$clauses = array(
|
||||
"contrib.contact_id = contact_a.id",
|
||||
"contrib.is_test = 0",
|
||||
);
|
||||
|
||||
$dateParams = array(
|
||||
'contribution_date_relative' => $this->_formValues['contribution_date_relative'],
|
||||
'contribution_date_low' => $this->_formValues['contribution_date_low'],
|
||||
'contribution_date_high' => $this->_formValues['contribution_date_high'],
|
||||
);
|
||||
foreach (CRM_Contact_BAO_Query::convertFormValues($dateParams) as $values) {
|
||||
list($name, $op, $value) = $values;
|
||||
if (strstr($name, '_low')) {
|
||||
$clauses[] = "contrib.receive_date >= " . CRM_Utils_Date::processDate($value);
|
||||
}
|
||||
else {
|
||||
$clauses[] = "contrib.receive_date <= " . CRM_Utils_Date::processDate($value);
|
||||
}
|
||||
}
|
||||
|
||||
if ($includeContactIDs) {
|
||||
$contactIDs = array();
|
||||
foreach ($this->_formValues as $id => $value) {
|
||||
if ($value &&
|
||||
substr($id, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX
|
||||
) {
|
||||
$contactIDs[] = substr($id, CRM_Core_Form::CB_PREFIX_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($contactIDs)) {
|
||||
$contactIDs = implode(', ', $contactIDs);
|
||||
$clauses[] = "contact_a.id IN ( $contactIDs )";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->_formValues['financial_type_id'])) {
|
||||
$financial_type_ids = implode(',', array_values($this->_formValues['financial_type_id']));
|
||||
$clauses[] = "contrib.financial_type_id IN ($financial_type_ids)";
|
||||
}
|
||||
if ($this->_aclWhere) {
|
||||
$clauses[] = " {$this->_aclWhere} ";
|
||||
}
|
||||
|
||||
return implode(' AND ', $clauses);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function having($includeContactIDs = FALSE) {
|
||||
$clauses = array();
|
||||
$min = CRM_Utils_Array::value('min_amount', $this->_formValues);
|
||||
if ($min) {
|
||||
$min = CRM_Utils_Rule::cleanMoney($min);
|
||||
$clauses[] = "sum(contrib.total_amount) >= $min";
|
||||
}
|
||||
|
||||
$max = CRM_Utils_Array::value('max_amount', $this->_formValues);
|
||||
if ($max) {
|
||||
$max = CRM_Utils_Rule::cleanMoney($max);
|
||||
$clauses[] = "sum(contrib.total_amount) <= $max";
|
||||
}
|
||||
|
||||
return implode(' AND ', $clauses);
|
||||
}
|
||||
|
||||
/*
|
||||
* Functions below generally don't need to be modified
|
||||
*/
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function count() {
|
||||
$sql = $this->all();
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql,
|
||||
CRM_Core_DAO::$_nullArray
|
||||
);
|
||||
return $dao->N;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $returnSQL Not used; included for consistency with parent; SQL is always returned
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = TRUE) {
|
||||
return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function &columns() {
|
||||
return $this->_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Search'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function summary() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,458 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_DateAdded extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
|
||||
protected $_debug = 0;
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
parent::__construct($formValues);
|
||||
|
||||
$this->_includeGroups = CRM_Utils_Array::value('includeGroups', $formValues, array());
|
||||
$this->_excludeGroups = CRM_Utils_Array::value('excludeGroups', $formValues, array());
|
||||
|
||||
$this->_columns = array(
|
||||
ts('Contact ID') => 'contact_id',
|
||||
ts('Contact Type') => 'contact_type',
|
||||
ts('Name') => 'sort_name',
|
||||
ts('Date Added') => 'date_added',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
$form->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'custom'));
|
||||
$form->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'custom'));
|
||||
|
||||
$groups = CRM_Core_PseudoConstant::nestedGroup();
|
||||
|
||||
$select2style = array(
|
||||
'multiple' => TRUE,
|
||||
'style' => 'width: 100%; max-width: 60em;',
|
||||
'class' => 'crm-select2',
|
||||
'placeholder' => ts('- select -'),
|
||||
);
|
||||
|
||||
$form->add('select', 'includeGroups',
|
||||
ts('Include Group(s)'),
|
||||
$groups,
|
||||
FALSE,
|
||||
$select2style
|
||||
);
|
||||
|
||||
$form->add('select', 'excludeGroups',
|
||||
ts('Exclude Group(s)'),
|
||||
$groups,
|
||||
FALSE,
|
||||
$select2style
|
||||
);
|
||||
|
||||
$this->setTitle('Search by date added to CiviCRM');
|
||||
|
||||
//redirect if group not available for search criteria
|
||||
if (count($groups) == 0) {
|
||||
CRM_Core_Error::statusBounce(ts("Atleast one Group must be present for search."),
|
||||
CRM_Utils_System::url('civicrm/contact/search/custom/list',
|
||||
'reset=1'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* if you are using the standard template, this array tells the template what elements
|
||||
* are part of the search criteria
|
||||
*/
|
||||
$form->assign('elements', array('start_date', 'end_date', 'includeGroups', 'excludeGroups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function summary() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $returnSQL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
|
||||
return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all(
|
||||
$offset = 0, $rowcount = 0, $sort = NULL,
|
||||
$includeContactIDs = FALSE, $justIDs = FALSE
|
||||
) {
|
||||
|
||||
$this->_includeGroups = CRM_Utils_Array::value('includeGroups', $this->_formValues, array());
|
||||
|
||||
$this->_excludeGroups = CRM_Utils_Array::value('excludeGroups', $this->_formValues, array());
|
||||
|
||||
$this->_allSearch = FALSE;
|
||||
$this->_groups = FALSE;
|
||||
|
||||
if (empty($this->_includeGroups) && empty($this->_excludeGroups)) {
|
||||
//empty search
|
||||
$this->_allSearch = TRUE;
|
||||
}
|
||||
|
||||
if (!empty($this->_includeGroups) || !empty($this->_excludeGroups)) {
|
||||
//group(s) selected
|
||||
$this->_groups = TRUE;
|
||||
}
|
||||
|
||||
if ($justIDs) {
|
||||
$selectClause = "contact_a.id as contact_id";
|
||||
$groupBy = " GROUP BY contact_a.id";
|
||||
$sort = "contact_a.id";
|
||||
}
|
||||
else {
|
||||
$selectClause = "contact_a.id as contact_id,
|
||||
contact_a.contact_type as contact_type,
|
||||
contact_a.sort_name as sort_name,
|
||||
d.date_added as date_added";
|
||||
$groupBy = " GROUP BY contact_id ";
|
||||
}
|
||||
|
||||
return $this->sql($selectClause,
|
||||
$offset, $rowcount, $sort,
|
||||
$includeContactIDs, $groupBy
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function from() {
|
||||
//define table name
|
||||
$randomNum = md5(uniqid());
|
||||
$this->_tableName = "civicrm_temp_custom_{$randomNum}";
|
||||
|
||||
//grab the contacts added in the date range first
|
||||
$sql = "CREATE TEMPORARY TABLE dates_{$this->_tableName} ( id int primary key, date_added date ) ENGINE=HEAP";
|
||||
if ($this->_debug > 0) {
|
||||
print "-- Date range query: <pre>";
|
||||
print "$sql;";
|
||||
print "</pre>";
|
||||
}
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
$startDate = CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::processDate($this->_formValues['start_date']));
|
||||
$endDateFix = NULL;
|
||||
if (!empty($this->_formValues['end_date'])) {
|
||||
$endDate = CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::processDate($this->_formValues['end_date']));
|
||||
# tack 11:59pm on to make search inclusive of the end date
|
||||
$endDateFix = "AND date_added <= '" . substr($endDate, 0, 10) . " 23:59:00'";
|
||||
}
|
||||
|
||||
$dateRange = "INSERT INTO dates_{$this->_tableName} ( id, date_added )
|
||||
SELECT
|
||||
civicrm_contact.id,
|
||||
min(civicrm_log.modified_date) AS date_added
|
||||
FROM
|
||||
civicrm_contact LEFT JOIN civicrm_log
|
||||
ON (civicrm_contact.id = civicrm_log.entity_id AND
|
||||
civicrm_log.entity_table = 'civicrm_contact')
|
||||
GROUP BY
|
||||
civicrm_contact.id
|
||||
HAVING
|
||||
date_added >= '$startDate'
|
||||
$endDateFix";
|
||||
|
||||
if ($this->_debug > 0) {
|
||||
print "-- Date range query: <pre>";
|
||||
print "$dateRange;";
|
||||
print "</pre>";
|
||||
}
|
||||
|
||||
CRM_Core_DAO::executeQuery($dateRange, CRM_Core_DAO::$_nullArray);
|
||||
|
||||
// Only include groups in the search query of one or more Include OR Exclude groups has been selected.
|
||||
// CRM-6356
|
||||
if ($this->_groups) {
|
||||
//block for Group search
|
||||
$smartGroup = array();
|
||||
$group = new CRM_Contact_DAO_Group();
|
||||
$group->is_active = 1;
|
||||
$group->find();
|
||||
while ($group->fetch()) {
|
||||
$allGroups[] = $group->id;
|
||||
if ($group->saved_search_id) {
|
||||
$smartGroup[$group->saved_search_id] = $group->id;
|
||||
}
|
||||
}
|
||||
$includedGroups = implode(',', $allGroups);
|
||||
|
||||
if (!empty($this->_includeGroups)) {
|
||||
$iGroups = implode(',', $this->_includeGroups);
|
||||
}
|
||||
else {
|
||||
//if no group selected search for all groups
|
||||
$iGroups = $includedGroups;
|
||||
}
|
||||
if (is_array($this->_excludeGroups)) {
|
||||
$xGroups = implode(',', $this->_excludeGroups);
|
||||
}
|
||||
else {
|
||||
$xGroups = 0;
|
||||
}
|
||||
|
||||
$sql = "DROP TEMPORARY TABLE IF EXISTS Xg_{$this->_tableName}";
|
||||
CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
|
||||
$sql = "CREATE TEMPORARY TABLE Xg_{$this->_tableName} ( contact_id int primary key) ENGINE=HEAP";
|
||||
CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
|
||||
|
||||
//used only when exclude group is selected
|
||||
if ($xGroups != 0) {
|
||||
$excludeGroup = "INSERT INTO Xg_{$this->_tableName} ( contact_id )
|
||||
SELECT DISTINCT civicrm_group_contact.contact_id
|
||||
FROM civicrm_group_contact, dates_{$this->_tableName} AS d
|
||||
WHERE
|
||||
d.id = civicrm_group_contact.contact_id AND
|
||||
civicrm_group_contact.status = 'Added' AND
|
||||
civicrm_group_contact.group_id IN( {$xGroups})";
|
||||
|
||||
CRM_Core_DAO::executeQuery($excludeGroup, CRM_Core_DAO::$_nullArray);
|
||||
|
||||
//search for smart group contacts
|
||||
foreach ($this->_excludeGroups as $keys => $values) {
|
||||
if (in_array($values, $smartGroup)) {
|
||||
$ssId = CRM_Utils_Array::key($values, $smartGroup);
|
||||
|
||||
$smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
|
||||
|
||||
$smartSql = $smartSql . " AND contact_a.id NOT IN (
|
||||
SELECT contact_id FROM civicrm_group_contact
|
||||
WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
|
||||
|
||||
$smartGroupQuery = " INSERT IGNORE INTO Xg_{$this->_tableName}(contact_id) $smartSql";
|
||||
|
||||
CRM_Core_DAO::executeQuery($smartGroupQuery, CRM_Core_DAO::$_nullArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "DROP TEMPORARY TABLE IF EXISTS Ig_{$this->_tableName}";
|
||||
CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
|
||||
$sql = "CREATE TEMPORARY TABLE Ig_{$this->_tableName}
|
||||
( id int PRIMARY KEY AUTO_INCREMENT,
|
||||
contact_id int,
|
||||
group_names varchar(64)) ENGINE=HEAP";
|
||||
|
||||
if ($this->_debug > 0) {
|
||||
print "-- Include groups query: <pre>";
|
||||
print "$sql;";
|
||||
print "</pre>";
|
||||
}
|
||||
|
||||
CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
|
||||
|
||||
$includeGroup = "INSERT INTO Ig_{$this->_tableName} (contact_id, group_names)
|
||||
SELECT d.id as contact_id, civicrm_group.name as group_name
|
||||
FROM dates_{$this->_tableName} AS d
|
||||
INNER JOIN civicrm_group_contact
|
||||
ON civicrm_group_contact.contact_id = d.id
|
||||
LEFT JOIN civicrm_group
|
||||
ON civicrm_group_contact.group_id = civicrm_group.id";
|
||||
|
||||
//used only when exclude group is selected
|
||||
if ($xGroups != 0) {
|
||||
$includeGroup .= " LEFT JOIN Xg_{$this->_tableName}
|
||||
ON d.id = Xg_{$this->_tableName}.contact_id";
|
||||
}
|
||||
$includeGroup .= " WHERE
|
||||
civicrm_group_contact.status = 'Added' AND
|
||||
civicrm_group_contact.group_id IN($iGroups)";
|
||||
|
||||
//used only when exclude group is selected
|
||||
if ($xGroups != 0) {
|
||||
$includeGroup .= " AND Xg_{$this->_tableName}.contact_id IS null";
|
||||
}
|
||||
|
||||
if ($this->_debug > 0) {
|
||||
print "-- Include groups query: <pre>";
|
||||
print "$includeGroup;";
|
||||
print "</pre>";
|
||||
}
|
||||
|
||||
CRM_Core_DAO::executeQuery($includeGroup, CRM_Core_DAO::$_nullArray);
|
||||
|
||||
//search for smart group contacts
|
||||
foreach ($this->_includeGroups as $keys => $values) {
|
||||
if (in_array($values, $smartGroup)) {
|
||||
|
||||
$ssId = CRM_Utils_Array::key($values, $smartGroup);
|
||||
|
||||
$smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
|
||||
|
||||
$smartSql .= " AND contact_a.id IN (
|
||||
SELECT id AS contact_id
|
||||
FROM dates_{$this->_tableName} )";
|
||||
|
||||
$smartSql .= " AND contact_a.id NOT IN (
|
||||
SELECT contact_id FROM civicrm_group_contact
|
||||
WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
|
||||
|
||||
//used only when exclude group is selected
|
||||
if ($xGroups != 0) {
|
||||
$smartSql .= " AND contact_a.id NOT IN (SELECT contact_id FROM Xg_{$this->_tableName})";
|
||||
}
|
||||
|
||||
$smartGroupQuery = " INSERT IGNORE INTO
|
||||
Ig_{$this->_tableName}(contact_id)
|
||||
$smartSql";
|
||||
|
||||
CRM_Core_DAO::executeQuery($smartGroupQuery, CRM_Core_DAO::$_nullArray);
|
||||
if ($this->_debug > 0) {
|
||||
print "-- Smart group query: <pre>";
|
||||
print "$smartGroupQuery;";
|
||||
print "</pre>";
|
||||
}
|
||||
$insertGroupNameQuery = "UPDATE IGNORE Ig_{$this->_tableName}
|
||||
SET group_names = (SELECT title FROM civicrm_group
|
||||
WHERE civicrm_group.id = $values)
|
||||
WHERE Ig_{$this->_tableName}.contact_id IS NOT NULL
|
||||
AND Ig_{$this->_tableName}.group_names IS NULL";
|
||||
CRM_Core_DAO::executeQuery($insertGroupNameQuery, CRM_Core_DAO::$_nullArray);
|
||||
if ($this->_debug > 0) {
|
||||
print "-- Smart group query: <pre>";
|
||||
print "$insertGroupNameQuery;";
|
||||
print "</pre>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// end if( $this->_groups ) condition
|
||||
$this->buildACLClause('contact_a');
|
||||
$from = "FROM civicrm_contact contact_a";
|
||||
|
||||
/* We need to join to this again to get the date_added value */
|
||||
|
||||
$from .= " INNER JOIN dates_{$this->_tableName} d ON (contact_a.id = d.id) {$this->_aclFrom}";
|
||||
|
||||
// Only include groups in the search query of one or more Include OR Exclude groups has been selected.
|
||||
// CRM-6356
|
||||
if ($this->_groups) {
|
||||
$from .= " INNER JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
|
||||
}
|
||||
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
$where = '(1)';
|
||||
if ($this->_aclWhere) {
|
||||
$where .= " AND {$this->_aclWhere} ";
|
||||
}
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Search'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function count() {
|
||||
$sql = $this->all();
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql,
|
||||
CRM_Core_DAO::$_nullArray
|
||||
);
|
||||
return $dao->N;
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
//drop the temp. tables if they exist
|
||||
if (!empty($this->_includeGroups)) {
|
||||
$sql = "DROP TEMPORARY TABLE IF EXISTS Ig_{$this->_tableName}";
|
||||
CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
|
||||
}
|
||||
|
||||
if (!empty($this->_excludeGroups)) {
|
||||
$sql = "DROP TEMPORARY TABLE IF EXISTS Xg_{$this->_tableName}";
|
||||
CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,377 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_EventAggregate extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
|
||||
protected $_formValues;
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
public $_permissionedComponent;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
$this->_formValues = $formValues;
|
||||
$this->_permissionedComponent = array('CiviContribute', 'CiviEvent');
|
||||
|
||||
/**
|
||||
* Define the columns for search result rows
|
||||
*/
|
||||
$this->_columns = array(
|
||||
ts('Event') => 'event_name',
|
||||
ts('Type') => 'event_type',
|
||||
ts('Number of<br />Participant') => 'participant_count',
|
||||
ts('Total Payment') => 'payment_amount',
|
||||
ts('Fee') => 'fee',
|
||||
ts('Net Payment') => 'net_payment',
|
||||
ts('Participant') => 'participant',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
|
||||
/**
|
||||
* You can define a custom title for the search form
|
||||
*/
|
||||
$this->setTitle('Find Totals for Events');
|
||||
|
||||
/**
|
||||
* Define the search form fields here
|
||||
*/
|
||||
|
||||
$form->addElement('checkbox', 'paid_online', ts('Only show Credit Card Payments'));
|
||||
|
||||
$form->addElement('checkbox', 'show_payees', ts('Show payees'));
|
||||
|
||||
$event_type = CRM_Core_OptionGroup::values('event_type', FALSE);
|
||||
foreach ($event_type as $eventId => $eventName) {
|
||||
$form->addElement('checkbox', "event_type_id[$eventId]", 'Event Type', $eventName);
|
||||
}
|
||||
$events = CRM_Event_BAO_Event::getEvents(1);
|
||||
$form->add('select', 'event_id', ts('Event Name'), array('' => ts('- select -')) + $events);
|
||||
|
||||
$form->addDate('start_date', ts('Payments Date From'), FALSE, array('formatType' => 'custom'));
|
||||
$form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom'));
|
||||
|
||||
/**
|
||||
* If you are using the sample template, this array tells the template fields to render
|
||||
* for the search form.
|
||||
*/
|
||||
$form->assign('elements', array(
|
||||
'paid_online',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'show_payees',
|
||||
'event_type_id',
|
||||
'event_id',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the smarty template used to layout the search form and results listings.
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom/EventDetails.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the search query.
|
||||
*
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all(
|
||||
$offset = 0, $rowcount = 0, $sort = NULL,
|
||||
$includeContactIDs = FALSE, $justIDs = FALSE
|
||||
) {
|
||||
// SELECT clause must include contact_id as an alias for civicrm_contact.id if you are going to use "tasks" like export etc.
|
||||
$select = "civicrm_participant.event_id as event_id,
|
||||
COUNT(civicrm_participant.id) as participant_count,
|
||||
GROUP_CONCAT(DISTINCT(civicrm_event.title)) as event_name,
|
||||
civicrm_event.event_type_id as event_type_id,
|
||||
civicrm_option_value.label as event_type,
|
||||
IF(civicrm_contribution.payment_instrument_id <>0 , 'Yes', 'No') as payment_instrument_id,
|
||||
SUM(civicrm_contribution.total_amount) as payment_amount,
|
||||
format(sum(if(civicrm_contribution.payment_instrument_id <>0,(civicrm_contribution.total_amount *.034) +.45,0)),2) as fee,
|
||||
format(sum(civicrm_contribution.total_amount - (if(civicrm_contribution.payment_instrument_id <>0,(civicrm_contribution.total_amount *.034) +.45,0))),2) as net_payment";
|
||||
|
||||
$from = $this->from();
|
||||
|
||||
$onLine = CRM_Utils_Array::value('paid_online',
|
||||
$this->_formValues
|
||||
);
|
||||
if ($onLine) {
|
||||
$from .= "
|
||||
inner join civicrm_entity_financial_trxn
|
||||
on (civicrm_entity_financial_trxn.entity_id = civicrm_participant_payment.contribution_id and civicrm_entity_financial_trxn.entity_table='civicrm_contribution')";
|
||||
}
|
||||
|
||||
$showPayees = CRM_Utils_Array::value('show_payees',
|
||||
$this->_formValues
|
||||
);
|
||||
if ($showPayees) {
|
||||
$select .= ", GROUP_CONCAT(DISTINCT(civicrm_contact.display_name)) as participant ";
|
||||
$from .= " inner join civicrm_contact
|
||||
on civicrm_contact.id = civicrm_participant.contact_id";
|
||||
}
|
||||
else {
|
||||
unset($this->_columns[ts('Participant')]);
|
||||
}
|
||||
|
||||
$where = $this->where();
|
||||
$groupFromSelect = "civicrm_option_value.label, civicrm_contribution.payment_instrument_id";
|
||||
|
||||
$groupBy = "event_id, event_type_id, {$groupFromSelect}";
|
||||
if (!empty($this->_formValues['event_type_id'])) {
|
||||
$groupBy = "event_type_id, event_id, {$groupFromSelect}";
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT $select
|
||||
FROM $from
|
||||
WHERE $where
|
||||
GROUP BY $groupBy
|
||||
";
|
||||
// Define ORDER BY for query in $sort, with default value
|
||||
if (!empty($sort)) {
|
||||
if (is_string($sort)) {
|
||||
$sql .= " ORDER BY $sort ";
|
||||
}
|
||||
else {
|
||||
$sql .= " ORDER BY " . trim($sort->orderBy());
|
||||
}
|
||||
}
|
||||
else {
|
||||
$sql .= "ORDER BY event_name desc";
|
||||
}
|
||||
|
||||
if ($rowcount > 0 && $offset >= 0) {
|
||||
$offset = CRM_Utils_Type::escape($offset, 'Int');
|
||||
$rowcount = CRM_Utils_Type::escape($rowcount, 'Int');
|
||||
$sql .= " LIMIT $offset, $rowcount ";
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function from() {
|
||||
$this->buildACLClause('contact_a');
|
||||
$from = "
|
||||
civicrm_participant_payment
|
||||
left join civicrm_participant
|
||||
on civicrm_participant_payment.participant_id=civicrm_participant.id
|
||||
|
||||
left join civicrm_contact contact_a
|
||||
on civicrm_participant.contact_id = contact_a.id
|
||||
|
||||
left join civicrm_event on
|
||||
civicrm_participant.event_id = civicrm_event.id
|
||||
|
||||
left join civicrm_contribution
|
||||
on civicrm_contribution.id = civicrm_participant_payment.contribution_id
|
||||
|
||||
left join civicrm_option_value on
|
||||
( civicrm_option_value.value = civicrm_event.event_type_id AND civicrm_option_value.option_group_id = 14) {$this->_aclFrom}";
|
||||
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* WHERE clause is an array built from any required JOINS plus conditional filters based on search criteria field values.
|
||||
*
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
$clauses = array();
|
||||
|
||||
$clauses[] = "civicrm_participant.status_id in ( 1 )";
|
||||
$clauses[] = "civicrm_contribution.is_test = 0";
|
||||
$onLine = CRM_Utils_Array::value('paid_online',
|
||||
$this->_formValues
|
||||
);
|
||||
if ($onLine) {
|
||||
$clauses[] = "civicrm_contribution.payment_instrument_id <> 0";
|
||||
}
|
||||
|
||||
$startDate = CRM_Utils_Date::processDate($this->_formValues['start_date']);
|
||||
if ($startDate) {
|
||||
$clauses[] = "civicrm_contribution.receive_date >= $startDate";
|
||||
}
|
||||
|
||||
$endDate = CRM_Utils_Date::processDate($this->_formValues['end_date']);
|
||||
if ($endDate) {
|
||||
$clauses[] = "civicrm_contribution.receive_date <= {$endDate}235959";
|
||||
}
|
||||
|
||||
if (!empty($this->_formValues['event_id'])) {
|
||||
$clauses[] = "civicrm_event.id = {$this->_formValues['event_id']}";
|
||||
}
|
||||
|
||||
if ($includeContactIDs) {
|
||||
$contactIDs = array();
|
||||
foreach ($this->_formValues as $id => $value) {
|
||||
if ($value &&
|
||||
substr($id, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX
|
||||
) {
|
||||
$contactIDs[] = substr($id, CRM_Core_Form::CB_PREFIX_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($contactIDs)) {
|
||||
$contactIDs = implode(', ', $contactIDs);
|
||||
$clauses[] = "contact.id IN ( $contactIDs )";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->_formValues['event_type_id'])) {
|
||||
$event_type_ids = implode(',', array_keys($this->_formValues['event_type_id']));
|
||||
$clauses[] = "civicrm_event.event_type_id IN ( $event_type_ids )";
|
||||
}
|
||||
if ($this->_aclWhere) {
|
||||
$clauses[] = "{$this->_aclWhere} ";
|
||||
}
|
||||
return implode(' AND ', $clauses);
|
||||
}
|
||||
|
||||
|
||||
/* This function does a query to get totals for some of the search result columns and returns a totals array. */
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function summary() {
|
||||
$totalSelect = "
|
||||
SUM(civicrm_contribution.total_amount) as payment_amount,COUNT(civicrm_participant.id) as participant_count,
|
||||
format(sum(if(civicrm_contribution.payment_instrument_id <>0,(civicrm_contribution.total_amount *.034) +.45,0)),2) as fee,
|
||||
format(sum(civicrm_contribution.total_amount - (if(civicrm_contribution.payment_instrument_id <>0,(civicrm_contribution.total_amount *.034) +.45,0))),2) as net_payment";
|
||||
|
||||
$from = $this->from();
|
||||
|
||||
$onLine = CRM_Utils_Array::value('paid_online',
|
||||
$this->_formValues
|
||||
);
|
||||
if ($onLine) {
|
||||
$from .= "
|
||||
inner join civicrm_entity_financial_trxn
|
||||
on (civicrm_entity_financial_trxn.entity_id = civicrm_participant_payment.contribution_id and civicrm_entity_financial_trxn.entity_table='civicrm_contribution')";
|
||||
}
|
||||
|
||||
$where = $this->where();
|
||||
|
||||
$sql = "
|
||||
SELECT $totalSelect
|
||||
FROM $from
|
||||
WHERE $where
|
||||
";
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql,
|
||||
CRM_Core_DAO::$_nullArray
|
||||
);
|
||||
$totals = array();
|
||||
while ($dao->fetch()) {
|
||||
$totals['payment_amount'] = $dao->payment_amount;
|
||||
$totals['fee'] = $dao->fee;
|
||||
$totals['net_payment'] = $dao->net_payment;
|
||||
$totals['participant_count'] = $dao->participant_count;
|
||||
}
|
||||
return $totals;
|
||||
}
|
||||
|
||||
/*
|
||||
* Functions below generally don't need to be modified
|
||||
*/
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function count() {
|
||||
$sql = $this->all();
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql,
|
||||
CRM_Core_DAO::$_nullArray
|
||||
);
|
||||
return $dao->N;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $returnSQL Not used; included for consistency with parent; SQL is always returned
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = TRUE) {
|
||||
return $this->all($offset, $rowcount, $sort);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function &columns() {
|
||||
return $this->_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Search'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,554 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_FullText extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
|
||||
const LIMIT = 10;
|
||||
|
||||
/**
|
||||
* @var array CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery
|
||||
*/
|
||||
protected $_partialQueries = NULL;
|
||||
|
||||
protected $_formValues;
|
||||
|
||||
protected $_columns;
|
||||
|
||||
protected $_text = NULL;
|
||||
|
||||
protected $_table = NULL;
|
||||
|
||||
protected $_tableName = NULL;
|
||||
|
||||
protected $_entityIDTableName = NULL;
|
||||
|
||||
protected $_tableFields = NULL;
|
||||
|
||||
/**
|
||||
* @var array|null NULL if no limit; or array(0 => $limit, 1 => $offset)
|
||||
*/
|
||||
protected $_limitClause = NULL;
|
||||
|
||||
/**
|
||||
* @var array|null NULL if no limit; or array(0 => $limit, 1 => $offset)
|
||||
*/
|
||||
protected $_limitRowClause = NULL;
|
||||
|
||||
/**
|
||||
* @var array|null NULL if no limit; or array(0 => $limit, 1 => $offset)
|
||||
*/
|
||||
protected $_limitDetailClause = NULL;
|
||||
|
||||
protected $_limitNumber = 10;
|
||||
protected $_limitNumberPlus1 = 11; // this should be one more than self::LIMIT
|
||||
|
||||
protected $_foundRows = array();
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
$this->_partialQueries = array(
|
||||
new CRM_Contact_Form_Search_Custom_FullText_Contact(),
|
||||
new CRM_Contact_Form_Search_Custom_FullText_Activity(),
|
||||
new CRM_Contact_Form_Search_Custom_FullText_Case(),
|
||||
new CRM_Contact_Form_Search_Custom_FullText_Contribution(),
|
||||
new CRM_Contact_Form_Search_Custom_FullText_Participant(),
|
||||
new CRM_Contact_Form_Search_Custom_FullText_Membership(),
|
||||
);
|
||||
|
||||
$formValues['table'] = $this->getFieldValue($formValues, 'table', 'String');
|
||||
$this->_table = $formValues['table'];
|
||||
|
||||
$formValues['text'] = trim($this->getFieldValue($formValues, 'text', 'String', ''));
|
||||
$this->_text = $formValues['text'];
|
||||
|
||||
if (!$this->_table) {
|
||||
$this->_limitClause = array($this->_limitNumberPlus1, NULL);
|
||||
$this->_limitRowClause = $this->_limitDetailClause = array($this->_limitNumber, NULL);
|
||||
}
|
||||
else {
|
||||
// when there is table specified, we would like to use the pager. But since
|
||||
// 1. this custom search has slightly different structure ,
|
||||
// 2. we are in constructor right now,
|
||||
// we 'll use a small hack -
|
||||
$rowCount = CRM_Utils_Array::value('crmRowCount', $_REQUEST, CRM_Utils_Pager::ROWCOUNT);
|
||||
$pageId = CRM_Utils_Array::value('crmPID', $_REQUEST, 1);
|
||||
$offset = ($pageId - 1) * $rowCount;
|
||||
$this->_limitClause = NULL;
|
||||
$this->_limitRowClause = array($rowCount, NULL);
|
||||
$this->_limitDetailClause = array($rowCount, $offset);
|
||||
}
|
||||
|
||||
$this->_formValues = $formValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value from $formValues. If missing, get it from the request.
|
||||
*
|
||||
* @param $formValues
|
||||
* @param $field
|
||||
* @param $type
|
||||
* @param null $default
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function getFieldValue($formValues, $field, $type, $default = NULL) {
|
||||
$value = CRM_Utils_Array::value($field, $formValues);
|
||||
if (!$value) {
|
||||
return CRM_Utils_Request::retrieve($field, $type, CRM_Core_DAO::$_nullObject, FALSE, $default);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
}
|
||||
|
||||
public function initialize() {
|
||||
static $initialized = FALSE;
|
||||
|
||||
if (!$initialized) {
|
||||
$initialized = TRUE;
|
||||
|
||||
$this->buildTempTable();
|
||||
|
||||
$this->fillTable();
|
||||
}
|
||||
}
|
||||
|
||||
public function buildTempTable() {
|
||||
$randomNum = md5(uniqid());
|
||||
$this->_tableName = "civicrm_temp_custom_details_{$randomNum}";
|
||||
|
||||
$this->_tableFields = array(
|
||||
'id' => 'int unsigned NOT NULL AUTO_INCREMENT',
|
||||
'table_name' => 'varchar(16)',
|
||||
'contact_id' => 'int unsigned',
|
||||
'sort_name' => 'varchar(128)',
|
||||
'display_name' => 'varchar(128)',
|
||||
'assignee_contact_id' => 'int unsigned',
|
||||
'assignee_sort_name' => 'varchar(128)',
|
||||
'target_contact_id' => 'int unsigned',
|
||||
'target_sort_name' => 'varchar(128)',
|
||||
'activity_id' => 'int unsigned',
|
||||
'activity_type_id' => 'int unsigned',
|
||||
'record_type' => 'varchar(16)',
|
||||
'client_id' => 'int unsigned',
|
||||
'case_id' => 'int unsigned',
|
||||
'case_start_date' => 'datetime',
|
||||
'case_end_date' => 'datetime',
|
||||
'case_is_deleted' => 'tinyint',
|
||||
'subject' => 'varchar(255)',
|
||||
'details' => 'varchar(255)',
|
||||
'contribution_id' => 'int unsigned',
|
||||
'financial_type' => 'varchar(255)',
|
||||
'contribution_page' => 'varchar(255)',
|
||||
'contribution_receive_date' => 'datetime',
|
||||
'contribution_total_amount' => 'decimal(20,2)',
|
||||
'contribution_trxn_Id' => 'varchar(255)',
|
||||
'contribution_source' => 'varchar(255)',
|
||||
'contribution_status' => 'varchar(255)',
|
||||
'contribution_check_number' => 'varchar(255)',
|
||||
'participant_id' => 'int unsigned',
|
||||
'event_title' => 'varchar(255)',
|
||||
'participant_fee_level' => 'varchar(255)',
|
||||
'participant_fee_amount' => 'int unsigned',
|
||||
'participant_source' => 'varchar(255)',
|
||||
'participant_register_date' => 'datetime',
|
||||
'participant_status' => 'varchar(255)',
|
||||
'participant_role' => 'varchar(255)',
|
||||
'membership_id' => 'int unsigned',
|
||||
'membership_fee' => 'int unsigned',
|
||||
'membership_type' => 'varchar(255)',
|
||||
'membership_start_date' => 'datetime',
|
||||
'membership_end_date' => 'datetime',
|
||||
'membership_source' => 'varchar(255)',
|
||||
'membership_status' => 'varchar(255)',
|
||||
// We may have multiple files to list on one record.
|
||||
// The temporary-table approach can't store full details for all of them
|
||||
'file_ids' => 'varchar(255)', // comma-separate id listing
|
||||
);
|
||||
|
||||
$sql = "
|
||||
CREATE TEMPORARY TABLE {$this->_tableName} (
|
||||
";
|
||||
|
||||
foreach ($this->_tableFields as $name => $desc) {
|
||||
$sql .= "$name $desc,\n";
|
||||
}
|
||||
|
||||
$sql .= "
|
||||
PRIMARY KEY ( id )
|
||||
) ENGINE=HEAP DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
$this->_entityIDTableName = "civicrm_temp_custom_entityID_{$randomNum}";
|
||||
$sql = "
|
||||
CREATE TEMPORARY TABLE {$this->_entityIDTableName} (
|
||||
id int unsigned NOT NULL AUTO_INCREMENT,
|
||||
entity_id int unsigned NOT NULL,
|
||||
|
||||
UNIQUE INDEX unique_entity_id ( entity_id ),
|
||||
PRIMARY KEY ( id )
|
||||
) ENGINE=HEAP DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
if (!empty($this->_formValues['is_unit_test'])) {
|
||||
$this->_tableNameForTest = $this->_tableName;
|
||||
}
|
||||
}
|
||||
|
||||
public function fillTable() {
|
||||
foreach ($this->_partialQueries as $partialQuery) {
|
||||
/** @var $partialQuery CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery */
|
||||
if (!$this->_table || $this->_table == $partialQuery->getName()) {
|
||||
if ($partialQuery->isActive()) {
|
||||
$result = $partialQuery->fillTempTable($this->_text, $this->_entityIDTableName, $this->_tableName, $this->_limitClause, $this->_limitDetailClause);
|
||||
$this->_foundRows[$partialQuery->getName()] = $result['count'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->filterACLContacts();
|
||||
}
|
||||
|
||||
public function filterACLContacts() {
|
||||
if (CRM_Core_Permission::check('view all contacts')) {
|
||||
CRM_Core_DAO::executeQuery("DELETE FROM {$this->_tableName} WHERE contact_id IN (SELECT id FROM civicrm_contact WHERE is_deleted = 1)");
|
||||
return;
|
||||
}
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$contactID = $session->get('userID');
|
||||
if (!$contactID) {
|
||||
$contactID = 0;
|
||||
}
|
||||
|
||||
CRM_Contact_BAO_Contact_Permission::cache($contactID);
|
||||
|
||||
$params = array(1 => array($contactID, 'Integer'));
|
||||
|
||||
$sql = "
|
||||
DELETE t.*
|
||||
FROM {$this->_tableName} t
|
||||
WHERE NOT EXISTS ( SELECT c.contact_id
|
||||
FROM civicrm_acl_contact_cache c
|
||||
WHERE c.user_id = %1 AND t.contact_id = c.contact_id )
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql, $params);
|
||||
|
||||
$sql = "
|
||||
DELETE t.*
|
||||
FROM {$this->_tableName} t
|
||||
WHERE t.table_name = 'Activity' AND
|
||||
NOT EXISTS ( SELECT c.contact_id
|
||||
FROM civicrm_acl_contact_cache c
|
||||
WHERE c.user_id = %1 AND ( t.target_contact_id = c.contact_id OR t.target_contact_id IS NULL ) )
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql, $params);
|
||||
|
||||
$sql = "
|
||||
DELETE t.*
|
||||
FROM {$this->_tableName} t
|
||||
WHERE t.table_name = 'Activity' AND
|
||||
NOT EXISTS ( SELECT c.contact_id
|
||||
FROM civicrm_acl_contact_cache c
|
||||
WHERE c.user_id = %1 AND ( t.assignee_contact_id = c.contact_id OR t.assignee_contact_id IS NULL ) )
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
$form->applyFilter('__ALL__', 'trim');
|
||||
$form->add('text',
|
||||
'text',
|
||||
ts('Find'),
|
||||
TRUE
|
||||
);
|
||||
|
||||
// also add a select box to allow the search to be constrained
|
||||
$tables = array('' => ts('All tables'));
|
||||
foreach ($this->_partialQueries as $partialQuery) {
|
||||
/** @var $partialQuery CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery */
|
||||
if ($partialQuery->isActive()) {
|
||||
$tables[$partialQuery->getName()] = $partialQuery->getLabel();
|
||||
}
|
||||
}
|
||||
|
||||
$form->add('select', 'table', ts('Tables'), $tables);
|
||||
|
||||
$form->assign('csID', $form->get('csid'));
|
||||
|
||||
// also add the limit constant
|
||||
$form->assign('limit', self::LIMIT);
|
||||
|
||||
// set form defaults
|
||||
if (!empty($form->_formValues)) {
|
||||
$defaults = array();
|
||||
|
||||
if (isset($form->_formValues['text'])) {
|
||||
$defaults['text'] = $form->_formValues['text'];
|
||||
}
|
||||
|
||||
if (isset($form->_formValues['table'])) {
|
||||
$defaults['table'] = $form->_formValues['table'];
|
||||
$form->assign('table', $form->_formValues['table']);
|
||||
}
|
||||
|
||||
$form->setDefaults($defaults);
|
||||
}
|
||||
|
||||
/**
|
||||
* You can define a custom title for the search form
|
||||
*/
|
||||
$this->setTitle(ts('Full-text Search'));
|
||||
|
||||
$searchService = CRM_Core_BAO_File::getSearchService();
|
||||
$form->assign('allowFileSearch', !empty($searchService) && CRM_Core_Permission::check('access uploaded files'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function &columns() {
|
||||
$this->_columns = array(
|
||||
ts('Contact ID') => 'contact_id',
|
||||
ts('Name') => 'sort_name',
|
||||
);
|
||||
|
||||
return $this->_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function summary() {
|
||||
$this->initialize();
|
||||
|
||||
$summary = array();
|
||||
foreach ($this->_partialQueries as $partialQuery) {
|
||||
/** @var $partialQuery CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery */
|
||||
$summary[$partialQuery->getName()] = array();
|
||||
}
|
||||
|
||||
// now iterate through the table and add entries to the relevant section
|
||||
$sql = "SELECT * FROM {$this->_tableName}";
|
||||
if ($this->_table) {
|
||||
$sql .= " {$this->toLimit($this->_limitRowClause)} ";
|
||||
}
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE);
|
||||
$roleIds = CRM_Event_PseudoConstant::participantRole();
|
||||
while ($dao->fetch()) {
|
||||
$row = array();
|
||||
foreach ($this->_tableFields as $name => $dontCare) {
|
||||
if ($name != 'activity_type_id') {
|
||||
$row[$name] = $dao->$name;
|
||||
}
|
||||
else {
|
||||
$row['activity_type'] = CRM_Utils_Array::value($dao->$name, $activityTypes);
|
||||
}
|
||||
}
|
||||
if (isset($row['participant_role'])) {
|
||||
$participantRole = explode(CRM_Core_DAO::VALUE_SEPARATOR, $row['participant_role']);
|
||||
$viewRoles = array();
|
||||
foreach ($participantRole as $v) {
|
||||
$viewRoles[] = $roleIds[$v];
|
||||
}
|
||||
$row['participant_role'] = implode(', ', $viewRoles);
|
||||
}
|
||||
if (!empty($row['file_ids'])) {
|
||||
$fileIds = (explode(',', $row['file_ids']));
|
||||
$fileHtml = '';
|
||||
foreach ($fileIds as $fileId) {
|
||||
$paperclip = CRM_Core_BAO_File::paperIconAttachment('*', $fileId);
|
||||
if ($paperclip) {
|
||||
$fileHtml .= implode('', $paperclip);
|
||||
}
|
||||
}
|
||||
$row['fileHtml'] = $fileHtml;
|
||||
}
|
||||
$summary[$dao->table_name][] = $row;
|
||||
}
|
||||
|
||||
$summary['Count'] = array();
|
||||
foreach (array_keys($summary) as $table) {
|
||||
$summary['Count'][$table] = CRM_Utils_Array::value($table, $this->_foundRows);
|
||||
if ($summary['Count'][$table] >= self::LIMIT) {
|
||||
$summary['addShowAllLink'][$table] = TRUE;
|
||||
}
|
||||
else {
|
||||
$summary['addShowAllLink'][$table] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return $summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function count() {
|
||||
$this->initialize();
|
||||
|
||||
if ($this->_table) {
|
||||
return $this->_foundRows[$this->_table];
|
||||
}
|
||||
else {
|
||||
return CRM_Core_DAO::singleValueQuery("SELECT count(id) FROM {$this->_tableName}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $returnSQL
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
|
||||
$this->initialize();
|
||||
|
||||
if ($returnSQL) {
|
||||
return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
|
||||
}
|
||||
else {
|
||||
return CRM_Core_DAO::singleValueQuery("SELECT contact_id FROM {$this->_tableName}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all($offset = 0, $rowcount = 0, $sort = NULL, $includeContactIDs = FALSE, $justIDs = FALSE) {
|
||||
$this->initialize();
|
||||
|
||||
if ($justIDs) {
|
||||
$select = "contact_a.id as contact_id";
|
||||
}
|
||||
else {
|
||||
$select = "
|
||||
contact_a.contact_id as contact_id ,
|
||||
contact_a.sort_name as sort_name
|
||||
";
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT $select
|
||||
FROM {$this->_tableName} contact_a
|
||||
{$this->toLimit($this->_limitRowClause)}
|
||||
";
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function from() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom/FullText.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $row
|
||||
*/
|
||||
public function alterRow(&$row) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|array $limit
|
||||
* @return string
|
||||
* SQL
|
||||
* @see CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery::toLimit
|
||||
*/
|
||||
public function toLimit($limit) {
|
||||
if (is_array($limit)) {
|
||||
list ($limit, $offset) = $limit;
|
||||
}
|
||||
if (empty($limit)) {
|
||||
return '';
|
||||
}
|
||||
$result = "LIMIT {$limit}";
|
||||
if ($offset) {
|
||||
$result .= " OFFSET {$offset}";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,344 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
abstract class CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $label
|
||||
*/
|
||||
public function __construct($name, $label) {
|
||||
$this->name = $name;
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get label.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLabel() {
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a query and write out a page worth of matches to $detailTable.
|
||||
*
|
||||
* TODO: Consider removing $entityIDTableName from the function-signature. Each implementation could be
|
||||
* responsible for its own temp tables.
|
||||
*
|
||||
* TODO: Understand why $queryLimit and $detailLimit are different
|
||||
*
|
||||
* @param string $queryText
|
||||
* A string of text to search for.
|
||||
* @param string $entityIDTableName
|
||||
* A temporary table into which we can write a list of all matching IDs.
|
||||
* @param string $detailTable
|
||||
* A table into which we can write details about a page worth of matches.
|
||||
* @param array|NULL $queryLimit overall limit (applied when building $entityIDTableName)
|
||||
* NULL if no limit; or array(0 => $limit, 1 => $offset)
|
||||
* @param array|NULL $detailLimit final limit (applied when building $detailTable)
|
||||
* NULL if no limit; or array(0 => $limit, 1 => $offset)
|
||||
* @return array
|
||||
* keys: match-descriptor
|
||||
* - count: int
|
||||
*/
|
||||
public abstract function fillTempTable($queryText, $entityIDTableName, $detailTable, $queryLimit, $detailLimit);
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $tables
|
||||
* @param $extends
|
||||
*/
|
||||
public function fillCustomInfo(&$tables, $extends) {
|
||||
$sql = "
|
||||
SELECT cg.table_name, cf.column_name
|
||||
FROM civicrm_custom_group cg
|
||||
INNER JOIN civicrm_custom_field cf ON cf.custom_group_id = cg.id
|
||||
WHERE cg.extends IN $extends
|
||||
AND cg.is_active = 1
|
||||
AND cf.is_active = 1
|
||||
AND cf.is_searchable = 1
|
||||
AND cf.html_type IN ( 'Text', 'TextArea', 'RichTextEditor' )
|
||||
";
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
while ($dao->fetch()) {
|
||||
if (!array_key_exists($dao->table_name, $tables)) {
|
||||
$tables[$dao->table_name] = array(
|
||||
'id' => 'entity_id',
|
||||
'fields' => array(),
|
||||
);
|
||||
}
|
||||
$tables[$dao->table_name]['fields'][$dao->column_name] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run queries.
|
||||
*
|
||||
* @param string $queryText
|
||||
* @param array $tables
|
||||
* A list of places to query. Keys may be:.
|
||||
* - sql: an array of SQL queries to execute
|
||||
* - final: an array of SQL queries to execute at the end
|
||||
* - *: All other keys are treated as table names
|
||||
* @param string $entityIDTableName
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
* Keys: match-descriptor
|
||||
* - count: int
|
||||
* - files: NULL | array
|
||||
* @throws \CRM_Core_Exception
|
||||
*/
|
||||
public function runQueries($queryText, &$tables, $entityIDTableName, $limit) {
|
||||
$sql = "TRUNCATE {$entityIDTableName}";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
$files = NULL;
|
||||
|
||||
foreach ($tables as $tableName => $tableValues) {
|
||||
if ($tableName == 'final') {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
if ($tableName == 'sql') {
|
||||
foreach ($tableValues as $sqlStatement) {
|
||||
$sql = "
|
||||
REPLACE INTO {$entityIDTableName} ( entity_id )
|
||||
$sqlStatement
|
||||
{$this->toLimit($limit)}
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
}
|
||||
}
|
||||
elseif ($tableName == 'file') {
|
||||
$searcher = CRM_Core_BAO_File::getSearchService();
|
||||
if (!($searcher && CRM_Core_Permission::check('access uploaded files'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$query = $tableValues + array(
|
||||
'text' => CRM_Utils_QueryFormatter::singleton()
|
||||
->format($queryText, CRM_Utils_QueryFormatter::LANG_SOLR),
|
||||
);
|
||||
list($intLimit, $intOffset) = $this->parseLimitOffset($limit);
|
||||
$files = $searcher->search($query, $intLimit, $intOffset);
|
||||
$matches = array();
|
||||
foreach ($files as $file) {
|
||||
$matches[] = array('entity_id' => $file['xparent_id']);
|
||||
}
|
||||
if ($matches) {
|
||||
$insertSql = CRM_Utils_SQL_Insert::into($entityIDTableName)->usingReplace()->rows($matches)->toSQL();
|
||||
CRM_Core_DAO::executeQuery($insertSql);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$fullTextFields = array(); // array (string $sqlColumnName)
|
||||
$clauses = array(); // array (string $sqlExpression)
|
||||
|
||||
foreach ($tableValues['fields'] as $fieldName => $fieldType) {
|
||||
if ($fieldType == 'Int') {
|
||||
if (is_numeric($queryText)) {
|
||||
$clauses[] = "$fieldName = {$queryText}";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$fullTextFields[] = $fieldName;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($fullTextFields)) {
|
||||
$clauses[] = $this->matchText($tableName, $fullTextFields, $queryText);
|
||||
}
|
||||
|
||||
if (empty($clauses)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$whereClause = implode(' OR ', $clauses);
|
||||
|
||||
//resolve conflict between entity tables.
|
||||
if ($tableName == 'civicrm_note' &&
|
||||
$entityTable = CRM_Utils_Array::value('entity_table', $tableValues)
|
||||
) {
|
||||
$whereClause .= " AND entity_table = '{$entityTable}'";
|
||||
}
|
||||
|
||||
$sql = "
|
||||
REPLACE INTO {$entityIDTableName} ( entity_id )
|
||||
SELECT {$tableValues['id']}
|
||||
FROM $tableName
|
||||
WHERE ( $whereClause )
|
||||
AND {$tableValues['id']} IS NOT NULL
|
||||
GROUP BY {$tableValues['id']}
|
||||
{$this->toLimit($limit)}
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($tables['final'])) {
|
||||
foreach ($tables['final'] as $sqlStatement) {
|
||||
CRM_Core_DAO::executeQuery($sqlStatement);
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'count' => CRM_Core_DAO::singleValueQuery("SELECT count(*) FROM {$entityIDTableName}"),
|
||||
'files' => $files,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a SQL expression for matching against a list of.
|
||||
* text columns.
|
||||
*
|
||||
* @param string $table
|
||||
* Eg "civicrm_note" or "civicrm_note mynote".
|
||||
* @param array|string $fullTextFields list of field names
|
||||
* @param string $queryText
|
||||
* @return string
|
||||
* SQL, eg "MATCH (col1) AGAINST (queryText)" or "col1 LIKE '%queryText%'"
|
||||
*/
|
||||
public function matchText($table, $fullTextFields, $queryText) {
|
||||
return CRM_Utils_QueryFormatter::singleton()->formatSql($table, $fullTextFields, $queryText);
|
||||
}
|
||||
|
||||
/**
|
||||
* For any records in $toTable that originated with this query,
|
||||
* append file information.
|
||||
*
|
||||
* @param string $toTable
|
||||
* @param string $parentIdColumn
|
||||
* @param array $files
|
||||
* See return format of CRM_Core_FileSearchInterface::search.
|
||||
*/
|
||||
public function moveFileIDs($toTable, $parentIdColumn, $files) {
|
||||
if (empty($files)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$filesIndex = CRM_Utils_Array::index(array('xparent_id', 'file_id'), $files);
|
||||
// ex: $filesIndex[$xparent_id][$file_id] = array(...the file record...);
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery("
|
||||
SELECT distinct {$parentIdColumn}
|
||||
FROM {$toTable}
|
||||
WHERE table_name = %1
|
||||
", array(
|
||||
1 => array($this->getName(), 'String'),
|
||||
));
|
||||
while ($dao->fetch()) {
|
||||
if (empty($filesIndex[$dao->{$parentIdColumn}])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CRM_Core_DAO::executeQuery("UPDATE {$toTable}
|
||||
SET file_ids = %1
|
||||
WHERE table_name = %2 AND {$parentIdColumn} = %3
|
||||
", array(
|
||||
1 => array(implode(',', array_keys($filesIndex[$dao->{$parentIdColumn}])), 'String'),
|
||||
2 => array($this->getName(), 'String'),
|
||||
3 => array($dao->{$parentIdColumn}, 'Int'),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|array $limit
|
||||
* @return string
|
||||
* SQL
|
||||
* @see CRM_Contact_Form_Search_Custom_FullText::toLimit
|
||||
*/
|
||||
public function toLimit($limit) {
|
||||
if (is_array($limit)) {
|
||||
list ($limit, $offset) = $limit;
|
||||
}
|
||||
if (empty($limit)) {
|
||||
return '';
|
||||
}
|
||||
$result = "LIMIT {$limit}";
|
||||
if ($offset) {
|
||||
$result .= " OFFSET {$offset}";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|int $limit
|
||||
* @return array
|
||||
* (0 => $limit, 1 => $offset)
|
||||
*/
|
||||
public function parseLimitOffset($limit) {
|
||||
if (is_scalar($limit)) {
|
||||
$intLimit = $limit;
|
||||
}
|
||||
else {
|
||||
list ($intLimit, $intOffset) = $limit;
|
||||
}
|
||||
if (!$intOffset) {
|
||||
$intOffset = 0;
|
||||
}
|
||||
return array($intLimit, $intOffset);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_FullText_Activity extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct('Activity', ts('Activities'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is search active for this user.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive() {
|
||||
return CRM_Core_Permission::check('view all activities');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function fillTempTable($queryText, $entityIDTableName, $toTable, $queryLimit, $detailLimit) {
|
||||
$queries = $this->prepareQueries($queryText, $entityIDTableName);
|
||||
$result = $this->runQueries($queryText, $queries, $entityIDTableName, $queryLimit);
|
||||
$this->moveIDs($entityIDTableName, $toTable, $detailLimit);
|
||||
if (!empty($result['files'])) {
|
||||
$this->moveFileIDs($toTable, 'activity_id', $result['files']);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $queryText
|
||||
* @param string $entityIDTableName
|
||||
*
|
||||
* @return array
|
||||
* list tables/queries (for runQueries)
|
||||
*/
|
||||
public function prepareQueries($queryText, $entityIDTableName) {
|
||||
// Note: For available full-text indices, see CRM_Core_InnoDBIndexer
|
||||
|
||||
$contactSQL = array();
|
||||
|
||||
$contactSQL[] = "
|
||||
SELECT distinct ca.id
|
||||
FROM civicrm_activity ca
|
||||
INNER JOIN civicrm_activity_contact cat ON cat.activity_id = ca.id
|
||||
INNER JOIN civicrm_contact c ON cat.contact_id = c.id
|
||||
LEFT JOIN civicrm_email e ON cat.contact_id = e.contact_id
|
||||
LEFT JOIN civicrm_option_group og ON og.name = 'activity_type'
|
||||
LEFT JOIN civicrm_option_value ov ON ( ov.option_group_id = og.id )
|
||||
WHERE (
|
||||
({$this->matchText('civicrm_contact c', array('sort_name', 'display_name', 'nick_name'), $queryText)})
|
||||
OR
|
||||
({$this->matchText('civicrm_email e', 'email', $queryText)} AND ca.activity_type_id = ov.value AND ov.name IN ('Inbound Email', 'Email') )
|
||||
)
|
||||
AND (ca.is_deleted = 0 OR ca.is_deleted IS NULL)
|
||||
AND (c.is_deleted = 0 OR c.is_deleted IS NULL)
|
||||
";
|
||||
|
||||
$contactSQL[] = "
|
||||
SELECT et.entity_id
|
||||
FROM civicrm_entity_tag et
|
||||
INNER JOIN civicrm_tag t ON et.tag_id = t.id
|
||||
INNER JOIN civicrm_activity ca ON et.entity_id = ca.id
|
||||
WHERE et.entity_table = 'civicrm_activity'
|
||||
AND et.tag_id = t.id
|
||||
AND ({$this->matchText('civicrm_tag t', 'name', $queryText)})
|
||||
AND (ca.is_deleted = 0 OR ca.is_deleted IS NULL)
|
||||
GROUP BY et.entity_id
|
||||
";
|
||||
|
||||
$contactSQL[] = "
|
||||
SELECT distinct ca.id
|
||||
FROM civicrm_activity ca
|
||||
WHERE ({$this->matchText('civicrm_activity ca', array('subject', 'details'), $queryText)})
|
||||
AND (ca.is_deleted = 0 OR ca.is_deleted IS NULL)
|
||||
";
|
||||
|
||||
$final = array();
|
||||
|
||||
$tables = array(
|
||||
'civicrm_activity' => array('fields' => array()),
|
||||
'file' => array(
|
||||
'xparent_table' => 'civicrm_activity',
|
||||
),
|
||||
'sql' => $contactSQL,
|
||||
'final' => $final,
|
||||
);
|
||||
|
||||
$this->fillCustomInfo($tables, "( 'Activity' )");
|
||||
return $tables;;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move IDs.
|
||||
*
|
||||
* @param string $fromTable
|
||||
* @param string $toTable
|
||||
* @param int $limit
|
||||
*/
|
||||
public function moveIDs($fromTable, $toTable, $limit) {
|
||||
$sql = "
|
||||
INSERT INTO {$toTable}
|
||||
( table_name, activity_id, subject, details, contact_id, sort_name, record_type,
|
||||
activity_type_id, case_id, client_id )
|
||||
SELECT 'Activity', ca.id, substr(ca.subject, 1, 50), substr(ca.details, 1, 250),
|
||||
c1.id, c1.sort_name, cac.record_type_id,
|
||||
ca.activity_type_id,
|
||||
cca.case_id,
|
||||
ccc.contact_id as client_id
|
||||
FROM {$fromTable} eid
|
||||
INNER JOIN civicrm_activity ca ON ca.id = eid.entity_id
|
||||
INNER JOIN civicrm_activity_contact cac ON cac.activity_id = ca.id
|
||||
INNER JOIN civicrm_contact c1 ON cac.contact_id = c1.id
|
||||
LEFT JOIN civicrm_case_activity cca ON cca.activity_id = ca.id
|
||||
LEFT JOIN civicrm_case_contact ccc ON ccc.case_id = cca.case_id
|
||||
WHERE (ca.is_deleted = 0 OR ca.is_deleted IS NULL)
|
||||
{$this->toLimit($limit)}
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_FullText_Case extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct('Case', ts('Cases'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is CiviCase active?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive() {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
return in_array('CiviCase', $config->enableComponents);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function fillTempTable($queryText, $entityIDTableName, $toTable, $queryLimit, $detailLimit) {
|
||||
$queries = $this->prepareQueries($queryText, $entityIDTableName);
|
||||
$result = $this->runQueries($queryText, $queries, $entityIDTableName, $queryLimit);
|
||||
$this->moveIDs($entityIDTableName, $toTable, $detailLimit);
|
||||
if (!empty($result['files'])) {
|
||||
$this->moveFileIDs($toTable, 'case_id', $result['files']);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare queries.
|
||||
*
|
||||
* @param string $queryText
|
||||
* @param string $entityIDTableName
|
||||
*
|
||||
* @return array
|
||||
* list tables/queries (for runQueries)
|
||||
*/
|
||||
public function prepareQueries($queryText, $entityIDTableName) {
|
||||
// Note: For available full-text indices, see CRM_Core_InnoDBIndexer
|
||||
|
||||
$contactSQL = array();
|
||||
|
||||
$contactSQL[] = "
|
||||
SELECT distinct cc.id
|
||||
FROM civicrm_case cc
|
||||
LEFT JOIN civicrm_case_contact ccc ON cc.id = ccc.case_id
|
||||
LEFT JOIN civicrm_contact c ON ccc.contact_id = c.id
|
||||
WHERE ({$this->matchText('civicrm_contact c', array('sort_name', 'display_name', 'nick_name'), $queryText)})
|
||||
AND (cc.is_deleted = 0 OR cc.is_deleted IS NULL)
|
||||
";
|
||||
|
||||
if (is_numeric($queryText)) {
|
||||
$contactSQL[] = "
|
||||
SELECT distinct cc.id
|
||||
FROM civicrm_case cc
|
||||
LEFT JOIN civicrm_case_contact ccc ON cc.id = ccc.case_id
|
||||
LEFT JOIN civicrm_contact c ON ccc.contact_id = c.id
|
||||
WHERE cc.id = {$queryText}
|
||||
AND (cc.is_deleted = 0 OR cc.is_deleted IS NULL)
|
||||
";
|
||||
}
|
||||
|
||||
$contactSQL[] = "
|
||||
SELECT et.entity_id
|
||||
FROM civicrm_entity_tag et
|
||||
INNER JOIN civicrm_tag t ON et.tag_id = t.id
|
||||
WHERE et.entity_table = 'civicrm_case'
|
||||
AND et.tag_id = t.id
|
||||
AND ({$this->matchText('civicrm_tag t', 'name', $queryText)})
|
||||
GROUP BY et.entity_id
|
||||
";
|
||||
|
||||
$tables = array(
|
||||
'civicrm_case' => array('fields' => array()),
|
||||
'file' => array(
|
||||
'xparent_table' => 'civicrm_case',
|
||||
),
|
||||
'sql' => $contactSQL,
|
||||
);
|
||||
|
||||
return $tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move IDs.
|
||||
*
|
||||
* @param string $fromTable
|
||||
* @param string $toTable
|
||||
* @param int $limit
|
||||
*/
|
||||
public function moveIDs($fromTable, $toTable, $limit) {
|
||||
$sql = "
|
||||
INSERT INTO {$toTable}
|
||||
( table_name, contact_id, sort_name, case_id, case_start_date, case_end_date, case_is_deleted )
|
||||
SELECT 'Case', c.id, c.sort_name, cc.id, DATE(cc.start_date), DATE(cc.end_date), cc.is_deleted
|
||||
FROM {$fromTable} ct
|
||||
INNER JOIN civicrm_case cc ON cc.id = ct.entity_id
|
||||
LEFT JOIN civicrm_case_contact ccc ON cc.id = ccc.case_id
|
||||
LEFT JOIN civicrm_contact c ON ccc.contact_id = c.id
|
||||
{$this->toLimit($limit)}
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_FullText_Contact extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct('Contact', ts('Contacts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if search is permitted.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive() {
|
||||
return CRM_Core_Permission::check('view all contacts');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function fillTempTable($queryText, $entityIDTableName, $toTable, $queryLimit, $detailLimit) {
|
||||
$queries = $this->prepareQueries($queryText, $entityIDTableName);
|
||||
$result = $this->runQueries($queryText, $queries, $entityIDTableName, $queryLimit);
|
||||
$this->moveIDs($entityIDTableName, $toTable, $detailLimit);
|
||||
if (!empty($result['files'])) {
|
||||
$this->moveFileIDs($toTable, 'contact_id', $result['files']);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $queryText
|
||||
* @param string $entityIDTableName
|
||||
* @return array
|
||||
* list tables/queries (for runQueries)
|
||||
*/
|
||||
public function prepareQueries($queryText, $entityIDTableName) {
|
||||
// Note: For available full-text indices, see CRM_Core_InnoDBIndexer
|
||||
|
||||
$contactSQL = array();
|
||||
$contactSQL[] = "
|
||||
SELECT et.entity_id
|
||||
FROM civicrm_entity_tag et
|
||||
INNER JOIN civicrm_tag t ON et.tag_id = t.id
|
||||
WHERE et.entity_table = 'civicrm_contact'
|
||||
AND et.tag_id = t.id
|
||||
AND ({$this->matchText('civicrm_tag t', 'name', $queryText)})
|
||||
GROUP BY et.entity_id
|
||||
";
|
||||
|
||||
// lets delete all the deceased contacts from the entityID box
|
||||
// this allows us to keep numbers in sync
|
||||
// when we have acl contacts, the situation gets even more murky
|
||||
$final = array();
|
||||
$final[] = "DELETE FROM {$entityIDTableName} WHERE entity_id IN (SELECT id FROM civicrm_contact WHERE is_deleted = 1)";
|
||||
|
||||
$tables = array(
|
||||
'civicrm_contact' => array(
|
||||
'id' => 'id',
|
||||
'fields' => array(
|
||||
'sort_name' => NULL,
|
||||
'nick_name' => NULL,
|
||||
'display_name' => NULL,
|
||||
),
|
||||
),
|
||||
'civicrm_address' => array(
|
||||
'id' => 'contact_id',
|
||||
'fields' => array(
|
||||
'street_address' => NULL,
|
||||
'city' => NULL,
|
||||
'postal_code' => NULL,
|
||||
),
|
||||
),
|
||||
'civicrm_email' => array(
|
||||
'id' => 'contact_id',
|
||||
'fields' => array('email' => NULL),
|
||||
),
|
||||
'civicrm_phone' => array(
|
||||
'id' => 'contact_id',
|
||||
'fields' => array('phone' => NULL),
|
||||
),
|
||||
'civicrm_note' => array(
|
||||
'id' => 'entity_id',
|
||||
'entity_table' => 'civicrm_contact',
|
||||
'fields' => array(
|
||||
'subject' => NULL,
|
||||
'note' => NULL,
|
||||
),
|
||||
),
|
||||
'file' => array(
|
||||
'xparent_table' => 'civicrm_contact',
|
||||
),
|
||||
'sql' => $contactSQL,
|
||||
'final' => $final,
|
||||
);
|
||||
|
||||
// get the custom data info
|
||||
$this->fillCustomInfo($tables,
|
||||
"( 'Contact', 'Individual', 'Organization', 'Household' )"
|
||||
);
|
||||
|
||||
return $tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move IDs.
|
||||
*
|
||||
* @param $fromTable
|
||||
* @param $toTable
|
||||
* @param $limit
|
||||
*/
|
||||
public function moveIDs($fromTable, $toTable, $limit) {
|
||||
$sql = "
|
||||
INSERT INTO {$toTable}
|
||||
( id, contact_id, sort_name, display_name, table_name )
|
||||
SELECT c.id, ct.entity_id, c.sort_name, c.display_name, 'Contact'
|
||||
FROM {$fromTable} ct
|
||||
INNER JOIN civicrm_contact c ON ct.entity_id = c.id
|
||||
{$this->toLimit($limit)}
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_FullText_Contribution extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct('Contribution', ts('Contributions'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if search is permitted.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive() {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
return in_array('CiviContribute', $config->enableComponents) &&
|
||||
CRM_Core_Permission::check('access CiviContribute');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function fillTempTable($queryText, $entityIDTableName, $toTable, $queryLimit, $detailLimit) {
|
||||
$queries = $this->prepareQueries($queryText, $entityIDTableName);
|
||||
$result = $this->runQueries($queryText, $queries, $entityIDTableName, $queryLimit);
|
||||
$this->moveIDs($entityIDTableName, $toTable, $detailLimit);
|
||||
if (!empty($result['files'])) {
|
||||
$this->moveFileIDs($toTable, 'contribution_id', $result['files']);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get contribution ids in entity tables.
|
||||
*
|
||||
* @param string $queryText
|
||||
* @param string $entityIDTableName
|
||||
* @return array
|
||||
* list tables/queries (for runQueries)
|
||||
*/
|
||||
public function prepareQueries($queryText, $entityIDTableName) {
|
||||
// Note: For available full-text indices, see CRM_Core_InnoDBIndexer
|
||||
|
||||
$contactSQL = array();
|
||||
$contactSQL[] = "
|
||||
SELECT distinct cc.id
|
||||
FROM civicrm_contribution cc
|
||||
INNER JOIN civicrm_contact c ON cc.contact_id = c.id
|
||||
WHERE ({$this->matchText('civicrm_contact c', array('sort_name', 'display_name', 'nick_name'), $queryText)})
|
||||
";
|
||||
$tables = array(
|
||||
'civicrm_contribution' => array(
|
||||
'id' => 'id',
|
||||
'fields' => array(
|
||||
'source' => NULL,
|
||||
'amount_level' => NULL,
|
||||
'trxn_Id' => NULL,
|
||||
'invoice_id' => NULL,
|
||||
'check_number' => 'Int', // Odd: This is really a VARCHAR, so why are we searching like an INT?
|
||||
'total_amount' => 'Int',
|
||||
),
|
||||
),
|
||||
'file' => array(
|
||||
'xparent_table' => 'civicrm_contribution',
|
||||
),
|
||||
'sql' => $contactSQL,
|
||||
'civicrm_note' => array(
|
||||
'id' => 'entity_id',
|
||||
'entity_table' => 'civicrm_contribution',
|
||||
'fields' => array(
|
||||
'subject' => NULL,
|
||||
'note' => NULL,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// get the custom data info
|
||||
$this->fillCustomInfo($tables, "( 'Contribution' )");
|
||||
return $tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move IDs.
|
||||
*
|
||||
* @param string $fromTable
|
||||
* @param string $toTable
|
||||
* @param int $limit
|
||||
*/
|
||||
public function moveIDs($fromTable, $toTable, $limit) {
|
||||
$sql = "
|
||||
INSERT INTO {$toTable}
|
||||
( table_name, contact_id, sort_name, contribution_id, financial_type, contribution_page, contribution_receive_date,
|
||||
contribution_total_amount, contribution_trxn_Id, contribution_source, contribution_status, contribution_check_number )
|
||||
SELECT 'Contribution', c.id, c.sort_name, cc.id, cct.name, ccp.title, cc.receive_date,
|
||||
cc.total_amount, cc.trxn_id, cc.source, contribution_status.label, cc.check_number
|
||||
FROM {$fromTable} ct
|
||||
INNER JOIN civicrm_contribution cc ON cc.id = ct.entity_id
|
||||
LEFT JOIN civicrm_contact c ON cc.contact_id = c.id
|
||||
LEFT JOIN civicrm_financial_type cct ON cct.id = cc.financial_type_id
|
||||
LEFT JOIN civicrm_contribution_page ccp ON ccp.id = cc.contribution_page_id
|
||||
LEFT JOIN civicrm_option_group option_group_contributionStatus ON option_group_contributionStatus.name = 'contribution_status'
|
||||
LEFT JOIN civicrm_option_value contribution_status ON
|
||||
( contribution_status.option_group_id = option_group_contributionStatus.id AND contribution_status.value = cc.contribution_status_id )
|
||||
{$this->toLimit($limit)}
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_FullText_Membership extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct('Membership', ts('Memberships'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if search is permitted.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive() {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
return in_array('CiviMember', $config->enableComponents) &&
|
||||
CRM_Core_Permission::check('access CiviMember');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function fillTempTable($queryText, $entityIDTableName, $toTable, $queryLimit, $detailLimit) {
|
||||
$queries = $this->prepareQueries($queryText, $entityIDTableName);
|
||||
$result = $this->runQueries($queryText, $queries, $entityIDTableName, $queryLimit);
|
||||
$this->moveIDs($entityIDTableName, $toTable, $detailLimit);
|
||||
if (!empty($result['files'])) {
|
||||
$this->moveFileIDs($toTable, 'membership_id', $result['files']);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get membership ids in entity tables.
|
||||
*
|
||||
* @param string $queryText
|
||||
* @param string $entityIDTableName
|
||||
*
|
||||
* @return array
|
||||
* list tables/queries (for runQueries)
|
||||
*/
|
||||
public function prepareQueries($queryText, $entityIDTableName) {
|
||||
// Note: For available full-text indices, see CRM_Core_InnoDBIndexer
|
||||
|
||||
$contactSQL = array();
|
||||
$contactSQL[] = "
|
||||
SELECT distinct cm.id
|
||||
FROM civicrm_membership cm
|
||||
INNER JOIN civicrm_contact c ON cm.contact_id = c.id
|
||||
WHERE ({$this->matchText('civicrm_contact c', array('sort_name', 'display_name', 'nick_name'), $queryText)})
|
||||
";
|
||||
$tables = array(
|
||||
'civicrm_membership' => array(
|
||||
'id' => 'id',
|
||||
'fields' => array('source' => NULL),
|
||||
),
|
||||
'file' => array(
|
||||
'xparent_table' => 'civicrm_membership',
|
||||
),
|
||||
'sql' => $contactSQL,
|
||||
);
|
||||
|
||||
// get the custom data info
|
||||
$this->fillCustomInfo($tables, "( 'Membership' )");
|
||||
return $tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move IDs.
|
||||
*
|
||||
* @param string $fromTable
|
||||
* @param string $toTable
|
||||
* @param int $limit
|
||||
*/
|
||||
public function moveIDs($fromTable, $toTable, $limit) {
|
||||
$sql = "
|
||||
INSERT INTO {$toTable}
|
||||
( table_name, contact_id, sort_name, membership_id, membership_type, membership_fee, membership_start_date,
|
||||
membership_end_date, membership_source, membership_status )
|
||||
SELECT 'Membership', c.id, c.sort_name, cm.id, cmt.name, cc.total_amount, cm.start_date, cm.end_date, cm.source, cms.name
|
||||
FROM {$fromTable} ct
|
||||
INNER JOIN civicrm_membership cm ON cm.id = ct.entity_id
|
||||
LEFT JOIN civicrm_contact c ON cm.contact_id = c.id
|
||||
LEFT JOIN civicrm_membership_type cmt ON cmt.id = cm.membership_type_id
|
||||
LEFT JOIN civicrm_membership_payment cmp ON cmp.membership_id = cm.id
|
||||
LEFT JOIN civicrm_contribution cc ON cc.id = cmp.contribution_id
|
||||
LEFT JOIN civicrm_membership_status cms ON cms.id = cm.status_id
|
||||
{$this->toLimit($limit)}
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_FullText_Participant extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct('Participant', ts('Participants'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has permission.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive() {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
return in_array('CiviEvent', $config->enableComponents) &&
|
||||
CRM_Core_Permission::check('view event participants');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function fillTempTable($queryText, $entityIDTableName, $toTable, $queryLimit, $detailLimit) {
|
||||
$queries = $this->prepareQueries($queryText, $entityIDTableName);
|
||||
$result = $this->runQueries($queryText, $queries, $entityIDTableName, $queryLimit);
|
||||
$this->moveIDs($entityIDTableName, $toTable, $detailLimit);
|
||||
if (!empty($result['files'])) {
|
||||
$this->moveFileIDs($toTable, 'participant_id', $result['files']);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get participant ids in entity tables.
|
||||
*
|
||||
* @param string $queryText
|
||||
* @param string $entityIDTableName
|
||||
*
|
||||
* @return array
|
||||
* list tables/queries (for runQueries)
|
||||
*/
|
||||
public function prepareQueries($queryText, $entityIDTableName) {
|
||||
// Note: For available full-text indices, see CRM_Core_InnoDBIndexer
|
||||
|
||||
$contactSQL = array();
|
||||
$contactSQL[] = "
|
||||
SELECT distinct cp.id
|
||||
FROM civicrm_participant cp
|
||||
INNER JOIN civicrm_contact c ON cp.contact_id = c.id
|
||||
WHERE ({$this->matchText('civicrm_contact c', array('sort_name', 'display_name', 'nick_name'), $queryText)})
|
||||
";
|
||||
$tables = array(
|
||||
'civicrm_participant' => array(
|
||||
'id' => 'id',
|
||||
'fields' => array(
|
||||
'source' => NULL,
|
||||
'fee_level' => NULL,
|
||||
'fee_amount' => 'Int',
|
||||
),
|
||||
),
|
||||
'file' => array(
|
||||
'xparent_table' => 'civicrm_participant',
|
||||
),
|
||||
'sql' => $contactSQL,
|
||||
'civicrm_note' => array(
|
||||
'id' => 'entity_id',
|
||||
'entity_table' => 'civicrm_participant',
|
||||
'fields' => array(
|
||||
'subject' => NULL,
|
||||
'note' => NULL,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// get the custom data info
|
||||
$this->fillCustomInfo($tables, "( 'Participant' )");
|
||||
return $tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move IDs.
|
||||
* @param string $fromTable
|
||||
* @param string $toTable
|
||||
* @param int $limit
|
||||
*/
|
||||
public function moveIDs($fromTable, $toTable, $limit) {
|
||||
$sql = "
|
||||
INSERT INTO {$toTable}
|
||||
( table_name, contact_id, sort_name, participant_id, event_title, participant_fee_level, participant_fee_amount,
|
||||
participant_register_date, participant_source, participant_status, participant_role )
|
||||
SELECT 'Participant', c.id, c.sort_name, cp.id, ce.title, cp.fee_level, cp.fee_amount, cp.register_date, cp.source,
|
||||
participantStatus.label, cp.role_id
|
||||
FROM {$fromTable} ct
|
||||
INNER JOIN civicrm_participant cp ON cp.id = ct.entity_id
|
||||
LEFT JOIN civicrm_contact c ON cp.contact_id = c.id
|
||||
LEFT JOIN civicrm_event ce ON ce.id = cp.event_id
|
||||
LEFT JOIN civicrm_participant_status_type participantStatus ON participantStatus.id = cp.status_id
|
||||
{$this->toLimit($limit)}
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,643 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_Group extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
|
||||
protected $_formValues;
|
||||
|
||||
protected $_tableName = NULL;
|
||||
|
||||
protected $_where = ' (1) ';
|
||||
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
$this->_formValues = $formValues;
|
||||
$this->_columns = array(
|
||||
ts('Contact ID') => 'contact_id',
|
||||
ts('Contact Type') => 'contact_type',
|
||||
ts('Name') => 'sort_name',
|
||||
ts('Group Name') => 'gname',
|
||||
ts('Tag Name') => 'tname',
|
||||
);
|
||||
|
||||
$this->_includeGroups = CRM_Utils_Array::value('includeGroups', $this->_formValues, array());
|
||||
$this->_excludeGroups = CRM_Utils_Array::value('excludeGroups', $this->_formValues, array());
|
||||
$this->_includeTags = CRM_Utils_Array::value('includeTags', $this->_formValues, array());
|
||||
$this->_excludeTags = CRM_Utils_Array::value('excludeTags', $this->_formValues, array());
|
||||
|
||||
//define variables
|
||||
$this->_allSearch = FALSE;
|
||||
$this->_groups = FALSE;
|
||||
$this->_tags = FALSE;
|
||||
$this->_andOr = CRM_Utils_Array::value('andOr', $this->_formValues);
|
||||
//make easy to check conditions for groups and tags are
|
||||
//selected or it is empty search
|
||||
if (empty($this->_includeGroups) && empty($this->_excludeGroups) &&
|
||||
empty($this->_includeTags) && empty($this->_excludeTags)
|
||||
) {
|
||||
//empty search
|
||||
$this->_allSearch = TRUE;
|
||||
}
|
||||
|
||||
$this->_groups = (!empty($this->_includeGroups) || !empty($this->_excludeGroups));
|
||||
|
||||
$this->_tags = (!empty($this->_includeTags) || !empty($this->_excludeTags));
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
// mysql drops the tables when connection is terminated
|
||||
// cannot drop tables here, since the search might be used
|
||||
// in other parts after the object is destroyed
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
|
||||
$this->setTitle(ts('Include / Exclude Search'));
|
||||
|
||||
$groups = CRM_Core_PseudoConstant::nestedGroup();
|
||||
|
||||
$tags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
|
||||
if (count($groups) == 0 || count($tags) == 0) {
|
||||
CRM_Core_Session::setStatus(ts("At least one Group and Tag must be present for Custom Group / Tag search."), ts('Missing Group/Tag'));
|
||||
$url = CRM_Utils_System::url('civicrm/contact/search/custom/list', 'reset=1');
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
|
||||
$select2style = array(
|
||||
'multiple' => TRUE,
|
||||
'style' => 'width: 100%; max-width: 60em;',
|
||||
'class' => 'crm-select2',
|
||||
'placeholder' => ts('- select -'),
|
||||
);
|
||||
|
||||
$form->add('select', 'includeGroups',
|
||||
ts('Include Group(s)'),
|
||||
$groups,
|
||||
FALSE,
|
||||
$select2style
|
||||
);
|
||||
|
||||
$form->add('select', 'excludeGroups',
|
||||
ts('Exclude Group(s)'),
|
||||
$groups,
|
||||
FALSE,
|
||||
$select2style
|
||||
);
|
||||
|
||||
$andOr = array(
|
||||
'1' => ts('Show contacts that meet the Groups criteria AND the Tags criteria'),
|
||||
'0' => ts('Show contacts that meet the Groups criteria OR the Tags criteria'),
|
||||
);
|
||||
$form->addRadio('andOr', ts('AND/OR'), $andOr, NULL, '<br />', TRUE);
|
||||
|
||||
$form->add('select', 'includeTags',
|
||||
ts('Include Tag(s)'),
|
||||
$tags,
|
||||
FALSE,
|
||||
$select2style
|
||||
);
|
||||
|
||||
$form->add('select', 'excludeTags',
|
||||
ts('Exclude Tag(s)'),
|
||||
$tags,
|
||||
FALSE,
|
||||
$select2style
|
||||
);
|
||||
|
||||
/**
|
||||
* if you are using the standard template, this array tells the template what elements
|
||||
* are part of the search criteria
|
||||
*/
|
||||
$form->assign('elements', array('includeGroups', 'excludeGroups', 'andOr', 'includeTags', 'excludeTags'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param NULL $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all(
|
||||
$offset = 0, $rowcount = 0, $sort = NULL,
|
||||
$includeContactIDs = FALSE, $justIDs = FALSE
|
||||
) {
|
||||
|
||||
if ($justIDs) {
|
||||
$selectClause = "contact_a.id as contact_id";
|
||||
}
|
||||
else {
|
||||
$selectClause = "contact_a.id as contact_id,
|
||||
contact_a.contact_type as contact_type,
|
||||
contact_a.sort_name as sort_name";
|
||||
|
||||
//distinguish column according to user selection
|
||||
if (($this->_includeGroups && !$this->_includeTags)) {
|
||||
unset($this->_columns[ts('Tag Name')]);
|
||||
$selectClause .= ", GROUP_CONCAT(DISTINCT group_names ORDER BY group_names ASC ) as gname";
|
||||
}
|
||||
elseif ($this->_includeTags && (!$this->_includeGroups)) {
|
||||
unset($this->_columns[ts('Group Name')]);
|
||||
$selectClause .= ", GROUP_CONCAT(DISTINCT tag_names ORDER BY tag_names ASC ) as tname";
|
||||
}
|
||||
elseif (!empty($this->_includeTags) && !empty($this->_includeGroups)) {
|
||||
$selectClause .= ", GROUP_CONCAT(DISTINCT group_names ORDER BY group_names ASC ) as gname , GROUP_CONCAT(DISTINCT tag_names ORDER BY tag_names ASC ) as tname";
|
||||
}
|
||||
else {
|
||||
unset($this->_columns[ts('Tag Name')]);
|
||||
unset($this->_columns[ts('Group Name')]);
|
||||
}
|
||||
}
|
||||
|
||||
$from = $this->from();
|
||||
|
||||
$where = $this->where($includeContactIDs);
|
||||
|
||||
if (!$justIDs && !$this->_allSearch) {
|
||||
$groupBy = " GROUP BY contact_a.id";
|
||||
}
|
||||
else {
|
||||
// CRM-10850
|
||||
// we do this since this if stmt is called by the smart group part of the code
|
||||
// adding a groupBy clause and saving it as a smart group messes up the query and
|
||||
// bad things happen
|
||||
// andrew hunt seemed to have rewritten this piece when he worked on this search
|
||||
$groupBy = NULL;
|
||||
}
|
||||
|
||||
$sql = "SELECT $selectClause $from WHERE $where $groupBy";
|
||||
|
||||
// Define ORDER BY for query in $sort, with default value
|
||||
if (!$justIDs) {
|
||||
if (!empty($sort)) {
|
||||
if (is_string($sort)) {
|
||||
$sort = CRM_Utils_Type::escape($sort, 'String');
|
||||
$sql .= " ORDER BY $sort ";
|
||||
}
|
||||
else {
|
||||
$sql .= " ORDER BY " . trim($sort->orderBy());
|
||||
}
|
||||
}
|
||||
else {
|
||||
$sql .= " ORDER BY contact_id ASC";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$sql .= " ORDER BY contact_a.id ASC";
|
||||
}
|
||||
|
||||
if ($offset >= 0 && $rowcount > 0) {
|
||||
$sql .= " LIMIT $offset, $rowcount ";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function from() {
|
||||
|
||||
$iGroups = $xGroups = $iTags = $xTags = 0;
|
||||
|
||||
//define table name
|
||||
$randomNum = md5(uniqid());
|
||||
$this->_tableName = "civicrm_temp_custom_{$randomNum}";
|
||||
|
||||
//block for Group search
|
||||
$smartGroup = array();
|
||||
if ($this->_groups || $this->_allSearch) {
|
||||
$group = new CRM_Contact_DAO_Group();
|
||||
$group->is_active = 1;
|
||||
$group->find();
|
||||
while ($group->fetch()) {
|
||||
$allGroups[] = $group->id;
|
||||
if ($group->saved_search_id) {
|
||||
$smartGroup[$group->saved_search_id] = $group->id;
|
||||
}
|
||||
}
|
||||
$includedGroups = implode(',', $allGroups);
|
||||
|
||||
if (!empty($this->_includeGroups)) {
|
||||
$iGroups = implode(',', $this->_includeGroups);
|
||||
}
|
||||
else {
|
||||
//if no group selected search for all groups
|
||||
$iGroups = NULL;
|
||||
}
|
||||
if (is_array($this->_excludeGroups)) {
|
||||
$xGroups = implode(',', $this->_excludeGroups);
|
||||
}
|
||||
else {
|
||||
$xGroups = 0;
|
||||
}
|
||||
|
||||
$sql = "CREATE TEMPORARY TABLE Xg_{$this->_tableName} ( contact_id int primary key) ENGINE=InnoDB";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
//used only when exclude group is selected
|
||||
if ($xGroups != 0) {
|
||||
$excludeGroup = "INSERT INTO Xg_{$this->_tableName} ( contact_id )
|
||||
SELECT DISTINCT civicrm_group_contact.contact_id
|
||||
FROM civicrm_group_contact, civicrm_contact
|
||||
WHERE
|
||||
civicrm_contact.id = civicrm_group_contact.contact_id AND
|
||||
civicrm_group_contact.status = 'Added' AND
|
||||
civicrm_group_contact.group_id IN( {$xGroups})";
|
||||
|
||||
CRM_Core_DAO::executeQuery($excludeGroup);
|
||||
|
||||
//search for smart group contacts
|
||||
foreach ($this->_excludeGroups as $keys => $values) {
|
||||
if (in_array($values, $smartGroup)) {
|
||||
$ssGroup = new CRM_Contact_DAO_Group();
|
||||
$ssGroup->id = $values;
|
||||
if (!$ssGroup->find(TRUE)) {
|
||||
CRM_Core_Error::fatal();
|
||||
}
|
||||
CRM_Contact_BAO_GroupContactCache::load($ssGroup);
|
||||
|
||||
$smartSql = "
|
||||
SELECT gcc.contact_id
|
||||
FROM civicrm_group_contact_cache gcc
|
||||
WHERE gcc.group_id = {$ssGroup->id}
|
||||
";
|
||||
$smartGroupQuery = " INSERT IGNORE INTO Xg_{$this->_tableName}(contact_id) $smartSql";
|
||||
CRM_Core_DAO::executeQuery($smartGroupQuery);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "CREATE TEMPORARY TABLE Ig_{$this->_tableName} ( id int PRIMARY KEY AUTO_INCREMENT,
|
||||
contact_id int,
|
||||
group_names varchar(64)) ENGINE=InnoDB";
|
||||
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
if ($iGroups) {
|
||||
$includeGroup = "INSERT INTO Ig_{$this->_tableName} (contact_id, group_names)
|
||||
SELECT civicrm_contact.id as contact_id, civicrm_group.title as group_name
|
||||
FROM civicrm_contact
|
||||
INNER JOIN civicrm_group_contact
|
||||
ON civicrm_group_contact.contact_id = civicrm_contact.id
|
||||
LEFT JOIN civicrm_group
|
||||
ON civicrm_group_contact.group_id = civicrm_group.id";
|
||||
}
|
||||
else {
|
||||
$includeGroup = "INSERT INTO Ig_{$this->_tableName} (contact_id, group_names)
|
||||
SELECT civicrm_contact.id as contact_id, ''
|
||||
FROM civicrm_contact";
|
||||
}
|
||||
//used only when exclude group is selected
|
||||
if ($xGroups != 0) {
|
||||
$includeGroup .= " LEFT JOIN Xg_{$this->_tableName}
|
||||
ON civicrm_contact.id = Xg_{$this->_tableName}.contact_id";
|
||||
}
|
||||
|
||||
if ($iGroups) {
|
||||
$includeGroup .= " WHERE
|
||||
civicrm_group_contact.status = 'Added' AND
|
||||
civicrm_group_contact.group_id IN($iGroups)";
|
||||
}
|
||||
else {
|
||||
$includeGroup .= " WHERE ( 1 ) ";
|
||||
}
|
||||
|
||||
//used only when exclude group is selected
|
||||
if ($xGroups != 0) {
|
||||
$includeGroup .= " AND Xg_{$this->_tableName}.contact_id IS null";
|
||||
}
|
||||
|
||||
CRM_Core_DAO::executeQuery($includeGroup);
|
||||
|
||||
//search for smart group contacts
|
||||
|
||||
foreach ($this->_includeGroups as $keys => $values) {
|
||||
if (in_array($values, $smartGroup)) {
|
||||
$ssGroup = new CRM_Contact_DAO_Group();
|
||||
$ssGroup->id = $values;
|
||||
if (!$ssGroup->find(TRUE)) {
|
||||
CRM_Core_Error::fatal();
|
||||
}
|
||||
CRM_Contact_BAO_GroupContactCache::load($ssGroup);
|
||||
|
||||
$smartSql = "
|
||||
SELECT gcc.contact_id
|
||||
FROM civicrm_group_contact_cache gcc
|
||||
WHERE gcc.group_id = {$ssGroup->id}
|
||||
";
|
||||
|
||||
//used only when exclude group is selected
|
||||
if ($xGroups != 0) {
|
||||
$smartSql .= " AND gcc.contact_id NOT IN (SELECT contact_id FROM Xg_{$this->_tableName})";
|
||||
}
|
||||
|
||||
$smartGroupQuery = " INSERT IGNORE INTO Ig_{$this->_tableName}(contact_id)
|
||||
$smartSql";
|
||||
|
||||
CRM_Core_DAO::executeQuery($smartGroupQuery);
|
||||
$insertGroupNameQuery = "UPDATE IGNORE Ig_{$this->_tableName}
|
||||
SET group_names = (SELECT title FROM civicrm_group
|
||||
WHERE civicrm_group.id = $values)
|
||||
WHERE Ig_{$this->_tableName}.contact_id IS NOT NULL
|
||||
AND Ig_{$this->_tableName}.group_names IS NULL";
|
||||
CRM_Core_DAO::executeQuery($insertGroupNameQuery);
|
||||
}
|
||||
}
|
||||
}
|
||||
//group contact search end here;
|
||||
|
||||
//block for Tags search
|
||||
if ($this->_tags || $this->_allSearch) {
|
||||
//find all tags
|
||||
$tag = new CRM_Core_DAO_Tag();
|
||||
$tag->is_active = 1;
|
||||
$tag->find();
|
||||
while ($tag->fetch()) {
|
||||
$allTags[] = $tag->id;
|
||||
}
|
||||
$includedTags = implode(',', $allTags);
|
||||
|
||||
if (!empty($this->_includeTags)) {
|
||||
$iTags = implode(',', $this->_includeTags);
|
||||
}
|
||||
else {
|
||||
//if no group selected search for all groups
|
||||
$iTags = NULL;
|
||||
}
|
||||
if (is_array($this->_excludeTags)) {
|
||||
$xTags = implode(',', $this->_excludeTags);
|
||||
}
|
||||
else {
|
||||
$xTags = 0;
|
||||
}
|
||||
|
||||
$sql = "CREATE TEMPORARY TABLE Xt_{$this->_tableName} ( contact_id int primary key) ENGINE=InnoDB";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
//used only when exclude tag is selected
|
||||
if ($xTags != 0) {
|
||||
$excludeTag = "INSERT INTO Xt_{$this->_tableName} ( contact_id )
|
||||
SELECT DISTINCT civicrm_entity_tag.entity_id
|
||||
FROM civicrm_entity_tag, civicrm_contact
|
||||
WHERE
|
||||
civicrm_entity_tag.entity_table = 'civicrm_contact' AND
|
||||
civicrm_contact.id = civicrm_entity_tag.entity_id AND
|
||||
civicrm_entity_tag.tag_id IN( {$xTags})";
|
||||
|
||||
CRM_Core_DAO::executeQuery($excludeTag);
|
||||
}
|
||||
|
||||
$sql = "CREATE TEMPORARY TABLE It_{$this->_tableName} ( id int PRIMARY KEY AUTO_INCREMENT,
|
||||
contact_id int,
|
||||
tag_names varchar(64)) ENGINE=InnoDB";
|
||||
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
if ($iTags) {
|
||||
$includeTag = "INSERT INTO It_{$this->_tableName} (contact_id, tag_names)
|
||||
SELECT civicrm_contact.id as contact_id, civicrm_tag.name as tag_name
|
||||
FROM civicrm_contact
|
||||
INNER JOIN civicrm_entity_tag
|
||||
ON ( civicrm_entity_tag.entity_table = 'civicrm_contact' AND
|
||||
civicrm_entity_tag.entity_id = civicrm_contact.id )
|
||||
LEFT JOIN civicrm_tag
|
||||
ON civicrm_entity_tag.tag_id = civicrm_tag.id";
|
||||
}
|
||||
else {
|
||||
$includeTag = "INSERT INTO It_{$this->_tableName} (contact_id, tag_names)
|
||||
SELECT civicrm_contact.id as contact_id, ''
|
||||
FROM civicrm_contact";
|
||||
}
|
||||
|
||||
//used only when exclude tag is selected
|
||||
if ($xTags != 0) {
|
||||
$includeTag .= " LEFT JOIN Xt_{$this->_tableName}
|
||||
ON civicrm_contact.id = Xt_{$this->_tableName}.contact_id";
|
||||
}
|
||||
if ($iTags) {
|
||||
$includeTag .= " WHERE civicrm_entity_tag.tag_id IN($iTags)";
|
||||
}
|
||||
else {
|
||||
$includeTag .= " WHERE ( 1 ) ";
|
||||
}
|
||||
|
||||
//used only when exclude tag is selected
|
||||
if ($xTags != 0) {
|
||||
$includeTag .= " AND Xt_{$this->_tableName}.contact_id IS null";
|
||||
}
|
||||
|
||||
CRM_Core_DAO::executeQuery($includeTag);
|
||||
}
|
||||
|
||||
$from = " FROM civicrm_contact contact_a";
|
||||
|
||||
/*
|
||||
* CRM-10850 / CRM-10848
|
||||
* If we use include / exclude groups as smart groups for ACL's having the below causes
|
||||
* a cycle which messes things up. Hence commenting out for now
|
||||
* $this->buildACLClause('contact_a');
|
||||
*/
|
||||
|
||||
/*
|
||||
* check the situation and set booleans
|
||||
*/
|
||||
$Ig = ($iGroups != 0);
|
||||
$It = ($iTags != 0);
|
||||
$Xg = ($xGroups != 0);
|
||||
$Xt = ($xTags != 0);
|
||||
|
||||
//PICK UP FROM HERE
|
||||
if (!$this->_groups && !$this->_tags) {
|
||||
$this->_andOr = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set from statement depending on array sel
|
||||
*/
|
||||
$whereitems = array();
|
||||
foreach (array('Ig', 'It') as $inc) {
|
||||
if ($this->_andOr == 1) {
|
||||
if ($$inc) {
|
||||
$from .= " INNER JOIN {$inc}_{$this->_tableName} temptable$inc ON (contact_a.id = temptable$inc.contact_id)";
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($$inc) {
|
||||
$from .= " LEFT JOIN {$inc}_{$this->_tableName} temptable$inc ON (contact_a.id = temptable$inc.contact_id)";
|
||||
}
|
||||
}
|
||||
if ($$inc) {
|
||||
$whereitems[] = "temptable$inc.contact_id IS NOT NULL";
|
||||
}
|
||||
}
|
||||
$this->_where = $whereitems ? "(" . implode(' OR ', $whereitems) . ')' : '(1)';
|
||||
foreach (array('Xg', 'Xt') as $exc) {
|
||||
if ($$exc) {
|
||||
$from .= " LEFT JOIN {$exc}_{$this->_tableName} temptable$exc ON (contact_a.id = temptable$exc.contact_id)";
|
||||
$this->_where .= " AND temptable$exc.contact_id IS NULL";
|
||||
}
|
||||
}
|
||||
|
||||
$from .= " LEFT JOIN civicrm_email ON ( contact_a.id = civicrm_email.contact_id AND ( civicrm_email.is_primary = 1 OR civicrm_email.is_bulkmail = 1 ) ) {$this->_aclFrom}";
|
||||
|
||||
if ($this->_aclWhere) {
|
||||
$this->_where .= " AND {$this->_aclWhere} ";
|
||||
}
|
||||
|
||||
// also exclude all contacts that are deleted
|
||||
// CRM-11627
|
||||
$this->_where .= " AND (contact_a.is_deleted != 1) ";
|
||||
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
if ($includeContactIDs) {
|
||||
$contactIDs = array();
|
||||
|
||||
foreach ($this->_formValues as $id => $value) {
|
||||
if ($value &&
|
||||
substr($id, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX
|
||||
) {
|
||||
$contactIDs[] = substr($id, CRM_Core_Form::CB_PREFIX_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($contactIDs)) {
|
||||
$contactIDs = implode(', ', $contactIDs);
|
||||
$clauses[] = "contact_a.id IN ( $contactIDs )";
|
||||
}
|
||||
$where = "{$this->_where} AND " . implode(' AND ', $clauses);
|
||||
}
|
||||
else {
|
||||
$where = $this->_where;
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
/*
|
||||
* Functions below generally don't need to be modified
|
||||
*/
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function count() {
|
||||
$sql = $this->all();
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
return $dao->N;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param NULL $sort
|
||||
* @param bool $returnSQL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
|
||||
return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define columns.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function &columns() {
|
||||
return $this->_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get summary.
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function summary() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title on search.
|
||||
*
|
||||
* @param string $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Search'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build ACL clause.
|
||||
*
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,302 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_MultipleValues extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
|
||||
protected $_groupTree;
|
||||
protected $_tables;
|
||||
protected $_options;
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
protected $fieldInfo = array();
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
parent::__construct($formValues);
|
||||
|
||||
$this->_groupTree = CRM_Core_BAO_CustomGroup::getTree("'Contact', 'Individual', 'Organization', 'Household'", NULL, NULL, -1);
|
||||
|
||||
$this->_group = CRM_Utils_Array::value('group', $this->_formValues);
|
||||
|
||||
$this->_tag = CRM_Utils_Array::value('tag', $this->_formValues);
|
||||
|
||||
$this->_columns = array(
|
||||
ts('Contact ID') => 'contact_id',
|
||||
ts('Contact Type') => 'contact_type',
|
||||
ts('Name') => 'sort_name',
|
||||
);
|
||||
|
||||
$this->_customGroupIDs = CRM_Utils_Array::value('custom_group', $formValues);
|
||||
|
||||
if (!empty($this->_customGroupIDs)) {
|
||||
$this->addColumns();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all the fields for chosen groups
|
||||
*/
|
||||
public function addColumns() {
|
||||
$this->_tables = array();
|
||||
foreach ($this->_groupTree as $groupID => $group) {
|
||||
if (empty($this->_customGroupIDs[$groupID])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->fieldInfo += $group['fields'];
|
||||
|
||||
// now handle all the fields
|
||||
foreach ($group['fields'] as $fieldID => $field) {
|
||||
$this->_columns[$field['label']] = "custom_{$field['id']}";
|
||||
if (!array_key_exists($group['table_name'], $this->_tables)) {
|
||||
$this->_tables[$group['table_name']] = array();
|
||||
}
|
||||
$this->_tables[$group['table_name']][$field['id']] = $field['column_name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
|
||||
$this->setTitle('Multiple Value Custom Group Search and Export');
|
||||
|
||||
$form->add('text', 'sort_name', ts('Contact Name'), TRUE);
|
||||
|
||||
$contactTypes = array('' => ts('- any contact type -')) + CRM_Contact_BAO_ContactType::getSelectElements();
|
||||
$form->add('select', 'contact_type', ts('Find...'), $contactTypes, array('class' => 'crm-select2 huge'));
|
||||
|
||||
// add select for groups
|
||||
$group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::group();
|
||||
$form->addElement('select', 'group', ts('in'), $group, array('class' => 'crm-select2 huge'));
|
||||
|
||||
// add select for tags
|
||||
$tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
|
||||
$form->addElement('select', 'tag', ts('Tagged'), $tag, array('class' => 'crm-select2 huge'));
|
||||
|
||||
if (empty($this->_groupTree)) {
|
||||
CRM_Core_Error::statusBounce(ts("Atleast one Custom Group must be present, for Custom Group search."),
|
||||
CRM_Utils_System::url('civicrm/contact/search/custom/list',
|
||||
'reset=1'
|
||||
)
|
||||
);
|
||||
}
|
||||
// add the checkbox for custom_groups
|
||||
foreach ($this->_groupTree as $groupID => $group) {
|
||||
if ($groupID == 'info') {
|
||||
continue;
|
||||
}
|
||||
$form->addElement('checkbox', "custom_group[$groupID]", NULL, $group['title']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function summary() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $returnSQL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
|
||||
return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all($offset = 0, $rowcount = 0, $sort = NULL, $includeContactIDs = FALSE, $justIDs = FALSE) {
|
||||
//redirect if custom group not select in search criteria
|
||||
if (empty($this->_formValues['custom_group'])) {
|
||||
CRM_Core_Error::statusBounce(ts("You must select at least one Custom Group as a search criteria."),
|
||||
CRM_Utils_System::url('civicrm/contact/search/custom',
|
||||
"reset=1&csid={$this->_formValues['customSearchID']}",
|
||||
FALSE, NULL, FALSE, TRUE
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($justIDs) {
|
||||
$selectClause = "contact_a.id as contact_id";
|
||||
$sort = "contact_a.id";
|
||||
|
||||
return $this->sql($selectClause, $offset, $rowcount, $sort, $includeContactIDs, NULL);
|
||||
}
|
||||
else {
|
||||
$selectClause = "
|
||||
contact_a.id as contact_id ,
|
||||
contact_a.contact_type as contact_type,
|
||||
contact_a.sort_name as sort_name,
|
||||
";
|
||||
}
|
||||
|
||||
$customClauses = array();
|
||||
foreach ($this->_tables as $tableName => $fields) {
|
||||
foreach ($fields as $fieldID => $fieldName) {
|
||||
$customClauses[] = "{$tableName}.{$fieldName} as custom_{$fieldID}";
|
||||
}
|
||||
}
|
||||
$selectClause .= implode(',', $customClauses);
|
||||
|
||||
return $this->sql($selectClause,
|
||||
$offset, $rowcount, $sort,
|
||||
$includeContactIDs, NULL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function from() {
|
||||
$this->buildACLClause('contact_a');
|
||||
$from = "FROM civicrm_contact contact_a {$this->_aclFrom}";
|
||||
$customFrom = array();
|
||||
// lets do an INNER JOIN so we get only relevant values rather than all values
|
||||
if (!empty($this->_tables)) {
|
||||
foreach ($this->_tables as $tableName => $fields) {
|
||||
$customFrom[] = " INNER JOIN $tableName ON {$tableName}.entity_id = contact_a.id ";
|
||||
}
|
||||
$from .= implode(' ', $customFrom);
|
||||
}
|
||||
|
||||
// This prevents duplicate rows when contacts have more than one tag any you select "any tag"
|
||||
if ($this->_tag) {
|
||||
$from .= " LEFT JOIN civicrm_entity_tag t ON (t.entity_table='civicrm_contact'
|
||||
AND contact_a.id = t.entity_id)";
|
||||
}
|
||||
|
||||
if ($this->_group) {
|
||||
$from .= " LEFT JOIN civicrm_group_contact cgc ON ( cgc.contact_id = contact_a.id
|
||||
AND cgc.status = 'Added')";
|
||||
}
|
||||
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
$count = 1;
|
||||
$clause = array();
|
||||
$params = array();
|
||||
$name = CRM_Utils_Array::value('sort_name',
|
||||
$this->_formValues
|
||||
);
|
||||
if ($name != NULL) {
|
||||
if (strpos($name, '%') === FALSE) {
|
||||
$name = "%{$name}%";
|
||||
}
|
||||
$params[$count] = array($name, 'String');
|
||||
$clause[] = "contact_a.sort_name LIKE %{$count}";
|
||||
$count++;
|
||||
}
|
||||
|
||||
$contact_type = CRM_Utils_Array::value('contact_type',
|
||||
$this->_formValues
|
||||
);
|
||||
if ($contact_type != NULL) {
|
||||
$contactType = explode('__', $contact_type);
|
||||
if (count($contactType) > 1) {
|
||||
$clause[] = "contact_a.contact_type = '$contactType[0]' AND contact_a.contact_sub_type = '$contactType[1]'";
|
||||
}
|
||||
else {
|
||||
$clause[] = "contact_a.contact_type = '$contactType[0]'";
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_tag) {
|
||||
$clause[] = "t.tag_id = {$this->_tag}";
|
||||
}
|
||||
|
||||
if ($this->_group) {
|
||||
$clause[] = "cgc.group_id = {$this->_group}";
|
||||
}
|
||||
if ($this->_aclWhere) {
|
||||
$clause[] = " {$this->_aclWhere}";
|
||||
}
|
||||
|
||||
$where = '( 1 )';
|
||||
if (!empty($clause)) {
|
||||
$where .= ' AND ' . implode(' AND ', $clause);
|
||||
}
|
||||
|
||||
return $this->whereClause($where, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom/MultipleValues.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $row
|
||||
*/
|
||||
public function alterRow(&$row) {
|
||||
foreach ($row as $fieldName => &$field) {
|
||||
if (strpos($fieldName, 'custom_') === 0) {
|
||||
$field = CRM_Core_BAO_CustomField::displayValue($field, $fieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_PostalMailing extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
parent::__construct($formValues);
|
||||
|
||||
$this->_columns = array(
|
||||
// If possible, don't use aliases for the columns you select.
|
||||
// You can prefix columns with table aliases, if needed.
|
||||
//
|
||||
// If you don't do this, selecting individual records from the
|
||||
// custom search result won't work if your results are sorted on the
|
||||
// aliased colums.
|
||||
// (This is why we map Contact ID on contact_a.id, and not on contact_id).
|
||||
ts('Contact ID') => 'contact_a.id',
|
||||
ts('Address') => 'street_address',
|
||||
ts('Contact Type') => 'contact_type',
|
||||
ts('Name') => 'sort_name',
|
||||
// You need to provide a table alias if there field exists in multiple
|
||||
// tables of your join. Name is also a field of address, so we prefix it
|
||||
// by state_province.
|
||||
// If you don't do this, the patch of CRM-16587 might cause database
|
||||
// errors.
|
||||
ts('State') => 'state_province.name',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
$groups = array('' => ts('- select group -')) + CRM_Core_PseudoConstant::nestedGroup(FALSE);
|
||||
$form->addElement('select', 'group_id', ts('Group'), $groups, array('class' => 'crm-select2 huge'));
|
||||
|
||||
/**
|
||||
* if you are using the standard template, this array tells the template what elements
|
||||
* are part of the search criteria
|
||||
*/
|
||||
$form->assign('elements', array('group_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $returnSQL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
|
||||
return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all(
|
||||
$offset = 0, $rowcount = 0, $sort = NULL,
|
||||
$includeContactIDs = FALSE, $justIDs = FALSE
|
||||
) {
|
||||
if ($justIDs) {
|
||||
$selectClause = "contact_a.id as contact_id";
|
||||
// Don't change sort order when $justIDs is TRUE, see CRM-14920.
|
||||
}
|
||||
else {
|
||||
// YOU NEED to select contact_a.id as contact_id, if you want to be able
|
||||
// to select individual records from the result.
|
||||
// But if you want to display the contact ID in your result set, you
|
||||
// also need to select contact_a.id. This is because of the patch we
|
||||
// use for CRM-16587.
|
||||
$selectClause = "
|
||||
DISTINCT contact_a.id as contact_id ,
|
||||
contact_a.id,
|
||||
contact_a.contact_type as contact_type,
|
||||
contact_a.sort_name as sort_name,
|
||||
address.street_address,
|
||||
state_province.name
|
||||
";
|
||||
}
|
||||
|
||||
return $this->sql($selectClause,
|
||||
$offset, $rowcount, $sort,
|
||||
$includeContactIDs, NULL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function from() {
|
||||
$this->buildACLClause('contact_a');
|
||||
$from = "
|
||||
FROM civicrm_group_contact as cgc,
|
||||
civicrm_contact as contact_a
|
||||
LEFT JOIN civicrm_address address ON (address.contact_id = contact_a.id AND
|
||||
address.is_primary = 1 )
|
||||
LEFT JOIN civicrm_state_province state_province ON state_province.id = address.state_province_id {$this->_aclFrom}
|
||||
";
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
$params = array();
|
||||
|
||||
$count = 1;
|
||||
$clause = array();
|
||||
$groupID = CRM_Utils_Array::value('group_id',
|
||||
$this->_formValues
|
||||
);
|
||||
if ($groupID) {
|
||||
$params[$count] = array($groupID, 'Integer');
|
||||
$clause[] = "cgc.group_id = %{$count}";
|
||||
}
|
||||
|
||||
$clause[] = "cgc.status = 'Added'";
|
||||
$clause[] = "contact_a.id = IF( EXISTS(select cr.id from civicrm_relationship cr where (cr.contact_id_a = cgc.contact_id AND (cr.relationship_type_id = 7 OR cr.relationship_type_id = 6))),
|
||||
(select cr.contact_id_b from civicrm_relationship cr where (cr.contact_id_a = cgc.contact_id AND (cr.relationship_type_id = 7 OR cr.relationship_type_id = 6))),
|
||||
cgc.contact_id )";
|
||||
$clause[] = "contact_a.contact_type IN ('Individual','Household')";
|
||||
|
||||
if ($this->_aclWhere) {
|
||||
$clause[] = " {$this->_aclWhere} ";
|
||||
}
|
||||
|
||||
if (!empty($clause)) {
|
||||
$where = implode(' AND ', $clause);
|
||||
}
|
||||
|
||||
return $this->whereClause($where, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,366 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_PriceSet extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
|
||||
protected $_eventID = NULL;
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
protected $_tableName = NULL;
|
||||
public $_permissionedComponent;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
parent::__construct($formValues);
|
||||
|
||||
$this->_eventID = CRM_Utils_Array::value('event_id',
|
||||
$this->_formValues
|
||||
);
|
||||
|
||||
$this->setColumns();
|
||||
|
||||
if ($this->_eventID) {
|
||||
$this->buildTempTable();
|
||||
$this->fillTable();
|
||||
}
|
||||
|
||||
// define component access permission needed
|
||||
$this->_permissionedComponent = 'CiviEvent';
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
/*
|
||||
if ( $this->_eventID ) {
|
||||
$sql = "DROP TEMPORARY TABLE {$this->_tableName}";
|
||||
CRM_Core_DAO::executeQuery( $sql );
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public function buildTempTable() {
|
||||
$randomNum = md5(uniqid());
|
||||
$this->_tableName = "civicrm_temp_custom_{$randomNum}";
|
||||
$sql = "
|
||||
CREATE TEMPORARY TABLE {$this->_tableName} (
|
||||
id int unsigned NOT NULL AUTO_INCREMENT,
|
||||
contact_id int unsigned NOT NULL,
|
||||
participant_id int unsigned NOT NULL,
|
||||
";
|
||||
|
||||
foreach ($this->_columns as $dontCare => $fieldName) {
|
||||
if (in_array($fieldName, array(
|
||||
'contact_id',
|
||||
'participant_id',
|
||||
'display_name',
|
||||
))) {
|
||||
continue;
|
||||
}
|
||||
$sql .= "{$fieldName} int default 0,\n";
|
||||
}
|
||||
|
||||
$sql .= "
|
||||
PRIMARY KEY ( id ),
|
||||
UNIQUE INDEX unique_participant_id ( participant_id )
|
||||
) ENGINE=HEAP
|
||||
";
|
||||
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
}
|
||||
|
||||
public function fillTable() {
|
||||
$sql = "
|
||||
REPLACE INTO {$this->_tableName}
|
||||
( contact_id, participant_id )
|
||||
SELECT c.id, p.id
|
||||
FROM civicrm_contact c,
|
||||
civicrm_participant p
|
||||
WHERE p.contact_id = c.id
|
||||
AND p.is_test = 0
|
||||
AND p.event_id = {$this->_eventID}
|
||||
AND p.status_id NOT IN (4,11,12)
|
||||
AND ( c.is_deleted = 0 OR c.is_deleted IS NULL )
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
$sql = "
|
||||
SELECT c.id as contact_id,
|
||||
p.id as participant_id,
|
||||
l.price_field_value_id as price_field_value_id,
|
||||
l.qty
|
||||
FROM civicrm_contact c,
|
||||
civicrm_participant p,
|
||||
civicrm_line_item l
|
||||
WHERE c.id = p.contact_id
|
||||
AND p.event_id = {$this->_eventID}
|
||||
AND p.id = l.entity_id
|
||||
AND l.entity_table ='civicrm_participant'
|
||||
ORDER BY c.id, l.price_field_value_id;
|
||||
";
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
// first store all the information by option value id
|
||||
$rows = array();
|
||||
while ($dao->fetch()) {
|
||||
$contactID = $dao->contact_id;
|
||||
$participantID = $dao->participant_id;
|
||||
if (!isset($rows[$participantID])) {
|
||||
$rows[$participantID] = array();
|
||||
}
|
||||
|
||||
$rows[$participantID][] = "price_field_{$dao->price_field_value_id} = {$dao->qty}";
|
||||
}
|
||||
|
||||
foreach (array_keys($rows) as $participantID) {
|
||||
$values = implode(',', $rows[$participantID]);
|
||||
$sql = "
|
||||
UPDATE {$this->_tableName}
|
||||
SET $values
|
||||
WHERE participant_id = $participantID;
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $eventID
|
||||
*
|
||||
* @return Object
|
||||
*/
|
||||
public function priceSetDAO($eventID = NULL) {
|
||||
|
||||
// get all the events that have a price set associated with it
|
||||
$sql = "
|
||||
SELECT e.id as id,
|
||||
e.title as title,
|
||||
p.price_set_id as price_set_id
|
||||
FROM civicrm_event e,
|
||||
civicrm_price_set_entity p
|
||||
|
||||
WHERE p.entity_table = 'civicrm_event'
|
||||
AND p.entity_id = e.id
|
||||
";
|
||||
|
||||
$params = array();
|
||||
if ($eventID) {
|
||||
$params[1] = array($eventID, 'Integer');
|
||||
$sql .= " AND e.id = $eventID";
|
||||
}
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql,
|
||||
$params
|
||||
);
|
||||
return $dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
$dao = $this->priceSetDAO();
|
||||
|
||||
$event = array();
|
||||
while ($dao->fetch()) {
|
||||
$event[$dao->id] = $dao->title;
|
||||
}
|
||||
|
||||
if (empty($event)) {
|
||||
CRM_Core_Error::fatal(ts('There are no events with Price Sets'));
|
||||
}
|
||||
|
||||
$form->add('select',
|
||||
'event_id',
|
||||
ts('Event'),
|
||||
$event,
|
||||
TRUE
|
||||
);
|
||||
|
||||
/**
|
||||
* You can define a custom title for the search form
|
||||
*/
|
||||
$this->setTitle('Price Set Export');
|
||||
|
||||
/**
|
||||
* if you are using the standard template, this array tells the template what elements
|
||||
* are part of the search criteria
|
||||
*/
|
||||
$form->assign('elements', array('event_id'));
|
||||
}
|
||||
|
||||
public function setColumns() {
|
||||
$this->_columns = array(
|
||||
ts('Contact ID') => 'contact_id',
|
||||
ts('Participant ID') => 'participant_id',
|
||||
ts('Name') => 'display_name',
|
||||
);
|
||||
|
||||
if (!$this->_eventID) {
|
||||
return;
|
||||
}
|
||||
|
||||
// for the selected event, find the price set and all the columns associated with it.
|
||||
// create a column for each field and option group within it
|
||||
$dao = $this->priceSetDAO($this->_formValues['event_id']);
|
||||
|
||||
if ($dao->fetch() &&
|
||||
!$dao->price_set_id
|
||||
) {
|
||||
CRM_Core_Error::fatal(ts('There are no events with Price Sets'));
|
||||
}
|
||||
|
||||
// get all the fields and all the option values associated with it
|
||||
$priceSet = CRM_Price_BAO_PriceSet::getSetDetail($dao->price_set_id);
|
||||
if (is_array($priceSet[$dao->price_set_id])) {
|
||||
foreach ($priceSet[$dao->price_set_id]['fields'] as $key => $value) {
|
||||
if (is_array($value['options'])) {
|
||||
foreach ($value['options'] as $oKey => $oValue) {
|
||||
$columnHeader = CRM_Utils_Array::value('label', $value);
|
||||
if (CRM_Utils_Array::value('html_type', $value) != 'Text') {
|
||||
$columnHeader .= ' - ' . $oValue['label'];
|
||||
}
|
||||
|
||||
$this->_columns[$columnHeader] = "price_field_{$oValue['id']}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function summary() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all(
|
||||
$offset = 0, $rowcount = 0, $sort = NULL,
|
||||
$includeContactIDs = FALSE, $justIDs = FALSE
|
||||
) {
|
||||
if ($justIDs) {
|
||||
$selectClause = "contact_a.id as contact_id";
|
||||
}
|
||||
else {
|
||||
$selectClause = "
|
||||
contact_a.id as contact_id ,
|
||||
contact_a.display_name as display_name";
|
||||
|
||||
foreach ($this->_columns as $dontCare => $fieldName) {
|
||||
if (in_array($fieldName, array(
|
||||
'contact_id',
|
||||
'display_name',
|
||||
))) {
|
||||
continue;
|
||||
}
|
||||
$selectClause .= ",\ntempTable.{$fieldName} as {$fieldName}";
|
||||
}
|
||||
}
|
||||
|
||||
return $this->sql($selectClause,
|
||||
$offset, $rowcount, $sort,
|
||||
$includeContactIDs, NULL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function from() {
|
||||
$this->buildACLClause('contact_a');
|
||||
$from = "
|
||||
FROM civicrm_contact contact_a
|
||||
INNER JOIN {$this->_tableName} tempTable ON ( tempTable.contact_id = contact_a.id ) {$this->_aclFrom}
|
||||
";
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
$where = ' ( 1 ) ';
|
||||
if ($this->_aclWhere) {
|
||||
$where .= " AND {$this->_aclWhere} ";
|
||||
}
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $row
|
||||
*/
|
||||
public function alterRow(&$row) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Export Price Set Info for an Event'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,323 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_Proximity extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
|
||||
protected $_latitude = NULL;
|
||||
protected $_longitude = NULL;
|
||||
protected $_distance = NULL;
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
parent::__construct($formValues);
|
||||
|
||||
// unset search profile and other search params if set
|
||||
unset($this->_formValues['uf_group_id']);
|
||||
unset($this->_formValues['component_mode']);
|
||||
unset($this->_formValues['operator']);
|
||||
|
||||
if (!empty($this->_formValues)) {
|
||||
// add the country and state
|
||||
if (!empty($this->_formValues['country_id'])) {
|
||||
$this->_formValues['country'] = CRM_Core_PseudoConstant::country($this->_formValues['country_id']);
|
||||
}
|
||||
|
||||
if (!empty($this->_formValues['state_province_id'])) {
|
||||
$this->_formValues['state_province'] = CRM_Core_PseudoConstant::stateProvince($this->_formValues['state_province_id']);
|
||||
}
|
||||
|
||||
// use the address to get the latitude and longitude
|
||||
CRM_Utils_Geocode_Google::format($this->_formValues);
|
||||
|
||||
if (!is_numeric(CRM_Utils_Array::value('geo_code_1', $this->_formValues)) ||
|
||||
!is_numeric(CRM_Utils_Array::value('geo_code_2', $this->_formValues)) ||
|
||||
!isset($this->_formValues['distance'])
|
||||
) {
|
||||
CRM_Core_Error::fatal(ts('Could not geocode input'));
|
||||
}
|
||||
|
||||
$this->_latitude = $this->_formValues['geo_code_1'];
|
||||
$this->_longitude = $this->_formValues['geo_code_2'];
|
||||
|
||||
if ($this->_formValues['prox_distance_unit'] == "miles") {
|
||||
$conversionFactor = 1609.344;
|
||||
}
|
||||
else {
|
||||
$conversionFactor = 1000;
|
||||
}
|
||||
$this->_distance = $this->_formValues['distance'] * $conversionFactor;
|
||||
}
|
||||
$this->_group = CRM_Utils_Array::value('group', $this->_formValues);
|
||||
|
||||
$this->_tag = CRM_Utils_Array::value('tag', $this->_formValues);
|
||||
|
||||
$this->_columns = array(
|
||||
ts('Name') => 'sort_name',
|
||||
ts('Street Address') => 'street_address',
|
||||
ts('City') => 'city',
|
||||
ts('Postal Code') => 'postal_code',
|
||||
ts('State') => 'state_province',
|
||||
ts('Country') => 'country',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$countryDefault = $config->defaultContactCountry;
|
||||
|
||||
$form->add('text', 'distance', ts('Distance'), NULL, TRUE);
|
||||
|
||||
$proxUnits = array('km' => ts('km'), 'miles' => ts('miles'));
|
||||
$form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, TRUE);
|
||||
|
||||
$form->add('text',
|
||||
'street_address',
|
||||
ts('Street Address')
|
||||
);
|
||||
|
||||
$form->add('text',
|
||||
'city',
|
||||
ts('City')
|
||||
);
|
||||
|
||||
$form->add('text',
|
||||
'postal_code',
|
||||
ts('Postal Code')
|
||||
);
|
||||
|
||||
$defaults = array();
|
||||
if ($countryDefault) {
|
||||
$defaults['country_id'] = $countryDefault;
|
||||
}
|
||||
$form->addChainSelect('state_province_id');
|
||||
|
||||
$country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
|
||||
$form->add('select', 'country_id', ts('Country'), $country, TRUE, array('class' => 'crm-select2'));
|
||||
|
||||
$group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::nestedGroup();
|
||||
$form->addElement('select', 'group', ts('Group'), $group, array('class' => 'crm-select2 huge'));
|
||||
|
||||
$tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
|
||||
$form->addElement('select', 'tag', ts('Tag'), $tag, array('class' => 'crm-select2 huge'));
|
||||
|
||||
/**
|
||||
* You can define a custom title for the search form
|
||||
*/
|
||||
$this->setTitle('Proximity Search');
|
||||
|
||||
/**
|
||||
* if you are using the standard template, this array tells the template what elements
|
||||
* are part of the search criteria
|
||||
*/
|
||||
$form->assign('elements', array(
|
||||
'distance',
|
||||
'prox_distance_unit',
|
||||
'street_address',
|
||||
'city',
|
||||
'postal_code',
|
||||
'country_id',
|
||||
'state_province_id',
|
||||
'group',
|
||||
'tag',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all(
|
||||
$offset = 0, $rowcount = 0, $sort = NULL,
|
||||
$includeContactIDs = FALSE, $justIDs = FALSE
|
||||
) {
|
||||
if ($justIDs) {
|
||||
$selectClause = "contact_a.id as contact_id";
|
||||
}
|
||||
else {
|
||||
$selectClause = "
|
||||
contact_a.id as contact_id ,
|
||||
contact_a.sort_name as sort_name ,
|
||||
address.street_address as street_address,
|
||||
address.city as city ,
|
||||
address.postal_code as postal_code ,
|
||||
state_province.name as state_province,
|
||||
country.name as country
|
||||
";
|
||||
}
|
||||
|
||||
return $this->sql($selectClause,
|
||||
$offset, $rowcount, $sort,
|
||||
$includeContactIDs, NULL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function from() {
|
||||
$this->buildACLClause('contact_a');
|
||||
$f = "
|
||||
FROM civicrm_contact contact_a
|
||||
LEFT JOIN civicrm_address address ON ( address.contact_id = contact_a.id AND
|
||||
address.is_primary = 1 )
|
||||
LEFT JOIN civicrm_state_province state_province ON state_province.id = address.state_province_id
|
||||
LEFT JOIN civicrm_country country ON country.id = address.country_id {$this->_aclFrom}
|
||||
";
|
||||
|
||||
// This prevents duplicate rows when contacts have more than one tag any you select "any tag"
|
||||
if ($this->_tag) {
|
||||
$f .= "
|
||||
LEFT JOIN civicrm_entity_tag t ON (t.entity_table='civicrm_contact' AND contact_a.id = t.entity_id)
|
||||
";
|
||||
}
|
||||
if ($this->_group) {
|
||||
$f .= "
|
||||
LEFT JOIN civicrm_group_contact cgc ON ( cgc.contact_id = contact_a.id AND cgc.status = 'Added')
|
||||
";
|
||||
}
|
||||
|
||||
return $f;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
$params = array();
|
||||
$clause = array();
|
||||
|
||||
$where = CRM_Contact_BAO_ProximityQuery::where($this->_latitude,
|
||||
$this->_longitude,
|
||||
$this->_distance,
|
||||
'address'
|
||||
);
|
||||
|
||||
if ($this->_tag) {
|
||||
$where .= "
|
||||
AND t.tag_id = {$this->_tag}
|
||||
";
|
||||
}
|
||||
if ($this->_group) {
|
||||
$where .= "
|
||||
AND cgc.group_id = {$this->_group}
|
||||
";
|
||||
}
|
||||
|
||||
$where .= " AND contact_a.is_deleted != 1 ";
|
||||
|
||||
if ($this->_aclWhere) {
|
||||
$where .= " AND {$this->_aclWhere} ";
|
||||
}
|
||||
|
||||
return $this->whereClause($where, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom/Proximity.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
if (!empty($this->_formValues)) {
|
||||
return $this->_formValues;
|
||||
}
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$countryDefault = $config->defaultContactCountry;
|
||||
$stateprovinceDefault = $config->defaultContactStateProvince;
|
||||
$defaults = array();
|
||||
|
||||
if ($countryDefault) {
|
||||
if ($countryDefault == '1228' || $countryDefault == '1226') {
|
||||
$defaults['prox_distance_unit'] = 'miles';
|
||||
}
|
||||
else {
|
||||
$defaults['prox_distance_unit'] = 'km';
|
||||
}
|
||||
$defaults['country_id'] = $countryDefault;
|
||||
if ($stateprovinceDefault) {
|
||||
$defaults['state_province_id'] = $stateprovinceDefault;
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $row
|
||||
*/
|
||||
public function alterRow(&$row) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Search'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,402 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_RandomSegment extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
|
||||
protected $_debug = 0;
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
parent::__construct($formValues);
|
||||
|
||||
$this->_columns = array(
|
||||
ts('Contact ID') => 'contact_id',
|
||||
ts('Contact Type') => 'contact_type',
|
||||
ts('Name') => 'sort_name',
|
||||
ts('Email') => 'email',
|
||||
);
|
||||
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
public function initialize() {
|
||||
$this->_segmentSize = CRM_Utils_Array::value('segmentSize', $this->_formValues);
|
||||
|
||||
$this->_includeGroups = CRM_Utils_Array::value('includeGroups', $this->_formValues);
|
||||
|
||||
$this->_excludeGroups = CRM_Utils_Array::value('excludeGroups', $this->_formValues);
|
||||
|
||||
$this->_allSearch = FALSE;
|
||||
$this->_groups = FALSE;
|
||||
|
||||
if (empty($this->_includeGroups) && empty($this->_excludeGroups)) {
|
||||
//empty search
|
||||
$this->_allSearch = TRUE;
|
||||
}
|
||||
|
||||
if (!empty($this->_includeGroups) || !empty($this->_excludeGroups)) {
|
||||
//group(s) selected
|
||||
$this->_groups = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
$form->add('text',
|
||||
'segmentSize',
|
||||
ts('Segment Size'),
|
||||
TRUE
|
||||
);
|
||||
|
||||
$groups = CRM_Core_PseudoConstant::nestedGroup();
|
||||
|
||||
$select2style = array(
|
||||
'multiple' => TRUE,
|
||||
'style' => 'width: 100%; max-width: 60em;',
|
||||
'class' => 'crm-select2',
|
||||
'placeholder' => ts('- select -'),
|
||||
);
|
||||
|
||||
$form->add('select', 'includeGroups',
|
||||
ts('Include Group(s)'),
|
||||
$groups,
|
||||
FALSE,
|
||||
$select2style
|
||||
);
|
||||
|
||||
$form->add('select', 'excludeGroups',
|
||||
ts('Exclude Group(s)'),
|
||||
$groups,
|
||||
FALSE,
|
||||
$select2style
|
||||
);
|
||||
|
||||
$this->setTitle('Create a random segment of contacts');
|
||||
|
||||
/**
|
||||
* if you are using the standard template, this array tells the template what elements
|
||||
* are part of the search criteria
|
||||
*/
|
||||
$form->assign('elements', array('segmentSize', 'includeGroups', 'excludeGroups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function summary() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all(
|
||||
$offset = 0, $rowcount = 0, $sort = NULL,
|
||||
$includeContactIDs = FALSE, $justIDs = FALSE
|
||||
) {
|
||||
if ($justIDs) {
|
||||
$selectClause = "contact_a.id as contact_id";
|
||||
}
|
||||
else {
|
||||
$selectClause = "contact_a.id as contact_id,
|
||||
contact_a.contact_type as contact_type,
|
||||
contact_a.sort_name as sort_name,
|
||||
civicrm_email.email as email";
|
||||
}
|
||||
|
||||
return $this->sql($selectClause,
|
||||
$offset, $rowcount, $sort,
|
||||
$includeContactIDs, NULL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function from() {
|
||||
//define table name
|
||||
$randomNum = md5(uniqid());
|
||||
$this->_tableName = "civicrm_temp_custom_{$randomNum}";
|
||||
|
||||
//block for Group search
|
||||
$smartGroup = array();
|
||||
$group = new CRM_Contact_DAO_Group();
|
||||
$group->is_active = 1;
|
||||
$group->find();
|
||||
while ($group->fetch()) {
|
||||
$allGroups[] = $group->id;
|
||||
if ($group->saved_search_id) {
|
||||
$smartGroup[$group->saved_search_id] = $group->id;
|
||||
}
|
||||
}
|
||||
$includedGroups = implode(',', $allGroups);
|
||||
|
||||
if (!empty($this->_includeGroups)) {
|
||||
$iGroups = implode(',', $this->_includeGroups);
|
||||
}
|
||||
else {
|
||||
//if no group selected search for all groups
|
||||
$iGroups = $includedGroups;
|
||||
}
|
||||
if (is_array($this->_excludeGroups)) {
|
||||
$xGroups = implode(',', $this->_excludeGroups);
|
||||
}
|
||||
else {
|
||||
$xGroups = 0;
|
||||
}
|
||||
|
||||
$sql = "DROP TEMPORARY TABLE IF EXISTS Xg_{$this->_tableName}";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
$sql = "CREATE TEMPORARY TABLE Xg_{$this->_tableName} ( contact_id int primary key) ENGINE=HEAP";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
//used only when exclude group is selected
|
||||
if ($xGroups != 0) {
|
||||
$excludeGroup = "INSERT INTO Xg_{$this->_tableName} ( contact_id )
|
||||
SELECT DISTINCT civicrm_group_contact.contact_id
|
||||
FROM civicrm_group_contact
|
||||
WHERE
|
||||
civicrm_group_contact.status = 'Added' AND
|
||||
civicrm_group_contact.group_id IN ( {$xGroups} )";
|
||||
|
||||
CRM_Core_DAO::executeQuery($excludeGroup);
|
||||
|
||||
//search for smart group contacts
|
||||
foreach ($this->_excludeGroups as $keys => $values) {
|
||||
if (in_array($values, $smartGroup)) {
|
||||
$ssId = CRM_Utils_Array::key($values, $smartGroup);
|
||||
|
||||
$smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
|
||||
|
||||
$smartSql = $smartSql . " AND contact_a.id NOT IN (
|
||||
SELECT contact_id FROM civicrm_group_contact
|
||||
WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
|
||||
|
||||
$smartGroupQuery = " INSERT IGNORE INTO Xg_{$this->_tableName}(contact_id) $smartSql";
|
||||
|
||||
CRM_Core_DAO::executeQuery($smartGroupQuery);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "DROP TEMPORARY TABLE IF EXISTS Ig_{$this->_tableName}";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
$sql = "CREATE TEMPORARY TABLE Ig_{$this->_tableName}
|
||||
( id int PRIMARY KEY AUTO_INCREMENT,
|
||||
contact_id int,
|
||||
group_names varchar(64)) ENGINE=HEAP";
|
||||
|
||||
if ($this->_debug > 0) {
|
||||
print "-- Include groups query: <pre>";
|
||||
print "$sql;";
|
||||
print "</pre>";
|
||||
}
|
||||
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
$includeGroup = "INSERT INTO Ig_{$this->_tableName} (contact_id, group_names)
|
||||
SELECT civicrm_group_contact.contact_id, civicrm_group.name as group_name
|
||||
FROM civicrm_group_contact
|
||||
LEFT JOIN civicrm_group
|
||||
ON civicrm_group_contact.group_id = civicrm_group.id";
|
||||
|
||||
//used only when exclude group is selected
|
||||
if ($xGroups != 0) {
|
||||
$includeGroup .= " LEFT JOIN Xg_{$this->_tableName}
|
||||
ON civicrm_group_contact.contact_id = Xg_{$this->_tableName}.contact_id";
|
||||
}
|
||||
$includeGroup .= " WHERE
|
||||
civicrm_group_contact.status = 'Added' AND
|
||||
civicrm_group_contact.group_id IN($iGroups)";
|
||||
|
||||
//used only when exclude group is selected
|
||||
if ($xGroups != 0) {
|
||||
$includeGroup .= " AND Xg_{$this->_tableName}.contact_id IS null";
|
||||
}
|
||||
|
||||
if ($this->_debug > 0) {
|
||||
print "-- Include groups query: <pre>";
|
||||
print "$includeGroup;";
|
||||
print "</pre>";
|
||||
}
|
||||
|
||||
CRM_Core_DAO::executeQuery($includeGroup);
|
||||
|
||||
//search for smart group contacts
|
||||
foreach ($this->_includeGroups as $keys => $values) {
|
||||
if (in_array($values, $smartGroup)) {
|
||||
|
||||
$ssId = CRM_Utils_Array::key($values, $smartGroup);
|
||||
|
||||
$smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
|
||||
|
||||
$smartSql .= " AND contact_a.id NOT IN (
|
||||
SELECT contact_id FROM civicrm_group_contact
|
||||
WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
|
||||
|
||||
//used only when exclude group is selected
|
||||
if ($xGroups != 0) {
|
||||
$smartSql .= " AND contact_a.id NOT IN (SELECT contact_id FROM Xg_{$this->_tableName})";
|
||||
}
|
||||
|
||||
$smartGroupQuery = " INSERT IGNORE INTO Ig_{$this->_tableName}(contact_id)
|
||||
$smartSql";
|
||||
|
||||
CRM_Core_DAO::executeQuery($smartGroupQuery);
|
||||
$insertGroupNameQuery = "UPDATE IGNORE Ig_{$this->_tableName}
|
||||
SET group_names = (SELECT title FROM civicrm_group
|
||||
WHERE civicrm_group.id = $values)
|
||||
WHERE Ig_{$this->_tableName}.contact_id IS NOT NULL
|
||||
AND Ig_{$this->_tableName}.group_names IS NULL";
|
||||
CRM_Core_DAO::executeQuery($insertGroupNameQuery);
|
||||
}
|
||||
}
|
||||
$this->buildACLClause('contact_a');
|
||||
|
||||
$from = "FROM civicrm_contact contact_a";
|
||||
|
||||
$fromTail = "LEFT JOIN civicrm_email ON ( contact_a.id = civicrm_email.contact_id AND civicrm_email.is_primary = 1 )";
|
||||
|
||||
$fromTail .= " INNER JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
|
||||
|
||||
// now create a temp table to store the randomized contacts
|
||||
$sql = "DROP TEMPORARY TABLE IF EXISTS random_{$this->_tableName}";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
$sql = "CREATE TEMPORARY TABLE random_{$this->_tableName} ( id int primary key ) ENGINE=HEAP";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
if (substr($this->_segmentSize, -1) == '%') {
|
||||
$countSql = "SELECT DISTINCT contact_a.id $from $fromTail
|
||||
WHERE " . $this->where();
|
||||
$dao = CRM_Core_DAO::executeQuery($countSql);
|
||||
$totalSize = $dao->N;
|
||||
$multiplier = substr($this->_segmentSize, 0, strlen($this->_segmentSize) - 1);
|
||||
$multiplier /= 100;
|
||||
$this->_segmentSize = round($totalSize * $multiplier);
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO random_{$this->_tableName} ( id )
|
||||
SELECT DISTINCT contact_a.id $from $fromTail
|
||||
WHERE " . $this->where() . "
|
||||
ORDER BY RAND()
|
||||
LIMIT {$this->_segmentSize}";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
$from = "FROM random_{$this->_tableName} random";
|
||||
|
||||
$from .= " INNER JOIN civicrm_contact contact_a ON random.id = contact_a.id {$this->_aclFrom}";
|
||||
|
||||
$from .= " $fromTail";
|
||||
|
||||
return $from;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
$where = '(1)';
|
||||
|
||||
if ($this->_aclWhere) {
|
||||
$where .= " AND {$this->_aclWhere} ";
|
||||
}
|
||||
|
||||
return '(1)';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Search'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function count() {
|
||||
$sql = $this->all();
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
return $dao->N;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor function.
|
||||
*/
|
||||
public function __destruct() {
|
||||
// the temporary tables are dropped automatically
|
||||
// so we don't do it here
|
||||
// but let mysql clean up
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,243 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_Sample extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
parent::__construct($formValues);
|
||||
|
||||
if (!isset($formValues['state_province_id'])) {
|
||||
$this->_stateID = CRM_Utils_Request::retrieve('stateID', 'Integer');
|
||||
if ($this->_stateID) {
|
||||
$formValues['state_province_id'] = $this->_stateID;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_columns = array(
|
||||
ts('Contact ID') => 'contact_id',
|
||||
ts('Contact Type') => 'contact_type',
|
||||
ts('Name') => 'sort_name',
|
||||
ts('State') => 'state_province',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build form.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
|
||||
$form->add('text',
|
||||
'household_name',
|
||||
ts('Household Name'),
|
||||
TRUE
|
||||
);
|
||||
|
||||
$stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant::stateProvince();
|
||||
$form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
|
||||
|
||||
/**
|
||||
* You can define a custom title for the search form
|
||||
*/
|
||||
$this->setTitle(ts('My Search Title'));
|
||||
|
||||
/**
|
||||
* if you are using the standard template, this array tells the template what elements
|
||||
* are part of the search criteria
|
||||
*/
|
||||
$form->assign('elements', array('household_name', 'state_province_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function summary() {
|
||||
$summary = array(
|
||||
'summary' => 'This is a summary',
|
||||
'total' => 50.0,
|
||||
);
|
||||
return $summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $returnSQL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
|
||||
return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all($offset = 0, $rowcount = 0, $sort = NULL, $includeContactIDs = FALSE, $justIDs = FALSE) {
|
||||
if ($justIDs) {
|
||||
$selectClause = "contact_a.id as contact_id";
|
||||
$sort = 'contact_a.id';
|
||||
}
|
||||
else {
|
||||
$selectClause = "
|
||||
contact_a.id as contact_id ,
|
||||
contact_a.contact_type as contact_type,
|
||||
contact_a.sort_name as sort_name,
|
||||
state_province.name as state_province
|
||||
";
|
||||
}
|
||||
|
||||
return $this->sql($selectClause,
|
||||
$offset, $rowcount, $sort,
|
||||
$includeContactIDs, NULL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function from() {
|
||||
$this->buildACLClause('contact_a');
|
||||
$from = "
|
||||
FROM civicrm_contact contact_a
|
||||
LEFT JOIN civicrm_address address ON ( address.contact_id = contact_a.id AND
|
||||
address.is_primary = 1 )
|
||||
LEFT JOIN civicrm_email ON ( civicrm_email.contact_id = contact_a.id AND
|
||||
civicrm_email.is_primary = 1 )
|
||||
LEFT JOIN civicrm_state_province state_province ON state_province.id = address.state_province_id {$this->_aclFrom}
|
||||
";
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
$params = array();
|
||||
$where = "contact_a.contact_type = 'Household'";
|
||||
|
||||
$count = 1;
|
||||
$clause = array();
|
||||
$name = CRM_Utils_Array::value('household_name',
|
||||
$this->_formValues
|
||||
);
|
||||
if ($name != NULL) {
|
||||
if (strpos($name, '%') === FALSE) {
|
||||
$name = "%{$name}%";
|
||||
}
|
||||
$params[$count] = array($name, 'String');
|
||||
$clause[] = "contact_a.household_name LIKE %{$count}";
|
||||
$count++;
|
||||
}
|
||||
|
||||
$state = CRM_Utils_Array::value('state_province_id',
|
||||
$this->_formValues
|
||||
);
|
||||
if (!$state &&
|
||||
$this->_stateID
|
||||
) {
|
||||
$state = $this->_stateID;
|
||||
}
|
||||
|
||||
if ($state) {
|
||||
$params[$count] = array($state, 'Integer');
|
||||
$clause[] = "state_province.id = %{$count}";
|
||||
}
|
||||
|
||||
if ($this->_aclWhere) {
|
||||
$clause[] = " {$this->_aclWhere} ";
|
||||
}
|
||||
|
||||
if (!empty($clause)) {
|
||||
$where .= ' AND ' . implode(' AND ', $clause);
|
||||
}
|
||||
|
||||
return $this->whereClause($where, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return array_merge(array('household_name' => ''), $this->_formValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $row
|
||||
*/
|
||||
public function alterRow(&$row) {
|
||||
$row['sort_name'] .= ' ( altered )';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Search'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,285 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_TagContributions extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
|
||||
protected $_formValues;
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
public $_permissionedComponent;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
$this->_formValues = $formValues;
|
||||
$this->_permissionedComponent = 'CiviContribute';
|
||||
|
||||
/**
|
||||
* Define the columns for search result rows
|
||||
*/
|
||||
$this->_columns = array(
|
||||
ts('Contact ID') => 'contact_id',
|
||||
ts('Full Name') => 'sort_name',
|
||||
ts('First Name') => 'first_name',
|
||||
ts('Last Name') => 'last_name',
|
||||
ts('Tag') => 'tag_name',
|
||||
ts('Totals') => 'amount',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
|
||||
/**
|
||||
* You can define a custom title for the search form
|
||||
*/
|
||||
$this->setTitle('Find Contribution Amounts by Tag');
|
||||
|
||||
/**
|
||||
* Define the search form fields here
|
||||
*/
|
||||
|
||||
$form->addDate('start_date', ts('Contribution Date From'), FALSE, array('formatType' => 'custom'));
|
||||
$form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom'));
|
||||
$tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
|
||||
$form->addElement('select', 'tag', ts('Tagged'), $tag);
|
||||
|
||||
/**
|
||||
* If you are using the sample template, this array tells the template fields to render
|
||||
* for the search form.
|
||||
*/
|
||||
$form->assign('elements', array('start_date', 'end_date', 'tag'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the smarty template used to layout the search form and results listings.
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the search query.
|
||||
*
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param string $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $onlyIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all(
|
||||
$offset = 0, $rowcount = 0, $sort = NULL,
|
||||
$includeContactIDs = FALSE, $onlyIDs = FALSE
|
||||
) {
|
||||
|
||||
// SELECT clause must include contact_id as an alias for civicrm_contact.id
|
||||
if ($onlyIDs) {
|
||||
$select = "contact_a.id as contact_id";
|
||||
}
|
||||
else {
|
||||
$select = "
|
||||
DISTINCT
|
||||
contact_a.id as contact_id,
|
||||
contact_a.sort_name as sort_name,
|
||||
contact_a.first_name as first_name,
|
||||
contact_a.last_name as last_name,
|
||||
GROUP_CONCAT(DISTINCT civicrm_tag.name ORDER BY civicrm_tag.name ASC ) as tag_name,
|
||||
sum(civicrm_contribution.total_amount) as amount
|
||||
";
|
||||
}
|
||||
$from = $this->from();
|
||||
|
||||
$where = $this->where($includeContactIDs);
|
||||
|
||||
$sql = "
|
||||
SELECT $select
|
||||
FROM $from
|
||||
WHERE $where
|
||||
";
|
||||
|
||||
$sql .= " GROUP BY contact_a.id";
|
||||
// Define ORDER BY for query in $sort, with default value
|
||||
if (!empty($sort)) {
|
||||
if (is_string($sort)) {
|
||||
$sort = CRM_Utils_Type::escape($sort, 'String');
|
||||
$sql .= " ORDER BY $sort ";
|
||||
}
|
||||
else {
|
||||
$sql .= " ORDER BY " . trim($sort->orderBy());
|
||||
}
|
||||
}
|
||||
else {
|
||||
$sql .= "";
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function from() {
|
||||
$this->buildACLClause('contact_a');
|
||||
$from = "
|
||||
civicrm_contribution,
|
||||
civicrm_contact contact_a
|
||||
LEFT JOIN civicrm_entity_tag ON ( civicrm_entity_tag.entity_table = 'civicrm_contact' AND
|
||||
civicrm_entity_tag.entity_id = contact_a.id )
|
||||
LEFT JOIN civicrm_tag ON civicrm_tag.id = civicrm_entity_tag.tag_id {$this->_aclFrom}
|
||||
";
|
||||
return $from;
|
||||
}
|
||||
|
||||
/*
|
||||
* WHERE clause is an array built from any required JOINS plus conditional filters based on search criteria field values
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
$clauses = array();
|
||||
|
||||
$clauses[] = "contact_a.contact_type = 'Individual'";
|
||||
$clauses[] = "civicrm_contribution.contact_id = contact_a.id";
|
||||
|
||||
$startDate = CRM_Utils_Date::processDate($this->_formValues['start_date']);
|
||||
if ($startDate) {
|
||||
$clauses[] = "civicrm_contribution.receive_date >= $startDate";
|
||||
}
|
||||
|
||||
$endDate = CRM_Utils_Date::processDate($this->_formValues['end_date']);
|
||||
if ($endDate) {
|
||||
$clauses[] = "civicrm_contribution.receive_date <= $endDate";
|
||||
}
|
||||
|
||||
$tag = CRM_Utils_Array::value('tag', $this->_formValues);
|
||||
if ($tag) {
|
||||
$clauses[] = "civicrm_entity_tag.tag_id = $tag";
|
||||
$clauses[] = "civicrm_tag.id = civicrm_entity_tag.tag_id";
|
||||
}
|
||||
else {
|
||||
$clauses[] = "civicrm_entity_tag.tag_id IS NOT NULL";
|
||||
}
|
||||
|
||||
if ($includeContactIDs) {
|
||||
$contactIDs = array();
|
||||
foreach ($this->_formValues as $id => $value) {
|
||||
if ($value &&
|
||||
substr($id, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX
|
||||
) {
|
||||
$contactIDs[] = substr($id, CRM_Core_Form::CB_PREFIX_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($contactIDs)) {
|
||||
$contactIDs = implode(', ', $contactIDs);
|
||||
$clauses[] = "contact_a.id IN ( $contactIDs )";
|
||||
}
|
||||
}
|
||||
if ($this->_aclWhere) {
|
||||
$clauses[] = " {$this->_aclWhere} ";
|
||||
}
|
||||
return implode(' AND ', $clauses);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Functions below generally don't need to be modified
|
||||
*/
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function count() {
|
||||
$sql = $this->all();
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql,
|
||||
CRM_Core_DAO::$_nullArray
|
||||
);
|
||||
return $dao->N;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $returnSQL Not used; included for consistency with parent; SQL is always returned
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = TRUE) {
|
||||
return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function &columns() {
|
||||
return $this->_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Search'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function summary() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,219 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contact_Form_Search_Custom_ZipCodeRange extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
|
||||
protected $_aclFrom = NULL;
|
||||
protected $_aclWhere = NULL;
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues) {
|
||||
parent::__construct($formValues);
|
||||
|
||||
$this->_columns = array(
|
||||
// If possible, don't use aliases for the columns you select.
|
||||
// You can prefix columns with table aliases, if needed.
|
||||
//
|
||||
// If you don't do this, selecting individual records from the
|
||||
// custom search result won't work if your results are sorted on the
|
||||
// aliased colums.
|
||||
// (This is why we map Contact ID on contact_a.id, and not on contact_id).
|
||||
ts('Contact ID') => 'contact_a.id',
|
||||
ts('Name') => 'sort_name',
|
||||
ts('Email') => 'email',
|
||||
ts('Zip') => 'postal_code',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form) {
|
||||
$form->add('text',
|
||||
'postal_code_low',
|
||||
ts('Postal Code Start'),
|
||||
TRUE
|
||||
);
|
||||
|
||||
$form->add('text',
|
||||
'postal_code_high',
|
||||
ts('Postal Code End'),
|
||||
TRUE
|
||||
);
|
||||
|
||||
/**
|
||||
* You can define a custom title for the search form
|
||||
*/
|
||||
$this->setTitle('Zip Code Range Search');
|
||||
|
||||
/**
|
||||
* if you are using the standard template, this array tells the template what elements
|
||||
* are part of the search criteria
|
||||
*/
|
||||
$form->assign('elements', array('postal_code_low', 'postal_code_high'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function summary() {
|
||||
$summary = array();
|
||||
return $summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $returnSQL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
|
||||
return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function all(
|
||||
$offset = 0, $rowcount = 0, $sort = NULL,
|
||||
$includeContactIDs = FALSE, $justIDs = FALSE
|
||||
) {
|
||||
if ($justIDs) {
|
||||
$selectClause = "contact_a.id as contact_id";
|
||||
// Don't change sort order when $justIDs is TRUE, see CRM-14920.
|
||||
}
|
||||
else {
|
||||
// We select contact_a.id twice. Once as contact_a.id,
|
||||
// because it is used to fill the prevnext_cache. And once
|
||||
// as contact_a.id, for the patch of CRM-16587 to work when
|
||||
// the results are sorted on contact ID.
|
||||
$selectClause = "
|
||||
contact_a.id as contact_id ,
|
||||
contact_a.id as id ,
|
||||
contact_a.sort_name as sort_name ,
|
||||
email.email as email ,
|
||||
address.postal_code as postal_code
|
||||
";
|
||||
}
|
||||
return $this->sql($selectClause,
|
||||
$offset, $rowcount, $sort,
|
||||
$includeContactIDs, NULL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function from() {
|
||||
$this->buildACLClause('contact_a');
|
||||
$from = "
|
||||
FROM civicrm_contact contact_a
|
||||
LEFT JOIN civicrm_address address ON ( address.contact_id = contact_a.id AND
|
||||
address.is_primary = 1 )
|
||||
LEFT JOIN civicrm_email email ON ( email.contact_id = contact_a.id AND
|
||||
email.is_primary = 1 ) {$this->_aclFrom}
|
||||
";
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeContactIDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE) {
|
||||
$params = array();
|
||||
|
||||
$low = CRM_Utils_Array::value('postal_code_low',
|
||||
$this->_formValues
|
||||
);
|
||||
$high = CRM_Utils_Array::value('postal_code_high',
|
||||
$this->_formValues
|
||||
);
|
||||
if ($low == NULL || $high == NULL) {
|
||||
CRM_Core_Error::statusBounce(ts('Please provide start and end postal codes'),
|
||||
CRM_Utils_System::url('civicrm/contact/search/custom',
|
||||
"reset=1&csid={$this->_formValues['customSearchID']}",
|
||||
FALSE, NULL, FALSE, TRUE
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$where = "ROUND(address.postal_code) >= %1 AND ROUND(address.postal_code) <= %2";
|
||||
$params = array(
|
||||
1 => array(trim($low), 'Integer'),
|
||||
2 => array(trim($high), 'Integer'),
|
||||
);
|
||||
|
||||
if ($this->_aclWhere) {
|
||||
$where .= " AND {$this->_aclWhere} ";
|
||||
}
|
||||
return $this->whereClause($where, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function templateFile() {
|
||||
return 'CRM/Contact/Form/Search/Custom.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Search'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableAlias
|
||||
*/
|
||||
public function buildACLClause($tableAlias = 'contact') {
|
||||
list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias);
|
||||
}
|
||||
|
||||
}
|
134
sites/all/modules/civicrm/CRM/Contact/Form/Search/Interface.php
Normal file
134
sites/all/modules/civicrm/CRM/Contact/Form/Search/Interface.php
Normal file
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
interface CRM_Contact_Form_Search_Interface {
|
||||
|
||||
/**
|
||||
* The constructor gets the submitted form values.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
public function __construct(&$formValues);
|
||||
|
||||
/**
|
||||
* Builds the list of tasks or actions that a searcher can perform on a result set.
|
||||
*
|
||||
* @param CRM_Core_Form_Search $form
|
||||
* @return array
|
||||
*/
|
||||
public function buildTaskList(CRM_Core_Form_Search $form);
|
||||
|
||||
/**
|
||||
* Builds the quickform for this search.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public function buildForm(&$form);
|
||||
|
||||
/**
|
||||
* Builds the search query for various cases. We break it down into finer cases
|
||||
* since you can optimize each query independently. All the functions below return
|
||||
* a sql clause with only SELECT, FROM, WHERE sub-parts. The ORDER BY and LIMIT is
|
||||
* added at a later stage
|
||||
*/
|
||||
|
||||
/**
|
||||
* Count of records that match the current input parameters.
|
||||
*
|
||||
* Used by pager.
|
||||
*/
|
||||
public function count();
|
||||
|
||||
/**
|
||||
* Summary information for the query that can be displayed in the template.
|
||||
*
|
||||
* This is useful to pass total / sub total information if needed
|
||||
*/
|
||||
public function summary();
|
||||
|
||||
/**
|
||||
* List of contact ids that match the current input parameters.
|
||||
*
|
||||
* Used by different tasks. Will be also used to optimize the
|
||||
* 'all' query below to avoid excessive LEFT JOIN blowup
|
||||
*
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
*/
|
||||
public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL);
|
||||
|
||||
/**
|
||||
* Retrieve all the values that match the current input parameters.
|
||||
*
|
||||
* Used by the selector
|
||||
*
|
||||
* @param int $offset
|
||||
* @param int $rowcount
|
||||
* @param null $sort
|
||||
* @param bool $includeContactIDs
|
||||
* @param bool $justIDs
|
||||
*/
|
||||
public function all($offset = 0, $rowcount = 0, $sort = NULL, $includeContactIDs = FALSE, $justIDs = FALSE);
|
||||
|
||||
/**
|
||||
* The below two functions (from and where) are ONLY used if you want to
|
||||
* expose a custom group as a smart group and be able to send a mailing
|
||||
* to them via CiviMail. civicrm_email should be part of the from clause
|
||||
* The from clause should be a valid sql from clause including the word FROM
|
||||
* CiviMail will pick up the contacts where the email is primary and
|
||||
* is not on hold / opt out / do not email
|
||||
*/
|
||||
|
||||
/**
|
||||
* The from clause for the query.
|
||||
*/
|
||||
public function from();
|
||||
|
||||
/**
|
||||
* The where clause for the query.
|
||||
*
|
||||
* @param bool $includeContactIDs
|
||||
*/
|
||||
public function where($includeContactIDs = FALSE);
|
||||
|
||||
/**
|
||||
* The template FileName to use to display the results.
|
||||
*/
|
||||
public function templateFile();
|
||||
|
||||
/**
|
||||
* Returns an array of column headers and field names and sort options.
|
||||
*/
|
||||
public function &columns();
|
||||
|
||||
}
|
533
sites/all/modules/civicrm/CRM/Contact/Form/Task.php
Normal file
533
sites/all/modules/civicrm/CRM/Contact/Form/Task.php
Normal file
|
@ -0,0 +1,533 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for search-result tasks.
|
||||
*/
|
||||
class CRM_Contact_Form_Task extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The task being performed
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_task;
|
||||
|
||||
/**
|
||||
* The array that holds all the contact ids
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_contactIds;
|
||||
|
||||
/**
|
||||
* The array that holds all the contact types
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_contactTypes;
|
||||
|
||||
/**
|
||||
* The additional clause that we restrict the search with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_componentClause = NULL;
|
||||
|
||||
/**
|
||||
* The name of the temp table where we store the contact IDs
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_componentTable = NULL;
|
||||
|
||||
/**
|
||||
* The array that holds all the component ids
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_componentIds;
|
||||
|
||||
/**
|
||||
* This includes the submitted values of the search form
|
||||
*/
|
||||
static protected $_searchFormValues;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
self::preProcessCommon($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common pre-processing function.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param bool $useTable
|
||||
*/
|
||||
public static function preProcessCommon(&$form, $useTable = FALSE) {
|
||||
$form->_contactIds = array();
|
||||
$form->_contactTypes = array();
|
||||
|
||||
$isStandAlone = in_array('task', $form->urlPath);
|
||||
if ($isStandAlone) {
|
||||
list($form->_task, $title) = CRM_Contact_Task::getTaskAndTitleByClass(get_class($form));
|
||||
if (!array_key_exists($form->_task, CRM_Contact_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission()))) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
$form->_contactIds = explode(',', CRM_Utils_Request::retrieve('cids', 'String', $form, TRUE));
|
||||
if (empty($form->_contactIds)) {
|
||||
CRM_Core_Error::statusBounce(ts('No Contacts Selected'));
|
||||
}
|
||||
$form->setTitle($title);
|
||||
}
|
||||
|
||||
// get the submitted values of the search form
|
||||
// we'll need to get fv from either search or adv search in the future
|
||||
$fragment = 'search';
|
||||
if ($form->_action == CRM_Core_Action::ADVANCED) {
|
||||
self::$_searchFormValues = $form->controller->exportValues('Advanced');
|
||||
$fragment .= '/advanced';
|
||||
}
|
||||
elseif ($form->_action == CRM_Core_Action::PROFILE) {
|
||||
self::$_searchFormValues = $form->controller->exportValues('Builder');
|
||||
$fragment .= '/builder';
|
||||
}
|
||||
elseif ($form->_action == CRM_Core_Action::COPY) {
|
||||
self::$_searchFormValues = $form->controller->exportValues('Custom');
|
||||
$fragment .= '/custom';
|
||||
}
|
||||
elseif (!$isStandAlone) {
|
||||
self::$_searchFormValues = $form->controller->exportValues('Basic');
|
||||
}
|
||||
|
||||
//set the user context for redirection of task actions
|
||||
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form);
|
||||
$urlParams = 'force=1';
|
||||
if (CRM_Utils_Rule::qfKey($qfKey)) {
|
||||
$urlParams .= "&qfKey=$qfKey";
|
||||
}
|
||||
|
||||
$cacheKey = "civicrm search {$qfKey}";
|
||||
|
||||
$url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams);
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->replaceUserContext($url);
|
||||
|
||||
$form->_task = CRM_Utils_Array::value('task', self::$_searchFormValues);
|
||||
$crmContactTaskTasks = CRM_Contact_Task::taskTitles();
|
||||
$form->assign('taskName', CRM_Utils_Array::value($form->_task, $crmContactTaskTasks));
|
||||
|
||||
if ($useTable) {
|
||||
$form->_componentTable = CRM_Core_DAO::createTempTableName('civicrm_task_action', TRUE, $qfKey);
|
||||
$sql = " DROP TABLE IF EXISTS {$form->_componentTable}";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
|
||||
$sql = "CREATE TABLE {$form->_componentTable} ( contact_id int primary key) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
}
|
||||
|
||||
// all contacts or action = save a search
|
||||
if ((CRM_Utils_Array::value('radio_ts', self::$_searchFormValues) == 'ts_all') ||
|
||||
($form->_task == CRM_Contact_Task::SAVE_SEARCH)
|
||||
) {
|
||||
$sortByCharacter = $form->get('sortByCharacter');
|
||||
$cacheKey = ($sortByCharacter && $sortByCharacter != 'all') ? "{$cacheKey}_alphabet" : $cacheKey;
|
||||
|
||||
// since we don't store all contacts in prevnextcache, when user selects "all" use query to retrieve contacts
|
||||
// rather than prevnext cache table for most of the task actions except export where we rebuild query to fetch
|
||||
// final result set
|
||||
if ($useTable) {
|
||||
$allCids = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, "getall");
|
||||
}
|
||||
else {
|
||||
$allCids[$cacheKey] = $form->getContactIds();
|
||||
}
|
||||
|
||||
$form->_contactIds = array();
|
||||
if ($useTable) {
|
||||
$count = 0;
|
||||
$insertString = array();
|
||||
foreach ($allCids[$cacheKey] as $cid => $ignore) {
|
||||
$count++;
|
||||
$insertString[] = " ( {$cid} ) ";
|
||||
if ($count % 200 == 0) {
|
||||
$string = implode(',', $insertString);
|
||||
$sql = "REPLACE INTO {$form->_componentTable} ( contact_id ) VALUES $string";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
$insertString = array();
|
||||
}
|
||||
}
|
||||
if (!empty($insertString)) {
|
||||
$string = implode(',', $insertString);
|
||||
$sql = "REPLACE INTO {$form->_componentTable} ( contact_id ) VALUES $string";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
}
|
||||
}
|
||||
elseif (empty($form->_contactIds)) {
|
||||
// filter duplicates here
|
||||
// CRM-7058
|
||||
// might be better to do this in the query, but that logic is a bit complex
|
||||
// and it decides when to use distinct based on input criteria, which needs
|
||||
// to be fixed and optimized.
|
||||
|
||||
foreach ($allCids[$cacheKey] as $cid => $ignore) {
|
||||
$form->_contactIds[] = $cid;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (CRM_Utils_Array::value('radio_ts', self::$_searchFormValues) == 'ts_sel') {
|
||||
// selected contacts only
|
||||
// need to perform action on only selected contacts
|
||||
$insertString = array();
|
||||
|
||||
// refire sql in case of custom search
|
||||
if ($form->_action == CRM_Core_Action::COPY) {
|
||||
// selected contacts only
|
||||
// need to perform action on only selected contacts
|
||||
foreach (self::$_searchFormValues as $name => $value) {
|
||||
if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
|
||||
$contactID = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
|
||||
if ($useTable) {
|
||||
$insertString[] = " ( {$contactID} ) ";
|
||||
}
|
||||
else {
|
||||
$form->_contactIds[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// fetching selected contact ids of passed cache key
|
||||
$selectedCids = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey);
|
||||
foreach ($selectedCids[$cacheKey] as $selectedCid => $ignore) {
|
||||
if ($useTable) {
|
||||
$insertString[] = " ( {$selectedCid} ) ";
|
||||
}
|
||||
else {
|
||||
$form->_contactIds[] = $selectedCid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($insertString)) {
|
||||
$string = implode(',', $insertString);
|
||||
$sql = "REPLACE INTO {$form->_componentTable} ( contact_id ) VALUES $string";
|
||||
CRM_Core_DAO::executeQuery($sql);
|
||||
}
|
||||
}
|
||||
|
||||
//contact type for pick up profiles as per selected contact types with subtypes
|
||||
//CRM-5521
|
||||
if ($selectedTypes = CRM_Utils_Array::value('contact_type', self::$_searchFormValues)) {
|
||||
if (!is_array($selectedTypes)) {
|
||||
$selectedTypes = explode(' ', $selectedTypes);
|
||||
}
|
||||
foreach ($selectedTypes as $ct => $dontcare) {
|
||||
if (strpos($ct, CRM_Core_DAO::VALUE_SEPARATOR) === FALSE) {
|
||||
$form->_contactTypes[] = $ct;
|
||||
}
|
||||
else {
|
||||
$separator = strpos($ct, CRM_Core_DAO::VALUE_SEPARATOR);
|
||||
$form->_contactTypes[] = substr($ct, $separator + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (CRM_Utils_Array::value('radio_ts', self::$_searchFormValues) == 'ts_sel'
|
||||
&& ($form->_action != CRM_Core_Action::COPY)
|
||||
) {
|
||||
$sel = CRM_Utils_Array::value('radio_ts', self::$_searchFormValues);
|
||||
$form->assign('searchtype', $sel);
|
||||
$result = CRM_Core_BAO_PrevNextCache::getSelectedContacts();
|
||||
$form->assign("value", $result);
|
||||
}
|
||||
|
||||
if (!empty($form->_contactIds)) {
|
||||
$form->_componentClause = ' contact_a.id IN ( ' . implode(',', $form->_contactIds) . ' ) ';
|
||||
$form->assign('totalSelectedContacts', count($form->_contactIds));
|
||||
|
||||
$form->_componentIds = $form->_contactIds;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contact id for custom search.
|
||||
*
|
||||
* we are not using prev/next table in case of custom search
|
||||
*/
|
||||
public function getContactIds() {
|
||||
// need to perform action on all contacts
|
||||
// fire the query again and get the contact id's + display name
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
|
||||
$selectorName = $this->controller->selectorName();
|
||||
require_once str_replace('_', DIRECTORY_SEPARATOR, $selectorName) . '.php';
|
||||
|
||||
$fv = $this->get('formValues');
|
||||
$customClass = $this->get('customSearchClass');
|
||||
require_once 'CRM/Core/BAO/Mapping.php';
|
||||
$returnProperties = CRM_Core_BAO_Mapping::returnProperties(self::$_searchFormValues);
|
||||
|
||||
$selector = new $selectorName($customClass, $fv, NULL, $returnProperties);
|
||||
|
||||
$params = $this->get('queryParams');
|
||||
|
||||
// fix for CRM-5165
|
||||
$sortByCharacter = $this->get('sortByCharacter');
|
||||
if ($sortByCharacter && $sortByCharacter != 1) {
|
||||
$params[] = array('sortByCharacter', '=', $sortByCharacter, 0, 0);
|
||||
}
|
||||
$queryOperator = $this->get('queryOperator');
|
||||
if (!$queryOperator) {
|
||||
$queryOperator = 'AND';
|
||||
}
|
||||
$dao = $selector->contactIDQuery($params, $this->_action, $sortID,
|
||||
CRM_Utils_Array::value('display_relationship_type', $fv),
|
||||
$queryOperator
|
||||
);
|
||||
|
||||
$contactIds = array();
|
||||
while ($dao->fetch()) {
|
||||
$contactIds[$dao->contact_id] = $dao->contact_id;
|
||||
}
|
||||
|
||||
return $contactIds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set default values for the form. Relationship that in edit/view action.
|
||||
*
|
||||
* The default values are retrieved from the database.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the rules for form.
|
||||
*/
|
||||
public function addRules() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addDefaultButtons(ts('Confirm Action'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple shell that derived classes can call to add form buttons.
|
||||
*
|
||||
* Allows customized title for the main Submit
|
||||
*
|
||||
* @param string $title
|
||||
* Title of the main button.
|
||||
* @param string $nextType
|
||||
* Button type for the form after processing.
|
||||
* @param string $backType
|
||||
* @param bool $submitOnce
|
||||
*/
|
||||
public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => $nextType,
|
||||
'name' => $title,
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => $backType,
|
||||
'name' => ts('Cancel'),
|
||||
'icon' => 'fa-times',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace ids of household members in $this->_contactIds with the id of their household.
|
||||
*
|
||||
* CRM-8338
|
||||
*/
|
||||
public function mergeContactIdsByHousehold() {
|
||||
if (empty($this->_contactIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$contactRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE,
|
||||
'name',
|
||||
FALSE
|
||||
);
|
||||
|
||||
// Get Head of Household & Household Member relationships
|
||||
$relationKeyMOH = CRM_Utils_Array::key('Household Member of', $contactRelationshipTypes);
|
||||
$relationKeyHOH = CRM_Utils_Array::key('Head of Household for', $contactRelationshipTypes);
|
||||
$householdRelationshipTypes = array(
|
||||
$relationKeyMOH => $contactRelationshipTypes[$relationKeyMOH],
|
||||
$relationKeyHOH => $contactRelationshipTypes[$relationKeyHOH],
|
||||
);
|
||||
|
||||
$relID = implode(',', $this->_contactIds);
|
||||
|
||||
foreach ($householdRelationshipTypes as $rel => $dnt) {
|
||||
list($id, $direction) = explode('_', $rel, 2);
|
||||
// identify the relationship direction
|
||||
$contactA = 'contact_id_a';
|
||||
$contactB = 'contact_id_b';
|
||||
if ($direction == 'b_a') {
|
||||
$contactA = 'contact_id_b';
|
||||
$contactB = 'contact_id_a';
|
||||
}
|
||||
|
||||
// Find related households.
|
||||
$relationSelect = "SELECT contact_household.id as household_id, {$contactA} as refContact ";
|
||||
$relationFrom = " FROM civicrm_contact contact_household
|
||||
INNER JOIN civicrm_relationship crel ON crel.{$contactB} = contact_household.id AND crel.relationship_type_id = {$id} ";
|
||||
|
||||
// Check for active relationship status only.
|
||||
$today = date('Ymd');
|
||||
$relationActive = " AND (crel.is_active = 1 AND ( crel.end_date is NULL OR crel.end_date >= {$today} ) )";
|
||||
$relationWhere = " WHERE contact_household.is_deleted = 0 AND crel.{$contactA} IN ( {$relID} ) {$relationActive}";
|
||||
$relationGroupBy = " GROUP BY crel.{$contactA}, contact_household.id";
|
||||
$relationQueryString = "$relationSelect $relationFrom $relationWhere $relationGroupBy";
|
||||
|
||||
$householdsDAO = CRM_Core_DAO::executeQuery($relationQueryString);
|
||||
while ($householdsDAO->fetch()) {
|
||||
// Remove contact's id from $this->_contactIds and replace with their household's id.
|
||||
foreach (array_keys($this->_contactIds, $householdsDAO->refContact) as $idKey) {
|
||||
unset($this->_contactIds[$idKey]);
|
||||
}
|
||||
if (!in_array($householdsDAO->household_id, $this->_contactIds)) {
|
||||
$this->_contactIds[] = $householdsDAO->household_id;
|
||||
}
|
||||
}
|
||||
$householdsDAO->free();
|
||||
}
|
||||
|
||||
// If contact list has changed, households will probably be at the end of
|
||||
// the list. Sort it again by sort_name.
|
||||
if (implode(',', $this->_contactIds) != $relID) {
|
||||
$result = civicrm_api3('Contact', 'get', array(
|
||||
'return' => array('id'),
|
||||
'id' => array('IN' => $this->_contactIds),
|
||||
'options' => array(
|
||||
'limit' => 0,
|
||||
'sort' => "sort_name",
|
||||
),
|
||||
));
|
||||
$this->_contactIds = array_keys($result['values']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given this task's list of targets, produce a hidden group.
|
||||
*
|
||||
* @return array
|
||||
* Array(0 => int $groupID, 1 => int|NULL $ssID).
|
||||
* @throws Exception
|
||||
*/
|
||||
public function createHiddenGroup() {
|
||||
// Did the user select "All" matches or cherry-pick a few records?
|
||||
$searchParams = $this->controller->exportValues();
|
||||
if ($searchParams['radio_ts'] == 'ts_sel') {
|
||||
// Create a static group.
|
||||
$randID = md5(time() . rand(1, 1000)); // groups require a unique name
|
||||
$grpTitle = "Hidden Group {$randID}";
|
||||
$grpID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $grpTitle, 'id', 'title');
|
||||
|
||||
if (!$grpID) {
|
||||
$groupParams = array(
|
||||
'title' => $grpTitle,
|
||||
'is_active' => 1,
|
||||
'is_hidden' => 1,
|
||||
'group_type' => array('2' => 1),
|
||||
);
|
||||
|
||||
$group = CRM_Contact_BAO_Group::create($groupParams);
|
||||
$grpID = $group->id;
|
||||
|
||||
CRM_Contact_BAO_GroupContact::addContactsToGroup($this->_contactIds, $group->id);
|
||||
|
||||
$newGroupTitle = "Hidden Group {$grpID}";
|
||||
$groupParams = array(
|
||||
'id' => $grpID,
|
||||
'name' => CRM_Utils_String::titleToVar($newGroupTitle),
|
||||
'title' => $newGroupTitle,
|
||||
'group_type' => array('2' => 1),
|
||||
);
|
||||
CRM_Contact_BAO_Group::create($groupParams);
|
||||
}
|
||||
|
||||
// note at this point its a static group
|
||||
return array($grpID, NULL);
|
||||
}
|
||||
else {
|
||||
// Create a smart group.
|
||||
$ssId = $this->get('ssID');
|
||||
$hiddenSmartParams = array(
|
||||
'group_type' => array('2' => 1),
|
||||
'form_values' => $this->get('formValues'),
|
||||
'saved_search_id' => $ssId,
|
||||
'search_custom_id' => $this->get('customSearchID'),
|
||||
'search_context' => $this->get('context'),
|
||||
);
|
||||
|
||||
list($smartGroupId, $savedSearchId) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams);
|
||||
return array($smartGroupId, $savedSearchId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
247
sites/all/modules/civicrm/CRM/Contact/Form/Task/AddToGroup.php
Normal file
247
sites/all/modules/civicrm/CRM/Contact/Form/Task/AddToGroup.php
Normal file
|
@ -0,0 +1,247 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to group contacts.
|
||||
*
|
||||
* This class provides functionality for the actual
|
||||
* addition of contacts to groups.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_AddToGroup extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* The context that we are working on
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_context;
|
||||
|
||||
/**
|
||||
* The groupId retrieved from the GET vars
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* The title of the group
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
// initialize the task and row fields
|
||||
parent::preProcess();
|
||||
|
||||
$this->_context = $this->get('context');
|
||||
$this->_id = $this->get('amtgID');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
//create radio buttons to select existing group or add a new group
|
||||
$options = array(ts('Add Contact To Existing Group'), ts('Create New Group'));
|
||||
|
||||
if (!$this->_id) {
|
||||
$this->addRadio('group_option', ts('Group Options'), $options, array('onclick' => "return showElements();"));
|
||||
|
||||
$this->add('text', 'title', ts('Group Name:') . ' ',
|
||||
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title')
|
||||
);
|
||||
$this->addRule('title', ts('Name already exists in Database.'),
|
||||
'objectExists', array('CRM_Contact_DAO_Group', $this->_id, 'title')
|
||||
);
|
||||
|
||||
$this->add('textarea', 'description', ts('Description:') . ' ',
|
||||
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description')
|
||||
);
|
||||
|
||||
$groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE);
|
||||
if (!CRM_Core_Permission::access('CiviMail')) {
|
||||
$isWorkFlowEnabled = CRM_Mailing_Info::workflowEnabled();
|
||||
if ($isWorkFlowEnabled &&
|
||||
!CRM_Core_Permission::check('create mailings') &&
|
||||
!CRM_Core_Permission::check('schedule mailings') &&
|
||||
!CRM_Core_Permission::check('approve mailings')
|
||||
) {
|
||||
unset($groupTypes['Mailing List']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($groupTypes)) {
|
||||
$this->addCheckBox('group_type',
|
||||
ts('Group Type'),
|
||||
$groupTypes,
|
||||
NULL, NULL, NULL, NULL, ' '
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// add select for groups
|
||||
$group = array('' => ts('- select group -')) + CRM_Core_PseudoConstant::nestedGroup();
|
||||
|
||||
$groupElement = $this->add('select', 'group_id', ts('Select Group'), $group, FALSE, array('class' => 'crm-select2 huge'));
|
||||
|
||||
$this->_title = $group[$this->_id];
|
||||
|
||||
if ($this->_context === 'amtg') {
|
||||
$groupElement->freeze();
|
||||
|
||||
// also set the group title
|
||||
$groupValues = array('id' => $this->_id, 'title' => $this->_title);
|
||||
$this->assign_by_ref('group', $groupValues);
|
||||
}
|
||||
|
||||
// Set dynamic page title for 'Add Members Group (confirm)'
|
||||
if ($this->_id) {
|
||||
CRM_Utils_System::setTitle(ts('Add Contacts: %1', array(1 => $this->_title)));
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Add Contacts to A Group'));
|
||||
}
|
||||
|
||||
$this->addDefaultButtons(ts('Add to Group'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default form values.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* the default array reference
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
if ($this->_context === 'amtg') {
|
||||
$defaults['group_id'] = $this->_id;
|
||||
}
|
||||
|
||||
$defaults['group_option'] = 0;
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add local and global form rules.
|
||||
*/
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Contact_Form_task_AddToGroup', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($params) {
|
||||
$errors = array();
|
||||
|
||||
if (!empty($params['group_option']) && empty($params['title'])) {
|
||||
$errors['title'] = "Group Name is a required field";
|
||||
}
|
||||
elseif (empty($params['group_option']) && empty($params['group_id'])) {
|
||||
$errors['group_id'] = "Select Group is a required field.";
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->controller->exportValues();
|
||||
$groupOption = CRM_Utils_Array::value('group_option', $params, NULL);
|
||||
if ($groupOption) {
|
||||
$groupParams = array();
|
||||
$groupParams['title'] = $params['title'];
|
||||
$groupParams['description'] = $params['description'];
|
||||
$groupParams['visibility'] = "User and User Admin Only";
|
||||
if (array_key_exists('group_type', $params) && is_array($params['group_type'])) {
|
||||
$groupParams['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
|
||||
array_keys($params['group_type'])
|
||||
) . CRM_Core_DAO::VALUE_SEPARATOR;
|
||||
}
|
||||
else {
|
||||
$groupParams['group_type'] = '';
|
||||
}
|
||||
$groupParams['is_active'] = 1;
|
||||
|
||||
$createdGroup = CRM_Contact_BAO_Group::create($groupParams);
|
||||
$groupID = $createdGroup->id;
|
||||
$groupName = $groupParams['title'];
|
||||
}
|
||||
else {
|
||||
$groupID = $params['group_id'];
|
||||
$group = CRM_Core_PseudoConstant::group();
|
||||
$groupName = $group[$groupID];
|
||||
}
|
||||
|
||||
list($total, $added, $notAdded) = CRM_Contact_BAO_GroupContact::addContactsToGroup($this->_contactIds, $groupID);
|
||||
|
||||
$status = array(
|
||||
ts('%count contact added to group', array(
|
||||
'count' => $added,
|
||||
'plural' => '%count contacts added to group',
|
||||
)),
|
||||
);
|
||||
if ($notAdded) {
|
||||
$status[] = ts('%count contact was already in group', array(
|
||||
'count' => $notAdded,
|
||||
'plural' => '%count contacts were already in group',
|
||||
));
|
||||
}
|
||||
$status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
|
||||
CRM_Core_Session::setStatus($status, ts('Added Contact to %1', array(
|
||||
1 => $groupName,
|
||||
'count' => $added,
|
||||
'plural' => 'Added Contacts to %1',
|
||||
)), 'success', array('expires' => 0));
|
||||
|
||||
if ($this->_context === 'amtg') {
|
||||
CRM_Core_Session::singleton()
|
||||
->pushUserContext(CRM_Utils_System::url('civicrm/group/search', "reset=1&force=1&context=smog&gid=$groupID"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to add contact(s) to Household.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_AddToHousehold extends CRM_Contact_Form_Task_AddToParentClass {
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->set('contactType', 'Household');
|
||||
$this->assign('contactType', 'Household');
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to add contact(s) to Individual.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_AddToIndividual extends CRM_Contact_Form_Task_AddToParentClass {
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->set('contactType', 'Individual');
|
||||
$this->assign('contactType', 'Individual');
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to add contact(s) to Organization.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_AddToOrganization extends CRM_Contact_Form_Task_AddToParentClass {
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->set('contactType', 'Organization');
|
||||
$this->assign('contactType', 'Organization');
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,284 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the shared functionality for addToHousehold and addToOrganization.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_AddToParentClass extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Exported parameters from the form.
|
||||
*
|
||||
* @var array.
|
||||
*/
|
||||
protected $params;
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
public function buildQuickForm() {
|
||||
$contactType = $this->get('contactType');
|
||||
CRM_Utils_System::setTitle(ts('Add Contacts to %1', array(1 => $contactType)));
|
||||
$this->addElement('text', 'name', ts('Find Target %1', array(1 => $contactType)));
|
||||
|
||||
$this->add('select',
|
||||
'relationship_type_id',
|
||||
ts('Relationship Type'),
|
||||
array(
|
||||
'' => ts('- select -'),
|
||||
) +
|
||||
CRM_Contact_BAO_Relationship::getRelationType($contactType), TRUE
|
||||
);
|
||||
|
||||
$searchRows = $this->get('searchRows');
|
||||
$searchCount = $this->get('searchCount');
|
||||
if ($searchRows) {
|
||||
$checkBoxes = array();
|
||||
$chekFlag = 0;
|
||||
foreach ($searchRows as $id => $row) {
|
||||
if (!$chekFlag) {
|
||||
$chekFlag = $id;
|
||||
}
|
||||
|
||||
$checkBoxes[$id] = $this->createElement('radio', NULL, NULL, NULL, $id);
|
||||
}
|
||||
|
||||
$this->addGroup($checkBoxes, 'contact_check');
|
||||
if ($chekFlag) {
|
||||
$checkBoxes[$chekFlag]->setChecked(TRUE);
|
||||
}
|
||||
$this->assign('searchRows', $searchRows);
|
||||
}
|
||||
|
||||
$this->assign('searchCount', $searchCount);
|
||||
$this->assign('searchDone', $this->get('searchDone'));
|
||||
$this->assign('contact_type_display', ts($contactType));
|
||||
$this->addElement('submit', $this->getButtonName('refresh'), ts('Search'), array('class' => 'crm-form-submit'));
|
||||
$this->addElement('submit', $this->getButtonName('cancel'), ts('Cancel'), array('class' => 'crm-form-submit'));
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Add to %1', array(1 => $contactType)),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Add relationships from form.
|
||||
*/
|
||||
public function addRelationships() {
|
||||
|
||||
if (!is_array($this->_contactIds)) {
|
||||
// Could this really happen?
|
||||
return;
|
||||
}
|
||||
$relationshipTypeParts = explode('_', $this->params['relationship_type_id']);
|
||||
$params = array(
|
||||
'relationship_type_id' => $relationshipTypeParts[0],
|
||||
'is_active' => 1,
|
||||
);
|
||||
$secondaryRelationshipSide = $relationshipTypeParts[1];
|
||||
$primaryRelationshipSide = $relationshipTypeParts[2];
|
||||
$primaryFieldName = 'contact_id_' . $primaryRelationshipSide;
|
||||
$secondaryFieldName = 'contact_id_' . $secondaryRelationshipSide;
|
||||
|
||||
$relationshipLabel = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType',
|
||||
$params['relationship_type_id'], "label_{$secondaryRelationshipSide}_{$primaryRelationshipSide}");
|
||||
|
||||
$params[$secondaryFieldName] = $this->_contactIds;
|
||||
$params[$primaryFieldName] = $this->params['contact_check'];
|
||||
$outcome = CRM_Contact_BAO_Relationship::createMultiple($params, $primaryRelationshipSide);
|
||||
|
||||
$relatedContactName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params[$primaryFieldName],
|
||||
'display_name');
|
||||
|
||||
$status = array(
|
||||
ts('%count %2 %3 relationship created', array(
|
||||
'count' => $outcome['valid'],
|
||||
'plural' => '%count %2 %3 relationships created',
|
||||
2 => $relationshipLabel,
|
||||
3 => $relatedContactName,
|
||||
)),
|
||||
);
|
||||
if ($outcome['duplicate']) {
|
||||
$status[] = ts('%count was skipped because the contact is already %2 %3', array(
|
||||
'count' => $outcome['duplicate'],
|
||||
'plural' => '%count were skipped because the contacts are already %2 %3',
|
||||
2 => $relationshipLabel,
|
||||
3 => $relatedContactName,
|
||||
));
|
||||
}
|
||||
if ($outcome['invalid']) {
|
||||
$status[] = ts('%count relationship was not created because the contact is not of the right type for this relationship', array(
|
||||
'count' => $outcome['invalid'],
|
||||
'plural' => '%count relationships were not created because the contact is not of the right type for this relationship',
|
||||
));
|
||||
}
|
||||
$status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
|
||||
CRM_Core_Session::setStatus($status, ts('Relationship created.', array(
|
||||
'count' => $outcome['valid'],
|
||||
'plural' => 'Relationships created.',
|
||||
)), 'success', array('expires' => 0));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the result of the search for Add to * forms.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $params
|
||||
* This contains elements for search criteria.
|
||||
*/
|
||||
public function search(&$form, &$params) {
|
||||
//max records that will be listed
|
||||
$searchValues = array();
|
||||
if (!empty($params['rel_contact'])) {
|
||||
if (isset($params['rel_contact_id']) &&
|
||||
is_numeric($params['rel_contact_id'])
|
||||
) {
|
||||
$searchValues[] = array('contact_id', '=', $params['rel_contact_id'], 0, 1);
|
||||
}
|
||||
else {
|
||||
$searchValues[] = array('sort_name', 'LIKE', $params['rel_contact'], 0, 1);
|
||||
}
|
||||
}
|
||||
$contactTypeAdded = FALSE;
|
||||
|
||||
$excludedContactIds = array();
|
||||
if (isset($form->_contactId)) {
|
||||
$excludedContactIds[] = $form->_contactId;
|
||||
}
|
||||
|
||||
if (!empty($params['relationship_type_id'])) {
|
||||
$relationshipType = new CRM_Contact_DAO_RelationshipType();
|
||||
list($rid, $direction) = explode('_', $params['relationship_type_id'], 2);
|
||||
|
||||
$relationshipType->id = $rid;
|
||||
if ($relationshipType->find(TRUE)) {
|
||||
if ($direction == 'a_b') {
|
||||
$type = $relationshipType->contact_type_b;
|
||||
$subType = $relationshipType->contact_sub_type_b;
|
||||
}
|
||||
else {
|
||||
$type = $relationshipType->contact_type_a;
|
||||
$subType = $relationshipType->contact_sub_type_a;
|
||||
}
|
||||
|
||||
$form->set('contact_type', $type);
|
||||
$form->set('contact_sub_type', $subType);
|
||||
if ($type == 'Individual' || $type == 'Organization' || $type == 'Household') {
|
||||
$searchValues[] = array('contact_type', '=', $type, 0, 0);
|
||||
$contactTypeAdded = TRUE;
|
||||
}
|
||||
|
||||
if ($subType) {
|
||||
$searchValues[] = array('contact_sub_type', '=', $subType, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$contactTypeAdded && !empty($params['contact_type'])) {
|
||||
$searchValues[] = array('contact_type', '=', $params['contact_type'], 0, 0);
|
||||
}
|
||||
|
||||
// get the count of contact
|
||||
$contactBAO = new CRM_Contact_BAO_Contact();
|
||||
$query = new CRM_Contact_BAO_Query($searchValues);
|
||||
$searchCount = $query->searchQuery(0, 0, NULL, TRUE);
|
||||
$form->set('searchCount', $searchCount);
|
||||
if ($searchCount <= 50) {
|
||||
// get the result of the search
|
||||
$result = $query->searchQuery(0, 50, NULL);
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$searchRows = array();
|
||||
|
||||
//variable is set if only one record is foun and that record already has relationship with the contact
|
||||
$duplicateRelationship = 0;
|
||||
|
||||
while ($result->fetch()) {
|
||||
$query->convertToPseudoNames($result);
|
||||
$contactID = $result->contact_id;
|
||||
if (in_array($contactID, $excludedContactIds)) {
|
||||
$duplicateRelationship++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$duplicateRelationship = 0;
|
||||
|
||||
$searchRows[$contactID]['id'] = $contactID;
|
||||
$searchRows[$contactID]['name'] = $result->sort_name;
|
||||
$searchRows[$contactID]['city'] = $result->city;
|
||||
$searchRows[$contactID]['state'] = $result->state_province;
|
||||
$searchRows[$contactID]['email'] = $result->email;
|
||||
$searchRows[$contactID]['phone'] = $result->phone;
|
||||
|
||||
$contact_type = '<img src="' . $config->resourceBase . 'i/contact_';
|
||||
|
||||
$searchRows[$contactID]['type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type
|
||||
);
|
||||
}
|
||||
|
||||
$form->set('searchRows', $searchRows);
|
||||
$form->set('duplicateRelationship', $duplicateRelationship);
|
||||
}
|
||||
else {
|
||||
// resetting the session variables if many records are found
|
||||
$form->set('searchRows', NULL);
|
||||
$form->set('duplicateRelationship', NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// store the submitted values in an array
|
||||
$this->params = $this->controller->exportValues($this->_name);
|
||||
$this->set('searchDone', 0);
|
||||
$contactType = $this->get('contactType');
|
||||
|
||||
if (!empty($_POST["_qf_AddTo{$contactType}_refresh"])) {
|
||||
$searchParams['contact_type'] = $contactType;
|
||||
$searchParams['rel_contact'] = $this->params['name'];
|
||||
$this->search($this, $searchParams);
|
||||
$this->set('searchDone', 1);
|
||||
return;
|
||||
}
|
||||
$this->addRelationships();
|
||||
}
|
||||
|
||||
}
|
155
sites/all/modules/civicrm/CRM/Contact/Form/Task/AddToTag.php
Normal file
155
sites/all/modules/civicrm/CRM/Contact/Form/Task/AddToTag.php
Normal file
|
@ -0,0 +1,155 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to delete a group of contacts.
|
||||
*
|
||||
* This class provides functionality for the actual addition of contacts to groups.
|
||||
*
|
||||
* Wow is that copy & paste gone wrong or what? What does this class do? Anyone, anyone.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_AddToTag extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Name of the tag.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_name;
|
||||
|
||||
/**
|
||||
* All the tags in the system.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_tags;
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
// add select for tag
|
||||
$this->_tags = CRM_Core_BAO_Tag::getTags();
|
||||
|
||||
foreach ($this->_tags as $tagID => $tagName) {
|
||||
$this->_tagElement = &$this->addElement('checkbox', "tag[$tagID]", NULL, $tagName);
|
||||
}
|
||||
|
||||
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
|
||||
CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_contact');
|
||||
|
||||
$this->addDefaultButtons(ts('Tag Contacts'));
|
||||
}
|
||||
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Contact_Form_Task_AddToTag', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
* @param $rule
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($form, $rule) {
|
||||
$errors = array();
|
||||
if (empty($form['tag']) && empty($form['contact_taglist'])) {
|
||||
$errors['_qf_default'] = ts("Please select at least one tag.");
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
//get the submitted values in an array
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
$contactTags = $tagList = array();
|
||||
|
||||
// check if contact tags exists
|
||||
if (!empty($params['tag'])) {
|
||||
$contactTags = $params['tag'];
|
||||
}
|
||||
|
||||
// check if tags are selected from taglists
|
||||
if (!empty($params['contact_taglist'])) {
|
||||
foreach ($params['contact_taglist'] as $val) {
|
||||
if ($val) {
|
||||
if (is_numeric($val)) {
|
||||
$tagList[$val] = 1;
|
||||
}
|
||||
else {
|
||||
$tagIDs = explode(',', $val);
|
||||
if (!empty($tagIDs)) {
|
||||
foreach ($tagIDs as $tagID) {
|
||||
if (is_numeric($tagID)) {
|
||||
$tagList[$tagID] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tagSets = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', FALSE, TRUE);
|
||||
|
||||
foreach ($tagSets as $key => $value) {
|
||||
$this->_tags[$key] = $value['name'];
|
||||
}
|
||||
|
||||
// merge contact and taglist tags
|
||||
$allTags = CRM_Utils_Array::crmArrayMerge($contactTags, $tagList);
|
||||
|
||||
$this->_name = array();
|
||||
foreach ($allTags as $key => $dnc) {
|
||||
$this->_name[] = $this->_tags[$key];
|
||||
|
||||
list($total, $added, $notAdded) = CRM_Core_BAO_EntityTag::addEntitiesToTag($this->_contactIds, $key,
|
||||
'civicrm_contact', FALSE);
|
||||
|
||||
$status = array(ts('%count contact tagged', array('count' => $added, 'plural' => '%count contacts tagged')));
|
||||
if ($notAdded) {
|
||||
$status[] = ts('%count contact already had this tag', array(
|
||||
'count' => $notAdded,
|
||||
'plural' => '%count contacts already had this tag',
|
||||
));
|
||||
}
|
||||
$status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
|
||||
CRM_Core_Session::setStatus($status, ts("Added Tag <em>%1</em>", array(1 => $this->_tags[$key])), 'success', array('expires' => 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to alter a privacy
|
||||
* options for selected contacts
|
||||
*/
|
||||
class CRM_Contact_Form_Task_AlterPreferences extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
// add select for preferences
|
||||
|
||||
$options = array(ts('Add Selected Options'), ts('Remove selected options'));
|
||||
|
||||
$this->addRadio('actionTypeOption', ts('actionTypeOption'), $options);
|
||||
|
||||
$privacyOptions = CRM_Core_SelectValues::privacy();
|
||||
|
||||
foreach ($privacyOptions as $prefID => $prefName) {
|
||||
$this->_prefElement = &$this->addElement('checkbox', "pref[$prefID]", NULL, $prefName);
|
||||
}
|
||||
|
||||
$this->addDefaultButtons(ts('Set Privacy Options'));
|
||||
}
|
||||
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Contact_Form_Task_AlterPreferences', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default form values.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* the default array reference
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
$defaults['actionTypeOption'] = 0;
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
* @param $rule
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($form, $rule) {
|
||||
$errors = array();
|
||||
if (empty($form['pref']) && empty($form['contact_taglist'])) {
|
||||
$errors['_qf_default'] = ts("Please select at least one privacy option.");
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
//get the submitted values in an array
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
$actionTypeOption = CRM_Utils_Array::value('actionTypeOption', $params, NULL);
|
||||
// If remove option has been selected set new privacy value to "false"
|
||||
$privacyValueNew = empty($actionTypeOption);
|
||||
|
||||
// check if any privay option has been checked
|
||||
if (!empty($params['pref'])) {
|
||||
$privacyValues = $params['pref'];
|
||||
$count = 0;
|
||||
foreach ($this->_contactIds as $contact_id) {
|
||||
$contact = new CRM_Contact_BAO_Contact();
|
||||
$contact->id = $contact_id;
|
||||
|
||||
foreach ($privacyValues as $privacy_key => $privacy_value) {
|
||||
$contact->$privacy_key = $privacyValueNew;
|
||||
}
|
||||
$contact->save();
|
||||
$count++;
|
||||
}
|
||||
// Status message
|
||||
$privacyOptions = CRM_Core_SelectValues::privacy();
|
||||
$status = array();
|
||||
foreach ($privacyValues as $privacy_key => $privacy_value) {
|
||||
$label = $privacyOptions[$privacy_key];
|
||||
$status[] = $privacyValueNew ? ts("Added '%1'", array(1 => $label)) : ts("Removed '%1'", array(1 => $label));
|
||||
}
|
||||
|
||||
$status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
|
||||
if ($count > 1) {
|
||||
$title = ts('%1 Contacts Updated', array(1 => $count));
|
||||
}
|
||||
else {
|
||||
$name = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contact_id, 'display_name');
|
||||
$title = ts('%1 Updated', array(1 => $name));
|
||||
}
|
||||
|
||||
CRM_Core_Session::setStatus($status, $title, 'success');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
319
sites/all/modules/civicrm/CRM/Contact/Form/Task/Batch.php
Normal file
319
sites/all/modules/civicrm/CRM/Contact/Form/Task/Batch.php
Normal file
|
@ -0,0 +1,319 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality for batch profile update.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* The title of the group.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Maximum contacts that should be allowed to update.
|
||||
*/
|
||||
protected $_maxContacts = 100;
|
||||
|
||||
/**
|
||||
* Maximum profile fields that will be displayed.
|
||||
*/
|
||||
protected $_maxFields = 9;
|
||||
|
||||
/**
|
||||
* Variable to store redirect path.
|
||||
*/
|
||||
protected $_userContext;
|
||||
|
||||
/**
|
||||
* When not to reset sort_name.
|
||||
*/
|
||||
protected $_preserveDefault = TRUE;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
// initialize the task and row fields
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$ufGroupId = $this->get('ufGroupId');
|
||||
|
||||
if (!$ufGroupId) {
|
||||
CRM_Core_Error::fatal('ufGroupId is missing');
|
||||
}
|
||||
$this->_title = ts('Update multiple contacts') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId);
|
||||
CRM_Utils_System::setTitle($this->_title);
|
||||
|
||||
$this->addDefaultButtons(ts('Save'));
|
||||
$this->_fields = CRM_Core_BAO_UFGroup::getFields($ufGroupId, FALSE, CRM_Core_Action::VIEW);
|
||||
|
||||
// remove file type field and then limit fields
|
||||
$suppressFields = FALSE;
|
||||
$removehtmlTypes = array('File', 'Autocomplete-Select');
|
||||
foreach ($this->_fields as $name => $field) {
|
||||
if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name) &&
|
||||
in_array($this->_fields[$name]['html_type'], $removehtmlTypes)
|
||||
) {
|
||||
$suppressFields = TRUE;
|
||||
unset($this->_fields[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
//FIX ME: phone ext field is added at the end and it gets removed because of below code
|
||||
//$this->_fields = array_slice($this->_fields, 0, $this->_maxFields);
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'name' => ts('Update Contact(s)'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->assign('profileTitle', $this->_title);
|
||||
$this->assign('componentIds', $this->_contactIds);
|
||||
|
||||
// if below fields are missing we should not reset sort name / display name
|
||||
// CRM-6794
|
||||
$preserveDefaultsArray = array(
|
||||
'first_name',
|
||||
'last_name',
|
||||
'middle_name',
|
||||
'organization_name',
|
||||
'prefix_id',
|
||||
'suffix_id',
|
||||
'household_name',
|
||||
);
|
||||
|
||||
foreach ($this->_contactIds as $contactId) {
|
||||
$profileFields = $this->_fields;
|
||||
CRM_Core_BAO_Address::checkContactSharedAddressFields($profileFields, $contactId);
|
||||
foreach ($profileFields as $name => $field) {
|
||||
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $contactId);
|
||||
|
||||
if (in_array($field['name'], $preserveDefaultsArray)) {
|
||||
$this->_preserveDefault = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('fields', $this->_fields);
|
||||
|
||||
// don't set the status message when form is submitted.
|
||||
$buttonName = $this->controller->getButtonName('submit');
|
||||
|
||||
if ($suppressFields && $buttonName != '_qf_BatchUpdateProfile_next') {
|
||||
CRM_Core_Session::setStatus(ts("File or Autocomplete-Select type field(s) in the selected profile are not supported for Update multiple contacts."), ts('Some Fields Excluded'), 'info');
|
||||
}
|
||||
|
||||
$this->addDefaultButtons(ts('Update Contacts'));
|
||||
$this->addFormRule(array('CRM_Contact_Form_Task_Batch', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
if (empty($this->_fields)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$defaults = $sortName = array();
|
||||
foreach ($this->_contactIds as $contactId) {
|
||||
$details[$contactId] = array();
|
||||
|
||||
//build sortname
|
||||
$sortName[$contactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
|
||||
$contactId,
|
||||
'sort_name'
|
||||
);
|
||||
|
||||
CRM_Core_BAO_UFGroup::setProfileDefaults($contactId, $this->_fields, $defaults, FALSE);
|
||||
}
|
||||
|
||||
$this->assign('sortName', $sortName);
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Global form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields) {
|
||||
$errors = array();
|
||||
$externalIdentifiers = array();
|
||||
foreach ($fields['field'] as $componentId => $field) {
|
||||
foreach ($field as $fieldName => $fieldValue) {
|
||||
if ($fieldName == 'external_identifier') {
|
||||
if (in_array($fieldValue, $externalIdentifiers)) {
|
||||
$errors["field[$componentId][external_identifier]"] = ts('Duplicate value for External ID.');
|
||||
}
|
||||
else {
|
||||
$externalIdentifiers[$componentId] = $fieldValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
$ufGroupId = $this->get('ufGroupId');
|
||||
$notify = NULL;
|
||||
$inValidSubtypeCnt = 0;
|
||||
//send profile notification email if 'notify' field is set
|
||||
$notify = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $ufGroupId, 'notify');
|
||||
foreach ($params['field'] as $key => $value) {
|
||||
|
||||
//CRM-5521
|
||||
//validate subtype before updating
|
||||
if (!empty($value['contact_sub_type']) && !CRM_Contact_BAO_ContactType::isAllowEdit($key)) {
|
||||
unset($value['contact_sub_type']);
|
||||
$inValidSubtypeCnt++;
|
||||
}
|
||||
|
||||
$value['preserveDBName'] = $this->_preserveDefault;
|
||||
|
||||
//parse street address, CRM-7768
|
||||
self::parseStreetAddress($value, $this);
|
||||
|
||||
CRM_Contact_BAO_Contact::createProfileContact($value, $this->_fields, $key, NULL, $ufGroupId, NULL, TRUE);
|
||||
if ($notify) {
|
||||
$values = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($ufGroupId, $key, NULL);
|
||||
CRM_Core_BAO_UFGroup::commonSendMail($key, $values);
|
||||
}
|
||||
}
|
||||
|
||||
CRM_Core_Session::setStatus('', ts("Updates Saved"), 'success');
|
||||
if ($inValidSubtypeCnt) {
|
||||
CRM_Core_Session::setStatus(ts('Contact Subtype field of 1 contact has not been updated.', array(
|
||||
'plural' => 'Contact Subtype field of %count contacts has not been updated.',
|
||||
'count' => $inValidSubtypeCnt,
|
||||
)), ts('Invalid Subtype'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse street address.
|
||||
*
|
||||
* @param array $contactValues
|
||||
* Contact values.
|
||||
* @param CRM_Core_Form $form
|
||||
* Form object.
|
||||
*/
|
||||
public static function parseStreetAddress(&$contactValues, &$form) {
|
||||
if (!is_array($contactValues) || !is_array($form->_fields)) {
|
||||
return;
|
||||
}
|
||||
|
||||
static $parseAddress;
|
||||
$addressFldKey = 'street_address';
|
||||
if (!isset($parseAddress)) {
|
||||
$parseAddress = FALSE;
|
||||
foreach ($form->_fields as $key => $fld) {
|
||||
if (strpos($key, $addressFldKey) !== FALSE) {
|
||||
$parseAddress = CRM_Utils_Array::value('street_address_parsing',
|
||||
CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'address_options'
|
||||
),
|
||||
FALSE
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$parseAddress) {
|
||||
return;
|
||||
}
|
||||
|
||||
$allParseValues = array();
|
||||
foreach ($contactValues as $key => $value) {
|
||||
if (strpos($key, $addressFldKey) !== FALSE) {
|
||||
$locTypeId = substr($key, strlen($addressFldKey) + 1);
|
||||
|
||||
// parse address field.
|
||||
$parsedFields = CRM_Core_BAO_Address::parseStreetAddress($value);
|
||||
|
||||
//street address consider to be parsed properly,
|
||||
//If we get street_name and street_number.
|
||||
if (empty($parsedFields['street_name']) || empty($parsedFields['street_number'])) {
|
||||
$parsedFields = array_fill_keys(array_keys($parsedFields), '');
|
||||
}
|
||||
|
||||
//merge parse values.
|
||||
foreach ($parsedFields as $fldKey => $parseVal) {
|
||||
if ($locTypeId) {
|
||||
$fldKey .= "-{$locTypeId}";
|
||||
}
|
||||
$allParseValues[$fldKey] = $parseVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//finally merge all parse values
|
||||
if (!empty($allParseValues)) {
|
||||
$contactValues += $allParseValues;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
299
sites/all/modules/civicrm/CRM/Contact/Form/Task/Delete.php
Normal file
299
sites/all/modules/civicrm/CRM/Contact/Form/Task/Delete.php
Normal file
|
@ -0,0 +1,299 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to delete a group of contacts.
|
||||
*
|
||||
* This class provides functionality for the actual deletion.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_Delete extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. sending email to one
|
||||
* specific contact?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Cache shared address message so we don't query twice
|
||||
*/
|
||||
protected $_sharedAddressMessage = NULL;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
|
||||
$cid = CRM_Utils_Request::retrieve('cid', 'Positive',
|
||||
$this, FALSE
|
||||
);
|
||||
|
||||
$this->_searchKey = CRM_Utils_Request::retrieve('key', 'String', $this);
|
||||
|
||||
// sort out whether it’s a delete-to-trash, delete-into-oblivion or restore (and let the template know)
|
||||
$values = $this->controller->exportValues();
|
||||
$this->_skipUndelete = (CRM_Core_Permission::check('access deleted contacts') and (CRM_Utils_Request::retrieve('skip_undelete', 'Boolean', $this) or CRM_Utils_Array::value('task', $values) == CRM_Contact_Task::DELETE_PERMANENTLY));
|
||||
$this->_restore = (CRM_Utils_Request::retrieve('restore', 'Boolean', $this) or CRM_Utils_Array::value('task', $values) == CRM_Contact_Task::RESTORE);
|
||||
|
||||
if ($this->_restore && !CRM_Core_Permission::check('access deleted contacts')) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this contact.'));
|
||||
}
|
||||
elseif (!CRM_Core_Permission::check('delete contacts')) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to delete this contact.'));
|
||||
}
|
||||
|
||||
$this->assign('trash', Civi::settings()->get('contact_undelete') and !$this->_skipUndelete);
|
||||
$this->assign('restore', $this->_restore);
|
||||
|
||||
if ($this->_restore) {
|
||||
CRM_Utils_System::setTitle(ts('Restore Contact'));
|
||||
}
|
||||
|
||||
if ($cid) {
|
||||
if (!CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::EDIT)) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to delete this contact. Note: you can delete contacts if you can edit them.'));
|
||||
}
|
||||
elseif (CRM_Contact_BAO_Contact::checkDomainContact($cid)) {
|
||||
CRM_Core_Error::fatal(ts('This contact is a special one for the contact information associated with the CiviCRM installation for this domain. No one is allowed to delete it because the information is used for special system purposes.'));
|
||||
}
|
||||
|
||||
$this->_contactIds = array($cid);
|
||||
$this->_single = TRUE;
|
||||
$this->assign('totalSelectedContacts', 1);
|
||||
}
|
||||
else {
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
$this->_sharedAddressMessage = $this->get('sharedAddressMessage');
|
||||
if (!$this->_restore && !$this->_sharedAddressMessage) {
|
||||
// we check for each contact for shared contact address
|
||||
$sharedContactList = array();
|
||||
$sharedAddressCount = 0;
|
||||
foreach ($this->_contactIds as $contactId) {
|
||||
// check if a contact that is being deleted has any shared addresses
|
||||
$sharedAddressMessage = CRM_Core_BAO_Address::setSharedAddressDeleteStatus(NULL, $contactId, TRUE);
|
||||
|
||||
if ($sharedAddressMessage['count'] > 0) {
|
||||
$sharedAddressCount += $sharedAddressMessage['count'];
|
||||
$sharedContactList = array_merge($sharedContactList,
|
||||
$sharedAddressMessage['contactList']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_sharedAddressMessage = array(
|
||||
'count' => $sharedAddressCount,
|
||||
'contactList' => $sharedContactList,
|
||||
);
|
||||
|
||||
if ($sharedAddressCount > 0) {
|
||||
if (count($this->_contactIds) > 1) {
|
||||
// more than one contact deleted
|
||||
$message = ts('One of the selected contacts has an address record that is shared with 1 other contact.', array(
|
||||
'plural' => 'One or more selected contacts have address records which are shared with %count other contacts.',
|
||||
'count' => $sharedAddressCount,
|
||||
));
|
||||
}
|
||||
else {
|
||||
// only one contact deleted
|
||||
$message = ts('This contact has an address record which is shared with 1 other contact.', array(
|
||||
'plural' => 'This contact has an address record which is shared with %count other contacts.',
|
||||
'count' => $sharedAddressCount,
|
||||
));
|
||||
}
|
||||
CRM_Core_Session::setStatus($message . ' ' . ts('Shared addresses will not be removed or altered but will no longer be shared.'), ts('Shared Addesses Owner'));
|
||||
}
|
||||
|
||||
// set in form controller so that queries are not fired again
|
||||
$this->set('sharedAddressMessage', $this->_sharedAddressMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$label = $this->_restore ? ts('Restore Contact(s)') : ts('Delete Contact(s)');
|
||||
|
||||
if ($this->_single) {
|
||||
// also fix the user context stack in case the user hits cancel
|
||||
$context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'basic');
|
||||
if ($context == 'search' && CRM_Utils_Rule::qfKey($this->_searchKey)) {
|
||||
$urlParams = "&context=$context&key=$this->_searchKey";
|
||||
}
|
||||
else {
|
||||
$urlParams = '';
|
||||
}
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view',
|
||||
'reset=1&cid=' . $this->_contactIds[0] . $urlParams
|
||||
));
|
||||
$this->addDefaultButtons($label, 'done', 'cancel');
|
||||
}
|
||||
else {
|
||||
$this->addDefaultButtons($label, 'done');
|
||||
}
|
||||
|
||||
$this->addFormRule(array('CRM_Contact_Form_Task_Delete', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param object $self
|
||||
* Form object.
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
// CRM-12929
|
||||
$error = array();
|
||||
if ($self->_skipUndelete) {
|
||||
CRM_Financial_BAO_FinancialItem::checkContactPresent($self->_contactIds, $error);
|
||||
}
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$currentUserId = $session->get('userID');
|
||||
|
||||
$context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'basic');
|
||||
$urlParams = 'force=1';
|
||||
$urlString = "civicrm/contact/search/$context";
|
||||
|
||||
if (CRM_Utils_Rule::qfKey($this->_searchKey)) {
|
||||
$urlParams .= "&qfKey=$this->_searchKey";
|
||||
}
|
||||
elseif ($context == 'search') {
|
||||
$urlParams .= "&qfKey={$this->controller->_key}";
|
||||
$urlString = 'civicrm/contact/search';
|
||||
}
|
||||
elseif ($context == 'smog') {
|
||||
$urlParams .= "&qfKey={$this->controller->_key}&context=smog";
|
||||
$urlString = 'civicrm/group/search';
|
||||
}
|
||||
else {
|
||||
$urlParams = "reset=1";
|
||||
$urlString = 'civicrm/dashboard';
|
||||
}
|
||||
|
||||
// Delete/Restore Contacts. Report errors.
|
||||
$deleted = 0;
|
||||
$not_deleted = array();
|
||||
foreach ($this->_contactIds as $cid) {
|
||||
$name = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'display_name');
|
||||
if (CRM_Contact_BAO_Contact::checkDomainContact($cid)) {
|
||||
$session->setStatus(ts("'%1' cannot be deleted because the information is used for special system purposes.", array(1 => $name)), 'Cannot Delete Domain Contact', 'error');
|
||||
continue;
|
||||
}
|
||||
if ($currentUserId == $cid && !$this->_restore) {
|
||||
$session->setStatus(ts("You are currently logged in as '%1'. You cannot delete yourself.", array(1 => $name)), 'Unable To Delete', 'error');
|
||||
continue;
|
||||
}
|
||||
if (CRM_Contact_BAO_Contact::deleteContact($cid, $this->_restore, $this->_skipUndelete)) {
|
||||
$deleted++;
|
||||
}
|
||||
else {
|
||||
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=$cid");
|
||||
$not_deleted[$cid] = "<a href='$url'>$name</a>";
|
||||
}
|
||||
}
|
||||
if ($deleted) {
|
||||
$title = ts('Deleted');
|
||||
if ($this->_restore) {
|
||||
$title = ts('Restored');
|
||||
$status = ts('%1 has been restored from the trash.', array(
|
||||
1 => $name,
|
||||
'plural' => '%count contacts restored from trash.',
|
||||
'count' => $deleted,
|
||||
));
|
||||
}
|
||||
elseif ($this->_skipUndelete) {
|
||||
$status = ts('%1 has been permanently deleted.', array(
|
||||
1 => $name,
|
||||
'plural' => '%count contacts permanently deleted.',
|
||||
'count' => $deleted,
|
||||
));
|
||||
}
|
||||
else {
|
||||
$status = ts('%1 has been moved to the trash.', array(
|
||||
1 => $name,
|
||||
'plural' => '%count contacts moved to trash.',
|
||||
'count' => $deleted,
|
||||
));
|
||||
}
|
||||
$session->setStatus($status, $title, 'success');
|
||||
}
|
||||
// Alert user of any failures
|
||||
if ($not_deleted) {
|
||||
$status = ts('The contact might be the Membership Organization of a Membership Type. You will need to edit the Membership Type and change the Membership Organization before you can delete this contact.');
|
||||
$title = ts('Unable to Delete');
|
||||
$session->setStatus('<ul><li>' . implode('</li><li>', $not_deleted) . '</li></ul>' . $status, $title, 'error');
|
||||
}
|
||||
|
||||
if (isset($this->_sharedAddressMessage) && $this->_sharedAddressMessage['count'] > 0 && !$this->_restore) {
|
||||
if (count($this->_sharedAddressMessage['contactList']) == 1) {
|
||||
$message = ts('The following contact had been sharing an address with a contact you just deleted. Their address will no longer be shared, but has not been removed or altered.');
|
||||
}
|
||||
else {
|
||||
$message = ts('The following contacts had been sharing addresses with a contact you just deleted. Their addressses will no longer be shared, but have not been removed or altered.');
|
||||
}
|
||||
$message .= '<ul><li>' . implode('</li><li>', $this->_sharedAddressMessage['contactList']) . '</li></ul>';
|
||||
|
||||
$session->setStatus($message, ts('Shared Addesses Owner Deleted'), 'info', array('expires' => 0));
|
||||
|
||||
$this->set('sharedAddressMessage', NULL);
|
||||
}
|
||||
|
||||
if ($this->_single && empty($this->_skipUndelete)) {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactIds[0]}"));
|
||||
}
|
||||
else {
|
||||
$session->replaceUserContext(CRM_Utils_System::url($urlString, $urlParams));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
170
sites/all/modules/civicrm/CRM/Contact/Form/Task/Email.php
Normal file
170
sites/all/modules/civicrm/CRM/Contact/Form/Task/Email.php
Normal file
|
@ -0,0 +1,170 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to email a group of contacts.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_Email extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode".
|
||||
*
|
||||
* Single mode means sending email to one specific contact.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. sending email to one
|
||||
* specific contact?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $_noEmails = FALSE;
|
||||
|
||||
/**
|
||||
* All the existing templates in the system.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_templates = NULL;
|
||||
|
||||
/**
|
||||
* Store "to" contact details.
|
||||
* @var array
|
||||
*/
|
||||
public $_toContactDetails = array();
|
||||
|
||||
/**
|
||||
* Store all selected contact id's, that includes to, cc and bcc contacts
|
||||
* @var array
|
||||
*/
|
||||
public $_allContactIds = array();
|
||||
|
||||
/**
|
||||
* Store only "to" contact ids.
|
||||
* @var array
|
||||
*/
|
||||
public $_toContactIds = array();
|
||||
|
||||
/**
|
||||
* Store only "cc" contact ids.
|
||||
* @var array
|
||||
*/
|
||||
public $_ccContactIds = array();
|
||||
|
||||
/**
|
||||
* Store only "bcc" contact ids.
|
||||
* @var array
|
||||
*/
|
||||
public $_bccContactIds = array();
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
// store case id if present
|
||||
$this->_caseId = CRM_Utils_Request::retrieve('caseid', 'String', $this, FALSE);
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
|
||||
$cid = CRM_Utils_Request::retrieve('cid', 'String', $this, FALSE);
|
||||
|
||||
// Allow request to specify email id rather than contact id
|
||||
$toEmailId = CRM_Utils_Request::retrieve('email_id', 'String', $this);
|
||||
if ($toEmailId) {
|
||||
$toEmail = civicrm_api('email', 'getsingle', array('version' => 3, 'id' => $toEmailId));
|
||||
if (!empty($toEmail['email']) && !empty($toEmail['contact_id'])) {
|
||||
$this->_toEmail = $toEmail;
|
||||
}
|
||||
if (!$cid) {
|
||||
$cid = $toEmail['contact_id'];
|
||||
$this->set('cid', $cid);
|
||||
}
|
||||
}
|
||||
|
||||
if ($cid) {
|
||||
$cid = explode(',', $cid);
|
||||
$displayName = array();
|
||||
|
||||
foreach ($cid as $val) {
|
||||
$displayName[] = CRM_Contact_BAO_Contact::displayName($val);
|
||||
}
|
||||
|
||||
CRM_Utils_System::setTitle(implode(',', $displayName) . ' - ' . ts('Email'));
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('New Email'));
|
||||
}
|
||||
CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($this);
|
||||
|
||||
if (!$cid && $this->_context != 'standalone') {
|
||||
parent::preProcess();
|
||||
}
|
||||
CRM_Contact_Form_Task_EmailCommon::bounceIfSimpleMailLimitExceeded(count($this->_contactIds));
|
||||
|
||||
$this->assign('single', $this->_single);
|
||||
if (CRM_Core_Permission::check('administer CiviCRM')) {
|
||||
$this->assign('isAdmin', 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//enable form element
|
||||
$this->assign('suppressForm', FALSE);
|
||||
$this->assign('emailTask', TRUE);
|
||||
|
||||
CRM_Contact_Form_Task_EmailCommon::buildQuickForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
CRM_Contact_Form_Task_EmailCommon::postProcess($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* List available tokens for this form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listTokens() {
|
||||
$tokens = CRM_Core_SelectValues::contactTokens();
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
}
|
640
sites/all/modules/civicrm/CRM/Contact/Form/Task/EmailCommon.php
Normal file
640
sites/all/modules/civicrm/CRM/Contact/Form/Task/EmailCommon.php
Normal file
|
@ -0,0 +1,640 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the common functionality for sending email to
|
||||
* one or a group of contact ids. This class is reused by all the search
|
||||
* components in CiviCRM (since they all have send email as a task)
|
||||
*/
|
||||
class CRM_Contact_Form_Task_EmailCommon {
|
||||
const MAX_EMAILS_KILL_SWITCH = 50;
|
||||
|
||||
public $_contactDetails = array();
|
||||
public $_allContactDetails = array();
|
||||
public $_toContactEmails = array();
|
||||
|
||||
/**
|
||||
* Generate an array of Domain email addresses.
|
||||
* @return array $domainEmails;
|
||||
*/
|
||||
public static function domainEmails() {
|
||||
$domainEmails = array();
|
||||
$domainFrom = CRM_Core_OptionGroup::values('from_email_address');
|
||||
foreach (array_keys($domainFrom) as $k) {
|
||||
$domainEmail = $domainFrom[$k];
|
||||
$domainEmails[$domainEmail] = htmlspecialchars($domainEmail);
|
||||
}
|
||||
return $domainEmails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre Process Form Addresses to be used in QUickfomr
|
||||
* @param CRM_Core_Form $form
|
||||
* @param bool $bounce determine if we want to throw a status bounce.
|
||||
*/
|
||||
public static function preProcessFromAddress(&$form, $bounce = TRUE) {
|
||||
$form->_single = FALSE;
|
||||
$className = CRM_Utils_System::getClassName($form);
|
||||
if (property_exists($form, '_context') &&
|
||||
$form->_context != 'search' &&
|
||||
$className == 'CRM_Contact_Form_Task_Email'
|
||||
) {
|
||||
$form->_single = TRUE;
|
||||
}
|
||||
|
||||
$form->_emails = $emails = array();
|
||||
|
||||
$contactID = CRM_Core_Session::singleton()->getLoggedInContactID();
|
||||
$fromDisplayName = CRM_Core_Session::singleton()->getLoggedInContactDisplayName();
|
||||
|
||||
$form->_contactIds = array($contactID);
|
||||
$contactEmails = CRM_Core_BAO_Email::allEmails($contactID);
|
||||
|
||||
$form->_onHold = array();
|
||||
|
||||
foreach ($contactEmails as $emailId => $item) {
|
||||
$email = $item['email'];
|
||||
if (!$email && (count($emails) < 1)) {
|
||||
// set it if no emails are present at all
|
||||
$form->_noEmails = TRUE;
|
||||
}
|
||||
else {
|
||||
if ($email) {
|
||||
if (in_array($email, $emails)) {
|
||||
// CRM-3624
|
||||
continue;
|
||||
}
|
||||
|
||||
$emails[$emailId] = '"' . $fromDisplayName . '" <' . $email . '> ';
|
||||
$form->_onHold[$emailId] = $item['on_hold'];
|
||||
$form->_noEmails = FALSE;
|
||||
}
|
||||
}
|
||||
if (!empty($email)) {
|
||||
$form->_emails[$emailId] = $emails[$emailId];
|
||||
$emails[$emailId] .= $item['locationType'];
|
||||
|
||||
if ($item['is_primary']) {
|
||||
$emails[$emailId] .= ' ' . ts('(preferred)');
|
||||
}
|
||||
$emails[$emailId] = htmlspecialchars($emails[$emailId]);
|
||||
}
|
||||
}
|
||||
|
||||
$form->assign('noEmails', $form->_noEmails);
|
||||
|
||||
if ($bounce) {
|
||||
if ($form->_noEmails) {
|
||||
CRM_Core_Error::statusBounce(ts('Your user record does not have a valid email address'));
|
||||
}
|
||||
}
|
||||
|
||||
// now add domain from addresses
|
||||
$domainEmails = self::domainEmails();
|
||||
foreach ($domainEmails as $domainEmail => $email) {
|
||||
$form->_emails[$domainEmail] = $domainEmail;
|
||||
}
|
||||
$form->_fromEmails = CRM_Utils_Array::crmArrayMerge($emails, $domainEmails);
|
||||
$form->_fromEmails = array_filter($form->_fromEmails);
|
||||
if (is_numeric(key($form->_fromEmails))) {
|
||||
// Add signature
|
||||
$defaultEmail = civicrm_api3('email', 'getsingle', array('id' => key($form->_fromEmails)));
|
||||
$defaults = array();
|
||||
if (!empty($defaultEmail['signature_html'])) {
|
||||
$defaults['html_message'] = '<br/><br/>--' . $defaultEmail['signature_html'];
|
||||
}
|
||||
if (!empty($defaultEmail['signature_text'])) {
|
||||
$defaults['text_message'] = "\n\n--\n" . $defaultEmail['signature_text'];
|
||||
}
|
||||
$form->setDefaults($defaults);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
$toArray = $ccArray = $bccArray = array();
|
||||
$suppressedEmails = 0;
|
||||
//here we are getting logged in user id as array but we need target contact id. CRM-5988
|
||||
$cid = $form->get('cid');
|
||||
if ($cid) {
|
||||
$form->_contactIds = explode(',', $cid);
|
||||
}
|
||||
if (count($form->_contactIds) > 1) {
|
||||
$form->_single = FALSE;
|
||||
}
|
||||
|
||||
$emailAttributes = array(
|
||||
'class' => 'huge',
|
||||
);
|
||||
$to = $form->add('text', 'to', ts('To'), $emailAttributes, TRUE);
|
||||
$cc = $form->add('text', 'cc_id', ts('CC'), $emailAttributes);
|
||||
$bcc = $form->add('text', 'bcc_id', ts('BCC'), $emailAttributes);
|
||||
|
||||
$setDefaults = TRUE;
|
||||
if (property_exists($form, '_context') && $form->_context == 'standalone') {
|
||||
$setDefaults = FALSE;
|
||||
}
|
||||
|
||||
$elements = array('to', 'cc', 'bcc');
|
||||
$form->_allContactIds = $form->_toContactIds = $form->_contactIds;
|
||||
foreach ($elements as $element) {
|
||||
if ($$element->getValue()) {
|
||||
$allEmails = explode(',', $$element->getValue());
|
||||
if ($element == 'to') {
|
||||
$form->_toContactIds = $form->_contactIds = array();
|
||||
}
|
||||
|
||||
foreach ($allEmails as $value) {
|
||||
list($contactId, $email) = explode('::', $value);
|
||||
if ($contactId) {
|
||||
switch ($element) {
|
||||
case 'to':
|
||||
$form->_contactIds[] = $form->_toContactIds[] = $contactId;
|
||||
$form->_toContactEmails[] = $email;
|
||||
break;
|
||||
|
||||
case 'cc':
|
||||
$form->_ccContactIds[] = $contactId;
|
||||
break;
|
||||
|
||||
case 'bcc':
|
||||
$form->_bccContactIds[] = $contactId;
|
||||
break;
|
||||
}
|
||||
|
||||
$form->_allContactIds[] = $contactId;
|
||||
}
|
||||
}
|
||||
|
||||
$setDefaults = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
//get the group of contacts as per selected by user in case of Find Activities
|
||||
if (!empty($form->_activityHolderIds)) {
|
||||
$contact = $form->get('contacts');
|
||||
$form->_allContactIds = $form->_contactIds = $contact;
|
||||
}
|
||||
|
||||
// check if we need to setdefaults and check for valid contact emails / communication preferences
|
||||
if (is_array($form->_allContactIds) && $setDefaults) {
|
||||
$returnProperties = array(
|
||||
'sort_name' => 1,
|
||||
'email' => 1,
|
||||
'do_not_email' => 1,
|
||||
'is_deceased' => 1,
|
||||
'on_hold' => 1,
|
||||
'display_name' => 1,
|
||||
'preferred_mail_format' => 1,
|
||||
);
|
||||
|
||||
// get the details for all selected contacts ( to, cc and bcc contacts )
|
||||
list($form->_contactDetails) = CRM_Utils_Token::getTokenDetails($form->_allContactIds,
|
||||
$returnProperties,
|
||||
FALSE,
|
||||
FALSE
|
||||
);
|
||||
|
||||
// make a copy of all contact details
|
||||
$form->_allContactDetails = $form->_contactDetails;
|
||||
|
||||
// perform all validations on unique contact Ids
|
||||
foreach (array_unique($form->_allContactIds) as $key => $contactId) {
|
||||
$value = $form->_contactDetails[$contactId];
|
||||
if ($value['do_not_email'] || empty($value['email']) || !empty($value['is_deceased']) || $value['on_hold']) {
|
||||
$suppressedEmails++;
|
||||
|
||||
// unset contact details for contacts that we won't be sending email. This is prevent extra computation
|
||||
// during token evaluation etc.
|
||||
unset($form->_contactDetails[$contactId]);
|
||||
}
|
||||
else {
|
||||
$email = $value['email'];
|
||||
|
||||
// build array's which are used to setdefaults
|
||||
if (in_array($contactId, $form->_toContactIds)) {
|
||||
$form->_toContactDetails[$contactId] = $form->_contactDetails[$contactId];
|
||||
// If a particular address has been specified as the default, use that instead of contact's primary email
|
||||
if (!empty($form->_toEmail) && $form->_toEmail['contact_id'] == $contactId) {
|
||||
$email = $form->_toEmail['email'];
|
||||
}
|
||||
$toArray[] = array(
|
||||
'text' => '"' . $value['sort_name'] . '" <' . $email . '>',
|
||||
'id' => "$contactId::{$email}",
|
||||
);
|
||||
}
|
||||
elseif (in_array($contactId, $form->_ccContactIds)) {
|
||||
$ccArray[] = array(
|
||||
'text' => '"' . $value['sort_name'] . '" <' . $email . '>',
|
||||
'id' => "$contactId::{$email}",
|
||||
);
|
||||
}
|
||||
elseif (in_array($contactId, $form->_bccContactIds)) {
|
||||
$bccArray[] = array(
|
||||
'text' => '"' . $value['sort_name'] . '" <' . $email . '>',
|
||||
'id' => "$contactId::{$email}",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($toArray)) {
|
||||
CRM_Core_Error::statusBounce(ts('Selected contact(s) do not have a valid email address, or communication preferences specify DO NOT EMAIL, or they are deceased or Primary email address is On Hold.'));
|
||||
}
|
||||
}
|
||||
|
||||
$form->assign('toContact', json_encode($toArray));
|
||||
$form->assign('ccContact', json_encode($ccArray));
|
||||
$form->assign('bccContact', json_encode($bccArray));
|
||||
|
||||
$form->assign('suppressedEmails', $suppressedEmails);
|
||||
|
||||
$form->assign('totalSelectedContacts', count($form->_contactIds));
|
||||
|
||||
$form->add('text', 'subject', ts('Subject'), 'size=50 maxlength=254', TRUE);
|
||||
|
||||
$form->add('select', 'fromEmailAddress', ts('From'), $form->_fromEmails, TRUE, array('class' => 'crm-select2 huge'));
|
||||
|
||||
CRM_Mailing_BAO_Mailing::commonCompose($form);
|
||||
|
||||
// add attachments
|
||||
CRM_Core_BAO_File::buildAttachment($form, NULL);
|
||||
|
||||
if ($form->_single) {
|
||||
// also fix the user context stack
|
||||
if ($form->_caseId) {
|
||||
$ccid = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseContact', $form->_caseId,
|
||||
'contact_id', 'case_id'
|
||||
);
|
||||
$url = CRM_Utils_System::url('civicrm/contact/view/case',
|
||||
"&reset=1&action=view&cid={$ccid}&id={$form->_caseId}"
|
||||
);
|
||||
}
|
||||
elseif ($form->_context) {
|
||||
$url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
|
||||
}
|
||||
else {
|
||||
$url = CRM_Utils_System::url('civicrm/contact/view',
|
||||
"&show=1&action=browse&cid={$form->_contactIds[0]}&selectedChild=activity"
|
||||
);
|
||||
}
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->replaceUserContext($url);
|
||||
$form->addDefaultButtons(ts('Send Email'), 'upload', 'cancel');
|
||||
}
|
||||
else {
|
||||
$form->addDefaultButtons(ts('Send Email'), 'upload');
|
||||
}
|
||||
|
||||
$fields = array(
|
||||
'followup_assignee_contact_id' => array(
|
||||
'type' => 'entityRef',
|
||||
'label' => ts('Assigned to'),
|
||||
'attributes' => array(
|
||||
'multiple' => TRUE,
|
||||
'create' => TRUE,
|
||||
'api' => array('params' => array('is_deceased' => 0)),
|
||||
),
|
||||
),
|
||||
'followup_activity_type_id' => array(
|
||||
'type' => 'select',
|
||||
'label' => ts('Followup Activity'),
|
||||
'attributes' => array('' => '- ' . ts('select activity') . ' -') + CRM_Core_PseudoConstant::ActivityType(FALSE),
|
||||
'extra' => array('class' => 'crm-select2'),
|
||||
),
|
||||
'followup_activity_subject' => array(
|
||||
'type' => 'text',
|
||||
'label' => ts('Subject'),
|
||||
'attributes' => CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity',
|
||||
'subject'
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
//add followup date
|
||||
$form->addDateTime('followup_date', ts('in'), FALSE, array('formatType' => 'activityDateTime'));
|
||||
|
||||
foreach ($fields as $field => $values) {
|
||||
if (!empty($fields[$field])) {
|
||||
$attribute = CRM_Utils_Array::value('attributes', $values);
|
||||
$required = !empty($values['required']);
|
||||
|
||||
if ($values['type'] == 'select' && empty($attribute)) {
|
||||
$form->addSelect($field, array('entity' => 'activity'), $required);
|
||||
}
|
||||
elseif ($values['type'] == 'entityRef') {
|
||||
$form->addEntityRef($field, $values['label'], $attribute, $required);
|
||||
}
|
||||
else {
|
||||
$form->add($values['type'], $field, $values['label'], $attribute, $required, CRM_Utils_Array::value('extra', $values));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Added for CRM-15984: Add campaign field
|
||||
CRM_Campaign_BAO_Campaign::addCampaign($form);
|
||||
|
||||
$form->addFormRule(array('CRM_Contact_Form_Task_EmailCommon', 'formRule'), $form);
|
||||
CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Contact/Form/Task/EmailCommon.js', 0, 'html-header');
|
||||
}
|
||||
|
||||
/**
|
||||
* Form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $dontCare
|
||||
* @param array $self
|
||||
* Additional values form 'this'.
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $dontCare, $self) {
|
||||
$errors = array();
|
||||
$template = CRM_Core_Smarty::singleton();
|
||||
|
||||
if (isset($fields['html_message'])) {
|
||||
$htmlMessage = str_replace(array("\n", "\r"), ' ', $fields['html_message']);
|
||||
$htmlMessage = str_replace('"', '\"', $htmlMessage);
|
||||
$template->assign('htmlContent', $htmlMessage);
|
||||
}
|
||||
|
||||
//Added for CRM-1393
|
||||
if (!empty($fields['saveTemplate']) && empty($fields['saveTemplateName'])) {
|
||||
$errors['saveTemplateName'] = ts("Enter name to save message template");
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function postProcess(&$form) {
|
||||
self::bounceIfSimpleMailLimitExceeded(count($form->_contactIds));
|
||||
|
||||
// check and ensure that
|
||||
$formValues = $form->controller->exportValues($form->getName());
|
||||
self::submit($form, $formValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the form values.
|
||||
*
|
||||
* This is also accessible for testing.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $formValues
|
||||
*/
|
||||
public static function submit(&$form, $formValues) {
|
||||
self::saveMessageTemplate($formValues);
|
||||
|
||||
$from = CRM_Utils_Array::value($formValues['fromEmailAddress'], $form->_emails);
|
||||
$subject = $formValues['subject'];
|
||||
|
||||
// CRM-13378: Append CC and BCC information at the end of Activity Details and format cc and bcc fields
|
||||
$elements = array('cc_id', 'bcc_id');
|
||||
$additionalDetails = NULL;
|
||||
$ccValues = $bccValues = array();
|
||||
foreach ($elements as $element) {
|
||||
if (!empty($formValues[$element])) {
|
||||
$allEmails = explode(',', $formValues[$element]);
|
||||
foreach ($allEmails as $value) {
|
||||
list($contactId, $email) = explode('::', $value);
|
||||
$contactURL = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$contactId}", TRUE);
|
||||
switch ($element) {
|
||||
case 'cc_id':
|
||||
$ccValues['email'][] = '"' . $form->_contactDetails[$contactId]['sort_name'] . '" <' . $email . '>';
|
||||
$ccValues['details'][] = "<a href='{$contactURL}'>" . $form->_contactDetails[$contactId]['display_name'] . "</a>";
|
||||
break;
|
||||
|
||||
case 'bcc_id':
|
||||
$bccValues['email'][] = '"' . $form->_contactDetails[$contactId]['sort_name'] . '" <' . $email . '>';
|
||||
$bccValues['details'][] = "<a href='{$contactURL}'>" . $form->_contactDetails[$contactId]['display_name'] . "</a>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cc = $bcc = '';
|
||||
if (!empty($ccValues)) {
|
||||
$cc = implode(',', $ccValues['email']);
|
||||
$additionalDetails .= "\ncc : " . implode(", ", $ccValues['details']);
|
||||
}
|
||||
if (!empty($bccValues)) {
|
||||
$bcc = implode(',', $bccValues['email']);
|
||||
$additionalDetails .= "\nbcc : " . implode(", ", $bccValues['details']);
|
||||
}
|
||||
|
||||
// CRM-5916: prepend case id hash to CiviCase-originating emails’ subjects
|
||||
if (isset($form->_caseId) && is_numeric($form->_caseId)) {
|
||||
$hash = substr(sha1(CIVICRM_SITE_KEY . $form->_caseId), 0, 7);
|
||||
$subject = "[case #$hash] $subject";
|
||||
}
|
||||
|
||||
$attachments = array();
|
||||
CRM_Core_BAO_File::formatAttachment($formValues,
|
||||
$attachments,
|
||||
NULL, NULL
|
||||
);
|
||||
|
||||
// format contact details array to handle multiple emails from same contact
|
||||
$formattedContactDetails = array();
|
||||
$tempEmails = array();
|
||||
foreach ($form->_contactIds as $key => $contactId) {
|
||||
// if we dont have details on this contactID, we should ignore
|
||||
// potentially this is due to the contact not wanting to receive email
|
||||
if (!isset($form->_contactDetails[$contactId])) {
|
||||
continue;
|
||||
}
|
||||
$email = $form->_toContactEmails[$key];
|
||||
// prevent duplicate emails if same email address is selected CRM-4067
|
||||
// we should allow same emails for different contacts
|
||||
$emailKey = "{$contactId}::{$email}";
|
||||
if (!in_array($emailKey, $tempEmails)) {
|
||||
$tempEmails[] = $emailKey;
|
||||
$details = $form->_contactDetails[$contactId];
|
||||
$details['email'] = $email;
|
||||
unset($details['email_id']);
|
||||
$formattedContactDetails[] = $details;
|
||||
}
|
||||
}
|
||||
|
||||
$contributionIds = array();
|
||||
if ($form->getVar('_contributionIds')) {
|
||||
$contributionIds = $form->getVar('_contributionIds');
|
||||
}
|
||||
|
||||
// send the mail
|
||||
list($sent, $activityId) = CRM_Activity_BAO_Activity::sendEmail(
|
||||
$formattedContactDetails,
|
||||
$subject,
|
||||
$formValues['text_message'],
|
||||
$formValues['html_message'],
|
||||
NULL,
|
||||
NULL,
|
||||
$from,
|
||||
$attachments,
|
||||
$cc,
|
||||
$bcc,
|
||||
array_keys($form->_toContactDetails),
|
||||
$additionalDetails,
|
||||
$contributionIds,
|
||||
CRM_Utils_Array::value('campaign_id', $formValues)
|
||||
);
|
||||
|
||||
$followupStatus = '';
|
||||
if ($sent) {
|
||||
$followupActivity = NULL;
|
||||
if (!empty($formValues['followup_activity_type_id'])) {
|
||||
$params['followup_activity_type_id'] = $formValues['followup_activity_type_id'];
|
||||
$params['followup_activity_subject'] = $formValues['followup_activity_subject'];
|
||||
$params['followup_date'] = $formValues['followup_date'];
|
||||
$params['followup_date_time'] = $formValues['followup_date_time'];
|
||||
$params['target_contact_id'] = $form->_contactIds;
|
||||
$params['followup_assignee_contact_id'] = explode(',', $formValues['followup_assignee_contact_id']);
|
||||
$followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activityId, $params);
|
||||
$followupStatus = ts('A followup activity has been scheduled.');
|
||||
|
||||
if (Civi::settings()->get('activity_assignee_notification')) {
|
||||
if ($followupActivity) {
|
||||
$mailToFollowupContacts = array();
|
||||
$assignee = array($followupActivity->id);
|
||||
$assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($assignee, TRUE, FALSE);
|
||||
foreach ($assigneeContacts as $values) {
|
||||
$mailToFollowupContacts[$values['email']] = $values;
|
||||
}
|
||||
|
||||
$sentFollowup = CRM_Activity_BAO_Activity::sendToAssignee($followupActivity, $mailToFollowupContacts);
|
||||
if ($sentFollowup) {
|
||||
$followupStatus .= '<br />' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s).");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$count_success = count($form->_toContactDetails);
|
||||
CRM_Core_Session::setStatus(ts('One message was sent successfully. ', array(
|
||||
'plural' => '%count messages were sent successfully. ',
|
||||
'count' => $count_success,
|
||||
)) . $followupStatus, ts('Message Sent', array('plural' => 'Messages Sent', 'count' => $count_success)), 'success');
|
||||
}
|
||||
|
||||
// Display the name and number of contacts for those email is not sent.
|
||||
// php 5.4 throws out a notice since the values of these below arrays are arrays.
|
||||
// the behavior is not documented in the php manual, but it does the right thing
|
||||
// suppressing the notices to get things in good shape going forward
|
||||
$emailsNotSent = @array_diff_assoc($form->_allContactDetails, $form->_contactDetails);
|
||||
|
||||
if ($emailsNotSent) {
|
||||
$not_sent = array();
|
||||
foreach ($emailsNotSent as $contactId => $values) {
|
||||
$displayName = $values['display_name'];
|
||||
$email = $values['email'];
|
||||
$contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=$contactId");
|
||||
$not_sent[] = "<a href='$contactViewUrl' title='$email'>$displayName</a>" . ($values['on_hold'] ? '(' . ts('on hold') . ')' : '');
|
||||
}
|
||||
$status = '(' . ts('because no email address on file or communication preferences specify DO NOT EMAIL or Contact is deceased or Primary email address is On Hold') . ')<ul><li>' . implode('</li><li>', $not_sent) . '</li></ul>';
|
||||
CRM_Core_Session::setStatus($status, ts('One Message Not Sent', array(
|
||||
'count' => count($emailsNotSent),
|
||||
'plural' => '%count Messages Not Sent',
|
||||
)), 'info');
|
||||
}
|
||||
|
||||
if (isset($form->_caseId)) {
|
||||
// if case-id is found in the url, create case activity record
|
||||
$cases = explode(',', $form->_caseId);
|
||||
foreach ($cases as $key => $val) {
|
||||
if (is_numeric($val)) {
|
||||
$caseParams = array(
|
||||
'activity_id' => $activityId,
|
||||
'case_id' => $val,
|
||||
);
|
||||
CRM_Case_BAO_Case::processCaseActivity($caseParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the template if update selected.
|
||||
*
|
||||
* @param array $formValues
|
||||
*/
|
||||
protected static function saveMessageTemplate($formValues) {
|
||||
if (!empty($formValues['saveTemplate']) || !empty($formValues['updateTemplate'])) {
|
||||
$messageTemplate = array(
|
||||
'msg_text' => $formValues['text_message'],
|
||||
'msg_html' => $formValues['html_message'],
|
||||
'msg_subject' => $formValues['subject'],
|
||||
'is_active' => TRUE,
|
||||
);
|
||||
|
||||
if (!empty($formValues['saveTemplate'])) {
|
||||
$messageTemplate['msg_title'] = $formValues['saveTemplateName'];
|
||||
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
|
||||
}
|
||||
|
||||
if (!empty($formValues['template']) && !empty($formValues['updateTemplate'])) {
|
||||
$messageTemplate['id'] = $formValues['template'];
|
||||
unset($messageTemplate['msg_title']);
|
||||
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bounce if there are more emails than permitted.
|
||||
*
|
||||
* @param int $count
|
||||
* The number of emails the user is attempting to send
|
||||
*/
|
||||
public static function bounceIfSimpleMailLimitExceeded($count) {
|
||||
$limit = Civi::settings()->get('simple_mail_limit');
|
||||
if ($count > $limit) {
|
||||
CRM_Core_Error::statusBounce(ts('Please do not use this task to send a lot of emails (greater than %1). Many countries have legal requirements when sending bulk emails and the CiviMail framework has opt out functionality and domain tokens to help meet these.',
|
||||
array(1 => $limit)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to save a search.
|
||||
*
|
||||
* Saved Searches are used for saving frequently used queries
|
||||
*/
|
||||
class CRM_Contact_Form_Task_HookSample extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
// display name and email of all contact ids
|
||||
$contactIDs = implode(',', $this->_contactIds);;
|
||||
$query = "
|
||||
SELECT c.id as contact_id, c.display_name as name,
|
||||
c.contact_type as contact_type, e.email as email
|
||||
FROM civicrm_contact c, civicrm_email e
|
||||
WHERE e.contact_id = c.id
|
||||
AND e.is_primary = 1
|
||||
AND c.id IN ( $contactIDs )";
|
||||
|
||||
$rows = array();
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$rows[] = array(
|
||||
'id' => $dao->contact_id,
|
||||
'name' => $dao->name,
|
||||
'contact_type' => $dao->contact_type,
|
||||
'email' => $dao->email,
|
||||
);
|
||||
}
|
||||
|
||||
$this->assign('rows', $rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addDefaultButtons(ts('Back to Search'), 'done');
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
}
|
||||
|
||||
}
|
404
sites/all/modules/civicrm/CRM/Contact/Form/Task/Label.php
Normal file
404
sites/all/modules/civicrm/CRM/Contact/Form/Task/Label.php
Normal file
|
@ -0,0 +1,404 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class helps to print the labels for contacts.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_Label extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->set('contactIds', $this->_contactIds);
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
self::buildLabelForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common Function to build Mailing Label Form.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function buildLabelForm($form) {
|
||||
CRM_Utils_System::setTitle(ts('Make Mailing Labels'));
|
||||
|
||||
//add select for label
|
||||
$label = CRM_Core_BAO_LabelFormat::getList(TRUE);
|
||||
|
||||
$form->add('select', 'label_name', ts('Select Label'), array('' => ts('- select label -')) + $label, TRUE);
|
||||
|
||||
// add select for Location Type
|
||||
$form->addElement('select', 'location_type_id', ts('Select Location'),
|
||||
array(
|
||||
'' => ts('Primary'),
|
||||
) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'), TRUE
|
||||
);
|
||||
|
||||
// checkbox for SKIP contacts with Do Not Mail privacy option
|
||||
$form->addElement('checkbox', 'do_not_mail', ts('Do not print labels for contacts with "Do Not Mail" privacy option checked'));
|
||||
|
||||
$form->add('checkbox', 'merge_same_address', ts('Merge labels for contacts with the same address'), NULL);
|
||||
$form->add('checkbox', 'merge_same_household', ts('Merge labels for contacts belonging to the same household'), NULL);
|
||||
|
||||
$form->addButtons(array(
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'name' => ts('Make Mailing Labels'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Done'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* @return array
|
||||
* array of default values
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
$format = CRM_Core_BAO_LabelFormat::getDefaultValues();
|
||||
$defaults['label_name'] = CRM_Utils_Array::value('name', $format);
|
||||
$defaults['do_not_mail'] = 1;
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$fv = $this->controller->exportValues($this->_name);
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$locName = NULL;
|
||||
//get the address format sequence from the config file
|
||||
$mailingFormat = Civi::settings()->get('mailing_format');
|
||||
|
||||
$sequence = CRM_Utils_Address::sequence($mailingFormat);
|
||||
|
||||
foreach ($sequence as $v) {
|
||||
$address[$v] = 1;
|
||||
}
|
||||
|
||||
if (array_key_exists('postal_code', $address)) {
|
||||
$address['postal_code_suffix'] = 1;
|
||||
}
|
||||
|
||||
//build the returnproperties
|
||||
$returnProperties = array('display_name' => 1, 'contact_type' => 1, 'prefix_id' => 1);
|
||||
$mailingFormat = Civi::settings()->get('mailing_format');
|
||||
|
||||
$mailingFormatProperties = array();
|
||||
if ($mailingFormat) {
|
||||
$mailingFormatProperties = CRM_Utils_Token::getReturnProperties($mailingFormat);
|
||||
$returnProperties = array_merge($returnProperties, $mailingFormatProperties);
|
||||
}
|
||||
//we should not consider addressee for data exists, CRM-6025
|
||||
if (array_key_exists('addressee', $mailingFormatProperties)) {
|
||||
unset($mailingFormatProperties['addressee']);
|
||||
}
|
||||
|
||||
$customFormatProperties = array();
|
||||
if (stristr($mailingFormat, 'custom_')) {
|
||||
foreach ($mailingFormatProperties as $token => $true) {
|
||||
if (substr($token, 0, 7) == 'custom_') {
|
||||
if (empty($customFormatProperties[$token])) {
|
||||
$customFormatProperties[$token] = $mailingFormatProperties[$token];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($customFormatProperties)) {
|
||||
$returnProperties = array_merge($returnProperties, $customFormatProperties);
|
||||
}
|
||||
|
||||
if (isset($fv['merge_same_address'])) {
|
||||
// we need first name/last name for summarising to avoid spillage
|
||||
$returnProperties['first_name'] = 1;
|
||||
$returnProperties['last_name'] = 1;
|
||||
}
|
||||
|
||||
$individualFormat = FALSE;
|
||||
|
||||
/*
|
||||
* CRM-8338: replace ids of household members with the id of their household
|
||||
* so we can merge labels by household.
|
||||
*/
|
||||
if (isset($fv['merge_same_household'])) {
|
||||
$this->mergeContactIdsByHousehold();
|
||||
$individualFormat = TRUE;
|
||||
}
|
||||
|
||||
//get the contacts information
|
||||
$params = array();
|
||||
if (!empty($fv['location_type_id'])) {
|
||||
$locType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
|
||||
$locName = $locType[$fv['location_type_id']];
|
||||
$location = array('location' => array("{$locName}" => $address));
|
||||
$returnProperties = array_merge($returnProperties, $location);
|
||||
$params[] = array('location_type', '=', array(1 => $fv['location_type_id']), 0, 0);
|
||||
}
|
||||
else {
|
||||
$returnProperties = array_merge($returnProperties, $address);
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach ($this->_contactIds as $key => $contactID) {
|
||||
$params[] = array(
|
||||
CRM_Core_Form::CB_PREFIX . $contactID,
|
||||
'=',
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
// fix for CRM-2651
|
||||
if (!empty($fv['do_not_mail'])) {
|
||||
$params[] = array('do_not_mail', '=', 0, 0, 0);
|
||||
}
|
||||
// fix for CRM-2613
|
||||
$params[] = array('is_deceased', '=', 0, 0, 0);
|
||||
|
||||
$custom = array();
|
||||
foreach ($returnProperties as $name => $dontCare) {
|
||||
$cfID = CRM_Core_BAO_CustomField::getKeyID($name);
|
||||
if ($cfID) {
|
||||
$custom[] = $cfID;
|
||||
}
|
||||
}
|
||||
|
||||
//get the total number of contacts to fetch from database.
|
||||
$numberofContacts = count($this->_contactIds);
|
||||
$query = new CRM_Contact_BAO_Query($params, $returnProperties);
|
||||
$details = $query->apiQuery($params, $returnProperties, NULL, NULL, 0, $numberofContacts);
|
||||
|
||||
$messageToken = CRM_Utils_Token::getTokens($mailingFormat);
|
||||
|
||||
// also get all token values
|
||||
CRM_Utils_Hook::tokenValues($details[0],
|
||||
$this->_contactIds,
|
||||
NULL,
|
||||
$messageToken,
|
||||
'CRM_Contact_Form_Task_Label'
|
||||
);
|
||||
|
||||
$tokens = array();
|
||||
CRM_Utils_Hook::tokens($tokens);
|
||||
$tokenFields = array();
|
||||
foreach ($tokens as $category => $catTokens) {
|
||||
foreach ($catTokens as $token => $tokenName) {
|
||||
$tokenFields[] = $token;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->_contactIds as $value) {
|
||||
foreach ($custom as $cfID) {
|
||||
if (isset($details[0][$value]["custom_{$cfID}"])) {
|
||||
$details[0][$value]["custom_{$cfID}"] = CRM_Core_BAO_CustomField::displayValue($details[0][$value]["custom_{$cfID}"], $cfID);
|
||||
}
|
||||
}
|
||||
$contact = CRM_Utils_Array::value($value, $details['0']);
|
||||
|
||||
if (is_a($contact, 'CRM_Core_Error')) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// we need to remove all the "_id"
|
||||
unset($contact['contact_id']);
|
||||
|
||||
if ($locName && !empty($contact[$locName])) {
|
||||
// If location type is not primary, $contact contains
|
||||
// one more array as "$contact[$locName] = array( values... )"
|
||||
|
||||
if (!self::tokenIsFound($contact, $mailingFormatProperties, $tokenFields)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$contact = array_merge($contact, $contact[$locName]);
|
||||
unset($contact[$locName]);
|
||||
|
||||
if (!empty($contact['county_id'])) {
|
||||
unset($contact['county_id']);
|
||||
}
|
||||
|
||||
foreach ($contact as $field => $fieldValue) {
|
||||
$rows[$value][$field] = $fieldValue;
|
||||
}
|
||||
|
||||
$valuesothers = array();
|
||||
$paramsothers = array('contact_id' => $value);
|
||||
$valuesothers = CRM_Core_BAO_Location::getValues($paramsothers, $valuesothers);
|
||||
if (!empty($fv['location_type_id'])) {
|
||||
foreach ($valuesothers as $vals) {
|
||||
if (CRM_Utils_Array::value('location_type_id', $vals) ==
|
||||
CRM_Utils_Array::value('location_type_id', $fv)
|
||||
) {
|
||||
foreach ($vals as $k => $v) {
|
||||
if (in_array($k, array(
|
||||
'email',
|
||||
'phone',
|
||||
'im',
|
||||
'openid',
|
||||
))) {
|
||||
if ($k == 'im') {
|
||||
$rows[$value][$k] = $v['1']['name'];
|
||||
}
|
||||
else {
|
||||
$rows[$value][$k] = $v['1'][$k];
|
||||
}
|
||||
$rows[$value][$k . '_id'] = $v['1']['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!self::tokenIsFound($contact, $mailingFormatProperties, $tokenFields)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($contact['addressee_display'])) {
|
||||
$contact['addressee_display'] = trim($contact['addressee_display']);
|
||||
}
|
||||
if (!empty($contact['addressee'])) {
|
||||
$contact['addressee'] = $contact['addressee_display'];
|
||||
}
|
||||
|
||||
// now create the rows for generating mailing labels
|
||||
foreach ($contact as $field => $fieldValue) {
|
||||
$rows[$value][$field] = $fieldValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($fv['merge_same_address'])) {
|
||||
CRM_Core_BAO_Address::mergeSameAddress($rows);
|
||||
$individualFormat = TRUE;
|
||||
}
|
||||
|
||||
// format the addresses according to CIVICRM_ADDRESS_FORMAT (CRM-1327)
|
||||
foreach ($rows as $id => $row) {
|
||||
if ($commMethods = CRM_Utils_Array::value('preferred_communication_method', $row)) {
|
||||
$val = array_filter(explode(CRM_Core_DAO::VALUE_SEPARATOR, $commMethods));
|
||||
$comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
|
||||
$temp = array();
|
||||
foreach ($val as $vals) {
|
||||
$temp[] = $comm[$vals];
|
||||
}
|
||||
$row['preferred_communication_method'] = implode(', ', $temp);
|
||||
}
|
||||
$row['id'] = $id;
|
||||
$formatted = CRM_Utils_Address::format($row, 'mailing_format', FALSE, TRUE, $individualFormat, $tokenFields);
|
||||
|
||||
// CRM-2211: UFPDF doesn't have bidi support; use the PECL fribidi package to fix it.
|
||||
// On Ubuntu (possibly Debian?) be aware of http://pecl.php.net/bugs/bug.php?id=12366
|
||||
// Due to FriBidi peculiarities, this can't be called on
|
||||
// a multi-line string, hence the explode+implode approach.
|
||||
if (function_exists('fribidi_log2vis')) {
|
||||
$lines = explode("\n", $formatted);
|
||||
foreach ($lines as $i => $line) {
|
||||
$lines[$i] = fribidi_log2vis($line, FRIBIDI_AUTO, FRIBIDI_CHARSET_UTF8);
|
||||
}
|
||||
$formatted = implode("\n", $lines);
|
||||
}
|
||||
$rows[$id] = array($formatted);
|
||||
}
|
||||
|
||||
//call function to create labels
|
||||
self::createLabel($rows, $fv['label_name']);
|
||||
CRM_Utils_System::civiExit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for presence of tokens to be swapped out.
|
||||
*
|
||||
* @param array $contact
|
||||
* @param array $mailingFormatProperties
|
||||
* @param array $tokenFields
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function tokenIsFound($contact, $mailingFormatProperties, $tokenFields) {
|
||||
foreach (array_merge($mailingFormatProperties, array_fill_keys($tokenFields, 1)) as $key => $dontCare) {
|
||||
//we should not consider addressee for data exists, CRM-6025
|
||||
if ($key != 'addressee' && !empty($contact[$key])) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create labels (pdf).
|
||||
*
|
||||
* @param array $contactRows
|
||||
* Associated array of contact data.
|
||||
* @param string $format
|
||||
* Format in which labels needs to be printed.
|
||||
* @param string $fileName
|
||||
* The name of the file to save the label in.
|
||||
*/
|
||||
public function createLabel(&$contactRows, &$format, $fileName = 'MailingLabels_CiviCRM.pdf') {
|
||||
$pdf = new CRM_Utils_PDF_Label($format, 'mm');
|
||||
$pdf->Open();
|
||||
$pdf->AddPage();
|
||||
|
||||
//build contact string that needs to be printed
|
||||
$val = NULL;
|
||||
foreach ($contactRows as $row => $value) {
|
||||
foreach ($value as $k => $v) {
|
||||
$val .= "$v\n";
|
||||
}
|
||||
|
||||
$pdf->AddPdfLabel($val);
|
||||
$val = '';
|
||||
}
|
||||
$pdf->Output($fileName, 'D');
|
||||
}
|
||||
|
||||
}
|
330
sites/all/modules/civicrm/CRM/Contact/Form/Task/LabelCommon.php
Normal file
330
sites/all/modules/civicrm/CRM/Contact/Form/Task/LabelCommon.php
Normal file
|
@ -0,0 +1,330 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the common functionality for sending email to one or a group of contact ids.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_LabelCommon {
|
||||
|
||||
/**
|
||||
* Create labels (pdf).
|
||||
*
|
||||
* @param array $contactRows
|
||||
* Associated array of contact data.
|
||||
* @param string $format
|
||||
* Format in which labels needs to be printed.
|
||||
* @param string $fileName
|
||||
* The name of the file to save the label in.
|
||||
*/
|
||||
public static function createLabel(&$contactRows, &$format, $fileName = 'MailingLabels_CiviCRM.pdf') {
|
||||
$pdf = new CRM_Utils_PDF_Label($format, 'mm');
|
||||
$pdf->Open();
|
||||
$pdf->AddPage();
|
||||
|
||||
//build contact string that needs to be printed
|
||||
$val = NULL;
|
||||
foreach ((array) $contactRows as $row => $value) {
|
||||
foreach ($value as $k => $v) {
|
||||
$val .= "$v\n";
|
||||
}
|
||||
|
||||
$pdf->AddPdfLabel($val);
|
||||
$val = '';
|
||||
}
|
||||
$pdf->Output($fileName, 'D');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the rows for the labels.
|
||||
*
|
||||
* @param $contactIDs
|
||||
* @param int $locationTypeID
|
||||
* @param bool $respectDoNotMail
|
||||
* @param $mergeSameAddress
|
||||
* @param bool $mergeSameHousehold
|
||||
* UNUSED.
|
||||
*
|
||||
* @return array
|
||||
* Array of rows for labels
|
||||
*/
|
||||
public static function getRows($contactIDs, $locationTypeID, $respectDoNotMail, $mergeSameAddress, $mergeSameHousehold) {
|
||||
$locName = NULL;
|
||||
$rows = array();
|
||||
//get the address format sequence from the config file
|
||||
$addressReturnProperties = CRM_Contact_Form_Task_LabelCommon::getAddressReturnProperties();
|
||||
|
||||
//build the return properties
|
||||
$returnProperties = array('display_name' => 1, 'contact_type' => 1, 'prefix_id' => 1);
|
||||
$mailingFormat = Civi::settings()->get('mailing_format');
|
||||
|
||||
$mailingFormatProperties = array();
|
||||
if ($mailingFormat) {
|
||||
$mailingFormatProperties = CRM_Utils_Token::getReturnProperties($mailingFormat);
|
||||
$returnProperties = array_merge($returnProperties, $mailingFormatProperties);
|
||||
}
|
||||
|
||||
$customFormatProperties = array();
|
||||
if (stristr($mailingFormat, 'custom_')) {
|
||||
foreach ($mailingFormatProperties as $token => $true) {
|
||||
if (substr($token, 0, 7) == 'custom_') {
|
||||
if (empty($customFormatProperties[$token])) {
|
||||
$customFormatProperties[$token] = $mailingFormatProperties[$token];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$returnProperties = array_merge($returnProperties, $customFormatProperties);
|
||||
|
||||
if ($mergeSameAddress) {
|
||||
// we need first name/last name for summarising to avoid spillage
|
||||
$returnProperties['first_name'] = 1;
|
||||
$returnProperties['last_name'] = 1;
|
||||
}
|
||||
|
||||
//get the contacts information
|
||||
$params = $custom = array();
|
||||
foreach ($contactIDs as $key => $contactID) {
|
||||
$params[] = array(
|
||||
CRM_Core_Form::CB_PREFIX . $contactID,
|
||||
'=',
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
// fix for CRM-2651
|
||||
if (!empty($respectDoNotMail['do_not_mail'])) {
|
||||
$params[] = array('do_not_mail', '=', 0, 0, 0);
|
||||
}
|
||||
// fix for CRM-2613
|
||||
$params[] = array('is_deceased', '=', 0, 0, 0);
|
||||
|
||||
if ($locationTypeID) {
|
||||
$locType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
|
||||
$locName = $locType[$locationTypeID];
|
||||
$location = array('location' => array("{$locName}" => $addressReturnProperties));
|
||||
$returnProperties = array_merge($returnProperties, $location);
|
||||
$params[] = array('location_type', '=', array($locationTypeID => 1), 0, 0);
|
||||
}
|
||||
else {
|
||||
$returnProperties = array_merge($returnProperties, $addressReturnProperties);
|
||||
}
|
||||
|
||||
foreach ($returnProperties as $name) {
|
||||
$cfID = CRM_Core_BAO_CustomField::getKeyID($name);
|
||||
if ($cfID) {
|
||||
$custom[] = $cfID;
|
||||
}
|
||||
}
|
||||
|
||||
//get the total number of contacts to fetch from database.
|
||||
$numberofContacts = count($contactIDs);
|
||||
//this does the same as calling civicrm_api3('contact, get, array('id' => array('IN' => $this->_contactIds)
|
||||
// except it also handles multiple locations
|
||||
$query = new CRM_Contact_BAO_Query($params, $returnProperties);
|
||||
$details = $query->apiQuery($params, $returnProperties, NULL, NULL, 0, $numberofContacts);
|
||||
|
||||
$messageToken = CRM_Utils_Token::getTokens($mailingFormat);
|
||||
$details = $details[0];
|
||||
$tokenFields = CRM_Contact_Form_Task_LabelCommon::getTokenData($details);
|
||||
|
||||
foreach ($contactIDs as $value) {
|
||||
foreach ($custom as $cfID) {
|
||||
if (isset($details[$value]["custom_{$cfID}"])) {
|
||||
$details[$value]["custom_{$cfID}"] = CRM_Core_BAO_CustomField::displayValue($details[$value]["custom_{$cfID}"], $cfID);
|
||||
}
|
||||
}
|
||||
$contact = CRM_Utils_Array::value($value, $details);
|
||||
|
||||
if (is_a($contact, 'CRM_Core_Error')) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// we need to remove all the "_id"
|
||||
unset($contact['contact_id']);
|
||||
|
||||
if ($locName && !empty($contact[$locName])) {
|
||||
// If location type is not primary, $contact contains
|
||||
// one more array as "$contact[$locName] = array( values... )"
|
||||
|
||||
if (!CRM_Contact_Form_Task_Label::tokenIsFound($contact, $mailingFormatProperties, $tokenFields)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unset($contact[$locName]);
|
||||
|
||||
if (!empty($contact['county_id'])) {
|
||||
unset($contact['county_id']);
|
||||
}
|
||||
|
||||
foreach ($contact as $field => $fieldValue) {
|
||||
$rows[$value][$field] = $fieldValue;
|
||||
}
|
||||
|
||||
$valuesothers = array();
|
||||
$paramsothers = array('contact_id' => $value);
|
||||
$valuesothers = CRM_Core_BAO_Location::getValues($paramsothers, $valuesothers);
|
||||
if ($locationTypeID) {
|
||||
foreach ($valuesothers as $vals) {
|
||||
if (CRM_Utils_Array::value('location_type_id', $vals) ==
|
||||
$locationTypeID
|
||||
) {
|
||||
foreach ($vals as $k => $v) {
|
||||
if (in_array($k, array(
|
||||
'email',
|
||||
'phone',
|
||||
'im',
|
||||
'openid',
|
||||
))) {
|
||||
if ($k == 'im') {
|
||||
$rows[$value][$k] = $v['1']['name'];
|
||||
}
|
||||
else {
|
||||
$rows[$value][$k] = $v['1'][$k];
|
||||
}
|
||||
$rows[$value][$k . '_id'] = $v['1']['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!CRM_Contact_Form_Task_Label::tokenIsFound($contact, $mailingFormatProperties, $tokenFields)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($contact['addressee_display'])) {
|
||||
$contact['addressee_display'] = trim($contact['addressee_display']);
|
||||
}
|
||||
if (!empty($contact['addressee'])) {
|
||||
$contact['addressee'] = $contact['addressee_display'];
|
||||
}
|
||||
|
||||
// now create the rows for generating mailing labels
|
||||
foreach ($contact as $field => $fieldValue) {
|
||||
$rows[$value][$field] = $fieldValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
// sigh couldn't extract out tokenfields yet
|
||||
return array($rows, $tokenFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get array of return properties for address fields required for mailing label.
|
||||
*
|
||||
* @return array
|
||||
* return properties for address e.g
|
||||
* [street_address => 1, supplemental_address_1 => 1, supplemental_address_2 => 1]
|
||||
*/
|
||||
public static function getAddressReturnProperties() {
|
||||
$mailingFormat = Civi::settings()->get('mailing_format');
|
||||
|
||||
$addressFields = CRM_Utils_Address::sequence($mailingFormat);
|
||||
$addressReturnProperties = array_fill_keys($addressFields, 1);
|
||||
|
||||
if (array_key_exists('postal_code', $addressReturnProperties)) {
|
||||
$addressReturnProperties['postal_code_suffix'] = 1;
|
||||
}
|
||||
return $addressReturnProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get token list from mailing format & contacts
|
||||
* @param array $contacts
|
||||
* @return array
|
||||
*/
|
||||
public static function getTokenData(&$contacts) {
|
||||
$mailingFormat = Civi::settings()->get('mailing_format');
|
||||
$tokens = $tokenFields = array();
|
||||
$messageToken = CRM_Utils_Token::getTokens($mailingFormat);
|
||||
|
||||
// also get all token values
|
||||
CRM_Utils_Hook::tokenValues($contacts,
|
||||
array_keys($contacts),
|
||||
NULL,
|
||||
$messageToken,
|
||||
'CRM_Contact_Form_Task_LabelCommon'
|
||||
);
|
||||
|
||||
CRM_Utils_Hook::tokens($tokens);
|
||||
|
||||
foreach ($tokens as $category => $catTokens) {
|
||||
foreach ($catTokens as $token => $tokenName) {
|
||||
$tokenFields[] = $token;
|
||||
}
|
||||
}
|
||||
return $tokenFields;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $rows
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function mergeSameHousehold(&$rows) {
|
||||
// group selected contacts by type
|
||||
$individuals = array();
|
||||
$households = array();
|
||||
foreach ($rows as $contact_id => $row) {
|
||||
if ($row['contact_type'] == 'Household') {
|
||||
$households[$contact_id] = $row;
|
||||
}
|
||||
elseif ($row['contact_type'] == 'Individual') {
|
||||
$individuals[$contact_id] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
// exclude individuals belonging to selected households
|
||||
foreach ($households as $household_id => $row) {
|
||||
$dao = new CRM_Contact_DAO_Relationship();
|
||||
$dao->contact_id_b = $household_id;
|
||||
$dao->find();
|
||||
while ($dao->fetch()) {
|
||||
$individual_id = $dao->contact_id_a;
|
||||
if (array_key_exists($individual_id, $individuals)) {
|
||||
unset($individuals[$individual_id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// merge back individuals and households
|
||||
$rows = array_merge($individuals, $households);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
}
|
236
sites/all/modules/civicrm/CRM/Contact/Form/Task/Map.php
Normal file
236
sites/all/modules/civicrm/CRM/Contact/Form/Task/Map.php
Normal file
|
@ -0,0 +1,236 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to map
|
||||
* the address for group of
|
||||
* contacts.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_Map extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. mapping address to one
|
||||
* specific contact?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$cid = CRM_Utils_Request::retrieve('cid', 'Positive',
|
||||
$this, FALSE
|
||||
);
|
||||
$lid = CRM_Utils_Request::retrieve('lid', 'Positive',
|
||||
$this, FALSE
|
||||
);
|
||||
$eid = CRM_Utils_Request::retrieve('eid', 'Positive',
|
||||
$this, FALSE
|
||||
);
|
||||
$profileGID = CRM_Utils_Request::retrieve('profileGID', 'Integer',
|
||||
$this, FALSE
|
||||
);
|
||||
$this->assign('profileGID', $profileGID);
|
||||
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
|
||||
$type = 'Contact';
|
||||
if ($cid) {
|
||||
$ids = array($cid);
|
||||
$this->_single = TRUE;
|
||||
if ($profileGID) {
|
||||
// this does a check and ensures that the user has permission on this profile
|
||||
// CRM-11766
|
||||
$profileIDs = CRM_Profile_Page_Listings::getProfileContact($profileGID);
|
||||
if (!in_array($cid, $profileIDs)) {
|
||||
CRM_Core_Error::fatal();
|
||||
}
|
||||
}
|
||||
elseif ($context) {
|
||||
$qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
|
||||
$urlParams = 'force=1';
|
||||
if (CRM_Utils_Rule::qfKey($qfKey)) {
|
||||
$urlParams .= "&qfKey=$qfKey";
|
||||
}
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$urlString = "civicrm/contact/search/$context";
|
||||
if ($context == 'search') {
|
||||
$urlString = 'civicrm/contact/search';
|
||||
}
|
||||
$url = CRM_Utils_System::url($urlString, $urlParams);
|
||||
$session->replaceUserContext($url);
|
||||
}
|
||||
}
|
||||
elseif ($eid) {
|
||||
$ids = $eid;
|
||||
$type = 'Event';
|
||||
}
|
||||
else {
|
||||
if ($profileGID) {
|
||||
$ids = CRM_Profile_Page_Listings::getProfileContact($profileGID);
|
||||
}
|
||||
else {
|
||||
parent::preProcess();
|
||||
$ids = $this->_contactIds;
|
||||
}
|
||||
}
|
||||
self::createMapXML($ids, $lid, $this, TRUE, $type);
|
||||
$this->assign('single', $this->_single);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'done',
|
||||
'name' => ts('Done'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign smarty variables to the template that will be used by google api to plot the contacts.
|
||||
*
|
||||
* @param array $ids
|
||||
* @param int $locationId
|
||||
* Location_id.
|
||||
* @param CRM_Core_Page $page
|
||||
* @param bool $addBreadCrumb
|
||||
* @param string $type
|
||||
*/
|
||||
public static function createMapXML($ids, $locationId, &$page, $addBreadCrumb, $type = 'Contact') {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
CRM_Utils_System::setTitle(ts('Map Location(s)'));
|
||||
$page->assign('query', 'CiviCRM Search Query');
|
||||
$page->assign('mapProvider', $config->mapProvider);
|
||||
$page->assign('mapKey', urlencode($config->mapAPIKey));
|
||||
if ($type == 'Contact') {
|
||||
$imageUrlOnly = FALSE;
|
||||
|
||||
// google needs image url, CRM-6564
|
||||
if ($config->mapProvider == 'Google' || $config->mapProvider == 'OpenStreetMaps') {
|
||||
$imageUrlOnly = TRUE;
|
||||
}
|
||||
$locations = CRM_Contact_BAO_Contact_Location::getMapInfo($ids, $locationId, $imageUrlOnly);
|
||||
}
|
||||
else {
|
||||
$locations = CRM_Event_BAO_Event::getMapInfo($ids);
|
||||
}
|
||||
|
||||
if (empty($locations)) {
|
||||
CRM_Core_Error::statusBounce(ts('This address does not contain latitude/longitude information and cannot be mapped.'));
|
||||
}
|
||||
|
||||
if (empty($config->mapProvider)) {
|
||||
CRM_Core_Error::statusBounce(ts('You need to configure a Mapping Provider before using this feature (Administer > System Settings > Mapping and Geocoding).'));
|
||||
}
|
||||
if ($addBreadCrumb) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$redirect = $session->readUserContext();
|
||||
if ($type == 'Contact') {
|
||||
$bcTitle = ts('Contact');
|
||||
}
|
||||
else {
|
||||
$bcTitle = ts('Event Info');
|
||||
$action = CRM_Utils_Request::retrieve('action', 'String',
|
||||
$page, FALSE
|
||||
);
|
||||
if ($action) {
|
||||
$args = 'reset=1&action=preview&id=';
|
||||
}
|
||||
else {
|
||||
$args = 'reset=1&id=';
|
||||
}
|
||||
$session->pushUserContext(CRM_Utils_System::url('civicrm/event/info', "{$args}{$ids}"));
|
||||
}
|
||||
CRM_Utils_System::appendBreadCrumb($bcTitle, $redirect);
|
||||
}
|
||||
|
||||
$page->assign_by_ref('locations', $locations);
|
||||
|
||||
// only issue a javascript warning if we know we will not
|
||||
// mess the poor user with too many warnings
|
||||
if (count($locations) <= 3) {
|
||||
$page->assign('geoCodeWarn', TRUE);
|
||||
}
|
||||
else {
|
||||
$page->assign('geoCodeWarn', FALSE);
|
||||
}
|
||||
|
||||
$sumLat = $sumLng = 0;
|
||||
$maxLat = $maxLng = -400;
|
||||
$minLat = $minLng = 400;
|
||||
foreach ($locations as $location) {
|
||||
$sumLat += $location['lat'];
|
||||
$sumLng += $location['lng'];
|
||||
|
||||
if ($location['lat'] > $maxLat) {
|
||||
$maxLat = $location['lat'];
|
||||
}
|
||||
if ($location['lat'] < $minLat) {
|
||||
$minLat = $location['lat'];
|
||||
}
|
||||
|
||||
if ($location['lng'] > $maxLng) {
|
||||
$maxLng = $location['lng'];
|
||||
}
|
||||
if ($location['lng'] < $minLng) {
|
||||
$minLng = $location['lng'];
|
||||
}
|
||||
}
|
||||
|
||||
$center = array(
|
||||
'lat' => (float ) $sumLat / count($locations),
|
||||
'lng' => (float ) $sumLng / count($locations),
|
||||
);
|
||||
$span = array(
|
||||
'lat' => (float ) ($maxLat - $minLat),
|
||||
'lng' => (float ) ($maxLng - $minLng),
|
||||
);
|
||||
$page->assign_by_ref('center', $center);
|
||||
$page->assign_by_ref('span', $span);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to map the address for group of contacts.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_Map_Event extends CRM_Contact_Form_Task_Map {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$ids = CRM_Utils_Request::retrieve('eid', 'Positive',
|
||||
$this, TRUE
|
||||
);
|
||||
$lid = CRM_Utils_Request::retrieve('lid', 'Positive',
|
||||
$this, FALSE
|
||||
);
|
||||
$type = 'Event';
|
||||
self::createMapXML($ids, $lid, $this, TRUE, $type);
|
||||
$this->assign('single', FALSE);
|
||||
$this->assign('skipLocationType', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the form name to create the tpl file name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplateFileName() {
|
||||
return 'CRM/Contact/Form/Task/Map.tpl';
|
||||
}
|
||||
|
||||
}
|
89
sites/all/modules/civicrm/CRM/Contact/Form/Task/Merge.php
Normal file
89
sites/all/modules/civicrm/CRM/Contact/Form/Task/Merge.php
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to Merge contacts.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_Merge extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
$statusMsg = NULL;
|
||||
$contactIds = array();
|
||||
if (is_array($this->_contactIds)) {
|
||||
$contactIds = array_unique($this->_contactIds);
|
||||
}
|
||||
if (count($contactIds) != 2) {
|
||||
$statusMsg = ts('Merge operation requires selecting two contacts.');
|
||||
}
|
||||
|
||||
// do check for same contact type.
|
||||
$contactTypes = array();
|
||||
if (!$statusMsg) {
|
||||
$sql = "SELECT contact_type FROM civicrm_contact WHERE id IN (" . implode(',', $contactIds) . ")";
|
||||
$contact = CRM_Core_DAO::executeQuery($sql);
|
||||
while ($contact->fetch()) {
|
||||
$contactTypes[$contact->contact_type] = TRUE;
|
||||
if (count($contactTypes) > 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (count($contactTypes) > 1) {
|
||||
$statusMsg = ts('Selected records must all be the same contact type (i.e. all Individuals).');
|
||||
}
|
||||
}
|
||||
if ($statusMsg) {
|
||||
CRM_Core_Error::statusBounce($statusMsg);
|
||||
}
|
||||
|
||||
// redirect to merge form directly.
|
||||
$cid = $contactIds[0];
|
||||
$oid = $contactIds[1];
|
||||
|
||||
//don't allow to delete logged in user.
|
||||
$session = CRM_Core_Session::singleton();
|
||||
if ($oid == $session->get('userID')) {
|
||||
$oid = $cid;
|
||||
$cid = $session->get('userID');
|
||||
}
|
||||
|
||||
$url = CRM_Utils_System::url('civicrm/contact/merge', "reset=1&cid={$cid}&oid={$oid}");
|
||||
|
||||
// redirect to merge page.
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
|
||||
}
|
128
sites/all/modules/civicrm/CRM/Contact/Form/Task/PDF.php
Normal file
128
sites/all/modules/civicrm/CRM/Contact/Form/Task/PDF.php
Normal file
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to create PDF letter for a group of contacts or a single contact.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_PDF extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* All the existing templates in the system.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_templates = NULL;
|
||||
|
||||
public $_single = NULL;
|
||||
|
||||
public $_cid = NULL;
|
||||
|
||||
public $_activityId = NULL;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
|
||||
$this->skipOnHold = $this->skipDeceased = FALSE;
|
||||
CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
|
||||
|
||||
// store case id if present
|
||||
$this->_caseId = CRM_Utils_Request::retrieve('caseid', 'Positive', $this, FALSE);
|
||||
|
||||
// retrieve contact ID if this is 'single' mode
|
||||
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
|
||||
|
||||
if ($cid) {
|
||||
// this is true in non-search context / single mode
|
||||
// in search context 'id' is the default profile id for search display
|
||||
// CRM-11227
|
||||
$this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
|
||||
}
|
||||
|
||||
if ($cid) {
|
||||
CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid);
|
||||
$this->_single = TRUE;
|
||||
$this->_cid = $cid;
|
||||
}
|
||||
else {
|
||||
parent::preProcess();
|
||||
}
|
||||
$this->assign('single', $this->_single);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (isset($this->_activityId)) {
|
||||
$params = array('id' => $this->_activityId);
|
||||
CRM_Activity_BAO_Activity::retrieve($params, $defaults);
|
||||
$defaults['html_message'] = CRM_Utils_Array::value('details', $defaults);
|
||||
}
|
||||
$defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//enable form element
|
||||
$this->assign('suppressForm', FALSE);
|
||||
CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
CRM_Contact_Form_Task_PDFLetterCommon::postProcess($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* List available tokens for this form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listTokens() {
|
||||
$tokens = CRM_Core_SelectValues::contactTokens();
|
||||
if (isset($this->_caseId)) {
|
||||
$caseTypeId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $this->_caseId, 'case_type_id');
|
||||
$tokens += CRM_Core_SelectValues::caseTokens($caseTypeId);
|
||||
}
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,625 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the common functionality for creating PDF letter for one or a group of contact ids.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_PDFLetterCommon {
|
||||
|
||||
protected static $tokenCategories;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* Array(string $machineName => string $label).
|
||||
*/
|
||||
public static function getLoggingOptions() {
|
||||
return array(
|
||||
'none' => ts('Do not record'),
|
||||
'multiple' => ts('Multiple activities (one per contact)'),
|
||||
'combined' => ts('One combined activity'),
|
||||
'combined-attached' => ts('One combined activity plus one file attachment'),
|
||||
// 'multiple-attached' <== not worth the work
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function preProcess(&$form) {
|
||||
$messageText = array();
|
||||
$messageSubject = array();
|
||||
$dao = new CRM_Core_BAO_MessageTemplate();
|
||||
$dao->is_active = 1;
|
||||
$dao->find();
|
||||
while ($dao->fetch()) {
|
||||
$messageText[$dao->id] = $dao->msg_text;
|
||||
$messageSubject[$dao->id] = $dao->msg_subject;
|
||||
}
|
||||
|
||||
$form->assign('message', $messageText);
|
||||
$form->assign('messageSubject', $messageSubject);
|
||||
CRM_Utils_System::setTitle('Print/Merge Document');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
* @param int $cid
|
||||
*/
|
||||
public static function preProcessSingle(&$form, $cid) {
|
||||
$form->_contactIds = array($cid);
|
||||
// put contact display name in title for single contact mode
|
||||
CRM_Utils_System::setTitle(ts('Print/Merge Document for %1', array(1 => CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'display_name'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @var CRM_Core_Form $form
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
// This form outputs a file so should never be submitted via ajax
|
||||
$form->preventAjaxSubmit();
|
||||
|
||||
//Added for CRM-12682: Add activity subject and campaign fields
|
||||
CRM_Campaign_BAO_Campaign::addCampaign($form);
|
||||
$form->add(
|
||||
'text',
|
||||
'subject',
|
||||
ts('Activity Subject'),
|
||||
array('size' => 45, 'maxlength' => 255),
|
||||
FALSE
|
||||
);
|
||||
|
||||
$form->add('static', 'pdf_format_header', NULL, ts('Page Format: %1', array(1 => '<span class="pdf-format-header-label"></span>')));
|
||||
$form->addSelect('format_id', array(
|
||||
'label' => ts('Select Format'),
|
||||
'placeholder' => ts('Default'),
|
||||
'entity' => 'message_template',
|
||||
'field' => 'pdf_format_id',
|
||||
'option_url' => 'civicrm/admin/pdfFormats',
|
||||
));
|
||||
$form->add(
|
||||
'select',
|
||||
'paper_size',
|
||||
ts('Paper Size'),
|
||||
array(0 => ts('- default -')) + CRM_Core_BAO_PaperSize::getList(TRUE),
|
||||
FALSE,
|
||||
array('onChange' => "selectPaper( this.value ); showUpdateFormatChkBox();")
|
||||
);
|
||||
$form->add('static', 'paper_dimensions', NULL, ts('Width x Height'));
|
||||
$form->add(
|
||||
'select',
|
||||
'orientation',
|
||||
ts('Orientation'),
|
||||
CRM_Core_BAO_PdfFormat::getPageOrientations(),
|
||||
FALSE,
|
||||
array('onChange' => "updatePaperDimensions(); showUpdateFormatChkBox();")
|
||||
);
|
||||
$form->add(
|
||||
'select',
|
||||
'metric',
|
||||
ts('Unit of Measure'),
|
||||
CRM_Core_BAO_PdfFormat::getUnits(),
|
||||
FALSE,
|
||||
array('onChange' => "selectMetric( this.value );")
|
||||
);
|
||||
$form->add(
|
||||
'text',
|
||||
'margin_left',
|
||||
ts('Left Margin'),
|
||||
array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"),
|
||||
TRUE
|
||||
);
|
||||
$form->add(
|
||||
'text',
|
||||
'margin_right',
|
||||
ts('Right Margin'),
|
||||
array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"),
|
||||
TRUE
|
||||
);
|
||||
$form->add(
|
||||
'text',
|
||||
'margin_top',
|
||||
ts('Top Margin'),
|
||||
array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"),
|
||||
TRUE
|
||||
);
|
||||
$form->add(
|
||||
'text',
|
||||
'margin_bottom',
|
||||
ts('Bottom Margin'),
|
||||
array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"),
|
||||
TRUE
|
||||
);
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
/** CRM-15883 Suppressing Stationery path field until we switch from DOMPDF to a library that supports it.
|
||||
if ($config->wkhtmltopdfPath == FALSE) {
|
||||
$form->add(
|
||||
'text',
|
||||
'stationery',
|
||||
ts('Stationery (relative path to PDF you wish to use as the background)'),
|
||||
array('size' => 25, 'maxlength' => 900, 'onkeyup' => "showUpdateFormatChkBox();"),
|
||||
FALSE
|
||||
);
|
||||
}
|
||||
*/
|
||||
$form->add('checkbox', 'bind_format', ts('Always use this Page Format with the selected Template'));
|
||||
$form->add('checkbox', 'update_format', ts('Update Page Format (this will affect all templates that use this format)'));
|
||||
|
||||
$form->assign('useThisPageFormat', ts('Always use this Page Format with the new template?'));
|
||||
$form->assign('useSelectedPageFormat', ts('Should the new template always use the selected Page Format?'));
|
||||
$form->assign('totalSelectedContacts', count($form->_contactIds));
|
||||
|
||||
$form->add('select', 'document_type', ts('Document Type'), CRM_Core_SelectValues::documentFormat());
|
||||
|
||||
$documentTypes = implode(',', CRM_Core_SelectValues::documentApplicationType());
|
||||
$form->addElement('file', "document_file", 'Upload Document', 'size=30 maxlength=255 accept="' . $documentTypes . '"');
|
||||
$form->addUploadElement("document_file");
|
||||
|
||||
CRM_Mailing_BAO_Mailing::commonCompose($form);
|
||||
|
||||
$buttons = array();
|
||||
if ($form->get('action') != CRM_Core_Action::VIEW) {
|
||||
$buttons[] = array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Download Document'),
|
||||
'isDefault' => TRUE,
|
||||
'icon' => 'fa-download',
|
||||
);
|
||||
$buttons[] = array(
|
||||
'type' => 'submit',
|
||||
'name' => ts('Preview'),
|
||||
'subName' => 'preview',
|
||||
'icon' => 'fa-search',
|
||||
'isDefault' => FALSE,
|
||||
);
|
||||
}
|
||||
$buttons[] = array(
|
||||
'type' => 'cancel',
|
||||
'name' => $form->get('action') == CRM_Core_Action::VIEW ? ts('Done') : ts('Cancel'),
|
||||
);
|
||||
$form->addButtons($buttons);
|
||||
|
||||
$form->addFormRule(array('CRM_Contact_Form_Task_PDFLetterCommon', 'formRule'), $form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values.
|
||||
*/
|
||||
public static function setDefaultValues() {
|
||||
$defaultFormat = CRM_Core_BAO_PdfFormat::getDefaultValues();
|
||||
$defaultFormat['format_id'] = $defaultFormat['id'];
|
||||
return $defaultFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* @param array $self
|
||||
* Additional values form 'this'.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if no errors, else array of errors.
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
$template = CRM_Core_Smarty::singleton();
|
||||
|
||||
// If user uploads non-document file other than odt/docx
|
||||
if (empty($fields['template']) &&
|
||||
!empty($files['document_file']['tmp_name']) &&
|
||||
array_search($files['document_file']['type'], CRM_Core_SelectValues::documentApplicationType()) == NULL
|
||||
) {
|
||||
$errors['document_file'] = ts('Invalid document file format');
|
||||
}
|
||||
//Added for CRM-1393
|
||||
if (!empty($fields['saveTemplate']) && empty($fields['saveTemplateName'])) {
|
||||
$errors['saveTemplateName'] = ts("Enter name to save message template");
|
||||
}
|
||||
if (!is_numeric($fields['margin_left'])) {
|
||||
$errors['margin_left'] = 'Margin must be numeric';
|
||||
}
|
||||
if (!is_numeric($fields['margin_right'])) {
|
||||
$errors['margin_right'] = 'Margin must be numeric';
|
||||
}
|
||||
if (!is_numeric($fields['margin_top'])) {
|
||||
$errors['margin_top'] = 'Margin must be numeric';
|
||||
}
|
||||
if (!is_numeric($fields['margin_bottom'])) {
|
||||
$errors['margin_bottom'] = 'Margin must be numeric';
|
||||
}
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the post process which prepare and extract information from the template.
|
||||
*
|
||||
*
|
||||
* @param array $formValues
|
||||
*
|
||||
* @return array
|
||||
* [$categories, $html_message, $messageToken, $returnProperties]
|
||||
*/
|
||||
public static function processMessageTemplate($formValues) {
|
||||
$html_message = CRM_Utils_Array::value('html_message', $formValues);
|
||||
|
||||
// process message template
|
||||
if (!empty($formValues['saveTemplate']) || !empty($formValues['updateTemplate'])) {
|
||||
$messageTemplate = array(
|
||||
'msg_text' => NULL,
|
||||
'msg_html' => $formValues['html_message'],
|
||||
'msg_subject' => NULL,
|
||||
'is_active' => TRUE,
|
||||
);
|
||||
|
||||
$messageTemplate['pdf_format_id'] = 'null';
|
||||
if (!empty($formValues['bind_format']) && $formValues['format_id']) {
|
||||
$messageTemplate['pdf_format_id'] = $formValues['format_id'];
|
||||
}
|
||||
if (!empty($formValues['saveTemplate']) && $formValues['saveTemplate']) {
|
||||
$messageTemplate['msg_title'] = $formValues['saveTemplateName'];
|
||||
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
|
||||
}
|
||||
|
||||
if (!empty($formValues['updateTemplate']) && $formValues['template'] && $formValues['updateTemplate']) {
|
||||
$messageTemplate['id'] = $formValues['template'];
|
||||
|
||||
unset($messageTemplate['msg_title']);
|
||||
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
|
||||
}
|
||||
}
|
||||
elseif (CRM_Utils_Array::value('template', $formValues) > 0) {
|
||||
if (!empty($formValues['bind_format']) && $formValues['format_id']) {
|
||||
$query = "UPDATE civicrm_msg_template SET pdf_format_id = {$formValues['format_id']} WHERE id = {$formValues['template']}";
|
||||
}
|
||||
else {
|
||||
$query = "UPDATE civicrm_msg_template SET pdf_format_id = NULL WHERE id = {$formValues['template']}";
|
||||
}
|
||||
CRM_Core_DAO::executeQuery($query);
|
||||
|
||||
$documentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_msg_template', $formValues['template']);
|
||||
foreach ((array) $documentInfo as $info) {
|
||||
list($html_message, $formValues['document_type']) = CRM_Utils_PDF_Document::docReader($info['fullPath'], $info['mime_type']);
|
||||
$formValues['document_file_path'] = $info['fullPath'];
|
||||
}
|
||||
}
|
||||
// extract the content of uploaded document file
|
||||
elseif (!empty($formValues['document_file'])) {
|
||||
list($html_message, $formValues['document_type']) = CRM_Utils_PDF_Document::docReader($formValues['document_file']['name'], $formValues['document_file']['type']);
|
||||
$formValues['document_file_path'] = $formValues['document_file']['name'];
|
||||
}
|
||||
|
||||
if (!empty($formValues['update_format'])) {
|
||||
$bao = new CRM_Core_BAO_PdfFormat();
|
||||
$bao->savePdfFormat($formValues, $formValues['format_id']);
|
||||
}
|
||||
|
||||
$categories = self::getTokenCategories();
|
||||
|
||||
//time being hack to strip ' '
|
||||
//from particular letter line, CRM-6798
|
||||
self::formatMessage($html_message);
|
||||
|
||||
$messageToken = CRM_Utils_Token::getTokens($html_message);
|
||||
|
||||
$returnProperties = array();
|
||||
if (isset($messageToken['contact'])) {
|
||||
foreach ($messageToken['contact'] as $key => $value) {
|
||||
$returnProperties[$value] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return array($formValues, $categories, $html_message, $messageToken, $returnProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @throws \CRM_Core_Exception
|
||||
*/
|
||||
public static function postProcess(&$form) {
|
||||
$formValues = $form->controller->exportValues($form->getName());
|
||||
list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($formValues);
|
||||
$buttonName = $form->controller->getButtonName();
|
||||
$skipOnHold = isset($form->skipOnHold) ? $form->skipOnHold : FALSE;
|
||||
$skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE;
|
||||
$html = $activityIds = array();
|
||||
|
||||
// CRM-21255 - Hrm, CiviCase 4+5 seem to report buttons differently...
|
||||
$c = $form->controller->container();
|
||||
$isLiveMode = ($buttonName == '_qf_PDF_upload') || isset($c['values']['PDF']['buttons']['_qf_PDF_upload']);
|
||||
|
||||
// CRM-16725 Skip creation of activities if user is previewing their PDF letter(s)
|
||||
if ($isLiveMode) {
|
||||
|
||||
// This seems silly, but the old behavior was to first check `_cid`
|
||||
// and then use the provided `$contactIds`. Probably not even necessary,
|
||||
// but difficult to audit.
|
||||
$contactIds = $form->_cid ? array($form->_cid) : $form->_contactIds;
|
||||
$activityIds = self::createActivities($form, $html_message, $contactIds, $formValues['subject'], CRM_Utils_Array::value('campaign_id', $formValues));
|
||||
}
|
||||
|
||||
if (!empty($formValues['document_file_path'])) {
|
||||
list($html_message, $zip) = CRM_Utils_PDF_Document::unzipDoc($formValues['document_file_path'], $formValues['document_type']);
|
||||
}
|
||||
|
||||
foreach ($form->_contactIds as $item => $contactId) {
|
||||
$caseId = NULL;
|
||||
$params = array('contact_id' => $contactId);
|
||||
|
||||
list($contact) = CRM_Utils_Token::getTokenDetails($params,
|
||||
$returnProperties,
|
||||
$skipOnHold,
|
||||
$skipDeceased,
|
||||
NULL,
|
||||
$messageToken,
|
||||
'CRM_Contact_Form_Task_PDFLetterCommon'
|
||||
);
|
||||
|
||||
if (civicrm_error($contact)) {
|
||||
$notSent[] = $contactId;
|
||||
continue;
|
||||
}
|
||||
|
||||
$tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken);
|
||||
if (!empty($form->_caseId)) {
|
||||
$caseId = $form->_caseId;
|
||||
}
|
||||
if (empty($caseId) && !empty($form->_caseIds[$item])) {
|
||||
$caseId = $form->_caseIds[$item];
|
||||
}
|
||||
if ($caseId) {
|
||||
$tokenHtml = CRM_Utils_Token::replaceCaseTokens($caseId, $tokenHtml, $messageToken);
|
||||
}
|
||||
$tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contact[$contactId], $categories, TRUE);
|
||||
|
||||
if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) {
|
||||
$smarty = CRM_Core_Smarty::singleton();
|
||||
// also add the contact tokens to the template
|
||||
$smarty->assign_by_ref('contact', $contact);
|
||||
$tokenHtml = $smarty->fetch("string:$tokenHtml");
|
||||
}
|
||||
|
||||
$html[] = $tokenHtml;
|
||||
}
|
||||
|
||||
$tee = NULL;
|
||||
if ($isLiveMode && Civi::settings()->get('recordGeneratedLetters') === 'combined-attached') {
|
||||
if (count($activityIds) !== 1) {
|
||||
throw new CRM_Core_Exception("When recordGeneratedLetters=combined-attached, there should only be one activity.");
|
||||
}
|
||||
$tee = CRM_Utils_ConsoleTee::create()->start();
|
||||
}
|
||||
|
||||
$type = $formValues['document_type'];
|
||||
$mimeType = self::getMimeType($type);
|
||||
// ^^ Useful side-effect: consistently throws error for unrecognized types.
|
||||
|
||||
if ($type == 'pdf') {
|
||||
$fileName = "CiviLetter.$type";
|
||||
CRM_Utils_PDF_Utils::html2pdf($html, $fileName, FALSE, $formValues);
|
||||
}
|
||||
elseif (!empty($formValues['document_file_path'])) {
|
||||
$fileName = pathinfo($formValues['document_file_path'], PATHINFO_FILENAME) . '.' . $type;
|
||||
CRM_Utils_PDF_Document::printDocuments($html, $fileName, $type, $zip);
|
||||
}
|
||||
else {
|
||||
$fileName = "CiviLetter.$type";
|
||||
CRM_Utils_PDF_Document::html2doc($html, $fileName, $formValues);
|
||||
}
|
||||
|
||||
if ($tee) {
|
||||
$tee->stop();
|
||||
$content = file_get_contents($tee->getFileName(), NULL, NULL, NULL, 5);
|
||||
if (empty($content)) {
|
||||
throw new \CRM_Core_Exception("Failed to capture document content (type=$type)!");
|
||||
}
|
||||
foreach ($activityIds as $activityId) {
|
||||
civicrm_api3('Attachment', 'create', array(
|
||||
'entity_table' => 'civicrm_activity',
|
||||
'entity_id' => $activityId,
|
||||
'name' => $fileName,
|
||||
'mime_type' => $mimeType,
|
||||
'options' => array(
|
||||
'move-file' => $tee->getFileName(),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$form->postProcessHook();
|
||||
|
||||
CRM_Utils_System::civiExit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
* @param string $html_message
|
||||
* @param array $contactIds
|
||||
* @param string $subject
|
||||
* @param int $campaign_id
|
||||
* @param array $perContactHtml
|
||||
*
|
||||
* @return array
|
||||
* List of activity IDs.
|
||||
* There may be 1 or more, depending on the system-settings
|
||||
* and use-case.
|
||||
*
|
||||
* @throws CRM_Core_Exception
|
||||
*/
|
||||
public static function createActivities($form, $html_message, $contactIds, $subject, $campaign_id, $perContactHtml = array()) {
|
||||
|
||||
$activityParams = array(
|
||||
'subject' => $subject,
|
||||
'campaign_id' => $campaign_id,
|
||||
'source_contact_id' => CRM_Core_Session::singleton()->getLoggedInContactID(),
|
||||
'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Print PDF Letter'),
|
||||
'activity_date_time' => date('YmdHis'),
|
||||
'details' => $html_message,
|
||||
);
|
||||
if (!empty($form->_activityId)) {
|
||||
$activityParams += array('id' => $form->_activityId);
|
||||
}
|
||||
|
||||
$activityIds = array();
|
||||
switch (Civi::settings()->get('recordGeneratedLetters')) {
|
||||
case 'none':
|
||||
return array();
|
||||
|
||||
case 'multiple':
|
||||
// One activity per contact.
|
||||
foreach ($contactIds as $contactId) {
|
||||
$fullParams = array(
|
||||
'target_contact_id' => $contactId,
|
||||
) + $activityParams;
|
||||
if (isset($perContactHtml[$contactId])) {
|
||||
$fullParams['details'] = implode('<hr>', $perContactHtml[$contactId]);
|
||||
}
|
||||
$activity = civicrm_api3('Activity', 'create', $fullParams);
|
||||
$activityIds[$contactId] = $activity['id'];
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'combined':
|
||||
case 'combined-attached':
|
||||
// One activity with all contacts.
|
||||
$fullParams = array(
|
||||
'target_contact_id' => $contactIds,
|
||||
) + $activityParams;
|
||||
$activity = CRM_Activity_BAO_Activity::create($fullParams);
|
||||
$activityIds[] = $activity->id;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new CRM_Core_Exception("Unrecognized option in recordGeneratedLetters: " . Civi::settings()->get('recordGeneratedLetters'));
|
||||
}
|
||||
|
||||
if (!empty($form->_caseId)) {
|
||||
foreach ($activityIds as $activityId) {
|
||||
$caseActivityParams = array('activity_id' => $activityId, 'case_id' => $form->_caseId);
|
||||
CRM_Case_BAO_Case::processCaseActivity($caseActivityParams);
|
||||
}
|
||||
}
|
||||
|
||||
return $activityIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
*/
|
||||
public static function formatMessage(&$message) {
|
||||
$newLineOperators = array(
|
||||
'p' => array(
|
||||
'oper' => '<p>',
|
||||
'pattern' => '/<(\s+)?p(\s+)?>/m',
|
||||
),
|
||||
'br' => array(
|
||||
'oper' => '<br />',
|
||||
'pattern' => '/<(\s+)?br(\s+)?\/>/m',
|
||||
),
|
||||
);
|
||||
|
||||
$htmlMsg = preg_split($newLineOperators['p']['pattern'], $message);
|
||||
foreach ($htmlMsg as $k => & $m) {
|
||||
$messages = preg_split($newLineOperators['br']['pattern'], $m);
|
||||
foreach ($messages as $key => & $msg) {
|
||||
$msg = trim($msg);
|
||||
$matches = array();
|
||||
if (preg_match('/^( )+/', $msg, $matches)) {
|
||||
$spaceLen = strlen($matches[0]) / 6;
|
||||
$trimMsg = ltrim($msg, ' ');
|
||||
$charLen = strlen($trimMsg);
|
||||
$totalLen = $charLen + $spaceLen;
|
||||
if ($totalLen > 100) {
|
||||
$spacesCount = 10;
|
||||
if ($spaceLen > 50) {
|
||||
$spacesCount = 20;
|
||||
}
|
||||
if ($charLen > 100) {
|
||||
$spacesCount = 1;
|
||||
}
|
||||
$msg = str_repeat(' ', $spacesCount) . $trimMsg;
|
||||
}
|
||||
}
|
||||
}
|
||||
$m = implode($newLineOperators['br']['oper'], $messages);
|
||||
}
|
||||
$message = implode($newLineOperators['p']['oper'], $htmlMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from a vague-type/file-extension to mime-type.
|
||||
*
|
||||
* @param string $type
|
||||
* @return string
|
||||
* @throws \CRM_Core_Exception
|
||||
*/
|
||||
private static function getMimeType($type) {
|
||||
$mimeTypes = array(
|
||||
'pdf' => 'application/pdf',
|
||||
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'odt' => 'application/vnd.oasis.opendocument.text',
|
||||
'html' => 'text/html',
|
||||
);
|
||||
if (isset($mimeTypes[$type])) {
|
||||
return $mimeTypes[$type];
|
||||
}
|
||||
else {
|
||||
throw new \CRM_Core_Exception("Cannot determine mime type");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the categories required for rendering tokens.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function getTokenCategories() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['token_categories'])) {
|
||||
$tokens = array();
|
||||
CRM_Utils_Hook::tokens($tokens);
|
||||
Civi::$statics[__CLASS__]['token_categories'] = array_keys($tokens);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['token_categories'];
|
||||
}
|
||||
|
||||
}
|
157
sites/all/modules/civicrm/CRM/Contact/Form/Task/PickProfile.php
Normal file
157
sites/all/modules/civicrm/CRM/Contact/Form/Task/PickProfile.php
Normal file
|
@ -0,0 +1,157 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality for Update multiple contacts
|
||||
*/
|
||||
class CRM_Contact_Form_Task_PickProfile extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* The title of the group
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Maximum contacts that should be allowed to update
|
||||
*/
|
||||
protected $_maxContacts = 100;
|
||||
|
||||
/**
|
||||
* Maximum profile fields that will be displayed
|
||||
*/
|
||||
protected $_maxFields = 9;
|
||||
|
||||
/**
|
||||
* Variable to store redirect path
|
||||
*/
|
||||
protected $_userContext;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
// initialize the task and row fields
|
||||
parent::preProcess();
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$this->_userContext = $session->readUserContext();
|
||||
|
||||
$validate = FALSE;
|
||||
//validations
|
||||
if (count($this->_contactIds) > $this->_maxContacts) {
|
||||
CRM_Core_Session::setStatus(ts("The maximum number of contacts you can select for Update multiple contacts is %1. You have selected %2. Please select fewer contacts from your search results and try again.", array(
|
||||
1 => $this->_maxContacts,
|
||||
2 => count($this->_contactIds),
|
||||
)), ts('Maximum Exceeded'), 'error');
|
||||
$validate = TRUE;
|
||||
}
|
||||
|
||||
if (CRM_Contact_BAO_Contact_Utils::checkContactType($this->_contactIds)) {
|
||||
CRM_Core_Session::setStatus(ts("Update multiple contacts requires that all selected contacts be the same basic type (e.g. all Individuals OR all Organizations...). Please modify your selection and try again."), ts('Contact Type Mismatch'), 'error');
|
||||
$validate = TRUE;
|
||||
}
|
||||
|
||||
// than redirect
|
||||
if ($validate) {
|
||||
CRM_Utils_System::redirect($this->_userContext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
CRM_Utils_System::setTitle(ts('Update multiple contacts'));
|
||||
|
||||
foreach ($this->_contactIds as $id) {
|
||||
$this->_contactTypes = CRM_Contact_BAO_Contact::getContactTypes($id);
|
||||
}
|
||||
|
||||
//add Contact type profiles
|
||||
$this->_contactTypes[] = 'Contact';
|
||||
|
||||
$profiles = CRM_Core_BAO_UFGroup::getProfiles($this->_contactTypes);
|
||||
|
||||
if (empty($profiles)) {
|
||||
$types = implode(' ' . ts('or') . ' ', $this->_contactTypes);
|
||||
CRM_Core_Session::setStatus(ts("The contact type selected for Update multiple contacts does not have a corresponding profile. Please set up a profile for %1s and try again.", array(1 => $types)), ts('No Profile Available'), 'error');
|
||||
CRM_Utils_System::redirect($this->_userContext);
|
||||
}
|
||||
$ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'), array('' => ts('- select profile -')) + $profiles, TRUE, array('class' => 'crm-select2 huge'));
|
||||
|
||||
$this->addDefaultButtons(ts('Continue'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add local and global form rules.
|
||||
*/
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Contact_Form_Task_PickProfile', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($fields) {
|
||||
if (CRM_Core_BAO_UFField::checkProfileType($fields['uf_group_id'])) {
|
||||
$errorMsg['uf_group_id'] = "You cannot select a mixed profile for Update multiple contacts.";
|
||||
}
|
||||
|
||||
if (!empty($errorMsg)) {
|
||||
return $errorMsg;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
$this->set('ufGroupId', $params['uf_group_id']);
|
||||
|
||||
// also reset the batch page so it gets new values from the db
|
||||
$this->controller->resetPage('Batch');
|
||||
}
|
||||
|
||||
}
|
136
sites/all/modules/civicrm/CRM/Contact/Form/Task/Print.php
Normal file
136
sites/all/modules/civicrm/CRM/Contact/Form/Task/Print.php
Normal file
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to save a search
|
||||
* Saved Searches are used for saving frequently used queries
|
||||
*/
|
||||
class CRM_Contact_Form_Task_Print extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preprocess();
|
||||
|
||||
// set print view, so that print templates are called
|
||||
$this->controller->setPrint(1);
|
||||
$this->assign('id', $this->get('id'));
|
||||
$this->assign('pageTitle', ts('CiviCRM Contact Listing'));
|
||||
|
||||
$params = $this->get('queryParams');
|
||||
if (!empty($this->_contactIds)) {
|
||||
//using _contactIds field for creating params for query so that multiple selections on multiple pages
|
||||
//can be printed.
|
||||
foreach ($this->_contactIds as $contactId) {
|
||||
$params[] = array(
|
||||
CRM_Core_Form::CB_PREFIX . $contactId,
|
||||
'=',
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// create the selector, controller and run - store results in session
|
||||
$fv = $this->get('formValues');
|
||||
$returnProperties = $this->get('returnProperties');
|
||||
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
|
||||
$includeContactIds = FALSE;
|
||||
if ($fv['radio_ts'] == 'ts_sel') {
|
||||
$includeContactIds = TRUE;
|
||||
}
|
||||
|
||||
$selectorName = $this->controller->selectorName();
|
||||
require_once str_replace('_', DIRECTORY_SEPARATOR, $selectorName) . '.php';
|
||||
|
||||
$returnP = isset($returnPropeties) ? $returnPropeties : "";
|
||||
$customSearchClass = $this->get('customSearchClass');
|
||||
$selector = new $selectorName($customSearchClass,
|
||||
$fv,
|
||||
$params,
|
||||
$returnP,
|
||||
$this->_action,
|
||||
$includeContactIds
|
||||
);
|
||||
$controller = new CRM_Core_Selector_Controller($selector,
|
||||
NULL,
|
||||
$sortID,
|
||||
CRM_Core_Action::VIEW,
|
||||
$this,
|
||||
CRM_Core_Selector_Controller::SCREEN
|
||||
);
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object - it consists of
|
||||
* - displaying the QILL (query in local language)
|
||||
* - displaying elements for saving the search
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//
|
||||
// just need to add a javacript to popup the window for printing
|
||||
//
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Print Contact List'),
|
||||
'js' => array('onclick' => 'window.print()'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'back',
|
||||
'name' => ts('Done'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// redirect to the main search page after printing is over
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to support Proximity Searches.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_ProximityCommon {
|
||||
|
||||
/**
|
||||
* The context that we are working on.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_context;
|
||||
|
||||
/**
|
||||
* The groupId retrieved from the GET vars.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* The title of the group.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param int $proxSearch
|
||||
*/
|
||||
static public function buildQuickForm($form, $proxSearch) {
|
||||
// is proximity search required (2) or optional (1)?
|
||||
$proxRequired = ($proxSearch == 2 ? TRUE : FALSE);
|
||||
$form->assign('proximity_search', TRUE);
|
||||
|
||||
$form->add('text', 'prox_street_address', ts('Street Address'), NULL, FALSE);
|
||||
|
||||
$form->add('text', 'prox_city', ts('City'), NULL, FALSE);
|
||||
|
||||
$form->add('text', 'prox_postal_code', ts('Postal Code'), NULL, FALSE);
|
||||
|
||||
$form->addChainSelect('prox_state_province_id', array('required' => $proxRequired));
|
||||
|
||||
$country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
|
||||
$form->add('select', 'prox_country_id', ts('Country'), $country, $proxRequired);
|
||||
|
||||
$form->add('text', 'prox_distance', ts('Distance'), NULL, $proxRequired);
|
||||
|
||||
$proxUnits = array('km' => ts('km'), 'miles' => ts('miles'));
|
||||
$form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, $proxRequired);
|
||||
// prox_distance_unit
|
||||
|
||||
$form->addFormRule(array('CRM_Contact_Form_Task_ProximityCommon', 'formRule'), $form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $form) {
|
||||
$errors = array();
|
||||
// If Distance is present, make sure state, country and city or postal code are populated.
|
||||
if (!empty($fields['prox_distance'])) {
|
||||
if (empty($fields['prox_state_province_id']) || empty($fields['prox_country_id'])) {
|
||||
$errors["prox_state_province_id"] = ts("Country AND State/Province are required to search by distance.");
|
||||
}
|
||||
if (!CRM_Utils_Array::value('prox_postal_code', $fields) AND
|
||||
!CRM_Utils_Array::value('prox_city', $fields)
|
||||
) {
|
||||
$errors["prox_distance"] = ts("City OR Postal Code are required to search by distance.");
|
||||
}
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default form values.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
* the default array reference
|
||||
*/
|
||||
static public function setDefaultValues($form) {
|
||||
$defaults = array();
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$countryDefault = $config->defaultContactCountry;
|
||||
|
||||
if ($countryDefault) {
|
||||
$defaults['prox_country_id'] = $countryDefault;
|
||||
if ($countryDefault == '1228') {
|
||||
$defaults['prox_distance_unit'] = 'miles';
|
||||
}
|
||||
else {
|
||||
$defaults['prox_distance_unit'] = 'km';
|
||||
}
|
||||
}
|
||||
$form->setDefaults($defaults);
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to delete a group of
|
||||
* contacts. This class provides functionality for the actual
|
||||
* addition of contacts to groups.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_RemoveFromGroup extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
// add select for groups
|
||||
$group = array('' => ts('- select group -')) + CRM_Core_PseudoConstant::nestedGroup();
|
||||
$groupElement = $this->add('select', 'group_id', ts('Select Group'), $group, TRUE, array('class' => 'crm-select2 huge'));
|
||||
|
||||
CRM_Utils_System::setTitle(ts('Remove Contacts from Group'));
|
||||
$this->addDefaultButtons(ts('Remove from Group'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default form values.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* the default array reference
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
if ($this->get('context') === 'smog') {
|
||||
$defaults['group_id'] = $this->get('gid');
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$groupId = $this->controller->exportValue('RemoveFromGroup', 'group_id');
|
||||
$group = CRM_Core_PseudoConstant::group();
|
||||
|
||||
list($total, $removed, $notRemoved) = CRM_Contact_BAO_GroupContact::removeContactsFromGroup($this->_contactIds, $groupId);
|
||||
|
||||
$status = array(
|
||||
ts("%count contact removed from '%2'", array(
|
||||
'count' => $removed,
|
||||
'plural' => "%count contacts removed from '%2'",
|
||||
2 => $group[$groupId],
|
||||
)),
|
||||
);
|
||||
if ($notRemoved) {
|
||||
$status[] = ts('1 contact was already not in this group', array(
|
||||
'count' => $notRemoved,
|
||||
'plural' => '%count contacts were already not in this group',
|
||||
));
|
||||
}
|
||||
$status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
|
||||
CRM_Core_Session::setStatus($status, ts("Removed Contact From Group", array(
|
||||
'plural' => "Removed Contacts From Group",
|
||||
'count' => $removed,
|
||||
)), 'success', array('expires' => 0));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to remove tags of contact(s).
|
||||
*/
|
||||
class CRM_Contact_Form_Task_RemoveFromTag extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Name of the tag.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_name;
|
||||
|
||||
/**
|
||||
* All the tags in the system.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_tags;
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
// add select for tag
|
||||
$this->_tags = CRM_Core_BAO_Tag::getTags();
|
||||
foreach ($this->_tags as $tagID => $tagName) {
|
||||
$this->_tagElement = &$this->addElement('checkbox', "tag[$tagID]", NULL, $tagName);
|
||||
}
|
||||
|
||||
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
|
||||
CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE);
|
||||
|
||||
$this->addDefaultButtons(ts('Remove Tags from Contacts'));
|
||||
}
|
||||
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Contact_Form_Task_RemoveFromTag', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
* @param $rule
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($form, $rule) {
|
||||
$errors = array();
|
||||
if (empty($form['tag']) && empty($form['contact_taglist'])) {
|
||||
$errors['_qf_default'] = "Please select atleast one tag.";
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
//get the submitted values in an array
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
$contactTags = $tagList = array();
|
||||
|
||||
// check if contact tags exists
|
||||
if (!empty($params['tag'])) {
|
||||
$contactTags = $params['tag'];
|
||||
}
|
||||
|
||||
// check if tags are selected from taglists
|
||||
if (!empty($params['contact_taglist'])) {
|
||||
foreach ($params['contact_taglist'] as $val) {
|
||||
if ($val) {
|
||||
if (is_numeric($val)) {
|
||||
$tagList[$val] = 1;
|
||||
}
|
||||
else {
|
||||
list($label, $tagID) = explode(',', $val);
|
||||
$tagList[$tagID] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$tagSets = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', FALSE, TRUE);
|
||||
|
||||
foreach ($tagSets as $key => $value) {
|
||||
$this->_tags[$key] = $value['name'];
|
||||
}
|
||||
// merge contact and taglist tags
|
||||
$allTags = CRM_Utils_Array::crmArrayMerge($contactTags, $tagList);
|
||||
|
||||
$this->_name = array();
|
||||
foreach ($allTags as $key => $dnc) {
|
||||
$this->_name[] = $this->_tags[$key];
|
||||
|
||||
list($total, $removed, $notRemoved) = CRM_Core_BAO_EntityTag::removeEntitiesFromTag($this->_contactIds, $key,
|
||||
'civicrm_contact', FALSE);
|
||||
|
||||
$status = array(
|
||||
ts('%count contact un-tagged', array(
|
||||
'count' => $removed,
|
||||
'plural' => '%count contacts un-tagged',
|
||||
)),
|
||||
);
|
||||
if ($notRemoved) {
|
||||
$status[] = ts('1 contact already did not have this tag', array(
|
||||
'count' => $notRemoved,
|
||||
'plural' => '%count contacts already did not have this tag',
|
||||
));
|
||||
}
|
||||
$status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
|
||||
CRM_Core_Session::setStatus($status, ts("Removed Tag <em>%1</em>", array(1 => $this->_tags[$key])), 'success', array('expires' => 0));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
107
sites/all/modules/civicrm/CRM/Contact/Form/Task/Result.php
Normal file
107
sites/all/modules/civicrm/CRM/Contact/Form/Task/Result.php
Normal file
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used for displaying results
|
||||
*/
|
||||
class CRM_Contact_Form_Task_Result extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
|
||||
//this is done to unset searchRows variable assign during AddToHousehold and AddToOrganization
|
||||
$this->set('searchRows', '');
|
||||
|
||||
$context = $this->get('context');
|
||||
if (in_array($context, array(
|
||||
'smog',
|
||||
'amtg',
|
||||
))) {
|
||||
$urlParams = 'reset=1&force=1&context=smog&gid=';
|
||||
$urlParams .= ($context == 'smog') ? $this->get('gid') : $this->get('amtgID');
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/group/search', $urlParams));
|
||||
return;
|
||||
}
|
||||
|
||||
$ssID = $this->get('ssID');
|
||||
|
||||
if ($this->_action == CRM_Core_Action::BASIC) {
|
||||
$fragment = 'search';
|
||||
}
|
||||
elseif ($this->_action == CRM_Core_Action::PROFILE) {
|
||||
$fragment = 'search/builder';
|
||||
}
|
||||
elseif ($this->_action == CRM_Core_Action::ADVANCED) {
|
||||
$fragment = 'search/advanced';
|
||||
}
|
||||
else {
|
||||
$fragment = 'search/custom';
|
||||
}
|
||||
|
||||
$path = 'force=1';
|
||||
if (isset($ssID)) {
|
||||
$path .= "&reset=1&ssID={$ssID}";
|
||||
}
|
||||
if (!CRM_Contact_Form_Search::isSearchContext($context)) {
|
||||
$context = 'search';
|
||||
}
|
||||
$path .= "&context=$context";
|
||||
|
||||
//set the user context for redirection of task actions
|
||||
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
|
||||
if (CRM_Utils_Rule::qfKey($qfKey)) {
|
||||
$path .= "&qfKey=$qfKey";
|
||||
}
|
||||
|
||||
$url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $path);
|
||||
$session->replaceUserContext($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'done',
|
||||
'name' => ts('Done'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
99
sites/all/modules/civicrm/CRM/Contact/Form/Task/SMS.php
Normal file
99
sites/all/modules/civicrm/CRM/Contact/Form/Task/SMS.php
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to sms a group of contacts.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_SMS extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. sending sms to one
|
||||
* specific contact?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $_single = FALSE;
|
||||
|
||||
/**
|
||||
* All the existing templates in the system.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_templates = NULL;
|
||||
|
||||
public function preProcess() {
|
||||
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
|
||||
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
|
||||
|
||||
CRM_Contact_Form_Task_SMSCommon::preProcessProvider($this);
|
||||
|
||||
if (!$cid && $this->_context != 'standalone') {
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
$this->assign('single', $this->_single);
|
||||
if (CRM_Core_Permission::check('administer CiviCRM')) {
|
||||
$this->assign('isAdmin', 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//enable form element
|
||||
$this->assign('suppressForm', FALSE);
|
||||
$this->assign('SMSTask', TRUE);
|
||||
CRM_Contact_Form_Task_SMSCommon::buildQuickForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
CRM_Contact_Form_Task_SMSCommon::postProcess($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* List available tokens for this form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listTokens() {
|
||||
$tokens = CRM_Core_SelectValues::contactTokens();
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
}
|
447
sites/all/modules/civicrm/CRM/Contact/Form/Task/SMSCommon.php
Normal file
447
sites/all/modules/civicrm/CRM/Contact/Form/Task/SMSCommon.php
Normal file
|
@ -0,0 +1,447 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the common functionality for sending sms to one or a group of contact ids.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_SMSCommon {
|
||||
const RECIEVED_SMS_ACTIVITY_SUBJECT = "SMS Received";
|
||||
|
||||
public $_contactDetails = array();
|
||||
|
||||
public $_allContactDetails = array();
|
||||
|
||||
public $_toContactPhone = array();
|
||||
|
||||
|
||||
/**
|
||||
* Pre process the provider.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function preProcessProvider(&$form) {
|
||||
$form->_single = FALSE;
|
||||
$className = CRM_Utils_System::getClassName($form);
|
||||
|
||||
if (property_exists($form, '_context') &&
|
||||
$form->_context != 'search' &&
|
||||
$className == 'CRM_Contact_Form_Task_SMS'
|
||||
) {
|
||||
$form->_single = TRUE;
|
||||
}
|
||||
|
||||
$providersCount = CRM_SMS_BAO_Provider::activeProviderCount();
|
||||
|
||||
if (!$providersCount) {
|
||||
CRM_Core_Error::statusBounce(ts('There are no SMS providers configured, or no SMS providers are set active'));
|
||||
}
|
||||
|
||||
if ($className == 'CRM_Activity_Form_Task_SMS') {
|
||||
$activityCheck = 0;
|
||||
foreach ($form->_activityHolderIds as $value) {
|
||||
if (CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $value, 'subject', 'id') != self::RECIEVED_SMS_ACTIVITY_SUBJECT) {
|
||||
$activityCheck++;
|
||||
}
|
||||
}
|
||||
if ($activityCheck == count($form->_activityHolderIds)) {
|
||||
CRM_Core_Error::statusBounce(ts("The Reply SMS Could only be sent for activities with '%1' subject.",
|
||||
array(1 => self::RECIEVED_SMS_ACTIVITY_SUBJECT)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
|
||||
$toArray = array();
|
||||
|
||||
$providers = CRM_SMS_BAO_Provider::getProviders(NULL, NULL, TRUE, 'is_default desc');
|
||||
|
||||
$providerSelect = array();
|
||||
foreach ($providers as $provider) {
|
||||
$providerSelect[$provider['id']] = $provider['title'];
|
||||
}
|
||||
$suppressedSms = 0;
|
||||
//here we are getting logged in user id as array but we need target contact id. CRM-5988
|
||||
$cid = $form->get('cid');
|
||||
|
||||
if ($cid) {
|
||||
$form->_contactIds = array($cid);
|
||||
}
|
||||
|
||||
$to = $form->add('text', 'to', ts('To'), array('class' => 'huge'), TRUE);
|
||||
$form->add('text', 'activity_subject', ts('Name The SMS'), array('class' => 'huge'), TRUE);
|
||||
|
||||
$toSetDefault = TRUE;
|
||||
if (property_exists($form, '_context') && $form->_context == 'standalone') {
|
||||
$toSetDefault = FALSE;
|
||||
}
|
||||
|
||||
// when form is submitted recompute contactIds
|
||||
$allToSMS = array();
|
||||
if ($to->getValue()) {
|
||||
$allToPhone = explode(',', $to->getValue());
|
||||
|
||||
$form->_contactIds = array();
|
||||
foreach ($allToPhone as $value) {
|
||||
list($contactId, $phone) = explode('::', $value);
|
||||
if ($contactId) {
|
||||
$form->_contactIds[] = $contactId;
|
||||
$form->_toContactPhone[] = $phone;
|
||||
}
|
||||
}
|
||||
$toSetDefault = TRUE;
|
||||
}
|
||||
|
||||
//get the group of contacts as per selected by user in case of Find Activities
|
||||
if (!empty($form->_activityHolderIds)) {
|
||||
$extendTargetContacts = 0;
|
||||
$invalidActivity = 0;
|
||||
$validActivities = 0;
|
||||
foreach ($form->_activityHolderIds as $key => $id) {
|
||||
//valid activity check
|
||||
if (CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $id, 'subject', 'id') != self::RECIEVED_SMS_ACTIVITY_SUBJECT) {
|
||||
$invalidActivity++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
|
||||
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
|
||||
//target contacts limit check
|
||||
$ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $targetID));
|
||||
|
||||
if (count($ids) > 1) {
|
||||
$extendTargetContacts++;
|
||||
continue;
|
||||
}
|
||||
$validActivities++;
|
||||
$form->_contactIds = empty($form->_contactIds) ? $ids : array_unique(array_merge($form->_contactIds, $ids));
|
||||
}
|
||||
|
||||
if (!$validActivities) {
|
||||
$errorMess = "";
|
||||
if ($extendTargetContacts) {
|
||||
$errorMess = ts('One selected activity consists of more than one target contact.', array(
|
||||
'count' => $extendTargetContacts,
|
||||
'plural' => '%count selected activities consist of more than one target contact.',
|
||||
));
|
||||
}
|
||||
if ($invalidActivity) {
|
||||
$errorMess = ($errorMess ? ' ' : '');
|
||||
$errorMess .= ts('The selected activity is invalid.', array(
|
||||
'count' => $invalidActivity,
|
||||
'plural' => '%count selected activities are invalid.',
|
||||
));
|
||||
}
|
||||
CRM_Core_Error::statusBounce(ts("%1: SMS Reply will not be sent.", array(1 => $errorMess)));
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($form->_contactIds) && !empty($form->_contactIds) && $toSetDefault) {
|
||||
$returnProperties = array(
|
||||
'sort_name' => 1,
|
||||
'phone' => 1,
|
||||
'do_not_sms' => 1,
|
||||
'is_deceased' => 1,
|
||||
'display_name' => 1,
|
||||
);
|
||||
|
||||
list($form->_contactDetails) = CRM_Utils_Token::getTokenDetails($form->_contactIds,
|
||||
$returnProperties,
|
||||
FALSE,
|
||||
FALSE
|
||||
);
|
||||
|
||||
// make a copy of all contact details
|
||||
$form->_allContactDetails = $form->_contactDetails;
|
||||
|
||||
foreach ($form->_contactIds as $key => $contactId) {
|
||||
$value = $form->_contactDetails[$contactId];
|
||||
|
||||
//to check if the phone type is "Mobile"
|
||||
$phoneTypes = CRM_Core_OptionGroup::values('phone_type', TRUE, FALSE, FALSE, NULL, 'name');
|
||||
|
||||
if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Form_Task_SMS') {
|
||||
//to check for "if the contact id belongs to a specified activity type"
|
||||
// @todo use the api instead - function is deprecated.
|
||||
$actDetails = CRM_Activity_BAO_Activity::getContactActivity($contactId);
|
||||
if (self::RECIEVED_SMS_ACTIVITY_SUBJECT !=
|
||||
CRM_Utils_Array::retrieveValueRecursive($actDetails, 'subject')
|
||||
) {
|
||||
$suppressedSms++;
|
||||
unset($form->_contactDetails[$contactId]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ((isset($value['phone_type_id']) && $value['phone_type_id'] != CRM_Utils_Array::value('Mobile', $phoneTypes)) || $value['do_not_sms'] || empty($value['phone']) || !empty($value['is_deceased'])) {
|
||||
|
||||
//if phone is not primary check if non-primary phone is "Mobile"
|
||||
if (!empty($value['phone'])
|
||||
&& $value['phone_type_id'] != CRM_Utils_Array::value('Mobile', $phoneTypes) && empty($value['is_deceased'])
|
||||
) {
|
||||
$filter = array('do_not_sms' => 0);
|
||||
$contactPhones = CRM_Core_BAO_Phone::allPhones($contactId, FALSE, 'Mobile', $filter);
|
||||
if (count($contactPhones) > 0) {
|
||||
$mobilePhone = CRM_Utils_Array::retrieveValueRecursive($contactPhones, 'phone');
|
||||
$form->_contactDetails[$contactId]['phone_id'] = CRM_Utils_Array::retrieveValueRecursive($contactPhones, 'id');
|
||||
$form->_contactDetails[$contactId]['phone'] = $mobilePhone;
|
||||
$form->_contactDetails[$contactId]['phone_type_id'] = CRM_Utils_Array::value('Mobile', $phoneTypes);
|
||||
}
|
||||
else {
|
||||
$suppressedSms++;
|
||||
unset($form->_contactDetails[$contactId]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$suppressedSms++;
|
||||
unset($form->_contactDetails[$contactId]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($mobilePhone)) {
|
||||
$phone = $mobilePhone;
|
||||
}
|
||||
elseif (empty($form->_toContactPhone)) {
|
||||
$phone = $value['phone'];
|
||||
}
|
||||
else {
|
||||
$phone = CRM_Utils_Array::value($key, $form->_toContactPhone);
|
||||
}
|
||||
|
||||
if ($phone) {
|
||||
$toArray[] = array(
|
||||
'text' => '"' . $value['sort_name'] . '" (' . $phone . ')',
|
||||
'id' => "$contactId::{$phone}",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($toArray)) {
|
||||
CRM_Core_Error::statusBounce(ts('Selected contact(s) do not have a valid Phone, or communication preferences specify DO NOT SMS, or they are deceased'));
|
||||
}
|
||||
}
|
||||
|
||||
//activity related variables
|
||||
if (isset($invalidActivity)) {
|
||||
$form->assign('invalidActivity', $invalidActivity);
|
||||
}
|
||||
if (isset($extendTargetContacts)) {
|
||||
$form->assign('extendTargetContacts', $extendTargetContacts);
|
||||
}
|
||||
|
||||
$form->assign('toContact', json_encode($toArray));
|
||||
$form->assign('suppressedSms', $suppressedSms);
|
||||
$form->assign('totalSelectedContacts', count($form->_contactIds));
|
||||
|
||||
$form->add('select', 'sms_provider_id', ts('From'), $providerSelect, TRUE);
|
||||
|
||||
CRM_Mailing_BAO_Mailing::commonCompose($form);
|
||||
|
||||
if ($form->_single) {
|
||||
// also fix the user context stack
|
||||
if ($form->_context) {
|
||||
$url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
|
||||
}
|
||||
else {
|
||||
$url = CRM_Utils_System::url('civicrm/contact/view',
|
||||
"&show=1&action=browse&cid={$form->_contactIds[0]}&selectedChild=activity"
|
||||
);
|
||||
}
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->replaceUserContext($url);
|
||||
$form->addDefaultButtons(ts('Send SMS'), 'upload', 'cancel');
|
||||
}
|
||||
else {
|
||||
$form->addDefaultButtons(ts('Send SMS'), 'upload');
|
||||
}
|
||||
|
||||
$form->addFormRule(array('CRM_Contact_Form_Task_SMSCommon', 'formRule'), $form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $dontCare
|
||||
* @param array $self
|
||||
* Additional values form 'this'.
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $dontCare, $self) {
|
||||
$errors = array();
|
||||
|
||||
$template = CRM_Core_Smarty::singleton();
|
||||
|
||||
if (empty($fields['sms_text_message'])) {
|
||||
$errors['sms_text_message'] = ts('Please provide Text message.');
|
||||
}
|
||||
else {
|
||||
if (!empty($fields['sms_text_message'])) {
|
||||
$messageCheck = CRM_Utils_Array::value('sms_text_message', $fields);
|
||||
$messageCheck = str_replace("\r\n", "\n", $messageCheck);
|
||||
if ($messageCheck && (strlen($messageCheck) > CRM_SMS_Provider::MAX_SMS_CHAR)) {
|
||||
$errors['sms_text_message'] = ts("You can configure the SMS message body up to %1 characters", array(1 => CRM_SMS_Provider::MAX_SMS_CHAR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Added for CRM-1393
|
||||
if (!empty($fields['SMSsaveTemplate']) && empty($fields['SMSsaveTemplateName'])) {
|
||||
$errors['SMSsaveTemplateName'] = ts("Enter name to save message template");
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function postProcess(&$form) {
|
||||
|
||||
// check and ensure that
|
||||
$thisValues = $form->controller->exportValues($form->getName());
|
||||
|
||||
$fromSmsProviderId = $thisValues['sms_provider_id'];
|
||||
|
||||
// process message template
|
||||
if (!empty($thisValues['SMSsaveTemplate']) || !empty($thisValues['SMSupdateTemplate'])) {
|
||||
$messageTemplate = array(
|
||||
'msg_text' => $thisValues['sms_text_message'],
|
||||
'is_active' => TRUE,
|
||||
'is_sms' => TRUE,
|
||||
);
|
||||
|
||||
if (!empty($thisValues['SMSsaveTemplate'])) {
|
||||
$messageTemplate['msg_title'] = $thisValues['SMSsaveTemplateName'];
|
||||
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
|
||||
}
|
||||
|
||||
if (!empty($thisValues['SMStemplate']) && !empty($thisValues['SMSupdateTemplate'])) {
|
||||
$messageTemplate['id'] = $thisValues['SMStemplate'];
|
||||
unset($messageTemplate['msg_title']);
|
||||
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
// format contact details array to handle multiple sms from same contact
|
||||
$formattedContactDetails = array();
|
||||
$tempPhones = array();
|
||||
|
||||
foreach ($form->_contactIds as $key => $contactId) {
|
||||
$phone = $form->_toContactPhone[$key];
|
||||
|
||||
if ($phone) {
|
||||
$phoneKey = "{$contactId}::{$phone}";
|
||||
if (!in_array($phoneKey, $tempPhones)) {
|
||||
$tempPhones[] = $phoneKey;
|
||||
if (!empty($form->_contactDetails[$contactId])) {
|
||||
$formattedContactDetails[] = $form->_contactDetails[$contactId];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// $smsParams carries all the arguments provided on form (or via hooks), to the provider->send() method
|
||||
// this gives flexibity to the users / implementors to add their own args via hooks specific to their sms providers
|
||||
$smsParams = $thisValues;
|
||||
unset($smsParams['sms_text_message']);
|
||||
$smsParams['provider_id'] = $fromSmsProviderId;
|
||||
$contactIds = array_keys($form->_contactDetails);
|
||||
$allContactIds = array_keys($form->_allContactDetails);
|
||||
|
||||
list($sent, $activityId, $countSuccess) = CRM_Activity_BAO_Activity::sendSMS($formattedContactDetails,
|
||||
$thisValues,
|
||||
$smsParams,
|
||||
$contactIds
|
||||
);
|
||||
|
||||
if ($countSuccess > 0) {
|
||||
CRM_Core_Session::setStatus(ts('One message was sent successfully.', array(
|
||||
'plural' => '%count messages were sent successfully.',
|
||||
'count' => $countSuccess,
|
||||
)), ts('Message Sent', array('plural' => 'Messages Sent', 'count' => $countSuccess)), 'success');
|
||||
}
|
||||
|
||||
if (is_array($sent)) {
|
||||
// At least one PEAR_Error object was generated.
|
||||
// Display the error messages to the user.
|
||||
$status = '<ul>';
|
||||
foreach ($sent as $errMsg) {
|
||||
$status .= '<li>' . $errMsg . '</li>';
|
||||
}
|
||||
$status .= '</ul>';
|
||||
CRM_Core_Session::setStatus($status, ts('One Message Not Sent', array(
|
||||
'count' => count($sent),
|
||||
'plural' => '%count Messages Not Sent',
|
||||
)), 'info');
|
||||
}
|
||||
else {
|
||||
//Display the name and number of contacts for those sms is not sent.
|
||||
$smsNotSent = array_diff_assoc($allContactIds, $contactIds);
|
||||
|
||||
if (!empty($smsNotSent)) {
|
||||
$not_sent = array();
|
||||
foreach ($smsNotSent as $index => $contactId) {
|
||||
$displayName = $form->_allContactDetails[$contactId]['display_name'];
|
||||
$phone = $form->_allContactDetails[$contactId]['phone'];
|
||||
$contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=$contactId");
|
||||
$not_sent[] = "<a href='$contactViewUrl' title='$phone'>$displayName</a>";
|
||||
}
|
||||
$status = '(' . ts('because no phone number on file or communication preferences specify DO NOT SMS or Contact is deceased');
|
||||
if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Form_Task_SMS') {
|
||||
$status .= ' ' . ts("or the contact is not part of the activity '%1'", array(1 => self::RECIEVED_SMS_ACTIVITY_SUBJECT));
|
||||
}
|
||||
$status .= ')<ul><li>' . implode('</li><li>', $not_sent) . '</li></ul>';
|
||||
CRM_Core_Session::setStatus($status, ts('One Message Not Sent', array(
|
||||
'count' => count($smsNotSent),
|
||||
'plural' => '%count Messages Not Sent',
|
||||
)), 'info');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
273
sites/all/modules/civicrm/CRM/Contact/Form/Task/SaveSearch.php
Normal file
273
sites/all/modules/civicrm/CRM/Contact/Form/Task/SaveSearch.php
Normal file
|
@ -0,0 +1,273 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to save a search.
|
||||
*
|
||||
* Saved Searches are used for saving frequently used queries
|
||||
*/
|
||||
class CRM_Contact_Form_Task_SaveSearch extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Saved search id if any.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_id = NULL;
|
||||
|
||||
// get the submitted values of the search form
|
||||
// we'll need to get fv from either search or adv search in the future
|
||||
if ($this->_action == CRM_Core_Action::ADVANCED) {
|
||||
$values = $this->controller->exportValues('Advanced');
|
||||
}
|
||||
elseif ($this->_action == CRM_Core_Action::PROFILE) {
|
||||
$values = $this->controller->exportValues('Builder');
|
||||
}
|
||||
elseif ($this->_action == CRM_Core_Action::COPY) {
|
||||
$values = $this->controller->exportValues('Custom');
|
||||
}
|
||||
else {
|
||||
$values = $this->controller->exportValues('Basic');
|
||||
}
|
||||
|
||||
$this->_task = CRM_Utils_Array::value('task', $values);
|
||||
$crmContactTaskTasks = CRM_Contact_Task::taskTitles();
|
||||
$this->assign('taskName', CRM_Utils_Array::value($this->_task, $crmContactTaskTasks));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* It consists of
|
||||
* - displaying the QILL (query in local language)
|
||||
* - displaying elements for saving the search
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
// @todo sync this more with CRM_Group_Form_Edit.
|
||||
$query = new CRM_Contact_BAO_Query($this->get('queryParams'));
|
||||
$this->assign('qill', $query->qill());
|
||||
|
||||
// Values from the search form
|
||||
$formValues = $this->controller->exportValues();
|
||||
|
||||
// the name and description are actually stored with the group and not the saved search
|
||||
$this->add('text', 'title', ts('Name'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'), TRUE
|
||||
);
|
||||
|
||||
$this->addElement('textarea', 'description', ts('Description'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description')
|
||||
);
|
||||
|
||||
$groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE);
|
||||
unset($groupTypes['Access Control']);
|
||||
if (!CRM_Core_Permission::access('CiviMail')) {
|
||||
$isWorkFlowEnabled = CRM_Mailing_Info::workflowEnabled();
|
||||
if ($isWorkFlowEnabled &&
|
||||
!CRM_Core_Permission::check('create mailings') &&
|
||||
!CRM_Core_Permission::check('schedule mailings') &&
|
||||
!CRM_Core_Permission::check('approve mailings')
|
||||
) {
|
||||
unset($groupTypes['Mailing List']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($groupTypes)) {
|
||||
$this->addCheckBox('group_type',
|
||||
ts('Group Type'),
|
||||
$groupTypes,
|
||||
NULL, NULL, NULL, NULL, ' '
|
||||
);
|
||||
}
|
||||
|
||||
//CRM-14190
|
||||
CRM_Group_Form_Edit::buildParentGroups($this);
|
||||
CRM_Group_Form_Edit::buildGroupOrganizations($this);
|
||||
|
||||
// get the group id for the saved search
|
||||
$groupID = NULL;
|
||||
if (isset($this->_id)) {
|
||||
$groupID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group',
|
||||
$this->_id,
|
||||
'id',
|
||||
'saved_search_id'
|
||||
);
|
||||
$this->addDefaultButtons(ts('Update Smart Group'));
|
||||
}
|
||||
else {
|
||||
$this->addDefaultButtons(ts('Save Smart Group'));
|
||||
$this->assign('partiallySelected', $formValues['radio_ts'] != 'ts_all');
|
||||
}
|
||||
$this->addRule('title', ts('Name already exists in Database.'),
|
||||
'objectExists', array('CRM_Contact_DAO_Group', $groupID, 'title')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// saved search form values
|
||||
// get form values of all the forms in this controller
|
||||
$formValues = $this->controller->exportValues();
|
||||
|
||||
$isAdvanced = $this->get('isAdvanced');
|
||||
$isSearchBuilder = $this->get('isSearchBuilder');
|
||||
|
||||
// add mapping record only for search builder saved search
|
||||
$mappingId = NULL;
|
||||
if ($isAdvanced == '2' && $isSearchBuilder == '1') {
|
||||
//save the mapping for search builder
|
||||
|
||||
if (!$this->_id) {
|
||||
//save record in mapping table
|
||||
$mappingParams = array(
|
||||
'mapping_type_id' => CRM_Core_OptionGroup::getValue('mapping_type',
|
||||
'Search Builder',
|
||||
'name'
|
||||
),
|
||||
);
|
||||
$mapping = CRM_Core_BAO_Mapping::add($mappingParams);
|
||||
$mappingId = $mapping->id;
|
||||
}
|
||||
else {
|
||||
//get the mapping id from saved search
|
||||
|
||||
$savedSearch = new CRM_Contact_BAO_SavedSearch();
|
||||
$savedSearch->id = $this->_id;
|
||||
$savedSearch->find(TRUE);
|
||||
$mappingId = $savedSearch->mapping_id;
|
||||
}
|
||||
|
||||
//save mapping fields
|
||||
CRM_Core_BAO_Mapping::saveMappingFields($formValues, $mappingId);
|
||||
}
|
||||
|
||||
//save the search
|
||||
$savedSearch = new CRM_Contact_BAO_SavedSearch();
|
||||
$savedSearch->id = $this->_id;
|
||||
$queryParams = $this->get('queryParams');
|
||||
|
||||
// Use the query parameters rather than the form values - these have already been assessed / converted
|
||||
// with the extra knowledge that the form has.
|
||||
// Note that we want to move towards a standardised way of saving the query that is not
|
||||
// an exact match for the form requirements & task the form layer with converting backwards and forwards.
|
||||
// Ideally per CRM-17075 we will use entity reference fields heavily in the form layer & convert to the
|
||||
// sql operator syntax at the query layer.
|
||||
if (!$isSearchBuilder) {
|
||||
CRM_Contact_BAO_SavedSearch::saveRelativeDates($queryParams, $formValues);
|
||||
CRM_Contact_BAO_SavedSearch::saveSkippedElement($queryParams, $formValues);
|
||||
$savedSearch->form_values = serialize($queryParams);
|
||||
}
|
||||
else {
|
||||
// We want search builder to be able to convert back & forth at the form layer
|
||||
// to a standardised style - but it can't yet!
|
||||
$savedSearch->form_values = serialize($formValues);
|
||||
}
|
||||
|
||||
$savedSearch->mapping_id = $mappingId;
|
||||
$savedSearch->search_custom_id = $this->get('customSearchID');
|
||||
$savedSearch->save();
|
||||
$this->set('ssID', $savedSearch->id);
|
||||
CRM_Core_Session::setStatus(ts("Your smart group has been saved as '%1'.", array(1 => $formValues['title'])), ts('Group Saved'), 'success');
|
||||
|
||||
// also create a group that is associated with this saved search only if new saved search
|
||||
$params = array();
|
||||
$params['title'] = $formValues['title'];
|
||||
$params['description'] = $formValues['description'];
|
||||
if (isset($formValues['group_type']) &&
|
||||
is_array($formValues['group_type'])
|
||||
) {
|
||||
$params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
|
||||
array_keys($formValues['group_type'])
|
||||
) . CRM_Core_DAO::VALUE_SEPARATOR;
|
||||
}
|
||||
else {
|
||||
$params['group_type'] = '';
|
||||
}
|
||||
$params['visibility'] = 'User and User Admin Only';
|
||||
$params['saved_search_id'] = $savedSearch->id;
|
||||
$params['is_active'] = 1;
|
||||
|
||||
//CRM-14190
|
||||
$params['parents'] = $formValues['parents'];
|
||||
|
||||
if ($this->_id) {
|
||||
$params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id');
|
||||
}
|
||||
|
||||
$group = CRM_Contact_BAO_Group::create($params);
|
||||
|
||||
// Update mapping with the name and description of the group.
|
||||
if ($mappingId && $group) {
|
||||
$mappingParams = array(
|
||||
'id' => $mappingId,
|
||||
'name' => CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $group->id, 'name', 'id'),
|
||||
'description' => CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $group->id, 'description', 'id'),
|
||||
'mapping_type_id' => CRM_Core_OptionGroup::getValue('mapping_type',
|
||||
'Search Builder',
|
||||
'name'
|
||||
),
|
||||
);
|
||||
CRM_Core_BAO_Mapping::add($mappingParams);
|
||||
}
|
||||
|
||||
// CRM-9464
|
||||
$this->_id = $savedSearch->id;
|
||||
|
||||
//CRM-14190
|
||||
if (!empty($formValues['parents'])) {
|
||||
CRM_Contact_BAO_GroupNestingCache::update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set form defaults.
|
||||
*
|
||||
* return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (empty($defaults['parents'])) {
|
||||
$defaults['parents'] = CRM_Core_BAO_Domain::getGroupId();
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to update a saved search.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_SaveSearch_Update extends CRM_Contact_Form_Task_SaveSearch {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
$this->_id = $this->get('ssID');
|
||||
if (!$this->_id) {
|
||||
// fetch the value from the group id gid
|
||||
$gid = $this->get('gid');
|
||||
if ($gid) {
|
||||
$this->_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $gid, 'saved_search_id');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
|
||||
$defaults = array();
|
||||
$params = array();
|
||||
|
||||
$params = array('saved_search_id' => $this->_id);
|
||||
CRM_Contact_BAO_Group::retrieve($params, $defaults);
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
}
|
46
sites/all/modules/civicrm/CRM/Contact/Form/Task/Unhold.php
Normal file
46
sites/all/modules/civicrm/CRM/Contact/Form/Task/Unhold.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Class CRM_Contact_Form_Task_Unhold
|
||||
*/
|
||||
class CRM_Contact_Form_Task_Unhold extends CRM_Contact_Form_Task {
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
public function buildQuickForm() {
|
||||
$this->addDefaultButtons(ts('Unhold Email'), 'done');
|
||||
}
|
||||
|
||||
public function postProcess() {
|
||||
// Query to unhold emails of selected contacts
|
||||
$num = count($this->_contactIds);
|
||||
if ($num >= 1) {
|
||||
$queryString = "
|
||||
UPDATE civicrm_email SET on_hold = 0, hold_date = null
|
||||
WHERE on_hold = 1 AND hold_date is not null AND contact_id in (" . implode(",", $this->_contactIds) . ")";
|
||||
$result = CRM_Core_DAO::executeQuery($queryString);
|
||||
$rowCount = $result->affectedRows();
|
||||
|
||||
if ($rowCount) {
|
||||
CRM_Core_Session::setStatus(ts('%count email was found on hold and updated.', array(
|
||||
'count' => $rowCount,
|
||||
'plural' => '%count emails were found on hold and updated.',
|
||||
)), ts('Emails Restored'), 'success');
|
||||
}
|
||||
else {
|
||||
CRM_Core_Session::setStatus(ts('The selected contact does not have an email on hold.', array(
|
||||
'plural' => 'None of the selected contacts have an email on hold.',
|
||||
)), ts('No Emails to Restore'), 'info');
|
||||
}
|
||||
}
|
||||
else {
|
||||
CRM_Core_Session::setStatus(ts('Please select one or more contact for this action'), ts('No Contacts Selected'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue