2022-01-02 14:57:19 +01:00
package Karte ;
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
use strict ;
use warnings ;
use CGI ':standard' ;
use Lib::Config ;
use Mod::DBtank ;
use Mod::APIfunc ;
sub new {
my $ class = shift ;
my $ self = { } ;
bless ( $ self , $ class ) ;
return $ self ;
}
#Template
sub tpl () {
my $ node_meta = shift ;
my $ users_dms = shift || "" ;
my $ mode = shift || "" ;
my $ varenv = shift ;
my $ users_sharee = shift || { c_id = > 0 } ;
my $ return = shift || "" ;
my $ q = new CGI ;
my $ cf = new Config ;
my $ dbt = new DBtank ;
my $ apif = new APIfunc ;
my $ api_file = "/var/www/copri4/shareeconf/apikeys.cfg" ;
my $ aconf = Config::General - > new ( $ api_file ) ;
my % apikeyconf = $ aconf - > getall ;
#print $apikeyconf{googlemap}->{google_key};
my $ api_return = { authcookie = > '' } ;
my $ coo = $ q - > cookie ( - name = > 'domcookie' ) || $ R:: sessionid ;
( $ api_return , $ users_sharee ) = $ apif - > auth_verify ( $ q , $ coo , "" ) ;
2022-01-09 18:31:20 +01:00
my $ initMap = $ dbt - > { website } - > { $ varenv - > { syshost } } - > { initMap } ;
2022-01-21 17:26:57 +01:00
my $ map_zoom = $ dbt - > { website } - > { $ varenv - > { syshost } } - > { map_zoom } || "10" ;
2022-01-28 09:54:34 +01:00
my $ project = "all" ;
2022-01-09 18:31:20 +01:00
if ( $ dbt - > { website } - > { $ varenv - > { syshost } } - > { merchant_id } ) {
$ api_return - > { authcookie } = $ dbt - > { website } - > { $ varenv - > { syshost } } - > { merchant_id } if ( ! $ api_return - > { authcookie } ) ;
2022-01-28 09:54:34 +01:00
$ project = $ dbt - > { website } - > { $ varenv - > { syshost } } - > { project } if ( $ dbt - > { website } - > { $ varenv - > { syshost } } - > { project } ) ;
2022-01-09 18:31:20 +01:00
} elsif ( $ dbt - > { operator } - > { $ varenv - > { dbname } } - > { merchant_id } ) {
$ api_return - > { authcookie } = $ dbt - > { operator } - > { $ varenv - > { dbname } } - > { merchant_id } if ( ! $ api_return - > { authcookie } ) ;
2022-01-28 09:54:34 +01:00
$ initMap = $ dbt - > { operator } - > { $ varenv - > { dbname } } - > { initMap } if ( $ dbt - > { operator } - > { $ varenv - > { dbname } } - > { initMap } ) ;
2022-01-21 17:26:57 +01:00
$ map_zoom = $ dbt - > { operator } - > { $ varenv - > { dbname } } - > { map_zoom } if ( $ dbt - > { operator } - > { $ varenv - > { dbname } } - > { map_zoom } ) ;
2022-01-28 09:54:34 +01:00
$ project = $ dbt - > { operator } - > { $ varenv - > { dbname } } - > { project } if ( $ dbt - > { operator } - > { $ varenv - > { dbname } } - > { project } ) ;
2022-01-09 18:31:20 +01:00
} elsif ( $ dbt - > { primary } - > { $ varenv - > { dbname } } - > { merchant_id } ) {
$ api_return - > { authcookie } = $ dbt - > { primary } - > { $ varenv - > { dbname } } - > { merchant_id } if ( ! $ api_return - > { authcookie } ) ;
2022-01-28 09:54:34 +01:00
$ initMap = $ dbt - > { primary } - > { $ varenv - > { dbname } } - > { initMap } if ( $ dbt - > { primary } - > { $ varenv - > { dbname } } - > { initMap } ) ;
}
my $ icon_green = "Open_Green.png" ;
my $ icon_red = "Open_Red.png" ;
my $ icon_blue = "Open_Blue.png" ;
if ( $ project eq "Bayern" ) {
$ icon_green = "LastenradBay_Standortpfeil_gruen_03a.png" ;
$ icon_red = "LastenradBay_Standortpfeil_rot_03a.png" ;
$ icon_blue = "LastenradBay_Standortpfeil_blau_03a.png" ;
2022-01-09 18:31:20 +01:00
}
$ users_sharee - > { c_id } = "0" if ( ! $ users_sharee - > { c_id } ) ;
$ initMap =~ s/\s//g ;
my ( $ lat , $ lng ) = split ( /,/ , $ initMap ) ;
2022-01-02 14:57:19 +01:00
require "Mod/KMLout.pm" ;
my $ kmlfile = Mod::KMLout:: kmlGenerator ( $ api_return , $ varenv , $ users_sharee ) ;
2022-01-11 10:53:21 +01:00
my $ filesize = - s "$varenv->{metahost}/xml/$kmlfile" ;
my $ preserve_view = "false" ;
$ preserve_view = "true" if ( $ filesize < 200 ) ; #it's like empty without publixc stations
2022-01-02 14:57:19 +01:00
print "<div style='background-color:#cccccc;width:100%;margin-top:40px;'>\n" ;
print "<div id='map' style='height:600px;'></div>\n" ;
print << EOF
<script>
function initMap ( ) {
var map = new google . maps . Map ( document . getElementById ( 'map' ) , {
scrollwheel: false ,
draggable: ! ( "ontouchend" in document ) ,
center: { lat: $ lat , lng: $ lng } ,
2022-01-21 17:26:57 +01:00
zoom: $ map_zoom
2022-01-02 14:57:19 +01:00
} ) ;
var ctaLayer = new google . maps . KmlLayer ( {
position: map . getCenter ( ) ,
2022-01-11 10:53:21 +01:00
preserveViewport: $ preserve_view ,
2022-01-02 14:57:19 +01:00
// url: '$dbt->{primary}->{sharee_primary}->{primaryApp}/KMLout?kml=' + ( new Date ( ) ) . getTime ( ) + '$users_sharee->{c_id}' ,
// url: '$varenv->{metahost}/xml/KMLout-3' ,
// url: '$varenv->{wwwhost}/?kml=' + ( new Date ( ) ) . getTime ( ) ,
url: '$varenv->{metahost}/xml/$kmlfile' ,
map : map
} ) ;
console . log ( '$varenv->{metahost}/xml/$kmlfile' ) ;
} ;
</script>
< script async defer
src = "https://maps.googleapis.com/maps/api/js?key=$apikeyconf{googlemap}->{google_key}&callback=initMap" >
</script>
EOF
;
print "</div>\n" ;
print $ q - > div ( { - class = > "content2_legende" , - style = > 'font-weight:bold;' } , "• Ist ein Lastenrad an einer Mietradstation verfügbar?" ) , "\n" ;
2022-01-28 09:54:34 +01:00
print $ q - > div ( { - class = > "content2_legende" } , $ q - > img ( { - style = > 'height:30px;' , - src = > "$varenv->{metahost}/img/$icon_green" } ) , "Lastenrad verfügbar" ) , "\n" ;
print $ q - > div ( { - class = > "content2_legende" } , $ q - > img ( { - style = > 'height:30px;' , - src = > "$varenv->{metahost}/img/$icon_red" } ) , "Lastenrad nicht verfügbar" ) , "\n" ;
print $ q - > div ( { - class = > "content2_legende" } , " " ) , "\n" ;
print "$initMap|$varenv->{dbname}|$api_return->{authcookie}|$users_sharee->{c_id}|$kmlfile" if ( $ users_dms - > { u_id } == $ dbt - > { copri_conf } - > { superu_id } ) ;
2022-01-02 14:57:19 +01:00
#print "$varenv->{syshost}/$varenv->{dbname} --> $dbt->{operator}->{$varenv->{dbname}}->{initMap}";
#if($R::ask_radID && $R::ask_radID =~ /^\d+$/){
# require "Tpl/ModalboxDialog.pm";
# &ModalboxDialog::mobox2($tpl_name,$tpl_id,$parent_id,$main_id,$u_id,$u_group,$lang,$users_sharee,$bg_color1,$bg_color2,$R::ask_radID);
# }
#
}
1 ;