3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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.
68 function states(&$config) {
70 if (isset($_GET['node1'])) {
71 require_once 'CRM/Utils/Type.php';
72 $countryId = CRM_Utils_Type
::escape($_GET['node1'], 'String');
76 if (isset($_GET['name'])) {
77 $stateName = trim(CRM_Utils_Type
::escape($_GET['name'], 'String'));
78 $stateName = str_replace('*', '%', $stateName);
82 if (isset($_GET['default'])) {
83 $default = trim(CRM_Utils_Type
::escape($_GET['default'], 'Boolean'));
87 if (isset($_GET['id'])) {
88 $stateId = CRM_Utils_Type
::escape($_GET['id'], 'Positive', FALSE);
92 SELECT civicrm_state_province.name name, civicrm_state_province.id id
93 FROM civicrm_state_province
94 WHERE civicrm_state_province.country_id={$countryId}
95 AND civicrm_state_province.name LIKE LOWER('$stateName%')
99 $dao = CRM_Core_DAO
::executeQuery($query, $nullArray);
102 while ($dao->fetch()) {
103 $elements[] = array('name' => ts($dao->name
),
109 while ($dao->fetch()) {
110 if ($dao->id
== $stateId) {
111 $elements[] = array('name' => ts($dao->name
),
119 while ($dao->fetch() && $count < 5) {
120 $elements[] = array('name' => ts($dao->name
),
127 if (empty($elements)) {
128 if ($stateName != '- type first letter(s) -') {
129 $label = '- state n/a -';
132 $label = '- type first letter(s) -';
134 $elements[] = array('name' => $label,
138 elseif (!$default && !$stateId && (!$stateName ||
$stateName == '- type first letter(s) -')) {
140 $elements[] = array('name' => '- type first letter(s) -',
146 $elements[] = array('name' => '- state n/a -',
152 require_once "CRM/Utils/JSON.php";
153 echo CRM_Utils_JSON
::encode($elements, 'value');
157 * Test Function used for new hs-widget.
159 function countries(&$config) {
160 //get the country limit and restrict the combo select options
161 $limitCodes = $config->countryLimit();
162 if (!is_array($limitCodes)) {
163 $limitCodes = array($config->countryLimit
=> 1);
166 $limitCodes = array_intersect(CRM_Core_PseudoConstant
::countryIsoCode(), $limitCodes);
167 // added for testing purpose
168 //$limitCodes['1101'] = 'IN';
169 if (count($limitCodes)) {
170 $whereClause = " iso_code IN ('" . implode("', '", $limitCodes) . "')";
177 require_once 'CRM/Utils/Type.php';
180 if (isset($_GET['name'])) {
181 $name = CRM_Utils_Type
::escape($_GET['name'], 'String');
185 if (isset($_GET['id'])) {
186 $countryId = CRM_Utils_Type
::escape($_GET['id'], 'Positive', FALSE);
189 //temporary fix to handle locales other than default US,
191 if (!$countryId && $name && $config->lcMessages
!= 'en_US') {
192 $countries = CRM_Core_PseudoConstant
::country();
194 // get the country name in en_US, since db has this locale
195 $countryName = array_search($name, $countries);
198 $countryId = $countryName;
203 if (!$name && !$countryId) {
209 $name = str_replace('*', '%', $name);
210 $countryClause = " civicrm_country.name LIKE LOWER('$name%') ";
213 $countryClause = " civicrm_country.id = {$countryId} ";
219 WHERE {$countryClause}
223 $nullArray = array();
224 $dao = CRM_Core_DAO
::executeQuery($query, $nullArray);
227 while ($dao->fetch() && $count < 5) {
228 $elements[] = array('name' => ts($dao->name
),
235 if (empty($elements)) {
236 if (isset($_GET['id'])) {
240 $elements[] = array('name' => trim($name, "%"),
241 'value' => trim($name, "%"),
245 require_once "CRM/Utils/JSON.php";
246 echo CRM_Utils_JSON
::encode($elements, 'value');