Browse Source

Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

jmontoyaa 8 years ago
parent
commit
8a50cd1c51

+ 7 - 128
main/admin/user_edit.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',

+ 7 - 128
main/auth/inscription.php

@@ -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)) {

+ 7 - 128
main/auth/profile.php

@@ -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(

+ 4 - 0
plugin/google_maps/README.md

@@ -0,0 +1,4 @@
+Google Maps Plugin
+===================
+
+Activa la funcionalidad de mostrar mapas usando el api de google maps

+ 9 - 0
plugin/google_maps/config.php

@@ -0,0 +1,9 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * Config the plugin
+ * @author José Loguercio Silva <jose.loguercio@beeznest.com>
+ * @package chamilo.plugin.google_maps
+ */
+
+define('TABLE_GOOGLE_MAPS', 'plugin_google_maps');

+ 11 - 0
plugin/google_maps/index.php

@@ -0,0 +1,11 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * Config the plugin
+ * @author José Loguercio Silva <jose.loguercio@beeznest.com>
+ * @package chamilo.plugin.google_maps
+ */
+require_once __DIR__ . '/config.php';
+
+$googleMapsPlugin = GoogleMapsPlugin::create();
+

+ 10 - 0
plugin/google_maps/install.php

@@ -0,0 +1,10 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * Initialization install
+ * @author José Loguercio Silva <jose.loguercio@beeznest.com>
+ * @package chamilo.plugin.google_maps
+ */
+require_once __DIR__ . '/config.php';
+
+GoogleMapsPlugin::create()->install();

+ 4 - 0
plugin/google_maps/lang/english.php

@@ -0,0 +1,4 @@
+<?php
+
+$strings['plugin_title'] = "Google Maps";
+$strings['plugin_comment'] = "Active la fonctionnalité pour afficher Google Maps";

+ 4 - 0
plugin/google_maps/lang/french.php

@@ -0,0 +1,4 @@
+<?php
+
+$strings['plugin_title'] = "Google Maps";
+$strings['plugin_comment'] = "Active la fonctionnalité pour afficher Google Maps";

+ 4 - 0
plugin/google_maps/lang/spanish.php

@@ -0,0 +1,4 @@
+<?php
+
+$strings['plugin_title'] = "Google Maps";
+$strings['plugin_comment'] = "Enable the functionality to show google maps";

+ 10 - 0
plugin/google_maps/plugin.php

@@ -0,0 +1,10 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * Show google maps
+ * @author José Loguercio Silva <jose.loguercio@beeznest.com>
+ * @package chamilo.plugin.google_maps
+ */
+require_once __DIR__.'/config.php';
+
+$plugin_info = GoogleMapsPlugin::create()->get_info();

+ 62 - 0
plugin/google_maps/src/GoogleMapsPluginPlugin.php

@@ -0,0 +1,62 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * The google maps class allows to use
+ * @author José Loguercio Silva <jose.loguercio@beeznest.com>
+ * @package chamilo.plugin.google_maps
+ */
+class GoogleMapsPlugin extends Plugin
+{
+    /**
+     * Class constructor
+     */
+    protected function __construct()
+    {
+        $parameters = array(
+            'enable_api' => 'boolean',
+            'api_key' => 'text'
+        );
+
+        parent::__construct('1.0', 'José Loguercio Silva', $parameters);
+    }
+
+    /**
+     * Get the plugin Name
+     *
+     * @return string
+     */
+    public function get_name()
+    {
+        return "google_maps";
+    }
+
+    /**
+     * Instance the plugin
+     * @staticvar null $result
+     * @return GoogleMapsPlugin
+     */
+    static function create()
+    {
+        static $result = null;
+
+        return $result ? $result : $result = new self();
+    }
+
+    /**
+     * Install the plugin
+     * @return void
+     */
+    public function install()
+    {
+        return true;
+    }
+
+    /**
+     * Uninstall the plugin
+     * @return void
+     */
+    public function uninstall()
+    {
+        return true;
+    }
+}

+ 10 - 0
plugin/google_maps/uninstall.php

@@ -0,0 +1,10 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * Initialization uninstall
+ * @author José Loguercio Silva <jose.loguercio@beeznest.com>
+ * @package chamilo.plugin.google_maps
+ */
+require_once __DIR__ . '/config.php';
+
+GoogleMapsPlugin::create()->uninstall();