| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.4 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2013 | |
| 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-2013 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | class CRM_Contact_Form_Location { |
| 36 | |
| 37 | /** |
| 38 | * Function to set variables up before form is built |
| 39 | * |
| 40 | * @return void |
| 41 | */ |
| 42 | static function preProcess(&$form) { |
| 43 | $form->_addBlockName = CRM_Utils_Request::retrieve('block', 'String', CRM_Core_DAO::$_nullObject); |
| 44 | $additionalblockCount = CRM_Utils_Request::retrieve('count', 'Positive', CRM_Core_DAO::$_nullObject); |
| 45 | |
| 46 | $form->assign('addBlock', FALSE); |
| 47 | if ($form->_addBlockName && $additionalblockCount) { |
| 48 | $form->assign('addBlock', TRUE); |
| 49 | $form->assign('blockName', $form->_addBlockName); |
| 50 | $form->assign('blockId', $additionalblockCount); |
| 51 | $form->set($form->_addBlockName . '_Block_Count', $additionalblockCount); |
| 52 | } |
| 53 | |
| 54 | $className = CRM_Utils_System::getClassName($form); |
| 55 | if (in_array($className, array( |
| 56 | 'CRM_Event_Form_ManageEvent_Location', 'CRM_Contact_Form_Domain'))) { |
| 57 | $form->_blocks = array('Address' => ts('Address'), |
| 58 | 'Email' => ts('Email'), |
| 59 | 'Phone' => ts('Phone'), |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | $form->assign('blocks', $form->_blocks); |
| 64 | $form->assign('className', $className); |
| 65 | |
| 66 | // get address sequence. |
| 67 | if (!$addressSequence = $form->get('addressSequence')) { |
| 68 | $addressSequence = CRM_Core_BAO_Address::addressSequence(); |
| 69 | $form->set('addressSequence', $addressSequence); |
| 70 | } |
| 71 | $form->assign('addressSequence', $addressSequence); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Function to build the form |
| 76 | * |
| 77 | * @return None |
| 78 | * @access public |
| 79 | */ |
| 80 | static function buildQuickForm(&$form) { |
| 81 | // required for subsequent AJAX requests. |
| 82 | $ajaxRequestBlocks = array(); |
| 83 | $generateAjaxRequest = 0; |
| 84 | |
| 85 | //build 1 instance of all blocks, without using ajax ... |
| 86 | foreach ($form->_blocks as $blockName => $label) { |
| 87 | require_once (str_replace('_', DIRECTORY_SEPARATOR, 'CRM_Contact_Form_Edit_' . $blockName) . '.php'); |
| 88 | $name = strtolower($blockName); |
| 89 | |
| 90 | $instances = array(1); |
| 91 | if (CRM_Utils_Array::value($name, $_POST) && is_array($_POST[$name])) { |
| 92 | $instances = array_keys($_POST[$name]); |
| 93 | } |
| 94 | elseif (property_exists($form, '_values') && CRM_Utils_Array::value($name, $form->_values) && is_array($form->_values[$name])) { |
| 95 | $instances = array_keys($form->_values[$name]); |
| 96 | } |
| 97 | |
| 98 | foreach ($instances as $instance) { |
| 99 | if ($instance == 1) { |
| 100 | $form->assign('addBlock', FALSE); |
| 101 | $form->assign('blockId', $instance); |
| 102 | } |
| 103 | else { |
| 104 | //we are going to build other block instances w/ AJAX |
| 105 | $generateAjaxRequest++; |
| 106 | $ajaxRequestBlocks[$blockName][$instance] = TRUE; |
| 107 | } |
| 108 | |
| 109 | $form->set($blockName . '_Block_Count', $instance); |
| 110 | $formName = 'CRM_Contact_Form_Edit_' . $blockName; |
| 111 | $formName::buildQuickForm( $form ); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | //assign to generate AJAX request for building extra blocks. |
| 116 | $form->assign('generateAjaxRequest', $generateAjaxRequest); |
| 117 | $form->assign('ajaxRequestBlocks', $ajaxRequestBlocks); |
| 118 | } |
| 119 | } |
| 120 | |