3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
28 * This file returns permissioned data required by dojo hierselect widget.
33 * call to invoke function
41 * Invoke function that redirects to respective functions
44 if (!isset($_GET['return'])) {
48 // intialize the system
49 require_once '../civicrm.config.php';
50 require_once 'CRM/Core/Config.php';
51 $config = &CRM_Core_Config
::singleton();
53 switch ($_GET['return']) {
55 return states($config);
58 return countries($config);
66 * Test Function used for new hs-widget.
69 function states(&$config) {
71 if (isset($_GET['node1'])) {
72 require_once 'CRM/Utils/Type.php';
73 $countryId = CRM_Utils_Type
::escape($_GET['node1'], 'String');
77 if (isset($_GET['name'])) {
78 $stateName = trim(CRM_Utils_Type
::escape($_GET['name'], 'String'));
79 $stateName = str_replace('*', '%', $stateName);
83 if (isset($_GET['default'])) {
84 $default = trim(CRM_Utils_Type
::escape($_GET['default'], 'Boolean'));
88 if (isset($_GET['id'])) {
89 $stateId = CRM_Utils_Type
::escape($_GET['id'], 'Positive', FALSE);
93 SELECT civicrm_state_province.name name, civicrm_state_province.id id
94 FROM civicrm_state_province
95 WHERE civicrm_state_province.country_id={$countryId}
96 AND civicrm_state_province.name LIKE LOWER('$stateName%')
100 $dao = CRM_Core_DAO
::executeQuery($query, $nullArray);
103 while ($dao->fetch()) {
104 $elements[] = array('name' => ts($dao->name
),
110 while ($dao->fetch()) {
111 if ($dao->id
== $stateId) {
112 $elements[] = array('name' => ts($dao->name
),
120 while ($dao->fetch() && $count < 5) {
121 $elements[] = array('name' => ts($dao->name
),
128 if (empty($elements)) {
129 if ($stateName != '- type first letter(s) -') {
130 $label = '- state n/a -';
133 $label = '- type first letter(s) -';
135 $elements[] = array('name' => $label,
139 elseif (!$default && !$stateId && (!$stateName ||
$stateName == '- type first letter(s) -')) {
141 $elements[] = array('name' => '- type first letter(s) -',
147 $elements[] = array('name' => '- state n/a -',
153 require_once "CRM/Utils/JSON.php";
154 echo CRM_Utils_JSON
::encode($elements, 'value');
158 * Test Function used for new hs-widget.
161 function countries(&$config) {
162 //get the country limit and restrict the combo select options
163 $limitCodes = $config->countryLimit();
164 if (!is_array($limitCodes)) {
165 $limitCodes = array($config->countryLimit
=> 1);
168 $limitCodes = array_intersect(CRM_Core_PseudoConstant
::countryIsoCode(), $limitCodes);
169 // added for testing purpose
170 //$limitCodes['1101'] = 'IN';
171 if (count($limitCodes)) {
172 $whereClause = " iso_code IN ('" . implode("', '", $limitCodes) . "')";
179 require_once 'CRM/Utils/Type.php';
182 if (isset($_GET['name'])) {
183 $name = CRM_Utils_Type
::escape($_GET['name'], 'String');
187 if (isset($_GET['id'])) {
188 $countryId = CRM_Utils_Type
::escape($_GET['id'], 'Positive', FALSE);
191 //temporary fix to handle locales other than default US,
193 if (!$countryId && $name && $config->lcMessages
!= 'en_US') {
194 $countries = CRM_Core_PseudoConstant
::country();
196 // get the country name in en_US, since db has this locale
197 $countryName = array_search($name, $countries);
200 $countryId = $countryName;
205 if (!$name && !$countryId) {
211 $name = str_replace('*', '%', $name);
212 $countryClause = " civicrm_country.name LIKE LOWER('$name%') ";
215 $countryClause = " civicrm_country.id = {$countryId} ";
221 WHERE {$countryClause}
225 $nullArray = array();
226 $dao = CRM_Core_DAO
::executeQuery($query, $nullArray);
229 while ($dao->fetch() && $count < 5) {
230 $elements[] = array('name' => ts($dao->name
),
237 if (empty($elements)) {
238 if (isset($_GET['id'])) {
242 $elements[] = array('name' => trim($name, "%"),
243 'value' => trim($name, "%"),
247 require_once "CRM/Utils/JSON.php";
248 echo CRM_Utils_JSON
::encode($elements, 'value');