From 60a60121f3fdd78b292ba7615475a71f36de56ec Mon Sep 17 00:00:00 2001 From: ragu Date: Sun, 2 Oct 2022 19:26:08 +0200 Subject: [PATCH] smartlock sequence refactoring --- copri4/main/src/Mod/APIfunc.pm | 449 +++++++++++++-------------------- copri4/main/src/Mod/DBtank.pm | 13 +- copri4/main/src/Mod/Payment.pm | 4 +- copri4/main/src/Tpl/Calorin.pm | 52 ++-- 4 files changed, 208 insertions(+), 310 deletions(-) diff --git a/copri4/main/src/Mod/APIfunc.pm b/copri4/main/src/Mod/APIfunc.pm index bff253a..3b1aa86 100755 --- a/copri4/main/src/Mod/APIfunc.pm +++ b/copri4/main/src/Mod/APIfunc.pm @@ -816,7 +816,7 @@ sub service_work { $return->{$article}->{$key_change}->{time_over} = "$time_over"; $return->{$article}->{$key_change}->{service_type} = "$service_type"; $return->{$article}->{$key_change}->{work_val} = "$pos_record->{$id}->{$key}" if($key =~ /int/); - $return->{$article}->{$key_change}->{work_val} .= "$pos_record->{$id}->{$key}" if($key =~ /txt/); + $return->{$article}->{$key_change}->{work_val} .= "$pos_record->{$id}->{$key}\n" if($key =~ /txt/); $return->{$article}->{$key_change}->{mtime} = "$pos_record->{$id}->{mtime}"; $return->{$article}->{$key_change}->{user_name} = "$u_name"; $return->{$article}->{$key_change}->{owner} = "$pos_record->{$id}->{owner}"; @@ -844,7 +844,7 @@ sub service_work { $return->{$article}->{$key}->{service_type} = "$service_type"; $return->{$article}->{$key}->{work_val} = "1" if($key =~ /int/); $return->{$article}->{$key}->{work_val} = "::erledigt::" if($key =~ /txt/); - $return->{$article}->{$key}->{mtime} = "2022-01-18 00:00"; + $return->{$article}->{$key}->{mtime} = "2022-09-29 00:00"; $return->{$article}->{$key}->{user_name} = "init"; $return->{$article}->{$key}->{owner} = "188"; @@ -968,7 +968,7 @@ sub booking_request(){ my $response_text = ""; #state and lock_state is only defined if requestes incl. occupied - $bw->log("booking_request bike to state $bike $state $lock_state, auth $auth->{c_id}, tarif $ct_tariff->{barcode}, bike:",$bike,""); + $bw->log("booking_request bike to state | $bike | $state | $lock_state, tarif $ct_tariff->{barcode}, auth:",$auth->{c_id},""); my $update_adr = { table => "contentadr", @@ -1099,7 +1099,6 @@ sub booking_update(){ my %varenv = $cf->envonline(); my $rows = 0; my $user_agent = $q->user_agent(); - my $record_pos = { c_id => 0 };#if fails #my $bike = $q->param('bike'); #my $bike_id = $1 if($q->escapeHTML($q->param('bike')) =~ /(\d+)/); my $bike = $q->escapeHTML($q->param('bike')) || ""; @@ -1141,6 +1140,7 @@ sub booking_update(){ int10 => "IN::('3','2')", }; + my $record_pos = { c_id => 0 }; $record_pos = $dbt->collect_post($dbh,$pref) if($q->param('bike')); my $pref_cc = { @@ -1150,10 +1150,10 @@ sub booking_update(){ barcode => $bike_id, }; - my $record_cc = {}; + my $record_cc = { c_id => 0 }; $record_cc = $dbt->fetch_record($dbh,$pref_cc) if($q->param('bike')); - $bw->log("booking_update bike to state $bike $state ($state_key) $lock_state, auth $auth->{c_id}, bike:",$bike,""); + $bw->log("booking_update bike to state | $bike | $state | $lock_state, auth:",$auth->{c_id},""); my $update_cc = { table => "content", @@ -1161,40 +1161,52 @@ sub booking_update(){ owner => "$owner", }; - - my $gps = ""; - my $latitude = ""; - my $longitude = ""; + my $gps_data = { + gps => "", + latitude => "", + longitude => "", + gps_age_miniutes => 60, + gps_accuracy => 0, + geo_distance => 1000000, + }; #old if($q->param('gps')){ my $gps_input = $q->param('gps'); $gps_input =~ s/\s//g; - $latitude = $q->escapeHTML($1) if($gps_input =~ /^(\d+\.\d+),\d+/); - $longitude = $q->escapeHTML($1) if($gps_input =~ /\d+,(\d+\.\d+)$/); - $gps = "$latitude,$longitude" if($latitude && $longitude); + $gps_data->{latitude} = $q->escapeHTML($1) if($gps_input =~ /^(\d+\.\d+),\d+/); + $gps_data->{longitude} = $q->escapeHTML($1) if($gps_input =~ /\d+,(\d+\.\d+)$/); + $gps_data->{gps} = "$gps_data->{latitude},$gps_data->{longitude}" if($gps_data->{latitude} && $gps_data->{longitude}); } #new if($q->param('latitude') && $q->param('longitude')){ my $latitude_in = $q->param('latitude'); my $longitude_in = $q->param('longitude'); - $latitude = $1 if($latitude_in =~ /(\d+\.\d+)/); - $longitude = $1 if($longitude_in =~ /(\d+\.\d+)/); - $gps = "$latitude,$longitude" if($latitude && $longitude); + $gps_data->{latitude} = $1 if($latitude_in =~ /(\d+\.\d+)/); + $gps_data->{longitude} = $1 if($longitude_in =~ /(\d+\.\d+)/); + $gps_data->{gps} = "$gps_data->{latitude},$gps_data->{longitude}" if($gps_data->{latitude} && $gps_data->{longitude}); } my $Ilockit_GUID = ""; $Ilockit_GUID = $q->escapeHTML($q->param('Ilockit_GUID')) if($q->param('Ilockit_GUID') && $q->param('Ilockit_GUID') =~ /\w+-\w+-\w+-\w+$/); - my $gps_age = 0; - my $gps_age_minutes = 60; - $gps_age = $q->escapeHTML($1) if($q->param('gps_age') =~ /^(\d+)/);#in milli-sec - $gps_age_minutes = $gps_age / 1000 / 60 if($gps_age); + #$update_pos->{txt17} = $Ilockit_GUID if($Ilockit_GUID); + $update_cc->{txt17} = $Ilockit_GUID if($Ilockit_GUID); - my $gps_accuracy = 0; - $gps_accuracy = $q->escapeHTML($1) if($q->param('gps_accuracy') =~ /^(\d+)/);#in meters - my $geo_distance = 1000000;#defaults to 1000000 Meter + my $gps_age = 0; + $gps_age = $1 if($q->param('gps_age') =~ /^(\d+)/);#in milisec + $gps_data->{gps_age_minutes} = $gps_age / 1000 / 60 if($gps_age); + $gps_data->{gps_accuracy} = $1 if($q->param('gps_accuracy') =~ /^(\d+)/);#in meters + + #2022-10-02 manage lock_state before state + if($lock_state && $lock_state =~ /locking|locked|unlocking|unlocked/ && $record_pos->{cc_id} && $record_pos->{cc_id} > 0){ + $booking_values = $self->smartlock($q,$varenv,$auth,$owner,$record_pos,$record_cc,$gps_data,$booking_values); + my $booking_pos = { + table => "contenttranspos", + fetch => "one", + c_id => "$record_pos->{c_id}", + }; + $record_pos = $dbt->fetch_tablerecord($dbh,$booking_pos); + } - #my $ct_state = $state; - my $ct_state = $record_pos->{int10};#2020-07-25 changed because ct_state cannot be canceled #6 = "canceled"|3 = "occupied"|1 = "available" if($state_key && ($state_key == 6 || $state_key == 3 || $state_key == 1) && $record_pos->{cc_id} && $record_pos->{cc_id} > 0){ @@ -1203,7 +1215,6 @@ sub booking_update(){ if($record_pos->{int11} && ($record_pos->{int11} == 2 || $record_pos->{int11} == 3)){ my $update_pos = { table => "contenttranspos", - #int10 => "$state_key", mtime => "now()", }; @@ -1213,11 +1224,11 @@ sub booking_update(){ $update_pos->{txt27} = $q->escapeHTML($q->param('app_debug')) if($q->param('app_debug')); } - #if($state =~ /canceled/ && $record_pos->{txt10} =~ /requested/) - if($state_key == 6 && $record_pos->{int10} == 2){ + #if($state eq canceled && $record_pos.state eq requested && $record_pos.lock_state eq locked) + if($state_key == 6 && $record_pos->{int10} == 2 && $record_pos->{int20} == 1){ $rows = $dbt->delete_content($dbh,"contenttranspos",$record_pos->{c_id}); if($rows > 0){ - $ct_state = "1";#1 = "available" + $update_cc->{int10} = 1; $booking_values->{response_state} = "OK: canceled bike " . $q->param('bike'); $booking_values->{response_text} = "Fahrrad Nr. " . $q->param('bike') . " wurde erfolgreich storniert"; $booking_values->{state} = "available"; @@ -1226,7 +1237,6 @@ sub booking_update(){ $booking_values->{response_text} = "Keine Reservierung zu Fahrrad Nr. " . $q->param('bike') . " gefunden."; } }else{ - $update_pos->{txt17} = $Ilockit_GUID if($Ilockit_GUID); #prevent reset occupied values OR only if genkey defined #if(($state eq "occupied" && $record_pos->{txt10} =~ /requested/) || ($state eq "occupied" && $record_pos->{txt10} =~ /occupied/ && $q->param('genkey') eq "1")) @@ -1234,15 +1244,14 @@ sub booking_update(){ $update_pos->{start_time} = "now()"; $update_pos->{end_time} = "now()"; - #$update_pos->{txt05} = "$gps";#start GPS, not exist on request $update_pos->{txt05} = "$record_cc->{txt06}";#pos start GPS from content end GPS $update_pos->{int06} = "$record_cc->{int04}";#pos start station from content station $update_pos->{txt12} = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}";#pos start station prefix - $update_pos->{int21} = "$gps_age_minutes"; - $update_pos->{int22} = "$gps_accuracy"; + $update_pos->{int21} = $gps_data->{gps_age_minutes}; + $update_pos->{int22} = $gps_data->{gps_accuracy}; $update_pos->{owner} = "$owner"; - $update_pos->{int10} = "$state_key"; + $update_pos->{int10} = 3; $update_pos->{txt11} = "$sig_book->{rentalId}" if($sig_book->{rentalId}); $update_pos->{txt22} = "$sig_book->{bikeId}" if($sig_book->{bikeId}); $rows = $dbt->update_record($dbh,$update_pos,$record_pos); @@ -1250,39 +1259,15 @@ sub booking_update(){ if($rows > 0){ $booking_values->{response_state} = "OK: occupied bike " . $q->param('bike'); $booking_values->{response_text} = "Fahrrad Nr. " . $q->param('bike') . " Miete gestartet. "; - $ct_state = $state_key; + $update_cc->{int10} = 3; } - #Mietende request state=available and pos-state 2=requested or 3=occupied - }elsif($state_key == 1 && ($record_pos->{int10} == 2 || $record_pos->{int10} == 3)){ - #int24 == 1 if if locked && end gps && end station && gps_age <= 3 min && in geo_fence - if($record_pos->{int24}){ - $update_pos->{owner_end} = "$owner"; - $update_pos->{end_time} = "now()"; + #rental end only if locked + #if(state eq available && $record_pos.lock_state eq locked and pos-state 2=requested or 3=occupied + }elsif($state_key == 1 && $record_pos->{int20} == 1 && ($record_pos->{int10} == 2 || $record_pos->{int10} == 3)){ - #return after booking_update - #my $pricing = $pri->sharee_pricing($record_pos,"calc_price"); - #new sharee_pricing - my ($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,""); - #int03 only used for tarif counting backwards compatibility - $update_pos->{int03} = "$pricing->{computed_hours}" if(looks_like_number($pricing->{computed_hours})); - $update_pos->{int38} = "$counting->{int38}" if(looks_like_number($counting->{int38})); - $update_pos->{int39} = "$counting->{int39}" if(looks_like_number($counting->{int39})); - $update_pos->{int40} = "$counting->{int40}" if(looks_like_number($counting->{int40})); - $update_pos->{int41} = "$counting->{int41}" if(looks_like_number($counting->{int41})); - - $update_pos->{int10} = "$state_key"; - $update_pos->{txt11} = "$sig_book->{rentalId}" if($sig_book->{rentalId}); - $rows = $dbt->update_record($dbh,$update_pos,$record_pos); - - $booking_values->{response_state} = "OK: available bike " . $q->param('bike') . ", still locked"; - $booking_values->{response_text} = "Danke! Die Miete Fahrrad Nr. " . $q->param('bike') . " wurde beendet. Schloß wurde bereits abgeschlossen."; - $ct_state = $state_key; - - - } #client GPS must have. sigo ist done without client gps - elsif(($gps && $gps_age_minutes <= 3) || ($record_pos->{int11} == 3)){ + if(($gps_data->{gps} && $gps_data->{gps_age_minutes} <= 3) || ($record_pos->{int11} == 3)){ #geofencing for Ilockit my $geo_distance_next = 100000; my $station_next = 0; @@ -1292,41 +1277,34 @@ sub booking_update(){ foreach my $id (sort { $stations_raw->{$a}->{barcode} <=> $stations_raw->{$b}->{barcode} } keys (%$stations_raw)){ my $latitude_station = $1 if($stations_raw->{$id}->{txt06} =~ /^(\d+\.\d+)/); my $longitude_station = $1 if($stations_raw->{$id}->{txt06} =~ /(\d+\.\d+)$/); - if((!looks_like_number($latitude) || !looks_like_number($longitude)) && ($record_pos->{int11} != 3)){ - $geo_debug .= "ERROR no user GPS: $stations_raw->{$id}->{barcode}|$latitude,$longitude,$latitude_station,$longitude_station --> $geo_distance Meter\n"; - }elsif((looks_like_number($latitude) && looks_like_number($longitude) && looks_like_number($latitude_station) && looks_like_number($longitude_station)) || ($record_pos->{int11} == 3)){ + if((!looks_like_number($gps_data->{latitude}) || !looks_like_number($gps_data->{longitude})) && ($record_pos->{int11} != 3)){ + $geo_debug .= "ERROR no user GPS: $stations_raw->{$id}->{barcode}|$gps_data->{latitude},$gps_data->{longitude},$latitude_station,$longitude_station --> $gps_data->{geo_distance} Meter\n"; + }elsif((looks_like_number($gps_data->{latitude}) && looks_like_number($gps_data->{longitude}) && looks_like_number($latitude_station) && looks_like_number($longitude_station)) || ($record_pos->{int11} == 3)){ $update_pos->{owner_end} = "$owner"; $update_pos->{end_time} = "now()"; - $geo_distance = $lb->geo_fencing($latitude,$longitude,$latitude_station,$longitude_station); - #$station_next = $stations_raw->{$id}->{int04}; - #if($geo_distance <= $stations_raw->{$id}->{int06}) + $gps_data->{geo_distance} = $lb->geo_fencing($gps_data->{latitude},$gps_data->{longitude},$latitude_station,$longitude_station); + #sigo development workaround without geofence - if(($geo_distance <= $stations_raw->{$id}->{int06}) || ($record_pos->{int11} == 3)){ - $geo_distance_next = $geo_distance; + if(($gps_data->{geo_distance} <= $stations_raw->{$id}->{int06}) || ($record_pos->{int11} == 3)){ + $geo_distance_next = $gps_data->{geo_distance}; #end-Station - $update_pos->{int04} = "$stations_raw->{$id}->{int04}"; - $update_cc->{int04} = "$stations_raw->{$id}->{int04}"; - #if($lock_state eq "locked"){ - $update_pos->{int24} = "1"; - $update_pos->{int10} = "$state_key"; - #} + $update_pos->{int04} = $stations_raw->{$id}->{int04}; + $update_cc->{int04} = $stations_raw->{$id}->{int04}; + $update_pos->{int10} = 1; $update_pos->{txt11} = "$sig_book->{rentalId}" if($sig_book->{rentalId}); - $update_cc->{txt06} = "$gps";#end content coordinates - $update_pos->{txt06} = "$gps";#end pos coordinates - $update_pos->{int21} = "$gps_age_minutes"; - $update_pos->{int22} = "$gps_accuracy"; - $update_pos->{int23} = "$geo_distance"; + $update_cc->{txt06} = "$gps_data->{gps}";#end content coordinates + $update_pos->{txt06} = "$gps_data->{gps}";#end pos coordinates + $update_pos->{int21} = $gps_data->{gps_age_minutes}; + $update_pos->{int22} = $gps_data->{gps_accuracy}; + $update_pos->{int23} = $gps_data->{geo_distance}; $update_pos->{int26} = "$sig_book->{distance}" if($sig_book->{distance}); $update_pos->{int28} = "$sig_book->{station_lock_state}" if($sig_book->{station_lock_state}); #end-Station prefix $update_pos->{txt13} = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}"; - #end-Station prefix $update_cc->{txt13} = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}"; #return after booking_update - #my $pricing = $pri->sharee_pricing($record_pos,"calc_price"); - #new sharee_pricing my ($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,""); #int03 only used for tarif counting backwards compatibility $update_pos->{int03} = "$pricing->{computed_hours}" if(looks_like_number($pricing->{computed_hours})); @@ -1338,33 +1316,29 @@ sub booking_update(){ $rows = $dbt->update_record($dbh,$update_pos,$record_pos); if($rows > 0){ - #if($rows > 0 && $lock_state eq "locked"){ - $booking_values->{response_state} = "OK: available bike " . $q->param('bike'); - $booking_values->{response_text} = "Danke! Die Miete Fahrrad Nr. " . $q->param('bike') . " wurde beendet."; - $ct_state = $state_key; + $update_cc->{int10} = 1; + $booking_values->{response_state} = "OK: available bike " . $q->param('bike'); + $booking_values->{response_text} = "Danke! Die Miete Fahrrad Nr. " . $q->param('bike') . " wurde beendet."; } - $geo_debug .= "Matching station: $stations_raw->{$id}->{barcode}|$latitude,$longitude,$latitude_station,$longitude_station --> $geo_distance Meter\n"; + $geo_debug .= "Matching station: $stations_raw->{$id}->{barcode}|$gps_data->{latitude},$gps_data->{longitude},$latitude_station,$longitude_station --> $gps_data->{geo_distance} Meter\n"; last; }else{ - if($geo_distance <= $geo_distance_next){ - $geo_distance_next = $geo_distance; + if($gps_data->{geo_distance} <= $geo_distance_next){ + $geo_distance_next = $gps_data->{geo_distance}; $station_next = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}$stations_raw->{$id}->{int04}"; } #2021-10-13 changed to save last gps @all - $update_cc->{txt06} = "$gps";#end content coordinates - $update_pos->{txt06} = "$gps";#end pos coordinates - $update_pos->{int21} = "$gps_age_minutes"; - $update_pos->{int22} = "$gps_accuracy"; - $update_pos->{int23} = "$geo_distance"; + $update_cc->{txt06} = "$gps_data->{gps}";#end content coordinates + $update_pos->{txt06} = "$gps_data->{gps}";#end pos coordinates + $update_pos->{int21} = $gps_data->{gps_age_minutes}; + $update_pos->{int22} = $gps_data->{gps_accuracy}; + $update_pos->{int23} = $gps_data->{geo_distance}; #end-Station prefix $update_pos->{txt13} = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}"; - #end-Station prefix $update_cc->{txt13} = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}"; #return after booking_update - #my $pricing = $pri->sharee_pricing($record_pos,"calc_price"); - #new sharee_pricing my ($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,""); #int03 only used for tarif counting backwards compatibility $update_pos->{int03} = "$pricing->{computed_hours}" if(looks_like_number($pricing->{computed_hours})); @@ -1375,14 +1349,14 @@ sub booking_update(){ $rows = $dbt->update_record($dbh,$update_pos,$record_pos); - $geo_debug .= "Out of station distance: $stations_raw->{$id}->{barcode}|$latitude,$longitude,$latitude_station,$longitude_station --> $geo_distance_next Meter ($geo_distance_next <= $geo_distance) station_next: $station_next\n"; + $geo_debug .= "Out of station distance: $stations_raw->{$id}->{barcode}|$gps_data->{latitude},$gps_data->{longitude},$latitude_station,$longitude_station --> $geo_distance_next Meter ($geo_distance_next <= $gps_data->{geo_distance}) station_next: $station_next\n"; $booking_values->{response_state} = "Failure 2178: bike " . $q->param('bike') . " out of GEO fencing. $geo_distance_next meter distance to next station $station_next ."; $booking_values->{response_text} = "Achtung! Ihr aktueller Standort liegt außerhalb einer Fahrradstation. Die Miete Fahrrad Nr. " . $q->param('bike') . " kann nicht $state_text werden. $geo_distance_next Meter Entfernung zur nächsten Station $station_next . Falls Sie sich doch an einer Station befinden, dann wiederholen Sie \"Miete beenden\"."; } }else{ - $geo_debug .= "ERROR no station GPS: $stations_raw->{$id}->{barcode}|$latitude,$longitude,$latitude_station,$longitude_station --> $geo_distance Meter\n"; + $geo_debug .= "ERROR no station GPS: $stations_raw->{$id}->{barcode}|$gps_data->{latitude},$gps_data->{longitude},$latitude_station,$longitude_station --> $gps_data->{geo_distance} Meter\n"; } } $booking_values->{geo_distance} = "$geo_distance_next"; @@ -1391,24 +1365,24 @@ sub booking_update(){ #end if gps && gps_age <= 3 and not sigo }elsif($record_pos->{int11} != 3){ - if(!$gps){ + if(!$gps_data->{gps}){ $booking_values->{response_state} = "Failure 2245: No GPS data, state change forbidden."; $booking_values->{response_text} = "Fehler! Keine GPS Standortdaten, Die Miete Fahrrad Nr. " . $q->param('bike') . " kann wegen fehlendem GPS nicht $state_text werden. Bitte aktivieren Sie das GPS."; }else{ - $booking_values->{response_state} = "Failure 2246: GPS age with $gps_age_minutes minutes too old, state change forbidden."; - $booking_values->{response_text} = "Fehler! GPS Daten sind mit $gps_age_minutes Minuten zu alt. Die Miete Fahrrad Nr. " . $q->param('bike') . " kann aufgrund nicht aktueller GPS nicht $state_text werden. Bitte aktivieren Sie das GPS."; + $booking_values->{response_state} = "Failure 2246: GPS age with $gps_data->{gps_age_minutes} minutes too old, state change forbidden."; + $booking_values->{response_text} = "Fehler! GPS Daten sind mit $gps_data->{gps_age_minutes} Minuten zu alt. Die Miete Fahrrad Nr. " . $q->param('bike') . " kann aufgrund nicht aktueller GPS nicht $state_text werden. Bitte aktivieren Sie das GPS."; } } - #end if($state eq "available" && - }elsif($state_key == 6 && $record_pos->{int10} == 3){ - $booking_values->{response_state} = "Failure 2012: occupied bike " . $q->param('bike') . " cannot be $state"; + #end if($state eq "available" && $record_pos.state eq occupied || $record_pos.lock_state ne locked + }elsif($state_key == 6 && ($record_pos->{int10} == 3 || $record_pos->{int20} != 1)){ + $booking_values->{response_state} = "Failure 2012: occupied bike " . $q->param('bike') . " cannot be state $state and $lock_state"; $booking_values->{response_text} = "Fahrrad Nr. " . $q->param('bike') . " ist in Benutzung und kann somit nicht storniert werden."; }elsif($state_key == 3 && $record_pos->{int10} == 1){ $booking_values->{response_state} = "Failure 2016: available bike " . $q->param('bike') . " have to be at first reserved, thats because cannot be $state"; $booking_values->{response_text} = "Fahrrad Nr. " . $q->param('bike') . " wurde nicht reserviert und kann somit nicht gemietet werden."; }else{ - $booking_values->{response_state} = "Failure 2035: bike " . $q->param('bike') . " state change to $state not possible."; + $booking_values->{response_state} = "Failure 2035: bike " . $q->param('bike') . " state change to state $state and $lock_state not possible."; $booking_values->{response_text} = "Fehler! Die Miete Fahrrad Nr. " . $q->param('bike') . " kann nicht mit dem vorhandenen Status $state_text werden."; } @@ -1421,11 +1395,6 @@ sub booking_update(){ my $record_ct->{c_id} = $record_pos->{ct_id}; $dbt->update_record($dbh,$update_ct,$record_ct); - if($q->param('voltage') && $q->param('voltage') =~ /(\d+)/){ - $update_cc->{int14} = $1; - #$self->service_automatic($q) if($1 <= 40); - } - $update_cc->{txt17} = $Ilockit_GUID if($Ilockit_GUID); } #end Ilockit || sigo }else{ @@ -1433,166 +1402,14 @@ sub booking_update(){ } #update bike content - $update_cc->{int10} = "$ct_state";#yes we believe it unsafe to get failure #if(looks_like_number($ct_state)); $bw->log("check ct_state on update_cc 2.",$update_cc,""); - #my $record_cc = { c_id => $record_pos->{cc_id} }; $dbt->update_record($dbh,$update_cc,$record_cc); - #require "Mod/KMLout.pm"; - #my $kmlfile = Mod::KMLout::kmlGenerator($auth,""); - - }#end if $state =~ /canceled|occupied|available/ - if($lock_state && $lock_state =~ /locking|locked|unlocking|unlocked/ && $record_pos->{cc_id} && $record_pos->{cc_id} > 0){ - #content - my $update_cc = { - table => "content", - mtime => "now()", - owner => "$owner", - }; - $update_cc->{txt28} = $q->escapeHTML($q->param('firmware')) if($q->param('firmware')); - #only by system=Ilockit - if($record_pos->{int11} eq "2" && $q->param('voltage') && $q->param('voltage') =~ /(\d+)/){ - $update_cc->{int14} = $1; - $self->service_automatic($q) if($1 <= 50); - } - - my $update_pos = { - table => "contenttranspos", - mtime => "now()", - int24 => 0, - }; - - if($user_agent && $user_agent !~ /axios/){#keep device info if sig push - $update_pos->{int14} = $q->escapeHTML($q->param('voltage')) if($q->param('voltage')); - $update_pos->{txt21} = $q->escapeHTML($q->param('user_device')) if($q->param('user_device')); - $update_pos->{txt26} = $q->escapeHTML($user_agent) if($user_agent); - $update_pos->{txt27} = $q->escapeHTML($q->param('app_debug')) if($q->param('app_debug')); - $update_pos->{txt28} = $q->escapeHTML($q->param('firmware')) if($q->param('firmware')); - } - - my $lock_value = 0; - if($lock_state eq "locked"){ - $lock_value = 1; - $update_cc->{int20} = "$lock_value"; - $update_pos->{int20} = "$lock_value"; - $update_pos->{end_time} = "now()";#2021-01-10 set also end_time on locked - - ####### save locked GPS if available - if($gps && $gps_age_minutes <= 3){ - #geofencing for Ilockit - my $geo_distance_next = $geo_distance; - my $geo_debug=""; - my ($stations,$stations_raw) = $self->stations_available($q,$varenv,$auth,$record_pos); - foreach my $id (sort { $stations_raw->{$a}->{barcode} <=> $stations_raw->{$b}->{barcode} } keys (%$stations_raw)){ - my $latitude_station = $1 if($stations_raw->{$id}->{txt06} =~ /^(\d+\.\d+)/); - my $longitude_station = $1 if($stations_raw->{$id}->{txt06} =~ /(\d+\.\d+)$/); - if(!looks_like_number($latitude) || !looks_like_number($longitude)){ - $geo_debug .= "locked ERROR no user GPS: $stations_raw->{$id}->{barcode}|$latitude,$longitude,$latitude_station,$longitude_station --> $geo_distance Meter\n"; - }elsif(looks_like_number($latitude) && looks_like_number($longitude) && looks_like_number($latitude_station) && looks_like_number($longitude_station)){ - $geo_distance = $lb->geo_fencing($latitude,$longitude,$latitude_station,$longitude_station); - $bw->log("geo_distance by geo_fencing:$latitude,$longitude,$latitude_station,$longitude_station|$stations_raw->{$id}->{txt06}",$geo_distance,""); - if($geo_distance <= $stations_raw->{$id}->{int06}){ - $geo_distance_next = $geo_distance; - #end-Station - $update_pos->{int04} = "$stations_raw->{$id}->{int04}"; - $update_cc->{int04} = "$stations_raw->{$id}->{int04}"; - $update_pos->{int24} = "1"; - - $geo_debug .= "locked Matching station: $stations_raw->{$id}->{barcode}|$latitude,$longitude,$latitude_station,$longitude_station --> $geo_distance Meter\n"; - last; - }else{ - $geo_distance_next = $geo_distance if($geo_distance <= $geo_distance_next); - $geo_debug .= "locked Out of station distance: $stations_raw->{$id}->{barcode}|$latitude,$longitude,$latitude_station,$longitude_station --> $geo_distance Meter\n"; - - } - - $update_pos->{txt06} = "$gps";#end pos coordinates - $update_pos->{int21} = "$gps_age_minutes"; - $update_pos->{int22} = "$gps_accuracy"; - $update_pos->{int23} = "$geo_distance"; - $update_cc->{txt06} = "$gps";#end content coordinates - #end-Station prefix - $update_pos->{txt13} = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}"; - #end-Station prefix - $update_cc->{txt13} = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}"; - $rows = $dbt->update_record($dbh,$update_pos,$record_pos); - - }else{ - $geo_debug .= "locked has no station GPS: $stations_raw->{$id}->{barcode}|$latitude,$longitude,$latitude_station,$longitude_station --> $geo_distance Meter\n"; - } - } - $booking_values->{geo_distance} = "$geo_distance_next"; - #print "$geo_debug\n"; - $bw->log("locked GEOfencing geo_debug:$geo_debug",$booking_values->{geo_distance},""); - - } - ######## end locke GPS - - if($state){ - $booking_values->{response_state} .= " OK: bike " . $q->param('bike') . " locked confirmed"; - $booking_values->{response_text} .= " Abschließen von Fahrrad Nr. " . $q->param('bike') . " bestätigt"; - }else{ - $booking_values->{response_state} = "OK: bike " . $q->param('bike') . " locked confirmed"; - $booking_values->{response_text} = "Abschließen von Fahrrad Nr. " . $q->param('bike') . " bestätigt"; - } - }elsif($lock_state eq "unlocked"){ - #int11=system >= 3 (sigo) with station_lock - #int30=Station Id - #int31=Slot Id - #int27=velofactur bike Id - #if($record_cc->{int11} && $record_cc->{int11} >=3 && $record_cc->{int30} && $record_cc->{int31} && $record_cc->{int27}){ - # $bw->log("unlock station lock with: '$record_cc->{int30}' '$record_cc->{int31}' '$record_cc->{int27}' 'Freigeben' '$record_pos->{c_id}'","",""); - #system(`$varenv{basedir}/src/scripts/velofaktur_client.pl $varenv{syshost} post_velo "$record_cc->{int30}" "$record_cc->{int31}" "$record_cc->{int27}" "Freigeben" "$record_pos->{c_id}"`); - #} - $lock_value = 2; - $update_cc->{int20} = "$lock_value"; - $update_pos->{int20} = "$lock_value"; - if($state){ - $booking_values->{response_state} .= " OK: bike " . $q->param('bike') . " unlocked confirmed"; - $booking_values->{response_text} .= " Aufschließen von Fahrrad Nr. " . $q->param('bike') . " bestätigt"; - }else{ - $booking_values->{response_state} = "OK: bike " . $q->param('bike') . " unlocked confirmed"; - $booking_values->{response_text} = "Aufschließen von Fahrrad Nr. " . $q->param('bike') . " bestätigt"; - } - }elsif($lock_state eq "locking"){ - $lock_value = 3; - $update_cc->{int20} = "$lock_value"; - $update_pos->{int20} = "$lock_value"; - $update_pos->{int23} = "$geo_distance"; - if($state){ - $booking_values->{response_state} .= " OK: bike " . $q->param('bike') . " locking in progress"; - $booking_values->{response_text} .= " Abschließen von Fahrrad Nr. " . $q->param('bike') . " ist im Prozess. Bitte warten bis das smartlock vollständig geschlossen wurde und das abschließen bestätigt wird."; - }else{ - $booking_values->{response_state} = "OK: bike " . $q->param('bike') . " locking in progress"; - $booking_values->{response_text} = "Abschließen von Fahrrad Nr. " . $q->param('bike') . " ist im Prozess. Bitte warten bis das smartlock vollständig geschlossen wurde und das abschließen bestätigt wird."; - } - if($varenv{dbname} ne "sharee_lv" && !$record_pos->{int32}){ - $bw->log("$varenv{basedir}/src/scripts/sms_message.pl $varenv{syshost} locking_progress $auth->{txt07} $record_pos->{c_id}",$record_pos->{c_id},""); - system("$varenv{basedir}/src/scripts/sms_message.pl $varenv{syshost} locking_progress $auth->{txt07} $record_pos->{c_id} &"); - } - $update_pos->{int32} = $record_pos->{int32} + 1;#sms_message sent marker - }elsif($lock_state eq "unlocking"){ - $lock_value = 4; - $update_cc->{int20} = "$lock_value"; - $update_pos->{int20} = "$lock_value"; - if($state){ - $booking_values->{response_state} .= " OK: bike " . $q->param('bike') . " unlocking in progress"; - $booking_values->{response_text} .= " Aufschließen von Fahrrad Nr. " . $q->param('bike') . " ist im Prozess."; - }else{ - $booking_values->{response_state} = "OK: bike " . $q->param('bike') . " unlocking in progress"; - $booking_values->{response_text} = "Aufschließen von Fahrrad Nr. " . $q->param('bike') . " ist im Prozess."; - } - } - - $dbt->update_record($dbh,$update_pos,$record_pos); - $dbt->update_record($dbh,$update_cc,$record_cc); - }#end locked - #fetch final booking state after request if($record_pos->{c_id} > 0){ my $booking_pos = { @@ -1606,10 +1423,7 @@ sub booking_update(){ #$booking_values->{bike} = "$booking->{ct_name}"; $booking_values->{bike} = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}$booking->{barcode}"; $booking_values->{state} = "$dbt->{copri_conf}->{bike_state}->{$booking->{int10}}"; - $booking_values->{lock_state} = "locked" if($booking->{int20} == 1); - $booking_values->{lock_state} = "unlocked" if($booking->{int20} == 2); - $booking_values->{lock_state} = "locking" if($booking->{int20} == 3); - $booking_values->{lock_state} = "unlocking" if($booking->{int20} == 4); + $booking_values->{lock_state} = "$dbt->{copri_conf}->{lock_state}->{$booking->{int20}}"; #user_miniquest_count on operator my $dbh_primary = $dbt->dbconnect_extern("sharee_primary"); @@ -1697,6 +1511,97 @@ sub booking_update(){ } #end booking_update # + +#smartlock state on request update +sub smartlock { + my $self = shift; + my $q = shift; + my $varenv = shift; + my $auth = shift; + my $owner = shift || 0; + my $record_pos = shift || {}; + my $record_cc = shift || {}; + my $gps_data = shift || {}; + my $booking_values = shift || {}; + my $user_agent = $q->user_agent(); + my $dbh = ""; + + #content + my $update_cc = { + table => "content", + mtime => "now()", + owner => "$owner", + }; + $update_cc->{txt28} = $q->escapeHTML($q->param('firmware')) if($q->param('firmware')); + + #only by system=Ilockit + if($record_pos->{int11} eq "2" && $q->param('voltage') && $q->param('voltage') =~ /(\d+)/){ + $update_cc->{int14} = $1; + $self->service_automatic($q) if($1 <= 50); + } + + my $update_pos = { + table => "contenttranspos", + mtime => "now()", + int24 => 0, + }; + + if($user_agent && $user_agent !~ /axios/){#keep device info if sig push + $update_pos->{int14} = $q->escapeHTML($q->param('voltage')) if($q->param('voltage')); + $update_pos->{txt21} = $q->escapeHTML($q->param('user_device')) if($q->param('user_device')); + $update_pos->{txt26} = $q->escapeHTML($user_agent) if($user_agent); + $update_pos->{txt27} = $q->escapeHTML($q->param('app_debug')) if($q->param('app_debug')); + $update_pos->{txt28} = $q->escapeHTML($q->param('firmware')) if($q->param('firmware')); + } + + my $lock_value = 0; + if($q->param('lock_state') eq "locked"){ + $lock_value = 1; + $update_cc->{int20} = "$lock_value"; + $update_pos->{int20} = "$lock_value"; + $update_pos->{end_time} = "now()"; + + $update_cc->{txt06} = $gps_data->{gps};#end content coordinates + $update_pos->{txt06} = $gps_data->{gps};#end pos coordinates + $update_pos->{int21} = $gps_data->{gps_age_minutes}; + $update_pos->{int22} = $gps_data->{gps_accuracy}; + $update_pos->{int23} = $gps_data->{geo_distance}; + $booking_values->{response_state} = "OK: bike " . $q->param('bike') . " locked confirmed. "; + $booking_values->{response_text} = "Abschließen von Fahrrad Nr. " . $q->param('bike') . " bestätigt. "; + + }elsif($q->param('lock_state') eq "unlocked"){ + $lock_value = 2; + $update_cc->{int20} = "$lock_value"; + $update_pos->{int20} = "$lock_value"; + $booking_values->{response_state} = "OK: bike " . $q->param('bike') . " unlocked confirmed. "; + $booking_values->{response_text} = "Aufschließen von Fahrrad Nr. " . $q->param('bike') . " bestätigt. "; + + }elsif($q->param('lock_state') eq "locking"){ + $lock_value = 3; + $update_cc->{int20} = "$lock_value"; + $update_pos->{int20} = "$lock_value"; + $booking_values->{response_state} = "OK: bike " . $q->param('bike') . " locking in progress. "; + $booking_values->{response_text} = "Abschließen von Fahrrad Nr. " . $q->param('bike') . " ist im Prozess. Bitte warten bis das smartlock vollständig geschlossen wurde und das abschließen bestätigt wird. "; + if($varenv->{dbname} ne "sharee_lv" && !$record_pos->{int32}){ + $bw->log("$varenv->{basedir}/src/scripts/sms_message.pl $varenv->{syshost} locking_progress $auth->{txt07} $record_pos->{c_id}",$record_pos->{c_id},""); + system("$varenv->{basedir}/src/scripts/sms_message.pl $varenv->{syshost} locking_progress $auth->{txt07} $record_pos->{c_id} &"); + } + $update_pos->{int32} = $record_pos->{int32} + 1;#sms_message sent marker + }elsif($q->param('lock_state') eq "unlocking"){ + $lock_value = 4; + $update_cc->{int20} = "$lock_value"; + $update_pos->{int20} = "$lock_value"; + $booking_values->{response_state} = "OK: bike " . $q->param('bike') . " unlocking in progress. "; + $booking_values->{response_text} = "Aufschließen von Fahrrad Nr. " . $q->param('bike') . " ist im Prozess. "; + } + + $dbt->update_record($dbh,$update_pos,$record_pos); + $dbt->update_record($dbh,$update_cc,$record_cc); + + return $booking_values; +}#end smartlock + + # #dedicated service insert automatic sub service_automatic { @@ -2775,7 +2680,7 @@ sub auth_verify(){ if ($auth_primary->{c_id} > 0 && $q->param('user_device')){ $update_primary->{txt14} = $q->escapeHTML($session_log) if($session_log); $update_primary->{txt21} = $q->escapeHTML($q->param('user_device')) if($q->param('user_device')); - $update_primary->{txt25} = $q->escapeHTML($clientIP) if($clientIP && $clientIP =~ /\d+\.\d+\.\d+\.\d+/); + $update_primary->{txt25} = $q->escapeHTML($clientIP) if($clientIP); $update_primary->{txt26} = $q->escapeHTML($user_agent) if($user_agent); } @@ -3040,7 +2945,7 @@ sub authcookie_manager { }; $update->{txt21} = $q->escapeHTML($q->param('user_device')) if($q->param('user_device')); - $update->{txt25} = $q->escapeHTML($clientIP) if($clientIP && $clientIP =~ /\d+\.\d+\.\d+\.\d+/); + $update->{txt25} = $q->escapeHTML($clientIP) if($clientIP); $update->{txt26} = $q->escapeHTML($user_agent) if($user_agent); my @registered_cookies; diff --git a/copri4/main/src/Mod/DBtank.pm b/copri4/main/src/Mod/DBtank.pm index d19a1cf..9b5d957 100755 --- a/copri4/main/src/Mod/DBtank.pm +++ b/copri4/main/src/Mod/DBtank.pm @@ -1112,15 +1112,16 @@ sub collect_transpos { $where .= " and cp.c_id = $search->{$key}" if(($key eq "c_id" || $key eq "cttpos_id") && $search->{$key}); $where .= " and cp.$key ilike '%$search->{$key}%'" if($key eq "txt08" && $search->{$key}); $where .= " and cp.$key ilike '%$search->{$key}%'" if($key eq "txt23" && $search->{$key}); - $where .= " and (cp.int04 = $search->{$key} OR cp.int06 = $search->{$key})" if($key eq "int04" && looks_like_number($search->{$key})); + $where .= " and cp.int04 = $search->{$key}" if($key eq "int04" && looks_like_number($search->{$key})); + $where .= " and cp.int06 = $search->{$key}" if($key eq "int06" && looks_like_number($search->{$key})); $where .= " and cp.ct_name = '$search->{$key}'" if($key eq "cp_ct_name" && $search->{$key}); $where .= " and ct.ct_name = '$search->{$key}'" if($key eq "ct_ct_name" && $search->{$key}); - $where .= " and ct.txt06 ilike '$search->{$key}%'" if($key eq "ct_txt06" && $search->{$key});#PLZ + $where .= " and ct.txt06 ilike '$search->{$key}%'" if($key eq "ct_txt06" && $search->{$key}); $where .= " and cp.$key = '$search->{$key}'" if($key eq "ct_id" && looks_like_number($search->{$key})); - $where .= " and cp.$key = $search->{$key}" if($key eq "int10" && looks_like_number($search->{$key}));#bike_state - $where .= " and cp.$key = $search->{$key}" if($key eq "int20" && looks_like_number($search->{$key}));#lock_state + $where .= " and cp.$key = $search->{$key}" if($key eq "int10" && looks_like_number($search->{$key})); + $where .= " and cp.$key = $search->{$key}" if($key eq "int20" && looks_like_number($search->{$key})); $where .= " and cp.$key = $search->{$key}" if($key eq "barcode" && looks_like_number($search->{$key})); - $where .= " and cp.$key = $search->{$key}" if($key eq "int12" && looks_like_number($search->{$key}));#flot_id + $where .= " and cp.$key = $search->{$key}" if($key eq "int12" && looks_like_number($search->{$key})); $where .= " and (cp.$key = $search->{$key} OR cp.owner_end = $search->{$key})" if($key eq "owner" && looks_like_number($search->{$key})); $where .= " and (cp.$key is $search->{$key} OR cp.$key = 0)" if($key eq "int34" && $search->{$key} eq "null"); } @@ -1389,7 +1390,7 @@ sub insert_pos(){ my $sth; #Verleihräder if($ct->{template_id} && $ct->{template_id} == 205){#Leihrad_list - $sth = $dbh->prepare("INSERT INTO contenttranspos (ct_id,cc_id,ca_id,ct_name,barcode,txt01,txt08,txt02,txt09,txt12,itime,start_time,end_time,int01,int02,int03,int06,int04,txt05,txt06,txt07,int10,int12,template_id,int13,owner,int07,txt04,int09,int17,int15,int16,int11,int18,int19,txt17,txt18,int20,int25,int29,int34,txt22,txt11,int35,int36,int37,int42,time01,time02) VALUES ('$ctt_id','$ct->{c_id}','$ctadr->{c_id}','$ct_name','$ct->{barcode}','$ct->{txt01}','$user_name','$ct->{txt02}','$ctadr->{txt09}','$prefix',now(),now(),'$endRental','1','$unit_price','$menge','$station','$station','$ct->{txt06}','$ct->{txt06}','$ct->{txt07}','$status','$from_main_id','$from_template_id','$deviceId','$owner','$rabatt','$tariff_desc','$tariff_nr','$daymax_price','$abo_price','$free_hours','$ct->{int11}','$sharing_type','$bike_charge','$ct->{txt17}','$ct->{txt18}','$ct->{int20}','$trackon','$bike_type_id','$staff','$sig_book->{bikeId}','$sig_book->{rentalId}','$unit_price1','$unit_price2','$start_price','$aa_station','$unit_time','$free_time') RETURNING c_id"); + $sth = $dbh->prepare("INSERT INTO contenttranspos (ct_id,cc_id,ca_id,ct_name,barcode,txt01,txt08,txt02,txt09,txt12,itime,start_time,end_time,int01,int02,int03,int06,int04,txt05,txt06,txt07,int10,int12,template_id,int13,owner,int07,txt04,int09,int17,int15,int16,int11,int18,int19,txt17,txt18,int20,int25,int29,int34,txt22,txt11,int35,int36,int37,int42,time01,time02) VALUES ('$ctt_id','$ct->{c_id}','$ctadr->{c_id}','$ct_name','$ct->{barcode}','$ct->{txt01}','$user_name','$ct->{txt02}','$ctadr->{txt09}','$prefix',now(),now(),'$endRental','1','$unit_price','$menge','$station','$station','$ct->{txt06}','$ct->{txt06}','$ct->{txt07}','$status','$from_main_id','$from_template_id','$deviceId','$owner','$rabatt','$tariff_desc','$tariff_nr','$daymax_price','$abo_price','$free_hours','$ct->{int11}','$sharing_type','$bike_charge','$ct->{txt17}','$ct->{txt18}','1','$trackon','$bike_type_id','$staff','$sig_book->{bikeId}','$sig_book->{rentalId}','$unit_price1','$unit_price2','$start_price','$aa_station','$unit_time','$free_time') RETURNING c_id"); }else{ $sth = $dbh->prepare("INSERT INTO contenttranspos (ct_id,cc_id,ca_id,ct_name,barcode,txt08,txt09,itime,int01,int02,int03,txt01,txt06,txt07,int10,int12,template_id,owner) VALUES ('$ctt_id','$ct->{c_id}','$ctadr->{c_id}','$ct_name','$ct->{barcode}','$user_name','$ctadr->{txt09}',now(),'1','$unit_price','1','$ct->{txt01}','$ct->{txt06}','$ct->{txt07}','0','$from_main_id','$from_template_id','$owner') RETURNING c_id"); } diff --git a/copri4/main/src/Mod/Payment.pm b/copri4/main/src/Mod/Payment.pm index 01ba7fe..b63b4fe 100755 --- a/copri4/main/src/Mod/Payment.pm +++ b/copri4/main/src/Mod/Payment.pm @@ -186,7 +186,7 @@ sub preauthorizationSEPA_main { bic => uc($ctadr->{txt23}), reference => "$reference" }; - $preauth_request->{ip} = "$ctadr->{txt25}" if($ctadr->{txt25} && $ctadr->{txt25} =~ /\d+\.\d+\.\d+\.\d+/); + $preauth_request->{ip} = "$ctadr->{txt25}" if($ctadr->{txt25}); my $request = { %$payone_conf, %$preauth_request}; $payoneret = $self->rpc("preauthorizationSEPA",$varenv,$request,$ctadr,$ctt,$owner) if($request); } @@ -321,7 +321,7 @@ sub preauthorizationCC_main { }; # https://docs.payone.com/display/public/PLATFORM/Special+remarks+-+Recurring+transactions+credit+card # https://docs.payone.com/display/public/INT/Best+Practices+for+PSD2#tab-3DS+2.0+Best+Case - $preauth_request->{ip} = "$ctadr->{txt25}" if($ctadr->{txt25} && $ctadr->{txt25} =~ /\d+\.\d+\.\d+\.\d+/); + $preauth_request->{ip} = "$ctadr->{txt25}" if($ctadr->{txt25}); my $request = { %$payone_conf, %$preauth_request}; $payoneret = $self->rpc("preauthorizationCC",$varenv,$request,$ctadr,$ctt,$owner) if($request); } diff --git a/copri4/main/src/Tpl/Calorin.pm b/copri4/main/src/Tpl/Calorin.pm index 281cc2c..ebd7585 100755 --- a/copri4/main/src/Tpl/Calorin.pm +++ b/copri4/main/src/Tpl/Calorin.pm @@ -163,36 +163,28 @@ sub tpl(){ table => "$node_meta->{ct_table}", limit => $q->escapeHTML($limit), offset => $q->escapeHTML($offset), - cal_sort_updown => $users_dms->{cal_sort_updown}, }; - if($R::base_edit !~ /transpos|save_pos/){ - $search = { %$search, - cttpos_id => $q->escapeHTML("$R::cttpos_id"), - txt06 => $q->escapeHTML("$R::txt06"), - txt08 => $q->escapeHTML("$R::txt08"), - txt23 => $q->escapeHTML("$R::txt23"), - int04 => $q->escapeHTML("$R::int04"), - int06 => $q->escapeHTML("$R::int06"), - int12 => $q->escapeHTML("$R::int12"), - int13 => $q->escapeHTML("$R::int13"), - cp_ct_name => $q->escapeHTML("$R::cp_ct_name"), - int10 => $q->escapeHTML("$R::int10"), - int20 => $q->escapeHTML("$R::int20"), - barcode => $q->escapeHTML("$R::barcode"), - ct_txt06 => $q->escapeHTML("$R::ct_txt06"),#PLZ - ct_ct_name => $q->escapeHTML("$R::ct_ct_name"), - } - } - - $search = { %$search, - start_date_time => "$start_date_time", - end_date_time => "$end_date_time", - owner => $q->escapeHTML("$R::owner"), - } if(!$R::cttpos_id && !$R::ct_id); - - #$search->{barcode} = $q->escapeHTML("$R::barcode") if($R::base_edit eq "save_pos" && $R::barcode); - $search->{ct_id} = $q->escapeHTML("$R::ct_id") if($R::ct_id);#done on save_pos and insert fee + if($R::ct_id){ + $search->{ct_id} = $q->escapeHTML("$R::ct_id"); + }else{ + $search->{start_date_time} = "$start_date_time"; + $search->{end_date_time} = "$end_date_time"; + $search->{cttpos_id} = $q->escapeHTML("$R::cttpos_id"); + $search->{txt06} = $q->escapeHTML("$R::txt06"); + $search->{txt08} = $q->escapeHTML("$R::txt08"); + $search->{txt23} = $q->escapeHTML("$R::txt23"); + $search->{int04} = $q->escapeHTML("$R::int04"); + $search->{int06} = $q->escapeHTML("$R::int06"); + $search->{int12} = $q->escapeHTML("$R::int12"); + $search->{int13} = $q->escapeHTML("$R::int13"); + $search->{cp_ct_name} = $q->escapeHTML("$R::cp_ct_name"); + $search->{int10} = $q->escapeHTML("$R::int10"); + $search->{int20} = $q->escapeHTML("$R::int20"); + $search->{barcode} = $q->escapeHTML("$R::barcode"); + $search->{ct_txt06} = $q->escapeHTML("$R::ct_txt06");#PLZ + $search->{ct_ct_name} = $q->escapeHTML("$R::ct_ct_name"); + } if(!$start_chck && !$end_chck){ if($node_meta->{ct_table} eq "contenttranspos"){ @@ -247,8 +239,8 @@ sub tpl(){ foreach(@tpl_order){ #$h++; my ($key,$des,$size) = split /=/,$_; - my $valxx = $q->param("$_"); - $valxx = "" if($R::base_edit eq "save_pos" && $key ne "barcode");#empty search fields, select only bike number + my $valxx = $q->param("$_") || ""; + #$valxx = "" if($R::base_edit eq "save_pos" && $key ne "barcode");#empty search fields, select only bike number if($key =~ /time/){ $size="10px";