<?php
// Get Joomla! framework define( '_JEXEC', 1 );
define( '_JEXEC', 1 );
define('JPATH_BASE', '/path/to/joomla');
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
// open db
$app = &JFactory::getApplication('site');
$db =& JFactory::getDbo();
// prepare search and country strings
$search = strip_tags(trim($_GET['q']));
$country = strip_tags(trim($_GET['country']));
// prepare query
$query = $db->getQuery(true);
$query = "SELECT #__hikashop_zone_link.zone_parent_namekey, #__hikashop_zone_link.zone_child_namekey, #__hikashop_zone.zone_namekey, #__hikashop_zone.zone_name_english ";
$query .= "FROM `#__hikashop_zone_link` ";
$query .= "INNER JOIN `#__hikashop_zone` ON #__hikashop_zone_link.zone_child_namekey = #__hikashop_zone.zone_namekey ";
$query .= "AND #__hikashop_zone_link.zone_parent_namekey = '".$db->escape($country)."' ";
$query .= "AND #__hikashop_zone.zone_published = 1 ";
$query .= "AND #__hikashop_zone.zone_name_english LIKE '%".$db->escape($search)."%' ";
$query .= "ORDER BY #__hikashop_zone.zone_name_english ASC ";
$query .= "LIMIT 40";
// fetch the results
$db->setQuery($query);
$results = $db-> loadAssocList();
// validate to make sure we have a result
if(count($results) > 0){
foreach ($results as $key => $value) {
$data[] = array('id' => $value['zone_namekey'], 'text' => $value['zone_name_english']);
}
} else {
$data[] = array('id' => '0', 'text' => 'No Area Found');
}
// close database connection
$db->freeResult();
// return the result in json
echo json_encode($data);
?>
<?php
/**
* @package HikaShop for Joomla!
* @version 2.5.0
* @author hikashop.com
* @copyright (C) 2010-2015 HIKARI SOFTWARE. All rights reserved.
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/
defined('_JEXEC') or die('Restricted access');
?><?php
$name = $this->type.'_address';
$uniq_id = 'hikashop_address_'.$this->type.'_'.$this->address_id;
$pfid = '';
if(!empty($this->fieldset_id))
$pfid = '&fid='.$this->fieldset_id;
else
$this->fieldset_id = $uniq_id;
$show_url = 'address&task=show&subtask='.$this->type.'&cid='.$this->address_id.$pfid;
$save_url = 'address&task=save&subtask='.$this->type.'&cid='.$this->address_id.$pfid;
$update_url = 'address&task=edit&subtask='.$this->type.'&cid='.$this->address_id.$pfid;
$delete_url = 'address&task=delete&subtask='.$this->type.'&cid='.$this->address_id.'&'.hikashop_getFormToken().'=1';
?><div id="<?php echo $uniq_id; ?>">
<?php
if(!isset($this->edit) || $this->edit !== true ) {
?> <div class="hika_edit">
<a href="<?php echo hikashop_completeLink($update_url, true);?>" id="<?php echo $uniq_id; ?>_edit" onclick="return window.hikashop.get(this,'<?php echo $this->fieldset_id; ?>');"><img src="<?php echo HIKASHOP_IMAGES; ?>edit.png" alt=""/><span><?php echo JText::_('HIKA_EDIT'); ?></span></a>
<a href="<?php echo hikashop_completeLink($delete_url, true);?>" id="<?php echo $uniq_id; ?>_delete" onclick="return window.addressMgr.delete(this,<?php echo $this->address_id; ?>,'<?php echo $uniq_id; ?>','<?php echo $this->type; ?>');"><img src="<?php echo HIKASHOP_IMAGES; ?>delete.png" alt=""/><span><?php echo JText::_('HIKA_DELETE'); ?></span></a>
</div>
<?php
} else {
?> <div class="hika_edit">
<a href="<?php echo hikashop_completeLink($save_url, true);?>" onclick="return window.hikashop.form(this,'<?php echo $this->fieldset_id; ?>');"><img src="<?php echo HIKASHOP_IMAGES; ?>ok.png" alt=""/><span><?php echo JText::_('HIKA_SAVE'); ?></span></a>
<a href="<?php echo hikashop_completeLink($show_url, true);?>" onclick="return window.hikashop.get(this,'<?php echo $this->fieldset_id; ?>');"><img src="<?php echo HIKASHOP_IMAGES; ?>cancel.png" alt=""/><span><?php echo JText::_('HIKA_CANCEL'); ?></span></a>
</div>
<?php
}
?>
<?php
$display = 'field_backend';
if(isset($this->edit) && $this->edit === true ) {
?>
<link href="/ajax/select2.min.css" rel="stylesheet" />
<script src="/ajax/select2.min.js"></script>
<script>
jQuery(document).ready(function() {
jQuery('.<?php echo $this->type;?>_address_country').select2();
jQuery('.<?php echo $this->type;?>_address_state').select2();
});
function refresh_area(type){
jQuery('.'+type+'_address_state').html('<option value="" id="address_country_" selected="selected">Please make a selection from the list</option>').select2({
ajax: {
url: '/ajax/fetch_data.php',
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term, // search term
country: get_country(type) // call to get_country function
};
},
processResults: function (data) {
return {
results: data
};
},
cache: true
}
});
}
function get_country(type){
var country = jQuery('.'+type+'_address_country').val();
return country;
}
</script>
<table class="admintable table">
<?php
foreach($this->fields as $field){
if($field->$display && $field->field_namekey != 'address_country' && $field->field_namekey != 'address_state'){
$fieldname = $field->field_namekey;
?>
<tr class="hikashop_<?php echo $this->type;?>_address_<?php echo $fieldname;?>" id="hikashop_<?php echo $this->type; ?>_address_<?php echo $fieldname; ?>">
<td>
<div>
<label><?php echo $this->fieldsClass->trans($field->field_realname);?></label>
</div>
<?php
$onWhat = 'onchange';
if($field->field_type == 'radio')
$onWhat = 'onclick';
$field->table_name = 'order';
echo $this->fieldsClass->display(
$field,
@$this->address->$fieldname,
'data['.$name.']['.$fieldname.']',
false,
' ' . $onWhat . '="hikashopToggleFields(this.value,\''.$fieldname.'\',\''.$name.'\',0);"',
false,
$this->fields,
$this->address
);
?></td>
</tr>
<?php
}
}
?>
<tr class="hikashop_<?php echo $this->type;?>_address_address_country" id="hikashop_<?php echo $this->type; ?>_address_address_country">
<td>
<div>
<label>Country</label>
</div>
<span class="data_billing_address_address_state_container'"><select id="address_country" onChange="refresh_area('<?php echo $this->type;?>');" class="hikashop_field_dropdown <?php echo $this->type;?>_address_country" name="data[<?php echo $this->type;?>_address][address_country]" style="width: 96%">
<option value="" id="address_country_" selected="selected">Please make a selection from the list</option>
<?php
// open db
$app = &JFactory::getApplication('site');
$db =& JFactory::getDbo();
// prepare query
$query = $db->getQuery(true);
$query = "SELECT * ";
$query .= "FROM `#__hikashop_zone` ";
$query .= "WHERE zone_type = 'country' ";
$query .= "AND zone_published = 1 ";
$query .= "ORDER BY `zone_name_english` ASC";
// fetch the results
$db->setQuery($query);
$results = $db-> loadAssocList();
// validate to make sure we have a result and return
if(count($results) > 0){
foreach ($results as $result) {
echo '<option value="'.$result['zone_namekey'].'" id="address_country_'.$result['zone_namekey'].'">'.$result['zone_name_english']."</option>";
}
} else {
echo '<option>No Country Found</option>';
}
// close database connection
$db->freeResult();
?>
</select></span>
<span class="hikashop_field_required">*</span>
</td>
</tr>
<tr class="hikashop_<?php echo $this->type;?>_address_address_state" id="hikashop_<?php echo $this->type; ?>_address_address_state">
<td>
<div>
<label>City/Suburb/Area</label>
</div>
<span id="data_<?php echo $this->type;?>_address_address_state_container">
<select id="data_<?php echo $this->type;?>_address_address_state" class="hikashop_field_dropdown <?php echo $this->type;?>_address_state" name="data[<?php echo $this->type;?>_address][address_state]" style="width: 96%">
<option value="" id="data_<?php echo $this->type;?>_address_address_state_" selected="selected">Please make a selection from the list</option>
</select>
</span>
<input type="hidden" id="data_<?php echo $this->type;?>_address_address_state_default_value" name="data_<?php echo $this->type;?>_address_address_state_default_value" value="">
<span class="hikashop_field_required">*</span>
</td>
</tr>
</table>
<?php
} else {
if(false) {
?>
<table class="admintable table">
<?php
foreach($this->fields as $field){
if($field->$display){
$fieldname = $field->field_namekey;
?>
<tr class="hikashop_<?php echo $this->type;?>order_address_<?php echo $fieldname;?>">
<td class="key"><label><?php echo $this->fieldsClass->trans($field->field_realname);?></label></td>
<td><span><?php echo $this->fieldsClass->show($field, @$this->address->$fieldname);?></span></td>
</tr>
<?php
}
}
?>
</table>
<?php
} else {
?>
<div class="hikashop_address_content" onclick="return window.addressMgr.click(this,<?php echo $this->address_id;?>,'<?php echo $uniq_id; ?>','<?php echo $this->type; ?>');">
<?php
if(empty($this->addressClass))
$this->addressClass = hikashop_get('class.address');
echo $this->addressClass->displayAddress($this->fields,$this->address,'address');
?>
</div>
<?php
}
}
if(isset($this->edit) && $this->edit === true) {
echo '<input type="hidden" name="data['.$name.'][address_id]" value="'.$this->address_id.'"/>';
echo JHTML::_( 'form.token' );
}
?>
<script type="text/javascript">
if(!window.addressMgr) window.addressMgr = {};
window.addressMgr.update<?php echo ucfirst($this->type);?> = function() {
window.Oby.xRequest('<?php echo hikashop_completeLink('address&task=show&subtask='.$this->type.'_address&cid='.$this->address_id, true, false, true); ?>',{update:'<?php echo $this->fieldset_id; ?>'});
};
<?php
static $hikashop_address_show_js_init = false;
if(!$hikashop_address_show_js_init) {
$hikashop_address_show_js_init = true;
?>
window.addressMgr.delete = function(el, cid, uid, type) {
if(!confirm('<?php echo JText::_('HIKASHOP_CONFIRM_DELETE_ADDRESS', true); ?>'))
return false;
var w = window, o = w.Oby, d = document;
o.xRequest(el.href, null, function(xhr) { if(xhr.status == 200) {
if(xhr.responseText == '1') {
var target = d.getElementById(uid);
if(target) target.parentNode.removeChild(target);
window.Oby.fireAjax('hikashop_address_deleted',{'type':type,'cid':cid,'uid':uid,'el':el});
} else if(xhr.responseText != '0')
o.updateElem(uid, xhr.responseText);
}});
return false;
};
window.addressMgr.click = function(el, cid, uid, type) { window.Oby.fireAjax('hikashop_address_click',{'type':type,'cid':cid,'uid':uid,'el':el}); }
<?php
}
if(JRequest::getVar('tmpl', '') == 'component') {
if(empty($this->addressClass))
$this->addressClass = hikashop_get('class.address');
$miniFormat = $this->addressClass->miniFormat($this->address);
?>
window.Oby.fireAjax('hikashop_address_changed',{'type':'<?php echo $this->type; ?>','edit':<?php echo $this->edit?'1':'0'; ?>,'cid':<?php echo $this->address_id; ?>,'miniFormat':'<?php echo str_replace('\'','\\\'', $miniFormat); ?>'<?php
$previous_id = JRequest::getVar('previous_cid', null);
if((!empty($previous_id) || $previous_id === 0) && is_int($previous_id))
echo ',\'previous_cid\':' . $previous_id;
?>});
<?php
echo $this->init_js;
}
?>
</script>
</div>