Commit 5a6072f2 authored by Rajesh Kumar's avatar Rajesh Kumar
Browse files

Make extension compatible for CiviCRM version 4.7.x

parent e9afee5b
......@@ -63,8 +63,9 @@ class CRM_Civicrmpostcodelookup_Page_Afd extends CRM_Core_Page {
##Close the XML source##
fclose($filetoparse);
$config = CRM_Core_Config::singleton();
if ($config->civiVersion < 4.5) {
// Check CiviCRM version & return result as appropriate
$civiVersion = CRM_Civicrmpostcodelookup_Utils::getCiviVersion();
if ($civiVersion < 4.5) {
foreach ($addresslist as $key => $val) {
echo "{$val['label']}|{$val['id']}\n";
}
......
......@@ -70,8 +70,9 @@ class CRM_Civicrmpostcodelookup_Page_Civipostcode extends CRM_Core_Page {
##Close the JSON source##
fclose($filetoparse);
$config = CRM_Core_Config::singleton();
if ($config->civiVersion < 4.5) {
// Check CiviCRM version & return result as appropriate
$civiVersion = CRM_Civicrmpostcodelookup_Utils::getCiviVersion();
if ($civiVersion < 4.5) {
foreach ($addresslist as $key => $val) {
echo "{$val['label']}|{$val['id']}\n";
}
......@@ -135,7 +136,7 @@ class CRM_Civicrmpostcodelookup_Page_Civipostcode extends CRM_Core_Page {
$addressObj = $simpleJSONData->results[0];
$address = self::formatAddressLines($addressObj);
##Close the JSON source##
fclose($filetoparse);
......@@ -167,11 +168,11 @@ class CRM_Civicrmpostcodelookup_Page_Civipostcode extends CRM_Core_Page {
->setSuOrganizationIndicator($addressObj->su_organisation_indicator)
->setDeliveryPointSuffix($addressObj->delivery_point_suffix);
$addressLines = $addressLineObj->getAddressLines();
if ($forList == FALSE) {
$address = array('id' => $addressObj->id);
}
if (!empty($addressLines[0])) {
$address["street_address"] = $addressLines[0];
}
......
......@@ -66,8 +66,9 @@ class CRM_PostcodeLookup_Page_Ajax extends CRM_Core_Page {
$response['address'] = $address;
}
$config = CRM_Core_Config::singleton();
if ($config->civiVersion < 4.5) {
// Check CiviCRM version & return result as appropriate
$civiVersion = CRM_Civicrmpostcodelookup_Utils::getCiviVersion();
if ($civiVersion < 4.5) {
foreach ($response as $key => $val) {
echo "{$val['label']}|{$val['id']}\n";
}
......
......@@ -53,8 +53,9 @@ class CRM_Civicrmpostcodelookup_Page_PostcodeAnywhere extends CRM_Core_Page {
$addresslist = self::getAddressList($simpleXMLData, $postcode);
}
$config = CRM_Core_Config::singleton();
if ($config->civiVersion < 4.5) {
// Check CiviCRM version & return result as appropriate
$civiVersion = CRM_Civicrmpostcodelookup_Utils::getCiviVersion();
if ($civiVersion < 4.5) {
foreach ($addresslist as $key => $val) {
echo "{$val['label']}|{$val['id']}\n";
}
......@@ -120,7 +121,7 @@ class CRM_Civicrmpostcodelookup_Page_PostcodeAnywhere extends CRM_Core_Page {
$address = array('id' => $moniker);
$addressItemRow = (array) $simpleXMLData->Rows;
$addressItem = (array) $addressItemRow['Row'];
$addressLineArray[] = $addressItem['@attributes']['Company'];
$addressLineArray[] = $addressItem['@attributes']['BuildingName'];
$addressLineArray[] = $addressItem['@attributes']['BuildingNumber'];
......
......@@ -102,4 +102,15 @@ class CRM_Civicrmpostcodelookup_Utils {
}
return $a_json;
}
/*
* Get CiviCRM version using SQL
* Using function to get version is not compatible with all versions
*/
public static function getCiviVersion() {
$sql = "SELECT version FROM civicrm_domain";
$dao = CRM_Core_DAO::executeQuery($sql);
$dao->fetch();
return $dao->version;
}
}
......@@ -17,10 +17,6 @@ $GLOBALS["providers"] = array(
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
*/
function civicrmpostcodelookup_civicrm_config(&$config) {
$settingsStr = CRM_Core_BAO_Setting::getItem('CiviCRM Postcode Lookup', 'api_details');
$settingsArray = unserialize($settingsStr);
$config->CiviPostCodeLookupProvider = $settingsArray['provider'];
_civicrmpostcodelookup_civix_civicrm_config($config);
}
......@@ -163,6 +159,15 @@ function civicrmpostcodelookup_civicrm_buildForm($formName, &$form) {
$formName == 'CRM_Contribute_Form_Contribution_Main' ||
$formName == 'CRM_Event_Form_ManageEvent_Location'
) {
// Assign the postcode lookup provider to form, so that we can call the related function in AJAX
$settingsStr = CRM_Core_BAO_Setting::getItem('CiviCRM Postcode Lookup', 'api_details');
$settingsArray = unserialize($settingsStr);
$form->assign('civiPostCodeLookupProvider', $settingsArray['provider']);
// Get CiviCRM version
$civiVersion = CRM_Civicrmpostcodelookup_Utils::getCiviVersion();
$form->assign('civiVersion', $civiVersion);
require_once 'CRM/Core/Resources.php';
CRM_Core_Resources::singleton()
->addScriptFile('uk.co.vedaconsulting.module.civicrmpostcodelookup', 'js/jquery.ui.autocomplete.html.js', 110, 'html-header', FALSE)
......
......@@ -21,6 +21,7 @@
<ver>4.4</ver>
<ver>4.5</ver>
<ver>4.6</ver>
<ver>4.7</ver>
</compatibility>
<comments>Developed by Veda NFP Consulting LTD.</comments>
<civix>
......
{literal}
<style type="text/css">
.ui-autocomplete { height: 200px; overflow-y: scroll; overflow-x: hidden;}
.ui-autocomplete { height: 200px; overflow-y: scroll; overflow-x: hidden;}
</style>
<script type="text/javascript">
cj(document).ready(function(){
......@@ -41,16 +41,16 @@ cj(document).ready(function(){
var addressResultsElement = '#addressResults_'+blockNo;
var minCharacters = 4;
var postcodeProvider = '{/literal}{$config->CiviPostCodeLookupProvider}{literal}';
var postcodeProvider = '{/literal}{$civiPostCodeLookupProvider}{literal}';
if (postcodeProvider !== 'civipostcode') {
cj(postcodeElement).attr("placeholder", "Type full postcode to find addresses");
minCharacters = 5;
}
cj(function() {
var sourceUrl = CRM.url('civicrm/{/literal}{$config->CiviPostCodeLookupProvider}{literal}/ajax/search', {"json": 1});
var sourceUrl = CRM.url('civicrm/{/literal}{$civiPostCodeLookupProvider}{literal}/ajax/search', {"json": 1});
{/literal}{if $config->civiVersion < 4.5}{literal}
{/literal}{if $civiVersion < 4.5}{literal}
cj( postcodeElement ).autocomplete( sourceUrl, {
width: 400,
......@@ -162,7 +162,7 @@ cj(document).ready(function(){
function findAddressValues(id , blockNo, blockPrefix) {
cj('#loaderimage_'+blockNo).show();
setAddressFields(false, blockNo, blockPrefix);
var sourceUrl = CRM.url('civicrm/{/literal}{$config->CiviPostCodeLookupProvider}{literal}/ajax/get', {"json": 1});
var sourceUrl = CRM.url('civicrm/{/literal}{$civiPostCodeLookupProvider}{literal}/ajax/get', {"json": 1});
cj.ajax({
dataType: 'json',
data: {id: id, mode: '0'},
......
{*
+--------------------------------------------------------------------+
| CiviCRM version 4.5 |
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
......@@ -34,7 +34,7 @@
{literal}
<style type="text/css">
.ui-autocomplete { height: 200px; overflow-y: scroll; overflow-x: hidden;}
.ui-autocomplete { height: 200px; overflow-y: scroll; overflow-x: hidden;}
</style>
<script type="text/javascript">
var info = []; //Needed to access data from outside the JSON processing function
......@@ -47,16 +47,16 @@ cj(document).ready(function() {
var addressResultsElement = '#addressResults_'+blockNo;
var minCharacters = 4;
var postcodeProvider = '{/literal}{$config->CiviPostCodeLookupProvider}{literal}';
var postcodeProvider = '{/literal}{$civiPostCodeLookupProvider}{literal}';
if (postcodeProvider !== 'civipostcode') {
cj(postcodeElement).attr("placeholder", "Type full postcode to find addresses");
minCharacters = 5;
}
cj(function() {
var sourceUrl = CRM.url('civicrm/{/literal}{$config->CiviPostCodeLookupProvider}{literal}/ajax/search', {"json": 1});
var sourceUrl = CRM.url('civicrm/{/literal}{$civiPostCodeLookupProvider}{literal}/ajax/search', {"json": 1});
{/literal}{if $config->civiVersion < 4.5}{literal}
{/literal}{if $civiVersion < 4.5}{literal}
cj( postcodeElement ).autocomplete( sourceUrl, {
width: 400,
......@@ -120,7 +120,7 @@ function addslashes (str) {
function findAddressValues(id , blockNo) {
cj('#loaderimage_'+blockNo).show();
setAddressFields(false, blockNo);
var sourceUrl = CRM.url('civicrm/{/literal}{$config->CiviPostCodeLookupProvider}{literal}/ajax/get', {"json": 1});
var sourceUrl = CRM.url('civicrm/{/literal}{$civiPostCodeLookupProvider}{literal}/ajax/get', {"json": 1});
cj.ajax({
dataType: 'json',
data: {id: id},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment