diff --git a/copri4/main/src/Mod/APIfunc.pm b/copri4/main/src/Mod/APIfunc.pm index fb6ca96..314134f 100755 --- a/copri4/main/src/Mod/APIfunc.pm +++ b/copri4/main/src/Mod/APIfunc.pm @@ -1985,6 +1985,7 @@ sub stations_available(){ my $op_return = {}; foreach my $id (sort { $record->{$a}->{barcode} <=> $record->{$b}->{barcode} } keys (%$record)){ $return->{$id}->{authed} = "$authed"; + $return->{$id}->{capacity} = $record->{$id}->{int05} || 1; $return->{$id}->{station} = "$dbt->{operator}->{$varenv->{dbname}}->{oprefix}$record->{$id}->{int04}"; $return->{$id}->{uri_operator} = "$varenv->{wwwhost}"; diff --git a/copri4/main/src/Mod/APIjsonserver.pm b/copri4/main/src/Mod/APIjsonserver.pm index 2e13eee..bf1906a 100755 --- a/copri4/main/src/Mod/APIjsonserver.pm +++ b/copri4/main/src/Mod/APIjsonserver.pm @@ -250,7 +250,7 @@ elsif($q->param('request') eq "booking_request"){ ($ct_bike,$ct_tariff) = $apif->fetch_bike_tariff(\%varenv,$authraw,$bike,$aowner); my $sig_book = { - bikeId => "$ct_bike->{txt22}", + bikeId => "$ct_bike->{txt22}", rentalId => "", reservationId => "" }; @@ -259,6 +259,7 @@ elsif($q->param('request') eq "booking_request"){ #sig reservation. not mandatory if($ct_bike->{int11} == 3){ $sig_book = $si->sig_booking(\%varenv,$authraw,$ct_bike,"","reserve"); + $sig_book->{bikeId} = "$ct_bike->{txt22}"; } $response_book = $apif->booking_request($q,\%varenv,$authraw,$bike,$ct_bike,$ct_tariff,$aowner,$gps,$sig_book); }elsif(!$ct_tariff->{barcode}){ @@ -360,7 +361,7 @@ elsif($q->param('request') eq "booking_cancel" || $q->param('request') eq "booki $sig_book = $si->sig_booking(\%varenv,$authraw,"",$ctpos,"reserve_end"); ($rows, $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,$sig_book); }else{ - ($rows, $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,$sig_book); + ($rows, $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,""); } $response = {%$response, %$booking_values}; diff --git a/copri4/main/src/Mod/APIsigclient.pm b/copri4/main/src/Mod/APIsigclient.pm index 6520c08..aba8352 100755 --- a/copri4/main/src/Mod/APIsigclient.pm +++ b/copri4/main/src/Mod/APIsigclient.pm @@ -7,7 +7,7 @@ package APIsigclient; # #380116b5-0522-43da-ab66-477744a731a3 # -use lib qw(/var/www/copri-bike/shareeapp-sx/src); +#use lib qw(/var/www/copri-bike/shareeapp-sx/src); use warnings; use strict; use POSIX; @@ -27,6 +27,7 @@ use Lib::Config; use Mod::DBtank; use Mod::Basework; use Mod::APIfunc; +use Mod::Shareework; use Data::Dumper; my $q = new CGI; @@ -34,6 +35,7 @@ my $json = JSON->new->allow_nonref; my $cf = new Config; my $dbt = new DBtank; my $apif = new APIfunc; +my $tk = new Shareework; my $bw = new Basework; sub new { @@ -69,7 +71,7 @@ sub sig_available { my $authed = 0; my $tariff_content = {}; $authed = 1 if(ref($ctadr) eq "HASH" && $ctadr->{c_id} && $ctadr->{c_id} > 0); - (my $bike_group,my $user_group,$tariff_content,my $user_tour) = $apif->fetch_tariff($varenv->{dbname},$ctadr,$q->param('ctadrcookie')); + (my $bike_group,my $user_group,$tariff_content,my $user_tour) = $apif->fetch_tariff($varenv->{dbname},$ctadr,$q->param('authcookie')); my $hotline_hash = { table => "contentuser", @@ -103,7 +105,7 @@ sub sig_available { #station (mainly using sigojson site object) my $station = "SX$resp->{site}->{id}"; - if($station && looks_like_number($resp->{site}->{id}) && $resp->{site}->{status} eq "ACTIVE" && $resp->{site}->{lat} && $resp->{site}->{lon}){ + if($station && looks_like_number($resp->{site}->{id})){ print FILE "Station: $station\n"; $response_out->{$station}->{station} = "$station"; $response_out->{$station}->{authed} = "$authed"; @@ -113,14 +115,15 @@ sub sig_available { $response_out->{$station}->{gps}->{latitude} = "$resp->{site}->{lat}" || ""; $response_out->{$station}->{gps}->{longitude} = "$resp->{site}->{lon}" || ""; $response_out->{$station}->{gps_radius} = "75"; + + #Other than Active status, should not be used to display information to a customer $response_out->{$station}->{state} = "defect"; - if($resp->{site}->{status} eq "ACTIVE"){#? + if(uc($resp->{site}->{status}) eq "ACTIVE"){ $response_out->{$station}->{state} = "available"; - }elsif($resp->{site}->{status} eq "MAINTANANCE"){ + }elsif(uc($resp->{site}->{status}) eq "MAINTANANCE"){ $response_out->{$station}->{state} = "maintanance"; - }elsif($resp->{site}->{status} eq "OFFLINE"){ - $response_out->{$station}->{state} = "defect"; } + $response_out->{$station}->{operator_data} = { "operator_name" => "", "operator_hours" => "", @@ -149,6 +152,7 @@ sub sig_available { } } + delete $response_out->{$station} if(uc($resp->{site}->{status}) ne "ACTIVE" || !$resp->{site}->{lat} || !$resp->{site}->{lon}); } }#end stations_available @@ -172,18 +176,19 @@ sub sig_available { $response_out->{$bike}->{gps}->{longitude} = "$resp->{state}->{lon}" || ""; $response_out->{$bike}->{bike_charge} = "$resp->{energy_level}" || "0"; $response_out->{$bike}->{state} = "defect"; - if($resp->{reservation_state} eq "RESERVED"){ + if(uc($resp->{reservation_state}) eq "RESERVED"){ $response_out->{$bike}->{state} = "requested"; - }elsif($resp->{reservation_state} eq "ACTIVE-RENTAL"){ + }elsif(uc($resp->{reservation_state}) eq "ACTIVE-RENTAL"){ $response_out->{$bike}->{state} = "occupied"; }elsif(!$resp->{reservation_state}){ $response_out->{$bike}->{state} = "available"; } - #$response_out->{$bike}->{lock_state} = "undefined";#? - #$response_out->{$bike}->{lock_state} = "locked";# I think default should be unlocked + #1. change can take up to 2 mins to reflect + #2. When a customer will start a reservation, it will always be unlock, + #Sigo software automatically handle this condition $response_out->{$bike}->{lock_state} = "unlocked"; - if($resp->{state}->{locked}){ + if($resp->{lock}->{status} eq "locked"){ $response_out->{$bike}->{lock_state} = "locked"; } $response_out->{$bike}->{system} = "sigo"; @@ -249,7 +254,8 @@ sub sig_available { $return2copri->{$bike}->{int20} = $key; } } - delete $response_out->{$bike} if($resp->{status} ne "ACTIVE");#don't view not active bikes + #delete if $resp->{status} ne "ACTIVE" || reservation_state ne Reserved|Active-Rental + delete $response_out->{$bike} if(uc($resp->{status}) ne "ACTIVE" || $resp->{reservation_state});#don't view not active bikes } }#end bikes_available @@ -296,6 +302,7 @@ sub sig_booking { ); } #reservation end, this sig request is still not defined. maybe end by rentalId + #int10 state will be set on booking_request elsif($todo eq "reserve_end"){ $endpoint .= "reserve/end"; %json = ( @@ -304,6 +311,7 @@ sub sig_booking { ); } #rental start + #int10 state will be set on main booking_update elsif($todo eq "rental"){ $endpoint .= "rental"; my $sig_bikeId = $ctpos->{txt22} || $ct_bike->{txt22}; @@ -357,12 +365,27 @@ sub sig_booking { if($ctpos->{c_id}){ + my $rows = 0; my $update_pos = { table => "contenttranspos", mtime => "now()", owner => "169", }; - my $rows = 0; + + #TODO try it with user_bikes_available + #on sig api states maybe not just in time available + #check and save sig bike states + #$q->param(-name=>'request',-value=>"bikes_available"); + #(my $response->{bikes},my $return2copri) = $self->sig_available($q,$varenv,$ctadr); + #my $ctrows = 0; + #$ctrows = $tk->sigbike_cupdate($return2copri); + #print FILE "<--- ctrows:$ctrows, update content state with:" . Dumper($return2copri) . "\n"; + + #foreach my $sid (keys (%{$return2copri})){ + # $update_pos->{int10} = "$return2copri->{$sid}->{int10}" if($return2copri->{$sid}->{int10}); + # $update_pos->{int20} = "$return2copri->{$sid}->{int20}" if($return2copri->{$sid}->{int20}); + #} + $update_pos->{txt10} = "$sig_book->{reservationId}" if($sig_book->{reservationId}); $update_pos->{txt11} = "$sig_book->{rentalId}" if($sig_book->{rentalid}); $rows = $dbt->update_record($dbh,$update_pos,$ctpos); diff --git a/copri4/main/src/Mod/GBFSout.pm b/copri4/main/src/Mod/GBFSout.pm new file mode 100755 index 0000000..26dd7d8 --- /dev/null +++ b/copri4/main/src/Mod/GBFSout.pm @@ -0,0 +1,208 @@ +package Mod::GBFSout; +# +# SPDX-License-Identifier: AGPL-3.0-or-later +# Copyright (c) Rainer Gümpelein, TeilRad GmbH +# +#without login only public Stations have to be viewable: +#https://shareeapp-primary.copri-bike.de/GBFSout +# +#with login and valid autcookie: +#https://shareeapp-primary.copri-bike.de/GBFSout?sessionid=a49aba2b5440be72816db2_rafo87znqx +# +# +use warnings; +use strict; +use POSIX; +use Exporter; +our @ISA = qw (Exporter); +use CGI::Cookie (); +use CGI ':standard'; +use Apache2::Const -compile => qw(OK ); +use Scalar::Util qw(looks_like_number); +use JSON; +use LWP::UserAgent; + +use Lib::Config; +use Mod::DBtank; +use Mod::APIfunc; +use Mod::Basework; +use Data::Dumper; +my $bw = new Basework; + +sub handler { + my $r = shift; + my $q = new CGI; + $q->import_names('R'); + my $dbt = new DBtank; + my $apif = new APIfunc; + my $cf = new Config; + my %varenv = $cf->envonline(); + + my $coo = $q->cookie('domcookie') || $R::sessionid || ""; + my $users_sharee = { c_id => 0 }; + my $api_return = { authcookie => '' }; + + ($api_return,$users_sharee) = $apif->auth_verify($q,$coo,""); + + if($dbt->{website}->{$varenv{syshost}}->{merchant_id}){ + $api_return->{authcookie} = $dbt->{website}->{$varenv{syshost}}->{merchant_id} if(!$api_return->{authcookie}); + }elsif($dbt->{operator}->{$varenv{dbname}}->{merchant_id}){ + $api_return->{authcookie} = $dbt->{operator}->{$varenv{dbname}}->{merchant_id} if(!$api_return->{authcookie}); + }elsif($dbt->{primary}->{$varenv{dbname}}->{merchant_id}){ + $api_return->{authcookie} = $dbt->{primary}->{$varenv{dbname}}->{merchant_id} if(!$api_return->{authcookie}); + } + $users_sharee->{c_id} = "0" if(!$users_sharee->{c_id}); + + $bw->log("GBFSout handler with api_return: ",$api_return,""); + + print $q->header(-type => "application/json", -charset => "utf-8", -'Access-Control-Allow-Origin' => "*"); + #main + my $project = "all"; + $project = $dbt->{website}->{$varenv{syshost}}->{project} if($dbt->{website}->{$varenv{syshost}}->{project}); + $project = $dbt->{operator}->{$varenv{dbname}}->{project} if($dbt->{operator}->{$varenv{dbname}}->{project}); + + #request primary will jsonclient loop_sharees + my $uri_request = $dbt->{primary}->{sharee_primary}->{primaryApp}; + #detect DMS, because this will do it directly without loop_sharees + $uri_request = $dbt->{operator}->{$varenv{dbname}}->{operatorApp} if($varenv{dbname} ne "sharee_primary" && $varenv{syshost} =~ /shareedms-/); + + if($R::request eq "stations_available"){ + station_information($api_return,\%varenv,$users_sharee,$uri_request,$project); + } + if($R::request eq "bikes_available"){ + vehicle_status($api_return,\%varenv,$users_sharee,$uri_request,$project); + } + + return Apache2::Const::OK; +} + + +sub station_information { + my $authcookie = shift || { authcookie => '' }; + my $varenv = shift; + my $users_sharee = shift || { c_id => 0 }; + my $uri_request = shift || ""; + my $project = shift || "all"; + my $json = JSON->new->allow_nonref; + + my $rest_stations = "request=stations_available&project=$project&authcookie=$authcookie->{authcookie}"; + my $gbfs_resp = {}; + my $stations_json = fetch_primary_json("",$uri_request,$rest_stations); + #decode json to hash + my $response_stations = decode_json($stations_json); + my @gbfs_stations = (); + + foreach my $station (keys (%{ $response_stations->{shareejson}->{stations} })) { + #print Dumper($response_stations->{shareejson}->{stations}->{$station}); + my %gbfs_station = (); + $gbfs_station{$station}{station_id} = $response_stations->{shareejson}->{stations}->{$station}->{station}; + $gbfs_station{$station}{name} = Encode::encode('utf-8', Encode::decode('iso-8859-1',$response_stations->{shareejson}->{stations}->{$station}->{description})); + $gbfs_station{$station}{capacity} = $response_stations->{shareejson}->{stations}->{$station}->{capacity}; + $gbfs_station{$station}{lat} = $response_stations->{shareejson}->{stations}->{$station}->{gps}->{latitude}; + $gbfs_station{$station}{lon} = $response_stations->{shareejson}->{stations}->{$station}->{gps}->{longitude}; + $gbfs_station{$station}{is_charging_station} = 1 if(grep(/300102/, @{$response_stations->{shareejson}->{stations}->{$station}->{station_group}}));#E-L + push (@gbfs_stations, $gbfs_station{$station}); + } + + $gbfs_resp = { + "last_updated" => 1653031183, + "ttl" => 10, + "version" => "2.2", + "data" => { + "stations" => [ @gbfs_stations ] + } + }; + + my $jrout = $json->pretty->encode($gbfs_resp); + print $jrout; + + return; +}#end station_information + + +sub vehicle_status { + my $authcookie = shift || { authcookie => '' }; + my $varenv = shift; + my $users_sharee = shift || { c_id => 0 }; + my $uri_request = shift || ""; + my $project = shift || "all"; + my $json = JSON->new->allow_nonref; + + my $rest_bikes = "request=bikes_available&project=$project&authcookie=$authcookie->{authcookie}"; + + my $gbfs_resp = {}; + my $bikes_json = fetch_primary_json("",$uri_request,$rest_bikes); + #decode json to hash + my $response_bikes = decode_json($bikes_json); + my @gbfs_bikes = (); + + foreach my $bike (keys (%{ $response_bikes->{shareejson}->{bikes} })) { + #if($response_bikes->{shareejson}->{bikes}->{$bike}->{station} eq "FR105"){ + my %gbfs_bike = (); + $gbfs_bike{$bike}{station_id} = $response_bikes->{shareejson}->{bikes}->{$bike}->{station}; + $gbfs_bike{$bike}{vehicle_id} = $response_bikes->{shareejson}->{bikes}->{$bike}->{bike}; + $gbfs_bike{$bike}{vehicle_name} = Encode::encode('utf-8', Encode::decode('iso-8859-1',$response_bikes->{shareejson}->{bikes}->{$bike}->{description}));#not part of gbfs + $gbfs_bike{$bike}{vehicle_type_id} = $response_bikes->{shareejson}->{bikes}->{$bike}->{bike_group}[0]; + #$gbfs_bike{$bike}{is_reserved} = 0; + #$gbfs_bike{$bike}{is_disabled} = 0; + push (@gbfs_bikes, $gbfs_bike{$bike}); + #} + } + + #{ + #"vehicle_id":"987fd100-b822-4347-86a4-b3eef8ca8b53", + #"last_reported":1609866204, + #"is_reserved":false, + #"is_disabled":false, + #"vehicle_type_id":"def456", + #"current_range_meters":6543.0, + #"station_id":"86", + #"pricing_plan_id":"plan3" + #} + + $gbfs_resp = { + "last_updated" => 1653031183, + "ttl" => 0, + "version" => "3.0", + "data" => { + "vehicles" => [ @gbfs_bikes ] + } + }; + + my $jrout = $json->pretty->encode($gbfs_resp); + print $jrout; + + return; +}#end vehicle_status + + +#requestor +sub fetch_primary_json { + my $self = shift; + my $primary_server = shift || ""; + my $rest = shift || ""; + my $primary_request = "$primary_server/APIjsonserver?$rest"; + $bw->log("GBFS primary_request: ",$primary_request,""); + + my $ua = LWP::UserAgent->new; + $ua->agent("sharee GBFSout"); + + my $req = HTTP::Request->new(GET => "$primary_request"); + $req->content_type('application/x-www-form-urlencoded'); + $req->content($rest); + + #Pass request to the user agent and get a response back + my $res = $ua->request($req); + # Check the outcome of the response + if ($res->is_success) { + #print $res->content; + return $res->content; + #print $res->status_line, "\n"; + }else { + return ""; + #print $res->status_line, "\n"; + } +} + + +1; diff --git a/copri4/main/src/Mod/KMLout.pm b/copri4/main/src/Mod/KMLout.pm index 68fafa1..2c33442 100755 --- a/copri4/main/src/Mod/KMLout.pm +++ b/copri4/main/src/Mod/KMLout.pm @@ -72,18 +72,14 @@ sub handler { return Apache2::Const::OK; } + sub kmlGenerator { my $authcookie = shift || { authcookie => '' }; my $varenv = shift; my $users_sharee = shift || { c_id => 0 }; $users_sharee->{c_id} = "0" if(!$users_sharee->{c_id}); - - my $q = new CGI; my $dbt = new DBtank; my $json = JSON->new->allow_nonref; - my $cf = new Config; - my $lang="de"; - my $dbh = ""; my $project = "all"; $project = $dbt->{website}->{$varenv->{syshost}}->{project} if($dbt->{website}->{$varenv->{syshost}}->{project}); @@ -93,9 +89,12 @@ sub kmlGenerator { my $icon_red = "Open_Red.png"; my $icon_blue = "Open_Blue.png"; if($project eq "Bayern"){ - $icon_green = "LastenradBay-custom-marker-gruen.png"; - $icon_red = "LastenradBay-custom-marker-rot.png"; - $icon_blue = "LastenradBay-custom-marker-bayblau.png"; + $icon_green = "LastenradBay_Standortpfeil_gruen_03a.png"; + $icon_red = "LastenradBay_Standortpfeil_rot_03a.png"; + $icon_blue = "LastenradBay_Standortpfeil_blau_03a.png"; + #$icon_green = "LastenradBay-custom-marker-gruen.png"; + #$icon_red = "LastenradBay-custom-marker-rot.png"; + #$icon_blue = "LastenradBay-custom-marker-bayblau.png"; } my $timestamp = strftime "%Y%m%d%H%M%S", localtime; @@ -225,31 +224,9 @@ sub kmlGenerator { print XML "\n"; print XML "\n"; close(XML); - chmod 0666, "$varenv->{basedir}/xml/$kmlfile"; - #my $update_kml = {}; - #if($users_sharee->{c_id} > 0){ - # $update_kml = { - # table => "contentadr", - # atime => "now()", - # c_id => $users_sharee->{c_id}, - # }; - #}else{ - # $update_kml = { - # table => "content", - # mtime => "now()", - # c_id => "3", - # }; - #} - #my $dbh_primary = $dbt->dbconnect_extern("sharee_primary"); - #$dbt->update_one($dbh_primary,$update_kml,"txt20='$kmlfile'"); - - #print "station_hash ALL:" . Dumper($station_hash); - #print "bike_hash ALL:" . Dumper($bike_hash); - # return $kmlfile; - }#end kmlGenerator #requestor diff --git a/copri4/main/src/Tpl/Karte_osm.pm b/copri4/main/src/Tpl/Karte_osm.pm new file mode 100755 index 0000000..a16cc24 --- /dev/null +++ b/copri4/main/src/Tpl/Karte_osm.pm @@ -0,0 +1,194 @@ +package Karte_osm; +# +# 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 $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; + + my $api_return = { authcookie => '' }; + my $coo = $q->cookie(-name=>'domcookie') || $R::sessionid; + ($api_return,$users_sharee) = $apif->auth_verify($q,$coo,""); + + my $initMap = $dbt->{website}->{$varenv->{syshost}}->{initMap}; + my $map_zoom = $dbt->{website}->{$varenv->{syshost}}->{map_zoom} || "10"; + my $project = "all"; + my $uri_request = $dbt->{primary}->{sharee_primary}->{primaryApp}; + + if($dbt->{website}->{$varenv->{syshost}}->{merchant_id}){ + $api_return->{authcookie} = $dbt->{website}->{$varenv->{syshost}}->{merchant_id} if(!$api_return->{authcookie}); + $project = $dbt->{website}->{$varenv->{syshost}}->{project} if($dbt->{website}->{$varenv->{syshost}}->{project}); + $uri_request = $dbt->{website}->{$varenv->{syshost}}->{operatorWeb}; + print $q->div({-class=>"content2_contact"},"Hier können Lastenfahrräder gemietet werden:"),"\n"; + }elsif($dbt->{operator}->{$varenv->{dbname}}->{merchant_id}){ + $api_return->{authcookie} = $dbt->{operator}->{$varenv->{dbname}}->{merchant_id} if(!$api_return->{authcookie}); + $initMap = $dbt->{operator}->{$varenv->{dbname}}->{initMap} if($dbt->{operator}->{$varenv->{dbname}}->{initMap}); + $map_zoom = $dbt->{operator}->{$varenv->{dbname}}->{map_zoom} if($dbt->{operator}->{$varenv->{dbname}}->{map_zoom}); + $project = $dbt->{operator}->{$varenv->{dbname}}->{project} if($dbt->{operator}->{$varenv->{dbname}}->{project}); + $uri_request = $dbt->{operator}->{$varenv->{dbname}}->{operatorDMS}; + print $q->div({-style=>'padding-top:25px;'},""),"\n"; + }elsif($dbt->{primary}->{$varenv->{dbname}}->{merchant_id}){ + $api_return->{authcookie} = $dbt->{primary}->{$varenv->{dbname}}->{merchant_id} if(!$api_return->{authcookie}); + $initMap = $dbt->{primary}->{$varenv->{dbname}}->{initMap} if($dbt->{primary}->{$varenv->{dbname}}->{initMap}); + $uri_request = $dbt->{primary}->{$varenv->{dbname}}->{primaryDMS}; + print $q->div({-style=>'padding-top:25px;'},""),"\n"; + } + + my $icon_green = "Open_Green.png"; + my $icon_red = "Open_Red.png"; + my $icon_blue = "Open_Blue.png"; + my $mapheight = "600px;"; + 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"; + $mapheight = "800px;" if($varenv->{syshost} !~ /shareedms-/); + } + + $users_sharee->{c_id} = "0" if(!$users_sharee->{c_id}); + $initMap =~ s/\s//g; + my ($lat,$lng) = split(/,/,$initMap); + + print "
\n"; + +print< + + + + + +EOF +; + + print "
\n"; + +print< + + var map = L.map('map').setView([$lat, $lng], $map_zoom); +L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { + attribution: '© OpenStreetMap contributors' +}).addTo(map); + +var icon_green = L.icon({ + iconUrl: '$varenv->{metahost}/img/$icon_green', + iconSize: [37, 41], + iconAnchor: [20, 41], + popupAnchor: [-2, -40] + //shadowUrl: 'marker-shadow.png', + //shadowSize: [68, 95], + //shadowAnchor: [22, 94] +}); +var icon_red = L.icon({ + iconUrl: '$varenv->{metahost}/img/$icon_red', + iconSize: [37, 41], + iconAnchor: [20, 41], + popupAnchor: [-2, -40] +}); + +Promise.all([ + fetch( + "$uri_request/GBFSout?request=stations_available&authcookie=$api_return->{authcookie}" + ), + fetch("$uri_request/GBFSout?request=bikes_available&authcookie=$api_return->{authcookie}") +]).then(async ([response1, response2]) => { + const responseData1 = await response1.json(); + const responseData2 = await response2.json(); + + const data1 = responseData1.data.stations; + const data2 = responseData2.data.vehicles; + + const layerGroup = L.featureGroup().addTo(map); + + data1.forEach(({ lat, lon, name, address, station_id: stationId }) => { + let bikesonstation = ''; + console.log('Station: ' + stationId , name); + + data2.forEach(({ station_id, vehicle_name, vehicle_id }) => { + if(typeof station_id !== 'undefined' && station_id == stationId){ + bikesonstation = bikesonstation.concat('• Verfügbar: ' + vehicle_name + ' ' + vehicle_id + '
'); + } + }); + console.log(bikesonstation); + + //bike_array.forEach((bike, index) => { + //console.log('xxxx ' + index + ':' + bike); + //}); + + if(bikesonstation){ + layerGroup.addLayer( + L.marker([lat, lon], { icon:icon_green }).bindPopup( + `Mietradstation: \${name} \${stationId}
+ \${bikesonstation} + ` + ) + ); + }else{ + layerGroup.addLayer( + L.marker([lat, lon], { icon:icon_red }).bindPopup( + `Mietradstation: \${name} \${stationId}
+ ` + ) + ); + + } + }); + + map.fitBounds(layerGroup.getBounds()); +}); + + +EOF +; + +print "
\n"; + +#print $q->div({-class=>"content2_legende", -style=>'font-weight:bold;'}, "• Ist ein Lastenrad an einer Mietradstation verfügbar?"),"\n"; +print $q->div({-class=>"content2_legende"}, $q->img({-style=>'height:38px;', -src=>"$varenv->{metahost}/img/$icon_green"}), "Lastenrad verfügbar"),"\n"; +print $q->div({-class=>"content2_legende"}, $q->img({-style=>'height:38px;', -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}" if($users_dms->{u_id} == $dbt->{copri_conf}->{superu_id}); + + +} +1; + diff --git a/copri4/main/src/scripts/sig_client.pl b/copri4/main/src/scripts/sig_client.pl index 9877011..44be7ff 100755 --- a/copri4/main/src/scripts/sig_client.pl +++ b/copri4/main/src/scripts/sig_client.pl @@ -36,10 +36,10 @@ my $dbh = ""; my $todo = $ARGV[1] || ""; my $user_id = $ARGV[2] || ""; -my $sig_bike_id = $ARGV[3] || ""; +my $pos_id = $ARGV[3] || ""; open(FILE,">>$varenv{logdir}/APIsigclient.log"); - print FILE "\n*** $now_dt 'sig_client fork with todo:$todo|user_id:$user_id|sig_bike_id:$sig_bike_id' \n"; + print FILE "\n*** $now_dt 'sig_client fork with todo:$todo|user_id:$user_id|pos_id:$pos_id' \n"; #get user and bike in copri by id my $apref = { @@ -58,10 +58,10 @@ my $posref = { fetch => "one", ca_id => "$ctadr->{c_id}", int10 => "IN::('3','2')", - txt22 => "$sig_bike_id", + c_id => "$pos_id", }; my $ctpos = { c_id => 0 }; -$ctpos = $dbt->fetch_tablerecord($dbh,$posref) if($user_id =~ /^\d+$/ && $user_id > 0 && $sig_bike_id); +$ctpos = $dbt->fetch_tablerecord($dbh,$posref) if($user_id =~ /^\d+$/ && $user_id > 0 && $pos_id); print FILE "fetched from DB ctadr:$ctadr->{c_id}|ctpos:$ctpos->{c_id}\n"; diff --git a/copri4/shareeapp-operator/css/favicon.ico b/copri4/shareeapp-operator/css/favicon.ico new file mode 100644 index 0000000..5b7c354 Binary files /dev/null and b/copri4/shareeapp-operator/css/favicon.ico differ diff --git a/copri4/shareeapp-operator/src/Tpl/Karte_osm.pm b/copri4/shareeapp-operator/src/Tpl/Karte_osm.pm new file mode 120000 index 0000000..68faca4 --- /dev/null +++ b/copri4/shareeapp-operator/src/Tpl/Karte_osm.pm @@ -0,0 +1 @@ +../../../main/src/Tpl/Karte_osm.pm \ No newline at end of file diff --git a/copri4/shareedms-operator/apache/shareedms-operator.conf b/copri4/shareedms-operator/apache/shareedms-operator.conf index bb388c4..34e3a92 100644 --- a/copri4/shareedms-operator/apache/shareedms-operator.conf +++ b/copri4/shareedms-operator/apache/shareedms-operator.conf @@ -74,6 +74,12 @@ Allow from all + + SetHandler perl-script + PerlInitHandler Apache2::Reload + PerlResponseHandler Mod::GBFSout + + SetHandler perl-script PerlInitHandler Apache2::Reload diff --git a/copri4/shareedms-operator/src/Lib/Mlogic.pm b/copri4/shareedms-operator/src/Lib/Mlogic.pm index 3cf8349..38f79c3 100755 --- a/copri4/shareedms-operator/src/Lib/Mlogic.pm +++ b/copri4/shareedms-operator/src/Lib/Mlogic.pm @@ -343,8 +343,8 @@ EOF require "Tpl/MandantConf.pm"; $return = &MandantConf::tpl($node_meta,$users_dms,$mode,$return); }elsif($node_meta->{tpl_id} == 1 && $node_meta->{main_id} == 200017){ - require "Tpl/Karte.pm"; - &Karte::tpl($node_meta,$users_dms,$mode,$varenv,"",$return); + require "Tpl/Karte_osm.pm"; + &Karte_osm::tpl($node_meta,$users_dms,$mode,$varenv,"",$return); }elsif($node_meta->{ct_table} =~ /contentpos|contentadrpos|users$/){#contentpos or contentadrpos require "Tpl/SubListe.pm"; $return = &SubListe::tpl($node_meta,$users_dms,$mode,$return); diff --git a/copri4/shareeweb-project/apache/shareeweb-operator.conf b/copri4/shareeweb-project/apache/shareeweb-operator.conf index 0fb5a3c..595919d 100644 --- a/copri4/shareeweb-project/apache/shareeweb-operator.conf +++ b/copri4/shareeweb-project/apache/shareeweb-operator.conf @@ -75,11 +75,11 @@ SSLCertificateKeyFile /etc/letsencrypt/live/example.tld-0003/privkey.pem Allow from all - - SetHandler perl-script - PerlInitHandler Apache2::Reload - PerlResponseHandler Mod::APIvelo - + # + # SetHandler perl-script + # PerlInitHandler Apache2::Reload + # PerlResponseHandler Mod::APIvelo + # SetHandler perl-script @@ -87,6 +87,12 @@ SSLCertificateKeyFile /etc/letsencrypt/live/example.tld-0003/privkey.pem PerlResponseHandler Mod::APIjsonserver + + SetHandler perl-script + PerlInitHandler Apache2::Reload + PerlResponseHandler Mod::GBFSout + + SetHandler perl-script PerlInitHandler Apache2::Reload diff --git a/copri4/shareeweb-project/src/Lib/Mlogic.pm b/copri4/shareeweb-project/src/Lib/Mlogic.pm index aa03266..ed2dd4e 100755 --- a/copri4/shareeweb-project/src/Lib/Mlogic.pm +++ b/copri4/shareeweb-project/src/Lib/Mlogic.pm @@ -188,8 +188,8 @@ sub tpl(){ print $q->div({-style=>"text-align:left;border:0px dotted #$fgcolor1;"},$q->ul({-id=>'TopNavi'},$lmenu0)),"\n"; if(($node_meta->{tpl_id} == 1 || $node_meta->{tpl_id} == 3) && $node_meta->{main_id} == 200017){ - require "Tpl/Karte.pm"; - &Karte::tpl($node_meta,$users_dms,$mode,$varenv,$users_sharee,$return); + require "Tpl/Karte_osm.pm"; + &Karte_osm::tpl($node_meta,$users_dms,$mode,$varenv,$users_sharee,$return); }else{ $self->tplselect($node_meta,$users_dms,$mode,$varenv,$users_sharee,$return); }