From a8891eb70456ad6e24200c6d57903537432df2c0 Mon Sep 17 00:00:00 2001 From: ragu Date: Fri, 10 Jun 2022 20:49:26 +0200 Subject: [PATCH] sig station_lock_state collect_post --- copri4/main/src/Mod/APIfunc.pm | 9 +++- copri4/main/src/Mod/APIjsonserver.pm | 6 ++- copri4/main/src/Mod/APIsigclient.pm | 47 ++++++++++++--------- copri4/main/src/Mod/DBtank.pm | 2 +- copri4/shareeapp-operator/src/Lib/Mlogic.pm | 4 +- 5 files changed, 42 insertions(+), 26 deletions(-) diff --git a/copri4/main/src/Mod/APIfunc.pm b/copri4/main/src/Mod/APIfunc.pm index a42b9e1..668f4bc 100755 --- a/copri4/main/src/Mod/APIfunc.pm +++ b/copri4/main/src/Mod/APIfunc.pm @@ -1647,6 +1647,7 @@ sub user_bikes_occupied(){ my $self = shift; my $q = shift; my $auth = shift; + my $station_lock_state = shift || ""; my $pref = { table => "contenttrans", @@ -1659,6 +1660,11 @@ sub user_bikes_occupied(){ int10 => "IN::('3','2')", "ct.close_time" => "is::null", }; + + #station_lock_stat enables a OR condition to view available as requested/occupied + ##selects also station_lock_state=locking bikes to view once miniquery + #true if not defined! it will only defined on booking_request, because there must be available + $pref->{station_lock_state} = "3" if(!$station_lock_state); my $record = $dbt->collect_post($dbh,$pref); return $record; }#end user_bikes_occupied @@ -1725,8 +1731,7 @@ sub rentals(){ } }#end mini_quest - #there seems some methodes which needs state, thats because disabled - #$return->{state} = "requested";#used once in App after sig rental-end push-notify + $return->{$id}->{state} = "returned";#used once in App after sig rental-end push-notify $return->{$id}->{rentalId} = "$record->{$id}->{txt11}"; my $update_pos = { diff --git a/copri4/main/src/Mod/APIjsonserver.pm b/copri4/main/src/Mod/APIjsonserver.pm index 0436d45..f91521b 100755 --- a/copri4/main/src/Mod/APIjsonserver.pm +++ b/copri4/main/src/Mod/APIjsonserver.pm @@ -209,7 +209,8 @@ elsif($q->param('request') eq "booking_request"){ $bike_id = $1 if($bike_id =~ /(\d+)/); #check count of occcupied/requested bikes - my $record = $apif->user_bikes_occupied($q,$authraw); + #"station_lock_state" disables a OR condition to view available as requested/occupied + my $record = $apif->user_bikes_occupied($q,$authraw,"station_lock_state"); my $count=0; my $still_requested = 0; foreach my $id (keys(%$record)){ @@ -308,7 +309,8 @@ elsif($q->param('request') eq "booking_request"){ } #return list of occupied/requested bikes - $record = $apif->user_bikes_occupied($q,$authraw); + #"station_lock_state" disables a OR condition to view available as requested/occupied + $record = $apif->user_bikes_occupied($q,$authraw,"station_lock_state"); $response->{bikes_occupied} = $apif->rentals($record,$authraw,"1");#returns JSON rental values }#end still_requested diff --git a/copri4/main/src/Mod/APIsigclient.pm b/copri4/main/src/Mod/APIsigclient.pm index d3dcf5a..649ea34 100755 --- a/copri4/main/src/Mod/APIsigclient.pm +++ b/copri4/main/src/Mod/APIsigclient.pm @@ -379,33 +379,42 @@ sub sig_booking { mtime => "now()", owner => "169", }; - - #reservation and rental will return only on success! "rentalId" - if($sig_book->{rentalId}){ - $update_pos->{txt11} = "$sig_book->{rentalId}"; - } - #without rentalId, bike will be available and unlocked! - elsif(($todo eq "reserve" || $todo eq "rental") && !$sig_book->{rentalId}){ - $update_pos->{int10} = 1; - $update_pos->{int20} = 1; - - #if($ct_bike->{c_id}){ - my $update_content = { + my $update_content = { table => "content", mtime => "now()", owner => "169", - int10 => 1, - int20 => 1, c_id => $ctpos->{cc_id}, - }; - $rows = $dbt->update_record($dbh,$update_content,$update_content); - print FILE "<--- rows: $rows, update_content: $ctpos->{cc_id}, with:" . Dumper($update_content) . "\n"; - #} + }; + + #rentalId will be only on success! + if($sig_book->{rentalId}){ + $update_pos->{txt11} = "$sig_book->{rentalId}"; } - #$update_pos->{txt10} = "$sig_book->{reservationId}" if($sig_book->{reservationId});#never used + if($todo eq "reserve" || $todo eq "rental"){ + #mark it as unlocked if rentalId on rental + if($todo eq "rental" && $sig_book->{rentalId}){ + $update_pos->{int20} = 2; + $update_content->{int20} = 2; + } + #without rentalId, bike will be available and unlocked! + else{ + $update_pos->{int10} = 1; + $update_pos->{int20} = 1; + $update_content->{int10} = 1; + $update_content->{int20} = 1; + } + } + + #keep in mind, all other states will be done on REST, hopefully $update_pos->{txt25} = "$ctpos->{txt25}\n$sig_book->{return_state}";# if($sig_book->{return_state}); $rows = $dbt->update_record($dbh,$update_pos,$ctpos); print FILE "<--- rows: $rows, update_pos: $ctpos->{c_id}, with:" . Dumper($update_pos) . "\n"; + + if($ctpos->{cc_id}){ + $rows = $dbt->update_record($dbh,$update_content,$update_content); + print FILE "<--- rows: $rows, update_content: $ctpos->{cc_id}, with:" . Dumper($update_content) . "\n"; + } + } close(FILE); diff --git a/copri4/main/src/Mod/DBtank.pm b/copri4/main/src/Mod/DBtank.pm index f2c19ad..12c5e15 100755 --- a/copri4/main/src/Mod/DBtank.pm +++ b/copri4/main/src/Mod/DBtank.pm @@ -625,7 +625,7 @@ sub collect_post(){ }elsif($key =~ /^(c_id|ca_id|ct_id|owner|barcode|int\d+)$/ && $value){ $cp_where .= " and cp.$key $op $value"; } - }elsif($key eq "int10" && $value eq "('3','2')"){ + }elsif($key eq "int10" && $value eq "('3','2')" && $fetch->{station_lock_state}){ #selects also station_lock_state=locking bikes to view once miniquery $cp_where .= " and (cp.$key $op $value OR cp.int28 = 3)"; }elsif($key =~ /^(c_id|ca_id|ct_id|owner|barcode|int\d+)$/ && $value){ diff --git a/copri4/shareeapp-operator/src/Lib/Mlogic.pm b/copri4/shareeapp-operator/src/Lib/Mlogic.pm index 64043c2..3131142 100755 --- a/copri4/shareeapp-operator/src/Lib/Mlogic.pm +++ b/copri4/shareeapp-operator/src/Lib/Mlogic.pm @@ -42,11 +42,11 @@ sub tpl(){ if($users_sharee->{c_id} && $R::sharee_edit ne "delete_account2" && ($users_sharee->{c_id} eq $varenv->{superu_id} || $dbt->{copri_conf}->{stage} eq "test" || $users_sharee->{txt08} eq "sigo\@sharee.bike")){ my $coo = $q->cookie('domcookie') || $q->param('sessionid') || ""; - #my $api_test = "sharee_fr01"; my $bike="FR1538"; + my $api_test = "sharee_fr01"; my $bike="FR1538"; #my $api_test = "sharee_fr01"; my $bike="FR4781";#Tracking and BVB test #my $api_test = "sharee_kn"; my $bike="KN205"; #my $api_test = "sharee_wue"; my $bike="WUE5524"; - my $api_test = "sharee_sx"; my $bike="S3X1001"; + #my $api_test = "sharee_sx"; my $bike="S3X1001"; #my $api_test = "sharee_ren"; my $bike="REN2"; print $q->div({-style=>'float:right;text-align:right;height:25px;padding:6px 15px;background-color:white'},$q->a({-style=>"background-color:#ffffff;color:#$bgcolor1;", -href=>"$varenv->{metahost}/src/scripts/tests/index.pl?sessionid=$coo\&api_test=$api_test\&bike=$bike", -target=>'_blank'}," [ tests --> $api_test ] "),"$users_sharee->{txt08}",$q->a({-style=>"color:#$bgcolor1;", -href=>"logout_sharee$session"},"logout")),"\n";