Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | class CRM_Contact_Form_Location { | |
34 | ||
35 | /** | |
fe482240 | 36 | * Set variables up before form is built. |
6a488035 | 37 | * |
c490a46a | 38 | * @param CRM_Core_Form $form |
6a488035 | 39 | */ |
00be9182 | 40 | public static function preProcess(&$form) { |
a3d827a7 CW |
41 | $form->_addBlockName = CRM_Utils_Request::retrieve('block', 'String'); |
42 | $additionalblockCount = CRM_Utils_Request::retrieve('count', 'Positive'); | |
6a488035 TO |
43 | |
44 | $form->assign('addBlock', FALSE); | |
45 | if ($form->_addBlockName && $additionalblockCount) { | |
46 | $form->assign('addBlock', TRUE); | |
47 | $form->assign('blockName', $form->_addBlockName); | |
48 | $form->assign('blockId', $additionalblockCount); | |
49 | $form->set($form->_addBlockName . '_Block_Count', $additionalblockCount); | |
50 | } | |
51 | ||
1f7c9105 TM |
52 | if (is_a($form, 'CRM_Event_Form_ManageEvent_Location') |
53 | || is_a($form, 'CRM_Contact_Form_Domain')) { | |
be2fb01f | 54 | $form->_blocks = [ |
6ea503d4 | 55 | 'Address' => ts('Address'), |
6a488035 TO |
56 | 'Email' => ts('Email'), |
57 | 'Phone' => ts('Phone'), | |
be2fb01f | 58 | ]; |
6a488035 TO |
59 | } |
60 | ||
61 | $form->assign('blocks', $form->_blocks); | |
9b01cb89 | 62 | $form->assign('className', CRM_Utils_System::getClassName($form)); |
6a488035 TO |
63 | |
64 | // get address sequence. | |
65 | if (!$addressSequence = $form->get('addressSequence')) { | |
66 | $addressSequence = CRM_Core_BAO_Address::addressSequence(); | |
67 | $form->set('addressSequence', $addressSequence); | |
68 | } | |
69 | $form->assign('addressSequence', $addressSequence); | |
70 | } | |
71 | ||
72 | /** | |
fe482240 | 73 | * Build the form object. |
6a488035 | 74 | * |
c490a46a | 75 | * @param CRM_Core_Form $form |
6a488035 | 76 | */ |
00be9182 | 77 | public static function buildQuickForm(&$form) { |
6a488035 | 78 | // required for subsequent AJAX requests. |
be2fb01f | 79 | $ajaxRequestBlocks = []; |
6a488035 TO |
80 | $generateAjaxRequest = 0; |
81 | ||
82 | //build 1 instance of all blocks, without using ajax ... | |
83 | foreach ($form->_blocks as $blockName => $label) { | |
6a488035 TO |
84 | $name = strtolower($blockName); |
85 | ||
be2fb01f | 86 | $instances = [1]; |
a7488080 | 87 | if (!empty($_POST[$name]) && is_array($_POST[$name])) { |
6a488035 TO |
88 | $instances = array_keys($_POST[$name]); |
89 | } | |
8cc574cf | 90 | elseif (property_exists($form, '_values') && !empty($form->_values[$name]) && is_array($form->_values[$name])) { |
6a488035 TO |
91 | $instances = array_keys($form->_values[$name]); |
92 | } | |
93 | ||
94 | foreach ($instances as $instance) { | |
95 | if ($instance == 1) { | |
96 | $form->assign('addBlock', FALSE); | |
97 | $form->assign('blockId', $instance); | |
98 | } | |
99 | else { | |
100 | //we are going to build other block instances w/ AJAX | |
101 | $generateAjaxRequest++; | |
102 | $ajaxRequestBlocks[$blockName][$instance] = TRUE; | |
103 | } | |
104 | ||
105 | $form->set($blockName . '_Block_Count', $instance); | |
e52506b0 | 106 | $formName = 'CRM_Contact_Form_Edit_' . $blockName; |
481a74f4 | 107 | $formName::buildQuickForm($form); |
6a488035 TO |
108 | } |
109 | } | |
110 | ||
111 | //assign to generate AJAX request for building extra blocks. | |
112 | $form->assign('generateAjaxRequest', $generateAjaxRequest); | |
113 | $form->assign('ajaxRequestBlocks', $ajaxRequestBlocks); | |
114 | } | |
96025800 | 115 | |
6a488035 | 116 | } |