Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for Address Section | |
38 | */ | |
39 | class CRM_Admin_Form_Preferences_Address extends CRM_Admin_Form_Preferences { | |
40 | function preProcess() { | |
41 | ||
42 | CRM_Utils_System::setTitle(ts('Settings - Addresses')); | |
43 | ||
44 | ||
45 | $this->_varNames = array( | |
46 | CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => | |
47 | array( | |
48 | 'address_options' => array( | |
49 | 'html_type' => 'checkboxes', | |
50 | 'title' => ts('Address Fields'), | |
51 | 'weight' => 1, | |
52 | ), | |
53 | 'address_format' => array( | |
54 | 'html_type' => 'textarea', | |
55 | 'title' => ts('Display Format'), | |
56 | 'description' => NULL, | |
57 | 'weight' => 2, | |
58 | ), | |
59 | 'mailing_format' => array( | |
60 | 'html_type' => 'textarea', | |
61 | 'title' => ts('Mailing Label Format'), | |
62 | 'description' => NULL, | |
63 | 'weight' => 3, | |
64 | ), | |
65 | ), | |
66 | CRM_Core_BAO_Setting::ADDRESS_STANDARDIZATION_PREFERENCES_NAME => | |
67 | array( | |
68 | 'address_standardization_provider' => array( | |
69 | 'html_type' => 'select', | |
70 | 'weight' => 4, | |
71 | ), | |
72 | 'address_standardization_userid' => array( | |
73 | 'html_type' => 'text', | |
74 | 'title' => ts('User ID'), | |
75 | 'description' => NULL, | |
76 | 'weight' => 5, | |
77 | ), | |
78 | 'address_standardization_url' => array( | |
79 | 'html_type' => 'text', | |
80 | 'title' => ts('Web Service URL'), | |
81 | 'description' => NULL, | |
82 | 'weight' => 6, | |
83 | ), | |
84 | ), | |
85 | ); | |
86 | ||
87 | parent::preProcess(); | |
88 | } | |
89 | ||
90 | function setDefaultValues() { | |
91 | $defaults = array(); | |
92 | $defaults['address_standardization_provider'] = $this->_config->address_standardization_provider; | |
93 | $defaults['address_standardization_userid'] = $this->_config->address_standardization_userid; | |
94 | $defaults['address_standardization_url'] = $this->_config->address_standardization_url; | |
95 | ||
96 | ||
97 | $this->addressSequence = isset($newSequence) ? $newSequence : ""; | |
98 | ||
99 | if (empty($this->_config->address_format)) { | |
100 | $defaults['address_format'] = " | |
101 | {contact.street_address} | |
102 | {contact.supplemental_address_1} | |
103 | {contact.supplemental_address_2} | |
104 | {contact.city}{, }{contact.state_province}{ }{contact.postal_code} | |
105 | {contact.country} | |
106 | "; | |
107 | } | |
108 | else { | |
109 | $defaults['address_format'] = $this->_config->address_format; | |
110 | } | |
111 | ||
112 | if (empty($this->_config->mailing_format)) { | |
113 | $defaults['mailing_format'] = " | |
114 | {contact.addressee} | |
115 | {contact.street_address} | |
116 | {contact.supplemental_address_1} | |
117 | {contact.supplemental_address_2} | |
118 | {contact.city}{, }{contact.state_province}{ }{contact.postal_code} | |
119 | {contact.country} | |
120 | "; | |
121 | } | |
122 | else { | |
123 | $defaults['mailing_format'] = $this->_config->mailing_format; | |
124 | } | |
125 | ||
126 | ||
127 | parent::cbsDefaultValues($defaults); | |
128 | ||
129 | return $defaults; | |
130 | } | |
131 | ||
132 | /** | |
133 | * Function to build the form | |
134 | * | |
355ba699 | 135 | * @return void |
6a488035 TO |
136 | * @access public |
137 | */ | |
138 | public function buildQuickForm() { | |
139 | $this->applyFilter('__ALL__', 'trim'); | |
140 | ||
141 | // Address Standardization | |
142 | $addrProviders = CRM_Core_SelectValues::addressProvider(); | |
143 | $this->addElement('select', | |
144 | 'address_standardization_provider', | |
145 | ts('Address Provider'), | |
146 | array( | |
147 | '' => '- select -') + $addrProviders | |
148 | ); | |
149 | ||
150 | $this->addFormRule(array('CRM_Admin_Form_Preferences_Address', 'formRule')); | |
151 | ||
152 | //get the tokens for Mailing Label field | |
153 | $tokens = CRM_Core_SelectValues::contactTokens(); | |
ac0a3db5 | 154 | $this->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens)); |
6a488035 TO |
155 | |
156 | parent::buildQuickForm(); | |
157 | } | |
158 | ||
159 | static function formRule($fields) { | |
160 | $p = $fields['address_standardization_provider']; | |
161 | $u = $fields['address_standardization_userid']; | |
162 | $w = $fields['address_standardization_url']; | |
163 | ||
164 | // make sure that there is a value for all of them | |
165 | // if any of them are set | |
166 | if ($p || $u || $w) { | |
167 | if (!CRM_Utils_System::checkPHPVersion(5, FALSE)) { | |
168 | $errors['_qf_default'] = ts('Address Standardization features require PHP version 5 or greater.'); | |
169 | return $errors; | |
170 | } | |
171 | ||
172 | if (!($p && $u && $w)) { | |
173 | $errors['_qf_default'] = ts('You must provide values for all three Address Standarization fields.'); | |
174 | return $errors; | |
175 | } | |
176 | } | |
177 | ||
178 | return TRUE; | |
179 | } | |
180 | ||
181 | /** | |
182 | * Function to process the form | |
183 | * | |
184 | * @access public | |
185 | * | |
355ba699 | 186 | * @return void |
6a488035 TO |
187 | */ |
188 | public function postProcess() { | |
189 | if ($this->_action == CRM_Core_Action::VIEW) { | |
190 | return; | |
191 | } | |
192 | ||
193 | $this->_params = $this->controller->exportValues($this->_name); | |
194 | ||
195 | ||
196 | // check if county option has been set | |
197 | $options = CRM_Core_OptionGroup::values('address_options', FALSE, FALSE, TRUE); | |
198 | foreach ($options as $key => $title) { | |
199 | if ($title == ts('County')) { | |
200 | // check if the $key is present in $this->_params | |
201 | if (isset($this->_params['address_options']) && | |
202 | !empty($this->_params['address_options'][$key]) | |
203 | ) { | |
204 | // print a status message to the user if county table seems small | |
205 | $sql = " | |
206 | SELECT count(*) | |
207 | FROM civicrm_county | |
208 | "; | |
209 | $countyCount = CRM_Core_DAO::singleValueQuery($sql); | |
210 | if ($countyCount < 10) { | |
5abf3b93 AH |
211 | CRM_Core_Session::setStatus(ts('You have enabled the County option. Please ensure you populate the county table in your CiviCRM Database. You can find extensions to populate counties in the ') . '<a href="https://civicrm.org/extensions/home?title=&body_value=counties">' . ts('CiviCRM Extensions Directory') . '</a>', |
212 | ts('Populate counties'), | |
6a488035 TO |
213 | "info" |
214 | ); | |
215 | } | |
216 | } | |
217 | } | |
218 | } | |
219 | ||
220 | $this->postProcessCommon(); | |
221 | } | |
222 | //end of function | |
223 | } | |
224 |