bebeboutik/adm/scaddressedit.php
2017-01-24 10:19:01 +01:00

512 lines
20 KiB
PHP

<?php
require_once(dirname(__FILE__).'/../config/config.inc.php');
require_once(dirname(__FILE__).'/init.php');
if($cookie->isLoggedBack() && $cart = Tools::getValue('id_cart')) {
$address = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE id_cart = '.pSQL(intval(Tools::getValue('id_cart'))).'
');
if($address) {
if(Tools::getValue('getPR')
&& ($h_xcoords = (float) Tools::getValue('h_xcoords'))
&& ($h_ycoords = (float) Tools::getValue('h_ycoords'))) {
$pr_list = array();
// ± 10km radius
header('Content-Type: text/json');
echo json_encode(Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'lapostews_pr`
WHERE `ycoords` >= '.(float) $h_ycoords.' - 0.02
AND `ycoords` <= '.(float) $h_ycoords.' + 0.02
AND `xcoords` >= '.(float) $h_xcoords.' - 0.01
AND `xcoords` <= '.(float) $h_xcoords.' + 0.01
'));
exit;
}
if(isset($_POST['submitSC'])) {
Db::getInstance()->Execute('UPDATE ps_socolissimo_delivery_info SET
delivery_mode = "'.pSQL(Tools::getValue('delivery_mode', '')).'",
prname = "'.pSQL(Tools::getValue('prname', '')).'",
prfirstname = "'.pSQL(Tools::getValue('prfirstname', '')).'",
cecompanyname = "'.pSQL(Tools::getValue('cecompanyname', '')).'",
cename = "'.pSQL(Tools::getValue('cename', '')).'",
cefirstname = "'.pSQL(Tools::getValue('cefirstname', '')).'",
prcompladress = "'.pSQL(Tools::getValue('prcompladress', '')).'",
pradress1 = "'.pSQL(Tools::getValue('pradress1', '')).'",
pradress2 = "'.pSQL(Tools::getValue('pradress2', '')).'",
pradress3 = "'.pSQL(Tools::getValue('pradress3', '')).'",
pradress4 = "'.pSQL(Tools::getValue('pradress4', '')).'",
przipcode = "'.pSQL(Tools::getValue('przipcode', '')).'",
prtown = "'.pSQL(Tools::getValue('prtown', '')).'",
cephonenumber = "'.pSQL(Tools::getValue('cephonenumber', '')).'",
ceemail = "'.pSQL(Tools::getValue('ceemail', '')).'",
cedeliveryinformation = "'.pSQL(Tools::getValue('cedeliveryinformation', '')).'",
cedoorcode1 = "'.pSQL(Tools::getValue('cedoorcode1', '')).'",
cedoorcode2 = "'.pSQL(Tools::getValue('cedoorcode2', '')).'",
prid = "'.pSQL(Tools::getValue('prid', '')).'"
WHERE id_cart = '.pSQL(intval(Tools::getValue('id_cart'))));
$order = Db::getInstance()->getRow('
SELECT date_add,id_order
FROM `'._DB_PREFIX_.'orders`
WHERE id_cart = '.pSQL(intval(Tools::getValue('id_cart'))).'
');
/* Log modif Address to check errors */
if($address['prfirstname'] != $address['cefirstname']
|| $address['cefirstname'] != Tools::getValue('cefirstname', '')
|| $address['cename'] != Tools::getValue('cename', '')) {
$message = 'Modification address Socol -- id_order :'.$order['id_order'];
$message .= ' -- ancien prfirstname : '.$address['prfirstname'].' remplacé par : '.Tools::getValue('prfirstname', '');
$message .= ' -- ancien cefirstname : '.$address['cefirstname'].' remplacé par : '.Tools::getValue('cefirstname', '');
$message .= ' -- ancien cename : '.$address['cename'].' remplacé par : '.Tools::getValue('cename', '');
Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'ant_log`
VALUES (
DEFAULT,
'.(int) $cookie->id_employee.',
"'.pSQL($message).'",
NOW()
)
');
}
/* mail('marion@antadis.com', '[BBB] Modif transporteur BO',
'ID Customer : ' . $address['id_customer'].
' , ID Order : ' . $order['id_order'].
' , Date Order : ' . $order['date_add'].
' , Date now : ' . date("Y-m-d H:i:s").
' , ID cart : ' . Tools::getValue('id_cart').
' , Mode en date : '.$address['delivery_mode'].' -- remplacé par : ' .Tools::getValue('delivery_mode', '').
' , Address1 en date : '.$address['pradress1'].' -- remplacé par : ' .Tools::getValue('pradress1', '').
' , Address2 en date : '.$address['pradress2'].' -- remplacé par : ' .Tools::getValue('pradress2', '').
' , Address3 en date : '.$address['pradress3'].' -- remplacé par : ' .Tools::getValue('pradress3', '').
' , Address4 en date : '.$address['pradress4'].' -- remplacé par : ' .Tools::getValue('pradress4', '').
' , Modif faite par : '.$cookie->id_employee
);*/
}
?>
<!doctype html>
<html><head>
<meta charset="utf-8" />
<style type="text/css">
body {
overflow: auto;
font-size: 12px;
color: #222222;
font-family: sans-serif;
}
label {
font-weight: bold;
display: block;
}
fieldset {
overflow: auto;
float: left;
width: 200px;
}
p {
overflow: auto;
}
#map_canvas {
width: 470px;
height: 300px;
display: inline-block;
}
h1 {
clear: both;
font-size: 16px;
padding-top: 20px;
}
#pr_list {
width: 200px;
height: 300px;
overflow-y: auto;
display: inline-block;
margin-left: 10px;
}
#pr_chooser {
clear: both;
}
#pr_chooser ul {
list-style: outside none;
margin: 0px;
padding: 0px;
}
#pr_chooser li {
cursor: pointer;
font-size: 12px;
margin: 10px 10px 10px 0px;
padding: 10px;
}
#pr_chooser li:hover {
background: #ccddee;
}
.maplink {
color: #1122ff;
cursor: pointer;
}
.maplink:hover {
text-decoration: underline;
}
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="/js/jquery/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.ui.map.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.ui.map.services.js"></script>
</head><body onunload="<?php if(isset($_POST['submitSC'])) {?>window.opener.location.reload(true);<?php } ?>" onload="<?php if(isset($_POST['submitSC'])) { ?>window.close();<?php } ?>">
<form action="" method="post">
<fieldset>
<p>
<label>Mode de livraison</label>
<select autocomplete="off" name="delivery_mode" style="width: 177px;">
<?php
$modes = array('DOM' => 'Livraison à domicile (DOM)', 'BPR' => 'Livraison en Bureau de Poste (BPR)',
'A2P' => 'Livraison Commerce de proximité (A2P)', 'MRL' => 'Livraison Commerce de proximité (MRL)', 'CMT' => 'Livraison Commerce (CMT)',
'CIT' => 'Livraison en Cityssimo (CIT)', 'ACP' => 'Agence ColiPoste (ACP)', 'CDI' => 'Centre de distribution (CDI)', 'BDP' => 'Bureau de poste Belge (BDP)',
'RDV' => 'Livraison sur Rendez-vous (RDV)');
foreach($modes as $k => $v) {
echo '<option value="'.$k.'"'.($address['delivery_mode'] == $k? ' selected="selected"': '').'>'.$v.'</option>';
}
?>
</select>
</p>
<p>
<label>Nom</label>
<input autocomplete="off" type="text" name="prname" value="<?php echo addslashes($address['prname']); ?>" />
</p>
<p>
<label>Prénom</label>
<input autocomplete="off" type="text" name="prfirstname" value="<?php echo addslashes($address['prfirstname']); ?>" />
</p>
<p>
<label>Téléphone</label>
<input autocomplete="off" type="text" name="cephonenumber" value="<?php echo addslashes($address['cephonenumber']); ?>" />
</p>
<p>
<label>Email</label>
<input autocomplete="off" type="text" name="ceemail" value="<?php echo addslashes($address['ceemail']); ?>" />
</p>
<p>
<label>Nom destinataire</label>
<input autocomplete="off" type="text" name="cename" value="<?php echo addslashes($address['cename']); ?>" />
</p>
<p>
<label>Prénom destinataire</label>
<input autocomplete="off" type="text" name="cefirstname" value="<?php echo addslashes($address['cefirstname']); ?>" />
</p>
<p>
<label>Entreprise</label>
<input autocomplete="off" type="text" name="cecompanyname" value="<?php echo addslashes($address['cecompanyname']); ?>" />
</p>
</fieldset>
<fieldset>
<p>
<label>Adresse 1</label>
<input autocomplete="off" type="text" name="pradress1" value="<?php echo addslashes($address['pradress1']); ?>" />
</p>
<p>
<label>Adresse 2</label>
<input autocomplete="off" type="text" name="pradress2" value="<?php echo addslashes($address['pradress2']); ?>" />
</p>
<p>
<label>Adresse 3</label>
<input autocomplete="off" type="text" name="pradress3" value="<?php echo addslashes($address['pradress3']); ?>" />
</p>
<p>
<label>Adresse 4</label>
<input autocomplete="off" type="text" name="pradress4" value="<?php echo addslashes($address['pradress4']); ?>" />
</p>
<p>
<label>Code postal</label>
<input autocomplete="off" type="text" name="przipcode" value="<?php echo addslashes($address['przipcode']); ?>" />
</p>
<p>
<label>Ville</label>
<input autocomplete="off" type="text" name="prtown" value="<?php echo addslashes($address['prtown']); ?>" />
</p>
</fieldset>
<fieldset>
<p>
<label>Complément d'adresse</label>
<input autocomplete="off" type="text" name="prcompladress" value="<?php echo addslashes($address['prcompladress']); ?>" />
</p>
<p>
<label>Informations sur la livraison</label>
<textarea><?php echo $address['cedeliveryinformation']; ?></textarea>
</p>
<p>
<label>Code porte 1</label>
<input autocomplete="off" type="text" name="cedoorcode1" value="<?php echo addslashes($address['cedoorcode1']); ?>" />
</p>
<p>
<label>Code porte 2</label>
<input autocomplete="off" type="text" name="cedoorcode2" value="<?php echo addslashes($address['cedoorcode2']); ?>" />
</p>
<p>
<label>ID point retrait</label>
<input autocomplete="off" type="text" name="prid" value="<?php echo addslashes($address['prid']); ?>" />
</p>
<p><input type="submit" value="Envoyer" name="submitSC" /></p>
</fieldset>
</form>
<?php
echo '
<script type="text/javascript">
<!--
markers = [];
-->
</script>
<div id="pr_chooser"><h1>Livraison hors domicile - Recherche d\'un point de retrait</h1>
<div id="map_canvas"></div><div id="pr_list"><ul></ul></div>
<script type="text/javascript">
<!--
function updateForm(delivery_mode, name, address1, address2, address3, address4, postcode, city, prid) {
$("select[name=delivery_mode]").val("");
$("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("");
$("select[name=delivery_mode]").val(delivery_mode);
$("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);
}
$.deparam = jq_deparam = function( params, coerce ) {
var obj = {},
coerce_types = { "true": !0, "false": !1, "null": null };
// 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 );
} 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() {
delivery_modes = {};
$("select[name=delivery_mode] option").each(function(id, el) {
delivery_modes[$(el).attr("value")] = $(el).text();
});
$("#map_canvas").gmap('.($pr_coords? '{ "center": "'.(float) $pr_coords['xcoords'].','.(float) $pr_coords['ycoords'].'" }': '').').bind("init", function(ev, map) {';
$current_address = htmlentities(preg_replace('/(, ){2,}/', ', ', preg_replace('/(, ){2,}/', ', ', implode(', ', array($address['pradress3'], $address['pradress4'], $address['pradress1'], $address['pradress2']))).', '.$address['przipcode'].' '.$address['prtown'].', FRANCE'));
echo '
$("#map_canvas").gmap("search", {"address": "'.$current_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);
});
$.getJSON("scaddressedit.php?id_cart='.(int) Tools::getValue('id_cart').'&getPR=1&h_xcoords=" + lat + "&h_ycoords=" + lng, 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"));
$.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);
}
}
});
}
});
});
});
-->
</script>
</div>';
?>
</body></html>
<?php
}
}
?>