First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
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');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
143
sites/all/modules/civicrm/CRM/Contact/Form/Task/Useradd.php
Normal file
143
sites/all/modules/civicrm/CRM/Contact/Form/Task/Useradd.php
Normal file
|
@ -0,0 +1,143 @@
|
|||
<?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 generic to useradd.
|
||||
*/
|
||||
class CRM_Contact_Form_Task_Useradd extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The contact id, used when adding user
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_contactId;
|
||||
|
||||
/**
|
||||
* Contact.display_name of contact for whom we are adding user
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_displayName;
|
||||
|
||||
/**
|
||||
* Primary email of contact for whom we are adding user.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_email;
|
||||
|
||||
public function preProcess() {
|
||||
$params = $defaults = $ids = array();
|
||||
|
||||
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
|
||||
$params['id'] = $params['contact_id'] = $this->_contactId;
|
||||
$contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids);
|
||||
$this->_displayName = $contact->display_name;
|
||||
$this->_email = $contact->email;
|
||||
CRM_Utils_System::setTitle(ts('Create User Record for %1', array(1 => $this->_displayName)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
$defaults['contactID'] = $this->_contactId;
|
||||
$defaults['name'] = $this->_displayName;
|
||||
if (!empty($this->_email)) {
|
||||
$defaults['email'] = $this->_email[1]['email'];
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$element = $this->add('text', 'name', ts('Full Name'), array('class' => 'huge'));
|
||||
$element->freeze();
|
||||
$this->add('text', 'cms_name', ts('Username'), array('class' => 'huge'));
|
||||
$this->addRule('cms_name', 'Username is required', 'required');
|
||||
$this->add('password', 'cms_pass', ts('Password'), array('class' => 'huge'));
|
||||
$this->add('password', 'cms_confirm_pass', ts('Confirm Password'), array('class' => 'huge'));
|
||||
$this->addRule('cms_pass', 'Password is required', 'required');
|
||||
$this->addRule(array('cms_pass', 'cms_confirm_pass'), 'ERROR: Password mismatch', 'compare');
|
||||
$this->add('text', 'email', ts('Email:'), array('class' => 'huge'))->freeze();
|
||||
$this->add('hidden', 'contactID');
|
||||
|
||||
//add a rule to check username uniqueness
|
||||
$this->addFormRule(array('CRM_Contact_Form_Task_Useradd', 'usernameRule'));
|
||||
|
||||
$this->addButtons(
|
||||
array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Add'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->setDefaults($this->setDefaultValues());
|
||||
}
|
||||
|
||||
/**
|
||||
* Post process function.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// store the submitted values in an array
|
||||
$params = $this->exportValues();
|
||||
|
||||
CRM_Core_BAO_CMSUser::create($params, 'email');
|
||||
CRM_Core_Session::setStatus('', ts('User Added'), 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation Rule.
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function usernameRule($params) {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$errors = array();
|
||||
$check_params = array(
|
||||
'name' => $params['cms_name'],
|
||||
'mail' => $params['email'],
|
||||
);
|
||||
$config->userSystem->checkUserNameEmailExists($check_params, $errors);
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue