| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 6 | | This work is published under the GNU AGPLv3 license with some | |
| 7 | | permitted exceptions and without any warranty. For full license | |
| 8 | | and copyright information, see https://civicrm.org/licensing | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | * @package CRM |
| 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * This class generates form components for DedupeRules. |
| 20 | */ |
| 21 | class CRM_Contact_Form_DedupeFind extends CRM_Admin_Form { |
| 22 | |
| 23 | /** |
| 24 | * Indicate if this form should warn users of unsaved changes |
| 25 | * @var bool |
| 26 | */ |
| 27 | protected $unsavedChangesWarn = FALSE; |
| 28 | |
| 29 | /** |
| 30 | * Pre processing. |
| 31 | */ |
| 32 | public function preProcess() { |
| 33 | $this->rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, FALSE, 0); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Build the form object. |
| 38 | */ |
| 39 | public function buildQuickForm() { |
| 40 | |
| 41 | $groupList = ['' => ts('- All Contacts -')] + CRM_Core_PseudoConstant::nestedGroup(); |
| 42 | |
| 43 | $this->add('select', 'group_id', ts('Select Group'), $groupList, FALSE, ['class' => 'crm-select2 huge']); |
| 44 | if (Civi::settings()->get('dedupe_default_limit')) { |
| 45 | $this->add('text', 'limit', ts('No of contacts to find matches for ')); |
| 46 | } |
| 47 | $this->addButtons([ |
| 48 | [ |
| 49 | 'type' => 'next', |
| 50 | 'name' => ts('Continue'), |
| 51 | 'isDefault' => TRUE, |
| 52 | ], |
| 53 | //hack to support cancel button functionality |
| 54 | [ |
| 55 | 'type' => 'submit', |
| 56 | 'class' => 'cancel', |
| 57 | 'icon' => 'fa-times', |
| 58 | 'name' => ts('Cancel'), |
| 59 | ], |
| 60 | ]); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Set the default values for the form. |
| 65 | * |
| 66 | * @return array |
| 67 | */ |
| 68 | public function setDefaultValues() { |
| 69 | $this->_defaults['limit'] = Civi::settings()->get('dedupe_default_limit'); |
| 70 | return $this->_defaults; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Process the form submission. |
| 75 | */ |
| 76 | public function postProcess() { |
| 77 | $values = $this->exportValues(); |
| 78 | if (!empty($_POST['_qf_DedupeFind_submit'])) { |
| 79 | //used for cancel button |
| 80 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/deduperules', 'reset=1')); |
| 81 | return; |
| 82 | } |
| 83 | $url = CRM_Utils_System::url('civicrm/contact/dedupefind', "reset=1&action=update&rgid={$this->rgid}"); |
| 84 | if ($values['group_id']) { |
| 85 | $url .= "&gid={$values['group_id']}"; |
| 86 | } |
| 87 | |
| 88 | if (!empty($values['limit'])) { |
| 89 | $url .= '&limit=' . $values['limit']; |
| 90 | } |
| 91 | |
| 92 | CRM_Utils_System::redirect($url); |
| 93 | } |
| 94 | |
| 95 | } |