Commit | Line | Data |
---|---|---|
7f254ad8 AE |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.6 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2015 | | |
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-2015 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class provides the functionality to add contact(s) to Organization | |
38 | */ | |
39 | class CRM_Contact_Form_Task_AddToOrganization extends CRM_Contact_Form_Task_AddToParentClass { | |
40 | ||
41 | /** | |
42 | * Build the form object. | |
43 | */ | |
44 | public function buildQuickForm() { | |
45 | CRM_Utils_System::setTitle(ts('Add Contacts to Organization')); | |
46 | $this->addElement('text', 'name', ts('Find Target Organization')); | |
47 | ||
48 | $this->add('select', | |
49 | 'relationship_type_id', | |
50 | ts('Relationship Type'), | |
51 | array( | |
52 | '' => ts('- select -'), | |
53 | ) + | |
54 | CRM_Contact_BAO_Relationship::getRelationType("Organization"), TRUE | |
55 | ); | |
56 | ||
57 | $searchRows = $this->get('searchRows'); | |
58 | $searchCount = $this->get('searchCount'); | |
59 | if ($searchRows) { | |
60 | $checkBoxes = array(); | |
61 | $chekFlag = 0; | |
62 | foreach ($searchRows as $id => $row) { | |
63 | if (!$chekFlag) { | |
64 | $chekFlag = $id; | |
65 | } | |
66 | ||
67 | $checkBoxes[$id] = $this->createElement('radio', NULL, NULL, NULL, $id); | |
68 | } | |
69 | ||
70 | $this->addGroup($checkBoxes, 'contact_check'); | |
71 | if ($chekFlag) { | |
72 | $checkBoxes[$chekFlag]->setChecked(TRUE); | |
73 | } | |
74 | $this->assign('searchRows', $searchRows); | |
75 | } | |
76 | ||
77 | $this->assign('searchCount', $searchCount); | |
78 | $this->assign('searchDone', $this->get('searchDone')); | |
79 | $this->assign('contact_type_display', ts('Organization')); | |
80 | $this->addElement('submit', $this->getButtonName('refresh'), ts('Search'), array('class' => 'crm-form-submit')); | |
81 | $this->addElement('submit', $this->getButtonName('cancel'), ts('Cancel'), array('class' => 'crm-form-submit')); | |
82 | ||
83 | $this->addButtons(array( | |
84 | array( | |
85 | 'type' => 'next', | |
86 | 'name' => ts('Add to Organization'), | |
87 | 'isDefault' => TRUE, | |
88 | ), | |
89 | array( | |
90 | 'type' => 'cancel', | |
91 | 'name' => ts('Cancel'), | |
92 | ), | |
93 | ) | |
94 | ); | |
95 | } | |
96 | ||
97 | /** | |
98 | * Process the form after the input has been submitted and validated. | |
99 | */ | |
100 | public function postProcess() { | |
101 | // store the submitted values in an array | |
102 | $this->params = $this->controller->exportValues($this->_name); | |
103 | ||
104 | $this->set('searchDone', 0); | |
105 | if (!empty($_POST['_qf_AddToOrganization_refresh'])) { | |
106 | $searchParams['contact_type'] = array('Organization' => 'Organization'); | |
107 | $searchParams['rel_contact'] = $this->params['name']; | |
108 | $this->search($this, $searchParams); | |
109 | $this->set('searchDone', 1); | |
110 | return; | |
111 | } | |
112 | ||
113 | $this->addRelationships(); | |
114 | } | |
115 | ||
116 | } |