bebeboutik/modules/ant_changeaddress/change_address.tpl

472 lines
26 KiB
Smarty
Raw Normal View History

<link media="all" type="text/css" rel="stylesheet" href="{$base_dir_ssl}modules/ant_changeaddress/change_address.css">
{include file="$tpl_dir./breadcrumb.tpl"}
{include file="$tpl_dir./errors.tpl"}
2016-10-12 16:45:24 +02:00
<h1>{l s='Change your delivery address for this order' mod='ant_changeaddress'}</h1>
{if $current_address}
2016-10-21 11:57:17 +02:00
{if isset($confirmation)}<p class="info-success">{l s='Your delivery address has been updated' mod='ant_changeaddress'}</p>{/if}
<form action="{$request_uri|escape:'htmlall':'UTF-8'}" class="std" method="post">
<fieldset>
<h3>{$mode[$cookie->id_lang]}</h3>
2016-10-12 16:45:24 +02:00
<p class="info">{l s='For reasons of tarification, you cannot change the delivery mode' mod='ant_changeaddress'}</p>
{if $delivery_mode == "DOM"}
2016-10-14 13:55:21 +02:00
<p class="error" style="display: none;"></p>
<p class="address_delivery select">
2016-10-12 16:45:24 +02:00
<label for="id_address_delivery">{l s='Choose a delivery address:' mod='ant_changeaddress'}</label>
<select name="id_address_delivery" id="id_address_delivery" class="address_select">
{foreach from=$addresses key=k item=address}
2016-10-12 16:45:24 +02:00
<option value="{$address.id_address|intval}" {if $address.id_address == $order->id_address_delivery}selected="selected"{/if}>{$address.alias|escape:'htmlall':'UTF-8'}</option>
{/foreach}
</select>
</p>
<ul class="address_box" >
{if !empty($current_address)}
{foreach from=$current_address name=address item=line}
<li>{$line}</li>
{/foreach}
{/if}
</ul>
{elseif $delivery_mode == "BPR" || $delivery_mode == "A2P"}
2016-10-12 16:45:24 +02:00
<div class='dest-info'>
<p>
<label>{l s='Nom destinataire' mod='ant_changeaddress'}</label>
<input autocomplete="off" type="text" name="cename" value="{addslashes($address['cename'])}" />
</p>
<p>
<label>{l s='Prénom destinataire' mod='ant_changeaddress'}</label>
<input autocomplete="off" type="text" name="cefirstname" value="{addslashes($address['cefirstname'])}" />
</p>
<p>
<label>{l s='Email' mod='ant_changeaddress'}</label>
<input autocomplete="off" type="text" name="ceemail" value="{addslashes($address['ceemail'])}" />
</p>
<p>
<label>{l s='Entreprise' mod='ant_changeaddress'}</label>
<input autocomplete="off" type="text" name="cecompanyname" value="{addslashes($address['cecompanyname'])}" />
</p>
<p>
<label>{l s='Téléphone' mod='ant_changeaddress'}</label>
<input autocomplete="off" type="text" name="cephonenumber" value="{addslashes($address['cephonenumber'])}" />
</p>
</div>
<div class="pr-info">
<ul class="address_box" >
{if !empty($current_address)}
{foreach from=$current_address name=address item=line}
<li>{$line}</li>
{/foreach}
{/if}
</ul>
</div>
<p class="hidden">
<input autocomplete="off" type="hidden" name="prname" value="{addslashes($address['prname'])}" />
<input autocomplete="off" type="hidden" name="pradress1" value="{addslashes($address['pradress1'])}" />
<input autocomplete="off" type="hidden" name="pradress2" value="{addslashes($address['pradress2'])}" />
<input autocomplete="off" type="hidden" name="pradress3" value="{addslashes($address['pradress3'])}" />
<input autocomplete="off" type="hidden" name="pradress4" value="{addslashes($address['pradress4'])}" />
<input autocomplete="off" type="hidden" name="przipcode" value="{addslashes($address['przipcode'])}" />
<input autocomplete="off" type="hidden" name="prtown" value="{addslashes($address['prtown'])}" />
<input autocomplete="off" type="hidden" name="prid" value="{addslashes($address['prid'])}" />
</p>
{/if}
<p class="submit_buttons">
2016-10-13 15:53:23 +02:00
<a href="{$link->getPageLink('history.php', true)}" title="{l s='Back' mod='ant_changeaddress'}" class="button_large">{l s='Back to my commands' mod='ant_changeaddress'}</a>
{if $delivery_mode == "DOM"}
2016-10-12 16:45:24 +02:00
<a href="{$link->getPageLink('address.php', true)}" title="{l s='Add' mod='ant_changeaddress'}" class="button_large">{l s='Add a new address' mod='ant_changeaddress'}</a>
{/if}
2016-10-12 16:45:24 +02:00
<input type="submit" name="submitChangeAddress" class="button_large" value="{l s='Update Delivery address' mod='ant_changeaddress'}">
<input autocomplete="off" type="hidden" name="delivery_mode" value="{$delivery_mode}">
<input autocomplete="off" type="hidden" name="id_cart" value="{$order_cart->id}">
</p>
</fieldset>
</form>
2016-10-12 16:45:24 +02:00
{if $delivery_mode == "BPR" || $delivery_mode == "A2P"}
<form action="" id="search_pr">
<p>
<label>{l s='Search address' mod='ant_changeaddress'}</label>
<input autocomplete="off" type="text" name="search" id="search" value="{addslashes($c_address)}" />
<button id="button-search" class="button_large" onclick="return false;">{l s='search'}</button>
</p>
<div id="map_canvas"></div><div id="pr_list"><ul></ul></div>
</form>
{/if}
2016-10-12 16:45:24 +02:00
<script type="text/javascript" src="http://maps.google.com/maps/api/js"></script>
<script type="text/javascript" src="{$base_dir_ssl}js/jquery/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="{$base_dir_ssl}js/jquery/jquery.ui.map.js"></script>
<script type="text/javascript" src="{$base_dir_ssl}js/jquery/jquery.ui.map.services.js"></script>
<script type="text/javascript">
{literal}
2016-10-12 16:45:24 +02:00
function updateForm(delivery_mode, name, address1, address2, address3, address4, postcode, city, prid) {
$("input[name=prname]").val("");
$("input[name=prfirstname]").val("");
$("input[name=pradress1]").val("");
$("input[name=pradress2]").val("");
$("input[name=pradress3]").val("");
$("input[name=pradress4]").val("");
$("input[name=przipcode]").val("");
$("input[name=prtown]").val("");
$("input[name=prid]").val("");
$("input[name=prcompladress]").val("");
$("input[name=cedoorcode1]").val("");
$("input[name=cedoorcode2]").val("");
$("input[name=prname]").val(name);
$("input[name=pradress1]").val(address3);
$("input[name=pradress2]").val(address4);
$("input[name=pradress3]").val(address1);
$("input[name=pradress4]").val(address2);
$("input[name=przipcode]").val(postcode);
$("input[name=prtown]").val(city);
$("input[name=prid]").val(prid);
data = [name,address1,address2,address3,address4,postcode,city];
updateBoxAddress(data);
}
function updateBoxAddress(data){
$("ul.address_box").empty();
html = "<li>"+$("input[name=cename]").val()+" "+$("input[name=cefirstname]").val()+"</li>";
for(var i=0; i < data.length; i++){
if(data[i] != ""){
html += "<li>"+data[i]+"</li>";
}
}
html += "<li>"+$("input[name=cephonenumber]").val()+"</li>";
$("ul.address_box").append(html);
}
markers = [];
delivery_modes = {};
delivery_modes['{/literal}{$delivery_mode}{literal}'] = "{/literal}{$mode[$cookie->id_lang]}{literal}";
2016-10-12 16:45:24 +02:00
$.deparam = jq_deparam = function( params, coerce ) {
var obj = {},
coerce_types = { "true": !0, "false": !1, "null": null };
2016-10-12 16:45:24 +02:00
// Iterate over all name=value pairs.
$.each( params.replace( /\+/g, " " ).split( "&" ), function(j,v){
var param = v.split( "=" ),
key = decodeURIComponent( param[0] ),
val,
cur = obj,
i = 0,
// If key is more complex than "foo", like "a[]" or "a[b][c]", split it
// into its component parts.
keys = key.split( "][" ),
keys_last = keys.length - 1;
// If the first keys part contains [ and the last ends with ], then []
// are correctly balanced.
if ( /\[/.test( keys[0] ) && /\]$/.test( keys[ keys_last ] ) ) {
// Remove the trailing ] from the last keys part.
keys[ keys_last ] = keys[ keys_last ].replace( /\]$/, "" );
// Split first keys part into two parts on the [ and add them back onto
// the beginning of the keys array.
keys = keys.shift().split("[").concat( keys );
keys_last = keys.length - 1;
} else {
// Basic "foo" style key.
keys_last = 0;
}
// Are we dealing with a name=value pair, or just a name?
if ( param.length === 2 ) {
val = decodeURIComponent( param[1] );
// Coerce values.
if ( coerce ) {
val = val && !isNaN(val) ? +val // number
: val === "undefined" ? undefined // undefined
: coerce_types[val] !== undefined ? coerce_types[val] // true, false, null
: val; // string
}
if ( keys_last ) {
// Complex key, build deep object structure based on a few rules:
// * The "cur" pointer starts at the object top-level.
// * [] = array push (n is set to array length), [n] = array if n is
// numeric, otherwise object.
// * If at the last keys part, set the value.
// * For each keys part, if the current level is undefined create an
// object or array based on the type of the next keys part.
// * Move the "cur" pointer to the next level.
// * Rinse & repeat.
for ( ; i <= keys_last; i++ ) {
key = keys[i] === "" ? cur.length : keys[i];
cur = cur[key] = i < keys_last
? cur[key] || ( keys[i+1] && isNaN( keys[i+1] ) ? {} : [] )
: val;
}
} else {
// Simple key, even simpler rules, since only scalars and shallow
// arrays are allowed.
if ( $.isArray( obj[key] ) ) {
// val is already an array, so push on the next value.
obj[key].push( val );
2016-10-12 16:45:24 +02:00
} else if ( obj[key] !== undefined ) {
// val isn"t an array, but since a second value has been specified,
// convert val into an array.
obj[key] = [ obj[key], val ];
} else {
// val is a scalar.
obj[key] = val;
}
}
} else if ( key ) {
// No value was defined, so set something meaningful.
obj[key] = coerce
? undefined
: "";
}
});
return obj;
};
// Method: jQuery.deparam.querystring
//
// Parse the query string from a URL or the current window.location,
// deserializing it into an object, optionally coercing numbers, booleans,
// null and undefined values.
//
// Usage:
//
// > jQuery.deparam.querystring( [ url ] [, coerce ] );
//
// Arguments:
//
// url - (String) An optional params string or URL containing query string
// params to be parsed. If url is omitted, the current window.location
// is used.
// coerce - (Boolean) If true, coerces any numbers or true, false, null, and
// undefined to their actual value. Defaults to false if omitted.
//
// Returns:
//
// (Object) An object representing the deserialized params string.
// Method: jQuery.deparam.fragment
//
// Parse the fragment (hash) from a URL or the current window.location,
// deserializing it into an object, optionally coercing numbers, booleans,
// null and undefined values.
//
// Usage:
//
// > jQuery.deparam.fragment( [ url ] [, coerce ] );
//
// Arguments:
//
// url - (String) An optional params string or URL containing fragment (hash)
// params to be parsed. If url is omitted, the current window.location
// is used.
// coerce - (Boolean) If true, coerces any numbers or true, false, null, and
// undefined to their actual value. Defaults to false if omitted.
//
// Returns:
//
// (Object) An object representing the deserialized params string.
function jq_deparam_sub( is_fragment, url_or_params, coerce ) {
if ( url_or_params === undefined || typeof url_or_params === "boolean" ) {
// url_or_params not specified.
coerce = url_or_params;
url_or_params = jq_param[ is_fragment ? str_fragment : str_querystring ]();
} else {
url_or_params = is_string( url_or_params )
? url_or_params.replace( is_fragment ? re_trim_fragment : re_trim_querystring, "" )
: url_or_params;
}
return jq_deparam( url_or_params, coerce );
};
$(document).ready(function() {
$("#id_address_delivery").change(function(){
var id_address = $("#id_address_delivery").val();
$.ajax({
type: 'POST',
url: '{/literal}{$base_dir_ssl}{literal}modules/ant_changeaddress/ajax.php',
dataType: 'json',
data: {
id_order : {/literal}{$order->id}{literal},
getAD : 1,
id_address : id_address,
2016-10-14 15:10:11 +02:00
id_cart : {/literal}{$order->id_cart}{literal},
2016-10-12 16:45:24 +02:00
token : static_token
},
success: function(jsonData) {
2016-10-14 15:10:11 +02:00
$("div.error").hide();
2016-10-14 13:55:21 +02:00
if(jsonData.error == "false") {
$("p.error").hide();
$("ul.address_box").empty();
$("ul.address_box").html(jsonData.text);
2016-10-14 15:10:11 +02:00
$("input[name='submitChangeAddress']").show();
2016-10-14 13:55:21 +02:00
} else{
$("p.error").html(jsonData.text);
$("p.error").show();
2016-10-14 15:10:11 +02:00
$("input[name='submitChangeAddress']").hide();
2016-10-14 13:55:21 +02:00
}
2016-10-12 16:45:24 +02:00
},
error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to get update address \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);}
});
});
$("form input[type='text']").change(function(){
data = [$("input[name=prname]").val(),$("input[name=pradress1]").val(),$("input[name=pradress2]").val(),$("input[name=pradress3]").val(),$("input[name=pradress4]").val(),$("input[name=przipcode]").val(),$("input[name=prtown]").val()];
updateBoxAddress(data);
});
$("#map_canvas").gmap({/literal}{if $pr_coords}{literal}'{ "center": "{/literal}{$pr_coords['xcoords']}{literal},{/literal}{$pr_coords['ycoords']}{literal}"}'{/literal}{/if}{literal}).bind("init", function(ev, map) {
$("#map_canvas").gmap("search", {"address": "{/literal}{$c_address}{literal}"}, function(results, status) {
if ( status === "OK" ) {
var lat = null;
var lng = null;
if(results[0].geometry.location.H) {
lat = results[0].geometry.location.H;
lng = results[0].geometry.location.L;
} else if(results[0].geometry.location.G) {
lat = results[0].geometry.location.G;
lng = results[0].geometry.location.K;
} else {
var loc = results[0].geometry.location.toString().replace("(", "").replace(")", "").replace(" ", "").split(",");
lat = loc[0];
lng = loc[1];
}
$("#map_canvas").gmap("addMarker", {"icon": "http://static.privatesportshop.com/img/admin/marker_home.png", "idpr": "pr_home", "position": lat + "," + lng, "bounds": true}).click(function() {
$("#map_canvas").gmap("openInfoWindow", {"content": "Adresse actuelle"}, this);
});
$.ajax({
type: 'GET',
url: '{/literal}{$base_dir_ssl}{literal}modules/ant_changeaddress/ajax.php',
dataType: 'json',
data: {
id_order : {/literal}{$order->id}{literal},
id_cart : {/literal}{$order_cart->id}{literal},
getPR : 1,
h_xcoords : lat,
h_ycoords : lng,
mode : "{/literal}{$delivery_mode}{literal}",
token : static_token
},
success: function(data) {
if(data) {
for(var i=0; i < data.length; i++) {
var prtext = [delivery_modes[data[i].type], data[i].name, data[i].address1, data[i].address2, data[i].address3, data[i].address4, data[i].postcode + " " + data[i].city].filter(function(x) { return x != ""; }).join("<br />");
var prtext_action = "<br /><a class=\"maplink\" onclick=\"$(\'#pr_list li[data-index=" + i + "]\').trigger(\'click\'); return false;\">Sélectionner</a>";
markers.push($("#map_canvas").gmap("addMarker", { "id": "pr_" + data[i].id_pr, "position": data[i].xcoords + "," + data[i].ycoords, "bounds": true, "content": prtext + prtext_action }));
markers[markers.length - 1].click(function() {
$("#map_canvas").gmap("openInfoWindow", {"content": $(this).attr("content")}, this);
});
2016-10-12 16:45:24 +02:00
var litem = $("<li />").attr("data-index", i).attr("data-content", $.param(data[i])).html(prtext).click(function() {
$("#pr_list ul li").removeClass('selected');
$(this).addClass('selected');
var data = $.deparam($(this).attr("data-content"));
$.each(markers, function(id, el) {
if(el[0].id == "pr_" + data.id_pr) {
google.maps.event.trigger(el[0], "click");
}
});
$("#map_canvas").gmap("option", "center", markers[parseInt($(this).attr("data-index"))][0].getPosition());
updateForm(data.type, data.name, data.address1, data.address2, data.address3, data.address4, data.postcode, data.city, data.id_pr);
});
$("#pr_list ul").append(litem);
}
}
}
2016-10-12 16:45:24 +02:00
});
}
});
$("input#search").change(function(){
address = $(this).val();
$("#pr_list ul").empty();
$("#map_canvas").gmap("search", {"address": address}, function(results, status) {
if ( status === "OK" ) {
var lat = null;
var lng = null;
if(results[0].geometry.location.H) {
lat = results[0].geometry.location.H;
lng = results[0].geometry.location.L;
} else if(results[0].geometry.location.G) {
lat = results[0].geometry.location.G;
lng = results[0].geometry.location.K;
} else {
var loc = results[0].geometry.location.toString().replace("(", "").replace(")", "").replace(" ", "").split(",");
lat = loc[0];
lng = loc[1];
}
$("#map_canvas").gmap("addMarker", {"icon": "http://static.privatesportshop.com/img/admin/marker_home.png", "idpr": "pr_home", "position": lat + "," + lng, "bounds": true}).click(function() {
$("#map_canvas").gmap("openInfoWindow", {"content": "Adresse actuelle"}, this);
});
$.ajax({
type: 'GET',
url: '{/literal}{$base_dir_ssl}{literal}modules/ant_changeaddress/ajax.php',
dataType: 'json',
data: {
id_order : {/literal}{$order->id}{literal},
id_cart : {/literal}{$order_cart->id}{literal},
getPR : 1,
h_xcoords : lat,
h_ycoords : lng,
mode : "{/literal}{$delivery_mode}{literal}",
token : static_token
},
success: function(data) {
if(data) {
for(var i=0; i < data.length; i++) {
var prtext = [delivery_modes[data[i].type], data[i].name, data[i].address1, data[i].address2, data[i].address3, data[i].address4, data[i].postcode + " " + data[i].city].filter(function(x) { return x != ""; }).join("<br />");
var prtext_action = "<br /><a class=\"maplink\" onclick=\"$(\'#pr_list li[data-index=" + i + "]\').trigger(\'click\'); return false;\">Sélectionner</a>";
markers.push($("#map_canvas").gmap("addMarker", { "id": "pr_" + data[i].id_pr, "position": data[i].xcoords + "," + data[i].ycoords, "bounds": true, "content": prtext + prtext_action }));
markers[markers.length - 1].click(function() {
$("#map_canvas").gmap("openInfoWindow", {"content": $(this).attr("content")}, this);
});
var litem = $("<li />").attr("data-index", i).attr("data-content", $.param(data[i])).html(prtext).click(function() {
var data = $.deparam($(this).attr("data-content"));
$("#pr_list ul li").removeClass('selected');
$(this).addClass('selected');
$.each(markers, function(id, el) {
if(el[0].id == "pr_" + data.id_pr) {
google.maps.event.trigger(el[0], "click");
}
});
$("#map_canvas").gmap("option", "center", markers[parseInt($(this).attr("data-index"))][0].getPosition());
updateForm(data.type, data.name, data.address1, data.address2, data.address3, data.address4, data.postcode, data.city, data.id_pr);
});
$("#pr_list ul").append(litem);
}
}
}
});
}
});
2016-10-12 16:45:24 +02:00
});
});
});
{/literal}
</script>
{/if}