WIP(90%) - Google Maps plugin - Refs BT#11371

pull/2487/head
José Loguercio 8 years ago
parent 5582a7e452
commit c5986d080e
  1. 135
      main/admin/user_edit.php
  2. 135
      main/auth/inscription.php
  3. 135
      main/auth/profile.php
  4. 1
      plugin/google_maps/src/GoogleMapsPluginPlugin.php

@ -68,11 +68,16 @@ function confirmation(name) {
}
</script>';
$userGeolocalization = api_get_setting('enable_profile_user_address_geolocalization') == 'true';
$gMapsPlugin = GoogleMapsPlugin::create();
$geolocalization = $gMapsPlugin->get('enable_api') === 'true';
if ($geolocalization) {
$gmapsApiKey = $gMapsPlugin->get('api_key');
$htmlHeadXtra[] = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=true&key='. $gmapsApiKey . '" ></script>';
}
$htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css');
$htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js');
$htmlHeadXtra[] = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=true" ></script>';
$libpath = api_get_path(LIBRARY_PATH);
$noPHP_SELF = true;
@ -101,106 +106,6 @@ $user_data['old_password'] = $user_data['password'];
$user_data['registration_date'] = api_get_local_time($user_data['registration_date']);
unset($user_data['password']);
if ($userGeolocalization) {
$htmlHeadXtra[] = '<script>
$(document).ready(function() {
var address = "' . $user_data['address'] . '";
initializeGeo(address, false);
$("#geolocalization").on("click", function() {
var address = $("#address").val();
initializeGeo(address, false);
return false;
});
$("#myLocation").on("click", function() {
myLocation();
return false;
});
$("#address").keypress(function (event) {
if (event.which == 13) {
$("#geolocalization").click();
return false;
}
});
});
function myLocation() {
if (navigator.geolocation) {
var geoPosition = function(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var latLng = new google.maps.LatLng(lat, lng);
initializeGeo(false, latLng)
};
var geoError = function(error) {
alert("Geocode ' . get_lang('Error') . ': " + error);
};
var geoOptions = {
enableHighAccuracy: true
};
navigator.geolocation.getCurrentPosition(geoPosition, geoError, geoOptions);
}
}
function initializeGeo(address, latLng) {
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
var parameter = address ? { "address": address } : latLng ? { "latLng": latLng } : false;
if (geocoder && parameter) {
geocoder.geocode(parameter, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.setCenter(results[0].geometry.location);
if (!address) {
$("#address").val(results[0].formatted_address);
}
var infowindow = new google.maps.InfoWindow({
content: "<b>" + $("#address").val() + "</b>",
size: new google.maps.Size(150, 50)
});
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title: $("#address").val()
});
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map, marker);
});
} else {
alert("' . get_lang("NotFound") . '");
}
} else {
alert("Geocode ' . get_lang('Error') . ': " + status);
}
});
}
}
</script>';
}
// Create the form
$form = new FormValidator(
'user_edit',
@ -260,32 +165,6 @@ if (api_get_setting('openid_authentication') == 'true') {
// Phone
$form->addElement('text', 'phone', get_lang('PhoneNumber'));
if ($userGeolocalization) {
// Geolocation
$form->addElement('text', 'address', get_lang('AddressField'), ['id' => 'address']);
$form->addHtml('
<div class="form-group">
<label for="geolocalization" class="col-sm-2 control-label"></label>
<div class="col-sm-8">
<button class="null btn btn-default " id="geolocalization" name="geolocalization" type="submit"><em class="fa fa-map-marker"></em> '.get_lang('Geolocalization').'</button>
<button class="null btn btn-default " id="myLocation" name="myLocation" type="submit"><em class="fa fa-crosshairs"></em> '.get_lang('MyLocation').'</button>
</div>
</div>
');
$form->addHtml('
<div class="form-group">
<label for="map" class="col-sm-2 control-label">
'.get_lang('Map').'
</label>
<div class="col-sm-8">
<div name="map" id="map" style="width:100%; height:300px;">
</div>
</div>
</div>
');
}
// Picture
$form->addFile(
'picture',

@ -30,7 +30,13 @@ if ($allowedFieldsConfiguration !== false) {
$allowedFields = $allowedFieldsConfiguration;
}
$userGeolocalization = api_get_setting('enable_profile_user_address_geolocalization') == 'true';
$gMapsPlugin = GoogleMapsPlugin::create();
$geolocalization = $gMapsPlugin->get('enable_api') === 'true';
if ($geolocalization) {
$gmapsApiKey = $gMapsPlugin->get('api_key');
$htmlHeadXtra[] = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=true&key='. $gmapsApiKey . '" ></script>';
}
$htmlHeadXtra[] = api_get_password_checker_js('#username', '#pass1');
// User is not allowed if Terms and Conditions are disabled and
@ -48,106 +54,6 @@ if (!empty($_SESSION['user_language_choice'])) {
} else {
$user_selected_language = api_get_setting('platformLanguage');
}
$htmlHeadXtra[] = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=true" ></script>';
if ($userGeolocalization) {
$htmlHeadXtra[] = '<script>
$(document).ready(function() {
initializeGeo(false, false);
$("#geolocalization").on("click", function() {
var address = $("#address").val();
initializeGeo(address, false);
return false;
});
$("#myLocation").on("click", function() {
myLocation();
return false;
});
$("#address").keypress(function (event) {
if (event.which == 13) {
$("#geolocalization").click();
return false;
}
});
});
function myLocation() {
if (navigator.geolocation) {
var geoPosition = function(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var latLng = new google.maps.LatLng(lat, lng);
initializeGeo(false, latLng)
};
var geoError = function(error) {
alert("Geocode ' . get_lang('Error') . ': " + error);
};
var geoOptions = {
enableHighAccuracy: true
};
navigator.geolocation.getCurrentPosition(geoPosition, geoError, geoOptions);
}
}
function initializeGeo(address, latLng) {
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-75.503, 22.921);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
var parameter = address ? { "address": address } : latLng ? { "latLng": latLng } : { "address": "Google" };
if (geocoder && parameter) {
geocoder.geocode(parameter, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.setCenter(results[0].geometry.location);
if (!address) {
$("#address").val(results[0].formatted_address);
}
var infowindow = new google.maps.InfoWindow({
content: "<b>" + $("#address").val() + "</b>",
size: new google.maps.Size(150, 50)
});
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title: $("#address").val()
});
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map, marker);
});
} else {
alert("' . get_lang("NotFound") . '");
}
} else {
alert("Geocode ' . get_lang('Error') . ': " + status);
}
});
}
}
</script>';
}
$form = new FormValidator('registration');
@ -284,33 +190,6 @@ if ($user_already_registered_show_terms === false) {
);
}
}
if ($userGeolocalization) {
// Geolocation
if (in_array('address', $allowedFields)) {
$form->addElement('text', 'address', get_lang('AddressField'), ['id' => 'address']);
$form->addHtml('
<div class="form-group">
<label for="geolocalization" class="col-sm-2 control-label"></label>
<div class="col-sm-8">
<button class="null btn btn-default " id="geolocalization" name="geolocalization" type="submit"><em class="fa fa-map-marker"></em> ' . get_lang('Geolocalization') . '</button>
<button class="null btn btn-default " id="myLocation" name="myLocation" type="submit"><em class="fa fa-crosshairs"></em> ' . get_lang('MyLocation') . '</button>
</div>
</div>
');
$form->addHtml('
<div class="form-group">
<label for="map" class="col-sm-2 control-label">
' . get_lang('Map') . '
</label>
<div class="col-sm-8">
<div name="map" id="map" style="width:100%; height:300px;">
</div>
</div>
</div>
');
}
}
// Language
if (in_array('language', $allowedFields)) {

@ -28,12 +28,17 @@ if (!(isset($_user['user_id']) && $_user['user_id']) || api_is_anonymous($_user[
api_not_allowed(true);
}
$userGeolocalization = api_get_setting('enable_profile_user_address_geolocalization') == 'true';
$gMapsPlugin = GoogleMapsPlugin::create();
$geolocalization = $gMapsPlugin->get('enable_api') === 'true';
if ($geolocalization) {
$gmapsApiKey = $gMapsPlugin->get('api_key');
$htmlHeadXtra[] = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=true&key='. $gmapsApiKey . '" ></script>';
}
$htmlHeadXtra[] = api_get_password_checker_js('#username', '#password1');
$htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css');
$htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js');
$htmlHeadXtra[] = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=true" ></script>';
$htmlHeadXtra[] = '<script>
$(document).ready(function() {
$("id_generate_api_key").on("click", function (e) {
@ -97,105 +102,6 @@ $id_temp_key = UserManager::get_api_key_id(api_get_user_id(), 'dokeos');
$value_array = $array_list_key[$id_temp_key];
$user_data['api_key_generate'] = $value_array;
if ($userGeolocalization) {
$htmlHeadXtra[] = '<script>
$(document).ready(function() {
var address = "' . $user_data['address'] . '";
initializeGeo(address, false);
$("#geolocalization").on("click", function() {
var address = $("#address").val();
initializeGeo(address, false);
return false;
});
$("#myLocation").on("click", function() {
myLocation();
return false;
});
$("#address").keypress(function (event) {
if (event.which == 13) {
$("#geolocalization").click();
return false;
}
});
});
function myLocation() {
if (navigator.geolocation) {
var geoPosition = function(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var latLng = new google.maps.LatLng(lat, lng);
initializeGeo(false, latLng)
};
var geoError = function(error) {
alert("Geocode ' . get_lang('Error') . ': " + error);
};
var geoOptions = {
enableHighAccuracy: true
};
navigator.geolocation.getCurrentPosition(geoPosition, geoError, geoOptions);
}
}
function initializeGeo(address, latLng) {
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
var parameter = address ? { "address": address } : latLng ? { "latLng": latLng } : false;
if (geocoder && parameter) {
geocoder.geocode(parameter, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.setCenter(results[0].geometry.location);
if (!address) {
$("#address").val(results[0].formatted_address);
}
var infowindow = new google.maps.InfoWindow({
content: "<b>" + $("#address").val() + "</b>",
size: new google.maps.Size(150, 50)
});
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title: $("#address").val()
});
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map, marker);
});
} else {
alert("' . get_lang("NotFound") . '");
}
} else {
alert("Geocode ' . get_lang('Error') . ': " + status);
}
});
}
}
</script>';
}
if ($user_data !== false) {
if (api_get_setting('login_is_email') == 'true') {
$user_data['username'] = $user_data['email'];
@ -295,33 +201,6 @@ $form->applyFilter('phone', 'stripslashes');
$form->applyFilter('phone', 'trim');
$form->applyFilter('phone', 'html_filter');
if ($userGeolocalization) {
// Geolocation
$form->addElement('text', 'address', get_lang('AddressField'), ['id' => 'address']);
$form->addHtml('
<div class="form-group">
<label for="geolocalization" class="col-sm-2 control-label"></label>
<div class="col-sm-8">
<button class="null btn btn-default " id="geolocalization" name="geolocalization" type="submit"><em class="fa fa-map-marker"></em> '.get_lang('Geolocalization').'</button>
<button class="null btn btn-default " id="myLocation" name="myLocation" type="submit"><em class="fa fa-crosshairs"></em> '.get_lang('MyLocation').'</button>
</div>
</div>
');
$form->addHtml('
<div class="form-group">
<label for="map" class="col-sm-2 control-label">
'.get_lang('Map').'
</label>
<div class="col-sm-8">
<div name="map" id="map" style="width:100%; height:300px;">
</div>
</div>
</div>
');
}
// PICTURE
if (is_profile_editable() && api_get_setting('profile', 'picture') == 'true') {
$form->addFile(

@ -13,6 +13,7 @@ class GoogleMapsPlugin extends Plugin
protected function __construct()
{
$parameters = array(
'enable_api' => 'boolean',
'api_key' => 'text'
);

Loading…
Cancel
Save