6b5f37d3 |
1 | <?php |
2 | /* |
3 | +--------------------------------------------------------------------+ |
4 | | CiviCRM version 4.7 | |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | |
9 | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
11 | | under the terms of the GNU Affero General Public License | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
13 | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
17 | | See the GNU Affero General Public License for more details. | |
18 | | | |
19 | | You should have received a copy of the GNU Affero General Public | |
20 | | License and the CiviCRM Licensing Exception along | |
21 | | with this program; if not, contact CiviCRM LLC | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
25 | +--------------------------------------------------------------------+ |
26 | */ |
27 | |
28 | /** |
29 | * |
30 | * @package CRM |
31 | * @copyright CiviCRM LLC (c) 2004-2017 |
32 | */ |
33 | |
34 | /** |
35 | * This class provides the functionality to add contact(s) to Individual. |
36 | */ |
37 | class CRM_Contact_Form_Task_AddToIndividual extends CRM_Contact_Form_Task_AddToParentClass { |
38 | |
39 | /** |
40 | * Build the form object. |
41 | */ |
42 | public function buildQuickForm() { |
43 | CRM_Utils_System::setTitle(ts('Add Contacts to Individual')); |
44 | $this->addElement('text', 'name', ts('Find Target Individual')); |
45 | |
46 | $this->add('select', |
47 | 'relationship_type_id', |
48 | ts('Relationship Type'), |
49 | array( |
50 | '' => ts('- select -'), |
51 | ) + |
52 | CRM_Contact_BAO_Relationship::getRelationType("Individual"), TRUE |
53 | ); |
54 | |
55 | $searchRows = $this->get('searchRows'); |
56 | $searchCount = $this->get('searchCount'); |
57 | if ($searchRows) { |
58 | $checkBoxes = array(); |
59 | $chekFlag = 0; |
60 | foreach ($searchRows as $id => $row) { |
61 | if (!$chekFlag) { |
62 | $chekFlag = $id; |
63 | } |
64 | |
65 | $checkBoxes[$id] = $this->createElement('radio', NULL, NULL, NULL, $id); |
66 | } |
67 | |
68 | $this->addGroup($checkBoxes, 'contact_check'); |
69 | if ($chekFlag) { |
70 | $checkBoxes[$chekFlag]->setChecked(TRUE); |
71 | } |
72 | $this->assign('searchRows', $searchRows); |
73 | } |
74 | |
75 | $this->assign('searchCount', $searchCount); |
76 | $this->assign('searchDone', $this->get('searchDone')); |
77 | $this->assign('contact_type_display', ts('Individual')); |
78 | $this->addElement('submit', $this->getButtonName('refresh'), ts('Search'), array('class' => 'crm-form-submit')); |
79 | $this->addElement('submit', $this->getButtonName('cancel'), ts('Cancel'), array('class' => 'crm-form-submit')); |
80 | $this->addButtons(array( |
81 | array( |
82 | 'type' => 'next', |
83 | 'name' => ts('Add to Individual'), |
84 | 'isDefault' => TRUE, |
85 | ), |
86 | array( |
87 | 'type' => 'cancel', |
88 | 'name' => ts('Cancel'), |
89 | ), |
90 | ) |
91 | ); |
92 | } |
93 | |
94 | /** |
95 | * Process the form after the input has been submitted and validated. |
96 | */ |
97 | public function postProcess() { |
98 | // store the submitted values in an array |
99 | $this->params = $this->controller->exportValues($this->_name); |
100 | |
101 | $this->set('searchDone', 0); |
102 | if (!empty($_POST['_qf_AddToIndividual_refresh'])) { |
103 | $searchParams['contact_type'] = 'Individual'; |
104 | $searchParams['rel_contact'] = $this->params['name']; |
105 | $this->search($this, $searchParams); |
106 | $this->set('searchDone', 1); |
107 | return; |
108 | } |
109 | |
110 | $this->addRelationships(); |
111 | } |
112 | |
113 | } |