Adding station_type, category and text-cms

This commit is contained in:
ragu 2023-03-30 17:45:12 +02:00
parent 47bf368903
commit cc82e0856a
8 changed files with 136 additions and 40 deletions

View file

@ -1486,7 +1486,7 @@ sub smartlock {
#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);
$self->service_automatic($q,"") if($1 <= 60);
}
my $update_pos = {
@ -1813,6 +1813,7 @@ sub bikes_available(){
$authed = 1 if(ref($auth) eq "HASH" && $auth->{c_id} > 0);
(my $bike_group,my $bike_node,my $user_tour,$tariff_content,$adrtarif_hash) = $self->fetch_tariff($varenv->{dbname},$auth,$q->param('authcookie'));
$bw->log("$varenv->{dbname} bikes_available bike_group:",$bike_group,"");
#print Dumper($bike_group);
#print Dumper($bike_node);
my $main_ids = join(",",@{$bike_node});
@ -2120,7 +2121,7 @@ sub stations_available(){
my $authcookie = $q->param('authcookie') || $q->cookie('domcookie');
my ($bike_group,$bike_node,$user_tour,$tariff_content,$adrtarif_hash) = $self->fetch_tariff($varenv->{dbname},$auth,$authcookie,$cachme);
$bw->log("fetch_tariff adrtarif_hash from $varenv->{dbname}\n",$adrtarif_hash,"");
#$bw->log("fetch_tariff adrtarif_hash from $varenv->{dbname}\n",$adrtarif_hash,"");
#station_group and bike_group alias bike nodes.type_id
my $station_group = "";
@ -2228,6 +2229,30 @@ sub stations_available(){
$return->{$id}->{description} = "$description";
$return->{$id}->{state} = "$dbt->{copri_conf}->{bike_state}->{$record->{$id}->{int10}}";
$return->{$id}->{gps_radius} = "$record->{$id}->{int06}";
#new station category
#defaults
$return->{$id}->{station_type} = {};
my @station_group = ();
if($record->{$id}->{txt25} && $record->{$id}->{txt25} =~ /\d\s\d/){
@station_group = split(/\s/,$record->{$id}->{txt25});
}elsif($record->{$id}->{txt25}){
@station_group = ("$record->{$id}->{txt25}");
}
foreach(@station_group){
if($_ && $dbt->{copri_conf}->{type_id}->{$_}){
$return->{$id}->{station_type}->{$dbt->{copri_conf}->{type_id}->{$_}}->{bike_group} = "$dbt->{operator}->{$varenv->{dbname}}->{oprefix}$_";
my $bike_count2 = 0;
foreach my $b_id (keys (%$record_bikes)){
if($record->{$id}->{int04} == $record_bikes->{$b_id}->{int04}){
$bike_count2++ if($_ == $record_bikes->{$b_id}->{type_id});
}
}
$return->{$id}->{station_type}->{$dbt->{copri_conf}->{type_id}->{$_}}->{bike_count} = "$bike_count2";
}
}
#deprecated
$return->{$id}->{station_group} = "";
if($record->{$id}->{txt25}){
$record->{$id}->{txt25} =~ s/(\d+)/$dbt->{operator}->{$varenv->{dbname}}->{oprefix}$1/g;
@ -2527,7 +2552,7 @@ sub fetch_tariff(){
}
#else select all available user tarif entries
$tariff_all = $dbt->fetch_record($dbh,$tariff);
$bw->log("$dbname Tariff type for operator registered user by int18:$tariff->{int18} select 4:",$tariff_all,"");
$bw->log("$dbname Tariff type for operator registered user with Tarif $auth_operator->{txt30} by int18:$tariff->{int18} select 4:",$tariff_all,"");
}
#end operators address
else{
@ -2546,12 +2571,14 @@ sub fetch_tariff(){
if($auth_operator->{txt30} && $auth_operator->{txt30} =~ /\d\s\d/){
%tarif_hash = map { $_ => 1 } split(/\s+/,$auth_operator->{txt30});
}elsif($auth_operator->{txt30}){
$tarif_hash{$auth_operator->{txt30}} = 1;
}elsif($auth_operator->{txt30} && $auth_operator->{txt30} =~ /(\d+)/){
$tarif_hash{$1} = 1;
}
if(ref($tariff_all) eq "HASH"){
foreach my $rid (keys (%$tariff_all)){
#$bw->log("$dbname Tariff hash $auth_operator->{txt30}|$tariff_all->{$rid}->{barcode} --> $tarif_hash{$tariff_all->{$rid}->{barcode}}",\%tarif_hash,"");
if(ref(\%tarif_hash) eq "HASH" && $tarif_hash{$tariff_all->{$rid}->{barcode}}){
foreach my $tk (keys(%tarif_hash)){
$bw->log("Tarif FOUND condition: $tk && $rid && $tariff_all->{$rid}->{barcode} == $tk","","");

View file

@ -96,8 +96,8 @@ sub loop_sharees {
my %prim_tarif_hash = ();
if($authraw->{txt30} =~ /\w\s\w/){
%prim_tarif_hash = map { $_ => 1 } split(/\s+/,$authraw->{txt30});
}elsif($authraw->{txt30}){
$prim_tarif_hash{$authraw->{txt30}} = 1;
}elsif($authraw->{txt30} && $authraw->{txt30} =~ /(\w+)/){
$prim_tarif_hash{$1} = 1;
}
foreach my $optarif (keys(%prim_tarif_hash)){
my $op_key = "";

View file

@ -94,6 +94,13 @@ my $response = {
}
};
if($varenv{dbname} eq $dbt->{primary}->{sharee_primary}->{database}->{dbname}){
$varenv{cms} = $dbt->fetch_cms($dbh,{ lang => $q->escapeHTML($R::lang) });
}else{
my $dbh_primary = $dbt->dbconnect_extern($dbt->{primary}->{sharee_primary}->{database}->{dbname});
$varenv{cms} = $dbt->fetch_cms($dbh_primary,{ lang => $q->escapeHTML($R::lang) });
}
my $aowner = 0;
my $coo = $q->param('authcookie') || $q->param('sessionid') || "";
if(!$coo && !$q->param('merchant_id')){
@ -478,7 +485,7 @@ elsif($q->param('request') eq "bikes_available"){
my $authraw = {};
($auth,$authraw) = $apif->auth_verify($q,"","",1);
$response = { %$response, %$auth };
#$bw->log("Y bikes_available by c_id $authraw->{c_id}, Tarif:",$authraw->{txt30},"");
#$bw->log("Y bikes_available $varenv{dbname} by c_id $authraw->{c_id}, Tarif: $authraw->{txt30}",$authraw->{txt30},"");
if($varenv{syshost} eq "shareeapp-sx"){
($response->{bikes},my $return2copri->{bikes}) = $si->sig_available($q,\%varenv,$authraw);
@ -683,17 +690,11 @@ elsif($q->param('request') eq "stations_available"){
#App update message
if($user_agent_subversion <= 348){
if($epoch_now >= $epoch_start && $epoch_now <= $epoch_end){
my $pref_ctu = {
table => "contentuser",
fetch => "one",
ct_name => "App-update-message",
};
my $uadr = { c_id => 0 };
$uadr = $dbt->fetch_tablerecord($dbh,$pref_ctu);
$response->{merchant_message} = $uadr->{txt01};
$response->{merchant_message} = $uadr->{txt02} if($q->param('lang') eq "en");
$response->{merchant_message} = $varenv{cms}->{'App-update-message'}->{txt};
}else{
$response->{merchant_message} = $varenv{cms}->{'App-update-message-expired'}->{txt};
$apif->authout($q,$coo);
$dbt->update_operatorsloop($varenv{dbname},$authraw->{c_id},"update");
}
}
@ -920,6 +921,8 @@ elsif($q->param('request') eq "service_done"){
($response_work, $node) = $apif->service_work($pos_record,$stations_allraw,"",$node_template);
}
#should not be mandatory here, maybe only for bike_count
#$apif->stations_caching($q,\%varenv,$authraw);
#inject oprefix
my $op_response_work = {};

View file

@ -684,6 +684,24 @@ sub collect_post(){
return $record;
}
#fetch CMS
#coalesce works only on null values
sub fetch_cms(){
my $self = shift;
my $dbh = shift || $dbh_intern;
my $fetch = shift;
my $langfield = "txt01";
$langfield = "txt02" if($fetch->{lang} eq "en");
$langfield = "txt03" if($fetch->{lang} eq "fr");
my $sql = "SELECT ct_name, coalesce($langfield, txt01) AS txt FROM contentuser, relation where template_id=194 and c_id=content_id";
my $sth = $dbh->prepare($sql);
my $rc = $sth->execute();
my $record = $sth->fetchall_hashref('ct_name');
return $record;
}#end fetch_cms
#fetch all|one content + relation + nodes
sub fetch_record(){
my $self = shift;
@ -803,7 +821,7 @@ sub fetch_tablerecord(){
$where .= " and $key $op $value";
}elsif($key =~ /time$/ && $value){
$where .= " and $key $op '$value'";
}elsif($key =~ /^(c_id|u_id|ct_id|ca_id|barcode|int\d+|owner|template_id)$/ && (looks_like_number($value) || $value eq "null")){
}elsif($key =~ /^(c_id|u_id|cc_id|ct_id|ca_id|barcode|int\d+|owner|template_id)$/ && (looks_like_number($value) || $value eq "null")){
if($value eq "null"){
$where .= " and ($key is null OR $key = 0)";
}elsif($value eq "nullOR1"){

View file

@ -16,18 +16,14 @@ use DBI;
use Apache2::RequestUtil ();
use Apache2::RequestIO ();
use Apache2::Const -compile => qw(OK);
use LWP::UserAgent;
use Digest::MD5 qw(md5 md5_hex);
use Scalar::Util qw(looks_like_number);
#use Encode;
#use URI::Encode qw(uri_encode uri_decode);
use Lib::Config;
use Mod::Buttons;
use Mod::Prelogic;
use Lib::Mlogic;
use Mod::Basework;
#use Mod::Premain;
use Mod::DBtank;
use Mod::Libenzdb;
use Mod::APIfunc;
@ -46,7 +42,6 @@ sub handler {
my $ml = new Mlogic;
my $bw = new Basework;
my $pre = new Prelogic;
#my $pm = new Premain;
my $tk = new Shareework;
my $dbt = new DBtank;
my $db = new Libenzdb;
@ -77,6 +72,7 @@ sub handler {
d_rows => 0,
};
#$mode is used to set GUI features like "maintainer" contextmenue
my $modes = $dbt->{shareedms_conf}->{modes};
my $mode = "";
@ -173,6 +169,12 @@ sub handler {
$users_dms = $dbt->select_users($dbh,$users_sharee->{c_id},"and cookie='$coo'");
}
if($varenv{dbname} eq $dbt->{primary}->{sharee_primary}->{database}->{dbname}){
$varenv{cms} = $dbt->fetch_cms($dbh,{ lang => $q->escapeHTML($R::lang) });
}else{
my $dbh_primary = $dbt->dbconnect_extern($dbt->{primary}->{sharee_primary}->{database}->{dbname});
$varenv{cms} = $dbt->fetch_cms($dbh_primary,{ lang => $q->escapeHTML($R::lang) });
}
#Save anyway on create ... and hopefully delete it later
if($R::sharee_edit && $R::sharee_edit =~ /create_account/ && $R::txt04 && $R::txt04 =~ /\w+/ && $R::txt08 && $R::txt08 =~ /\w+\@\w+/){

View file

@ -183,6 +183,8 @@ sub save_content {
}else{
$feedb->{message} = "failure::Eingabefehler \"$valxx\", hier sind nur numerische Werte erlaubt";
}
}elsif($node_meta->{template_id} == 194 && $_ =~ /txt/ && !$valxx){
$update_ct->{$_} = "null";#important for coalesce select alias lang fallback
}elsif($_ =~ /ct_name|txt|state|time/){
$update_ct->{$_} = "$valxx";
}

View file

@ -80,6 +80,17 @@ sub tpl(){
my $occupied_style = "";
if($node_meta->{ct_table} eq "content" && $node_meta->{tpl_id} && $c_id){
#check rental state
if($node_meta->{tpl_id} == 205){
my $pref = {
table => "contenttranspos",
fetch => "one",
int10 => "IN::(2,3)",
cc_id => $c_id,
};
$cttpos = $dbt->fetch_tablerecord($dbh,$pref);
$occupied_style = "color:#ff1493" if($cttpos->{int10} == 2 ||$cttpos->{int10} == 3);
}
my $ref = {
table => "$node_meta->{ct_table}",
fetch => "one",
@ -523,7 +534,23 @@ EOF
my $seldes = $des;
$des .= " ($key)" if($users_dms->{u_id} eq $varenv{superu_id});
if($key =~ /c_id|ct_name|barcode|txt/ && $size eq "readonly"){
if($key =~ /txt25/ && $node_meta->{tpl_id} == 225 && $size eq "readonly"){
my %station_filter_hash = ();
if($ctrel->{txt25} && $ctrel->{txt25} =~ /\d\s\d/){
%station_filter_hash = map { $_ => 1 } split(/\s+/,$ctrel->{txt25});
}elsif($ctrel->{txt25} && $ctrel->{txt25} =~ /(\d+)/){
$station_filter_hash{$1} = 1;
}
my $station_filter = "";
foreach my $type_id (keys (%station_filter_hash)){
$station_filter .= "$dbt->{copri_conf}->{type_id}->{$type_id}<br />";
}
print $q->Tr();
print $q->td({-class=>'left_italic_cms',-style=>'vertical-align:top;',-colspan=>'1'},"$des");
print $q->td({-class=>'content1_cms',-colspan=>'1'},$station_filter);
}
elsif($key =~ /c_id|ct_name|barcode|txt/ && $size eq "readonly"){
print $q->Tr();
print $q->td({-class=>'left_italic_cms'},"$des"),"\n";
print $q->td({-class=>'content1_cms',-colspan=>2},$q->textfield(-class=>'etxt', -style=>"width:$w;color:grey;",-name=>"$key", -default=>"$ctrel->{$key}", -readonly=>1)),"\n";
@ -621,13 +648,17 @@ EOF
print $q->td({-class=>'content1_cms',-colspan=>'1'},$but->selector_class("$key","eselect","width:350px;",$ctrel->{$key},@_valxx));
}
elsif($key =~ /int10/ && "$size" eq "select" && $node_meta->{tpl_id} == 205){#bike_state
my @_lock_valxx = ();
foreach my $s_key (sort keys (%{ $dbt->{copri_conf}->{bike_state} })) {
push @_lock_valxx, "$s_key:$dbt->{copri_conf}->{bike_state}->{$s_key}";
}
print $q->Tr();
print $q->td({-class=>'left_italic_cms'},"$des"),"\n";
print $q->td({-class=>'content1_cms',-colspan=>'2'},$but->selector_class("$key","eselect","",$ctrel->{$key},@_lock_valxx));
if($occupied_style){
print $q->td({-class=>'content1_cms',-colspan=>'2'},"$dbt->{copri_conf}->{bike_state}->{$cttpos->{$key}}", $q->span({-style=>"$occupied_style"},"Das Rad ist in Benutzung. Der Mietvorgang kann nur über das Mietjournal beendet werden")),"\n";
}else{
my @_lock_valxx = ();
foreach my $s_key (sort keys (%{ $dbt->{copri_conf}->{bike_state} })) {
push @_lock_valxx, "$s_key:$dbt->{copri_conf}->{bike_state}->{$s_key}";
}
print $q->td({-class=>'content1_cms',-colspan=>'2'},$but->selector_class("$key","eselect","",$ctrel->{$key},@_lock_valxx));
}
}
elsif($key =~ /int10/ && "$size" eq "select" && $node_meta->{tpl_id} == 225){#station_state
my @_lock_valxx = ();
@ -742,11 +773,9 @@ EOF
print $q->td({-class=>'content1_cms',-colspan=>'1'},$but->selector2("$key","50px;","$height",$ctrel->{$key},@_service_valxx));
}
elsif($key =~ /txt24/ && $node_meta->{tpl_id} == 225){ #Station on station_group (bikenode.main_ids)
#my %station_filter_hash = ();
#my @_valxx_filter = ("");
my @_valxx = ("");
foreach my $rid (sort { $bike_nodes->{$a}->{node_name} cmp $bike_nodes->{$b}->{node_name} } keys (%$bike_nodes)){
push (@_valxx, "$bike_nodes->{$rid}->{main_id}:$bike_nodes->{$rid}->{node_name} - $dbt->{copri_conf}->{type_id}->{$bike_nodes->{$rid}->{type_id}}");
push (@_valxx, "$bike_nodes->{$rid}->{main_id}:$bike_nodes->{$rid}->{node_name}");
}
my $height = scalar(@_valxx);
@ -754,6 +783,7 @@ EOF
print $q->td({-class=>'left_italic_cms',-style=>'vertical-align:top;',-colspan=>'1'},"$des");
print $q->td({-class=>'content1_cms',-colspan=>'1'},$but->selector2("$key","250px;","$height",$ctrel->{$key},@_valxx));
}
#sharee user_group Tarif-2.0 (tarif.c_ids)
elsif($key =~ /txt30/ && $varenv{dbname} ne $dbt->{primary}->{sharee_primary}->{database}->{dbname}){
my @_valxx = ("");

View file

@ -588,7 +588,7 @@ EOF
foreach(@tpl_order){
$h++;
my ($key,$val,$size) = split /=/,$_;
if($size !~ /select/){
if($size !~ /select|readonly/){
if($size =~ /area/){
$size = "5em";
}elsif($key =~ /int0|c_id|ct_name/){
@ -612,11 +612,13 @@ EOF
push (@s_valxx, "$bike_nodes->{$rid}->{main_id}:$bike_nodes->{$rid}->{node_name} - $dbt->{copri_conf}->{type_id}->{$bike_nodes->{$rid}->{type_id}}");
}
print $q->td({-class=>'search_line'},$but->selector_class("s_$key","","",$s_val,@s_valxx)),"\n";
}elsif($size =~ /select/ && $key =~ /txt24/ && $tpl_id =~ /225/){#txt24=bike_group (for station filter)
}
#txt24=bike_group
elsif($size =~ /select/ && $key =~ /txt24/ && $tpl_id =~ /225/){
#my %station_filter_hash = ();
my @s_valxx = ("");
foreach my $rid (sort { $bike_nodes->{$a}->{node_name} cmp $bike_nodes->{$b}->{node_name} } keys (%$bike_nodes)){
push (@s_valxx, "$bike_nodes->{$rid}->{main_id}:$bike_nodes->{$rid}->{node_name} - $dbt->{copri_conf}->{type_id}->{$bike_nodes->{$rid}->{type_id}}");
push (@s_valxx, "$bike_nodes->{$rid}->{main_id}:$bike_nodes->{$rid}->{node_name}");
}
print $q->td({-class=>'search_line'},$but->selector_class("s_$key","","",$s_val,@s_valxx)),"\n";
@ -628,7 +630,7 @@ EOF
}
print $q->td({-class=>'search_line'},$but->selector_class("s_$key","","",$s_val,@s_valxx)),"\n";
}elsif($size =~ /select/ && $key !~ /txt23|txt24/){#txt23=color-code or txt24=Flotten ID select
}elsif($size =~ /select|readonly/ && $key !~ /txt23|txt24/){#txt23=color-code or txt24=Flotten ID select
my @s_valxx = ("");
my $s_hash = {};
$s_hash = $dbt->{copri_conf}->{lock_state} if($tpl_id == 205 && $key eq "int20");
@ -636,15 +638,14 @@ EOF
$s_hash = $dbt->{copri_conf}->{station_state} if($tpl_id == 225 && $key eq "int10");
$s_hash = $dbt->{copri_conf}->{lock_system} if($tpl_id == 205 && $key eq "int11");
$s_hash = $dbt->{copri_conf}->{sharing_type} if($tpl_id == 210 && $key eq "int18");
#$s_hash = $dbt->{copri_conf}->{tariff_unit} if($tpl_id == 210 && $key eq "int01");
$s_hash = $dbt->{copri_conf}->{type_id} if($tpl_id == 225 && $key eq "txt25");
$s_hash = { 1 => 1, 2 => 2, 3 => 3, 4 => 4 } if($tpl_id == 225 && $key eq "txt07");
#while (my ($key, $value) = each %{ $s_hash }) {
foreach my $s_key (sort keys (%{ $s_hash })) {
push @s_valxx, "$s_key:$s_hash->{$s_key}";#[2:unlocked]
}
print $q->td({-class=>'search_line'},$but->selector_class("s_$key","","",$s_val,@s_valxx)),"\n";
}else{
print $q->td({-class=>"search_line"},$q->textfield(-class=>'stxt',-name=>"s_$key",-default=>"$s_val",-size=>"$size",-maxlength=>40),"\n");
print $q->td({-class=>"search_line"},$q->textfield(-class=>'stxt',-name=>"s_$key",-default=>"$s_val",-size=>"$size",-maxlength=>40)),"\n";
}
}elsif($key =~ /owner/){
print $q->td({-class=>'search_line'},$but->selector("s_$key","120px","$s_val",@_users)),"\n";
@ -1034,9 +1035,22 @@ EOF
}elsif($ct4rel->{$id}->{template_id} == 225 && $key eq "txt24"){
my $flotten = "";
foreach my $rid (sort { $bike_nodes->{$a}->{node_name} cmp $bike_nodes->{$b}->{node_name} } keys (%$bike_nodes)){
$flotten .= "$bike_nodes->{$rid}->{node_name} - $dbt->{copri_conf}->{type_id}->{$bike_nodes->{$rid}->{type_id}}<br />" if($ct4rel->{$id}->{$key} =~ /$bike_nodes->{$rid}->{main_id}/);
$flotten .= "$bike_nodes->{$rid}->{node_name}<br />" if($ct4rel->{$id}->{$key} =~ /$bike_nodes->{$rid}->{main_id}/);
}
print $q->td({-class=>'tdtxt',-style=>"$txtstyle $set_style"},"$flotten"),"\n";
}elsif($ct4rel->{$id}->{template_id} == 225 && $key eq "txt25"){
my %station_filter_hash = ();
if($ct4rel->{$id}->{txt25} && $ct4rel->{$id}->{txt25} =~ /\d\s\d/){
%station_filter_hash = map { $_ => 1 } split(/\s+/,$ct4rel->{$id}->{txt25});
}elsif($ct4rel->{$id}->{txt25} && $ct4rel->{$id}->{txt25} =~ /(\d+)/){
$station_filter_hash{$1} = 1;
}
my $station_filter = "";
foreach my $type_id (keys (%station_filter_hash)){
$station_filter .= "$dbt->{copri_conf}->{type_id}->{$type_id}<br />";
}
print $q->td({-class=>'tdtxt',-style=>"$txtstyle $set_style"},"$station_filter"),"\n";
}elsif($ct4rel->{$id}->{template_id} == 228 && $key =~ /int21|int22/){
my $bonustarif = "";
foreach my $rid (sort { $tariff_all->{$a}->{barcode} <=> $tariff_all->{$b}->{barcode} } keys (%$tariff_all)){