From df954371f24ff1fd5a9ce50b405fc8f01808c043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rainer=20G=C3=BCmpelein?= Date: Mon, 14 Mar 2022 17:37:49 +0100 Subject: [PATCH] station tour, operator hotline and 24h SMS --- copri4/main/src/Mod/APIfunc.pm | 98 ++++++-------------- copri4/main/src/Mod/APIjsonserver.pm | 2 +- copri4/main/src/Mod/DBtank.pm | 29 ++++-- copri4/main/src/Mod/Premain.pm | 7 ++ copri4/main/src/Mod/SMSTransport.pm | 18 +++- copri4/main/src/Tpl/BaseEdit.pm | 16 ++-- copri4/main/src/Tpl/Calorin.pm | 19 ++-- copri4/main/src/Tpl/Liste3.pm | 7 +- copri4/main/src/scripts/sms_message.pl | 79 ++++++++++++++-- copri4/shareeapp-operator/src/Tpl/Contact.pm | 1 + 10 files changed, 170 insertions(+), 106 deletions(-) diff --git a/copri4/main/src/Mod/APIfunc.pm b/copri4/main/src/Mod/APIfunc.pm index 3ae30b7..baa6f09 100755 --- a/copri4/main/src/Mod/APIfunc.pm +++ b/copri4/main/src/Mod/APIfunc.pm @@ -204,43 +204,6 @@ sub service_work_search(){ return $pos_record; } -#service pre-collect all or with bike/station ID -#obsolte and should be deleted -sub service_work_select(){ - my $self = shift; - my $bike = shift || ""; - my $station = shift || ""; - my $interval = shift || 0; - my $content_template_id = shift || 0; - my $dt1 = DateTime->now; - my $return={}; - - my $bike_id = $1 if($bike =~ /(\d+)/); - my $station_id = $1 if($station =~ /(\d+)/); - - my $pref = { - table => "content", - table_pos => "contentpos", - fetch => "all", - catch => "content_contentpos", - keyfield => "c_id", - template_id => "$content_template_id", - }; - if(looks_like_number($bike_id)){ - $pref->{barcode} = "=::" . $bike_id; - } - if(looks_like_number($station_id)){ - $pref->{int04} = "=::" . $station_id; - } - - $pref = { %$pref, mtime => ">=::(now() - interval '$interval day')" } if($interval > 0); - - - my $pos_record = $dbt->collect_post($dbh,$pref); - return $pos_record; -}#end service_work_select - - #service_select by service_id=service-c_id sub service_select { my $self = shift; @@ -762,7 +725,7 @@ sub service_work { $return->{$article}->{$key_change}->{interval} = "$interval"; $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}"; + $return->{$article}->{$key_change}->{work_val} .= "$pos_record->{$id}->{$key}\n"; $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}"; @@ -1665,34 +1628,13 @@ sub stations_available(){ $pref_sql = "" if($pref_sql !~ /\d/); my $record = {}; - #on servicetool only stations on user_tour - #shareetool - if($q->param('authcookie') && $dbt->{merchant_ids}->{$varenv->{merchant_id}}->{id} && $dbt->{merchant_ids}->{$varenv->{merchant_id}}->{id} == 187){ - if(scalar(@{$user_tour}) >= 1){ - $pref_sql .= " AND ("; - foreach(@{$user_tour}){ - if($_ =~ /(\d+)/){ - $pref_sql .= " ct.int07=$1 OR"; - } - } - $pref_sql =~ s/OR$//; - $pref_sql .= ")"; - $record = $dbt->fetch_record($dbh,$pref,$pref_sql) if(ref($bike_group) eq "ARRAY" && @{$bike_group}[0]); - } - }else{ - $record = $dbt->fetch_record($dbh,$pref,$pref_sql) if(ref($bike_group) eq "ARRAY" && @{$bike_group}[0]); - } + $record = $dbt->fetch_record($dbh,$pref,$pref_sql) if(ref($bike_group) eq "ARRAY" && @{$bike_group}[0]); my $op_return = {}; foreach my $id (sort { $record->{$a}->{barcode} <=> $record->{$b}->{barcode} } keys (%$record)){ $return->{$id}->{authed} = "$authed"; $return->{$id}->{station} = "$dbt->{operator}->{$varenv->{dbname}}->{oprefix}$record->{$id}->{int04}"; - if($record->{$id}->{int07}){ - $return->{$id}->{service_tour} = "$dbt->{operator}->{$varenv->{dbname}}->{oprefix}$record->{$id}->{int07}"; - }else{ - $return->{$id}->{service_tour} = ""; - } $return->{$id}->{uri_operator} = "$varenv->{wwwhost}"; ($return->{$id}->{gps}->{latitude},$return->{$id}->{gps}->{longitude}) = split(/,/,$record->{$id}->{txt06}); #$return->{$id}->{description} = "$record->{$id}->{txt01}"; @@ -1735,7 +1677,7 @@ sub stations_available(){ }#end stations_available -#stations_all +#stations_all (should only called by shareetool) sub stations_all(){ my $self = shift; my $q = shift || ""; @@ -1779,6 +1721,9 @@ sub stations_all(){ $pref_sql = "" if($pref_sql !~ /\d/); my $record = {}; + my $op_return = {}; + my %user_tour = (); + #on servicetool only stations on user_tour #shareetool $bw->log("stations user_tour by merchant id $dbt->{merchant_ids}->{$varenv->{merchant_id}}->{id} on $varenv->{dbname}",$user_tour,""); @@ -1788,20 +1733,19 @@ sub stations_all(){ $pref_sql .= " AND ("; foreach(@{$user_tour}){ if($_ =~ /(\d+)/){ - $pref_sql .= " ct.int07=$1 OR"; + #$pref_sql .= " ct.int07=$1 OR"; + $user_tour{$1} = 1; + $pref_sql .= " ct.txt07 like '%$1%' OR"; } } $pref_sql =~ s/OR$//; $pref_sql .= ")"; $record = $dbt->fetch_record($dbh,$pref,$pref_sql) if(ref($bike_group) eq "ARRAY" && @{$bike_group}[0]); + } - #stations_all only if authenticated - #}else{ - #$record = $dbt->fetch_record($dbh,$pref,$pref_sql) if(ref($bike_group) eq "ARRAY" && @{$bike_group}[0]); } - my $op_return = {}; #only nececarry if amount of available bikes lower then bike_soll (like konrad) #my $bike_ist_factor = 1; #$bike_ist_factor = $self->bikes_soll($record,$bikes_on_station); @@ -1813,11 +1757,25 @@ sub stations_all(){ #$bike_soll =~ s/\.\d+//;#rounded integer $return->{$id}->{authed} = "$authed"; $return->{$id}->{station} = "$dbt->{operator}->{$varenv->{dbname}}->{oprefix}$record->{$id}->{int04}"; - if($record->{$id}->{int07}){ - $return->{$id}->{service_tour} = "$dbt->{operator}->{$varenv->{dbname}}->{oprefix}$record->{$id}->{int07}"; - }else{ - $return->{$id}->{service_tour} = ""; + + $return->{$id}->{service_tour} = ""; + #hashed because of one station can have multi station tour + #there is a restriction in servicetool because of service_tour assignment (can keep only one value) + #keep in mind to select only users user_tour which in service_tour, + #because there can only one station assignmemt. Should be array, also in shareetool! + my %station_tour = (); + if($record->{$id}->{txt07} && $record->{$id}->{txt07} =~ /\d\s\d/){ + %station_tour = map { $_ => 1 } split(/\s+/,$record->{$id}->{txt07}); + }elsif($record->{$id}->{txt07}){ + $station_tour{$record->{$id}->{txt07}} = 1; } + #if multi station tour defined then last numerical will assigend + foreach my $stour (sort { $a <=> $b }keys (%user_tour)){ + if($station_tour{$stour}){ + $return->{$id}->{service_tour} = "$dbt->{operator}->{$varenv->{dbname}}->{oprefix}$stour"; + } + } + $return->{$id}->{uri_operator} = "$varenv->{wwwhost}"; ($return->{$id}->{gps}->{latitude},$return->{$id}->{gps}->{longitude}) = split(/,/,$record->{$id}->{txt06}); if($return->{$id}->{description}){ diff --git a/copri4/main/src/Mod/APIjsonserver.pm b/copri4/main/src/Mod/APIjsonserver.pm index e2ce2e5..fe3b81d 100755 --- a/copri4/main/src/Mod/APIjsonserver.pm +++ b/copri4/main/src/Mod/APIjsonserver.pm @@ -512,7 +512,7 @@ elsif($q->param('request') eq "bikes_all"){ foreach my $id (keys(%{$response_work->{$biselect}})){ - $bw->log("response_work:$biselect","|$id|$response_work->{$biselect}->{$id}->{mtime}|$response_work->{$biselect}->{$id}->{service_type}|$response_work->{$biselect}->{$id}->{time_over}|$response_work->{$biselect}->{$id}->{work_val}",""); + #$bw->log("response_work:$biselect","|$id|$response_work->{$biselect}->{$id}->{mtime}|$response_work->{$biselect}->{$id}->{service_type}|$response_work->{$biselect}->{$id}->{time_over}|$response_work->{$biselect}->{$id}->{work_val}",""); #time_over && (service_type || Aufgaben) if(($response_work->{$biselect}->{$id}->{time_over} == 1 && $response_work->{$biselect}->{$id}->{service_type} >= 1) || ($id eq "txt01" && $response_work->{$biselect}->{$id}->{work_val})){ diff --git a/copri4/main/src/Mod/DBtank.pm b/copri4/main/src/Mod/DBtank.pm index f3d21a8..e991aaa 100755 --- a/copri4/main/src/Mod/DBtank.pm +++ b/copri4/main/src/Mod/DBtank.pm @@ -1052,15 +1052,22 @@ sub collect_transpos { $search->{offset} = 0 if(!$search->{offset}); my $updown = "ASC"; - $updown = "DESC" if($search->{cal_sort_updown} eq "down"); + $updown = "DESC" if($search->{cal_sort_updown} && $search->{cal_sort_updown} eq "down"); my $where = "where cp.ct_id=ct.c_id"; - foreach my $key (%$search){ - $search->{$key} =~ s/\s//g; + foreach my $key (keys (%$search)){ + $search->{$key} =~ s/\s//g if($key ne "start_time_interval"); $where .= " and cp.c_id = $search->{$key}" if($key eq "cttpos_id" && $search->{$key}); - $where .= " and cp.end_time >= '$search->{$key}'" if($key eq "start_date_time"); - $where .= " and cp.end_time <= '$search->{$key}'" if($key eq "end_date_time"); - $where .= " and cp.start_time <= '$search->{$key}'" if($key eq "end_date_time"); + if($key eq "start_time_interval"){ + $where .= " and cp.start_time <= $search->{$key}"; + } + if($key eq "start_date_time"){ + $where .= " and cp.end_time >= '$search->{$key}'"; + } + if($key eq "end_date_time"){ + $where .= " and cp.end_time <= '$search->{$key}'"; + $where .= " and cp.start_time <= '$search->{$key}'"; + } $where .= " and cp.$key ilike '%$search->{$key}%'" if($key eq "txt08" && $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.ct_name = '$search->{$key}'" if($key eq "cp_ct_name" && $search->{$key}); @@ -1072,11 +1079,13 @@ sub collect_transpos { $where .= " and cp.$key = $search->{$key}" if($key eq "int12" && looks_like_number($search->{$key}));#bike_group $where .= " and cp.$key = $search->{$key}" if($key eq "owner" && looks_like_number($search->{$key})); } + $where .= " ORDER BY cp.end_time $updown LIMIT $search->{limit} OFFSET $search->{offset}" if($search->{limit}); - my $sth = $dbh->prepare("SELECT cp.* from $search->{table} cp, contenttrans ct $where"); + my $sql = "SELECT cp.*,ct.txt07 AS phone from $search->{table} cp, contenttrans ct $where"; + my $sth = $dbh->prepare($sql); my $rc = $sth->execute(); my $ct = $sth->fetchall_hashref("c_id"); - $sth->finish; + $bw->log("collect_transpos",$sql,"") if($debug); return $ct; } @@ -1088,10 +1097,10 @@ sub collect_theftpos { $search->{offset} = 0 if(!$search->{offset}); my $updown = "ASC"; - $updown = "DESC" if($search->{cal_sort_updown} eq "down"); + $updown = "DESC" if($search->{cal_sort_updown} && $search->{cal_sort_updown} eq "down"); my $where = "where 1=1"; - foreach my $key (%$search){ + foreach my $key (keys (%$search)){ $search->{$key} =~ s/\s//g; $where .= " and cp.c_id = $search->{$key}" if($key eq "cttpos_id" && $search->{$key}); $where .= " and cp.end_time >= '$search->{$key}'" if($key eq "start_date_time"); diff --git a/copri4/main/src/Mod/Premain.pm b/copri4/main/src/Mod/Premain.pm index e0aaef7..b5b4075 100755 --- a/copri4/main/src/Mod/Premain.pm +++ b/copri4/main/src/Mod/Premain.pm @@ -532,6 +532,13 @@ print ATTR "next: $next\n" if($debug); $valxx = $q->escapeHTML("@val"); $u_rows += $db->updater("$table","c_id",$c_id,$_,$valxx,$users_dms->{u_id}); } + #txt07 station user_tour multiple select + elsif($tpl->{tpl_id} == 225 && $_ eq "txt07"){ + my @val = $q->param($_); + #@txt18 = grep {!/null/} @txt18; + $valxx = $q->escapeHTML("@val"); + $u_rows += $db->updater("$table","c_id",$c_id,$_,$valxx,$users_dms->{u_id}); + } #txt24 bike_group/station_group multiple select elsif($tpl->{tpl_id} == 225 && $_ eq "txt24"){ my @val = $q->param($_); diff --git a/copri4/main/src/Mod/SMSTransport.pm b/copri4/main/src/Mod/SMSTransport.pm index da8263f..a5921f9 100755 --- a/copri4/main/src/Mod/SMSTransport.pm +++ b/copri4/main/src/Mod/SMSTransport.pm @@ -102,6 +102,8 @@ sub sms_ack_digest { #used for sending message if lock_state=locking and after 45 sec no lock_state=locked sub sms_message { my $self = shift; + my $todo = shift; + my $hotline = shift; my $sms_to = shift; my $bike = shift; @@ -120,7 +122,20 @@ sub sms_message { $sms_tosub =~ s/^0/\+49/; $sms_to = $sms_tosub; } - $sms_message .= "Ihre Miete von $bike wurde nicht beendet! Ihre kostenpflichtige Miete läuft weiter! Stellen Sie sicher, dass das Schloss geschlossen ist. Hotline 0761-45370099"; + if($todo eq "locking_progress"){ + $sms_message .= "Ihre Miete von $bike wurde nicht beendet! Ihre kostenpflichtige Miete läuft weiter! Stellen Sie sicher, dass das Schloss geschlossen ist. $hotline"; + } + + if($todo eq "24h_occupied"){ + $sms_message .= "Zur Info! Sie haben $bike seit 24 Stunden kostenpflichtig gemietet!. $hotline"; + } + if($todo eq "48h_occupied"){ + $sms_message .= "Zur Info! Sie haben $bike seit 48 Stunden kostenpflichtig gemietet!. $hotline"; + } + if($todo eq "72h_occupied"){ + $sms_message .= "Zur Info! Sie haben $bike seit 72 Stunden kostenpflichtig gemietet!. $hotline"; + } + my $message = Encode::encode('iso-8859-1', Encode::decode('utf-8',"$sms_message")); open(FILE,">>$dbt->{copri_conf}->{logdir}/sms_gtx.log"); @@ -134,6 +149,7 @@ sub sms_message { print FILE "---> request:\n" . Dumper($request); + #my $ret_json = "";#$self->get_sms_gtx($request);#for testing without send my $ret_json = $self->get_sms_gtx($request); eval { diff --git a/copri4/main/src/Tpl/BaseEdit.pm b/copri4/main/src/Tpl/BaseEdit.pm index acd23c8..189123f 100755 --- a/copri4/main/src/Tpl/BaseEdit.pm +++ b/copri4/main/src/Tpl/BaseEdit.pm @@ -362,12 +362,6 @@ EOF print $q->td({-class=>'left_italic_cms',-colspan=>'1'},"$des"); print $q->td({-class=>'content1_cms',-colspan=>'1'},$but->selector_class("$key","eselect","width:350px;",$ctrel->{$key},@_valxx)); } - elsif($key =~ /int07/ && "$size" eq "select" && $node_meta->{tpl_id} == 225){#Station Service Tour - my $selsize="50px"; - print $q->Tr(); - print $q->td({-class=>'left_italic_cms'},"$des"),"\n"; - print $q->td({-class=>'content1_cms',-colspan=>'2'},$but->selector("$key","$selsize",$ctrel->{$key},@_service_valxx)); - } elsif($key =~ /int10/ && "$size" eq "select" && ($node_meta->{tpl_id} == 205 || $node_meta->{tpl_id} == 225)){#bike_state my @_lock_valxx = (); while (my ($key, $value) = each %{ $dbt->{copri_conf}->{bike_state} }) { @@ -466,13 +460,19 @@ EOF } elsif($key =~ /txt/ && "$size" =~ /select/){ if($size =~ /_multiple/){ - if($key =~ /txt18/ && $node_meta->{tpl_id} eq "202"){ #service_tour alias user_tour + if($key =~ /txt18/ && $node_meta->{tpl_id} eq "202"){ #user defined service_tour alias user_tour my $height = scalar(@_service_valxx); 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'},$but->selector2("$key","50px;","$height",$ctrel->{$key},@_service_valxx)); } - elsif($key =~ /txt24/ && $node_meta->{tpl_id} == 225){ #sharee station_group (bikenode.main_ids) + elsif($key =~ /txt07/ && $node_meta->{tpl_id} eq "225"){ # station defined Service Tour + my $height = scalar(@_service_valxx); + 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'},$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 @_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} - $bike_nodes->{$rid}->{main_id}"); diff --git a/copri4/main/src/Tpl/Calorin.pm b/copri4/main/src/Tpl/Calorin.pm index bdb455a..4261b75 100755 --- a/copri4/main/src/Tpl/Calorin.pm +++ b/copri4/main/src/Tpl/Calorin.pm @@ -353,20 +353,21 @@ sub tpl(){ $end_time = $lb->time4de($cttpos->{$pid}->{end_time},1); } - my $u_name = $cttpos->{$pid}->{owner}; - my $u_name_end = $cttpos->{$pid}->{owner_end}; + my $u_name = $cttpos->{$pid}->{owner} || ""; + my $u_name_end = $cttpos->{$pid}->{owner_end} || ""; foreach my $ctu_id (keys (%$ct_users)){ - if($channel_map->{$u_name}){ + if($u_name && $channel_map->{$u_name}){ $u_name = $channel_map->{$u_name}; }elsif($cttpos->{$pid}->{owner} eq $ct_users->{$ctu_id}->{c_id}){ $u_name = $ct_users->{$ctu_id}->{txt01}; } - if($channel_map->{$u_name_end}){ + if($u_name_end && $channel_map->{$u_name_end}){ $u_name_end = $channel_map->{$u_name_end}; }elsif($cttpos->{$pid}->{owner_end} eq $ct_users->{$ctu_id}->{c_id}){ $u_name_end = $ct_users->{$ctu_id}->{txt01}; } } + $u_name_end = "-" if(!$u_name_end); #if($ct_name){ @@ -389,8 +390,8 @@ sub tpl(){ $txt21 = substr($cttpos->{$pid}->{txt21},0,50) . " ..." if(length($cttpos->{$pid}->{txt21}) > 50); $user_device = ""; $user_device .= " → lock charge $cttpos->{$pid}->{int14} %" if($cttpos->{$pid}->{int14}); - $user_device .= " → agent $txt26" if($txt26); - $user_device .= " → device $txt21" if($txt21); + $user_device .= " → $txt26" if($txt26); + $user_device .= " → $txt21" if($txt21); } my $bikenr = "$cttpos->{$pid}->{barcode}"; @@ -407,6 +408,10 @@ sub tpl(){ $lock_state = "locked" if($cttpos->{$pid}->{int20} == 1); $lock_state = "unlocked" if($cttpos->{$pid}->{int20} == 2); $lock_state = "locking in progress" if($cttpos->{$pid}->{int20} == 3); + if($cttpos->{$pid}->{int20} ne $ct4rel_ware->{$cttpos->{$pid}->{cc_id}}->{int20}){ + $lock_state = "$dbt->{copri_conf}->{lock_state}->{$cttpos->{$pid}->{int20}}"; + } + my $track_info = ""; my $co2saving = ""; @@ -423,7 +428,7 @@ sub tpl(){ $end_station = $q->a({-class=>"linknav3",-style=>"",-href=>"/DMS/Waren/?detail_search=1&s_int04=$cttpos->{$pid}->{int04}",-title=>"Rad Warenstamm nach Station filtern"},"$cttpos->{$pid}->{int04}") if($ct4rel_ware->{$cttpos->{$pid}->{cc_id}}->{rel_id}); my $kunde = $q->a({-class=>"linknav3",-style=>"$ware_style",-href=>"/DMS/Kunden/?detail_search=1&s_c_id=$cttpos->{$pid}->{ca_id}",-title=>"Kunde im Kundenstamm"},"$cttpos->{$pid}->{txt08} ($cttpos->{$pid}->{ca_id})");#2021-05-24 saves kd name - print $q->div({-style=>'float:left;margin-left:1em;font-size:0.91em;'}, "$i) $start_time – $end_time → $kunde → Start Station $start_station → End Station $end_station → Rad $bikenr $status $lock_state $track_info → $u_name $pos_id"),"\n"; + print $q->div({-style=>'float:left;margin-left:1em;font-size:0.91em;'}, "$i) $start_time – $end_time → $kunde → Start Station $start_station → End Station $end_station → Rad $bikenr $status $lock_state $track_info → $u_name/$u_name_end $pos_id"),"\n"; print $q->div({-style=>'float:left;margin-left:1em;font-size:0.91em;'}, "→ Faktura", $q->a({-class=>"linknav3",-style=>"$trans_style",-href=>"/DMS/Faktura?ct_trans=open\&c_id4trans=$c_id4trans\&tpl_id4trans=$tpl_id4trans\&kind_of_trans=Faktura\&owner=$users_dms->{owner}",-title=>"Faktura Terminal öffnen"},"\#$ct_name")),"\n" if($c_id4trans && $tpl_id4trans); print $q->div({-style=>'float:left;margin-left:1em;font-size:0.91em;'}, "$user_device"),"\n"; diff --git a/copri4/main/src/Tpl/Liste3.pm b/copri4/main/src/Tpl/Liste3.pm index 851e155..aee2640 100755 --- a/copri4/main/src/Tpl/Liste3.pm +++ b/copri4/main/src/Tpl/Liste3.pm @@ -596,9 +596,10 @@ sub tpl(){ $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 = { 1 => 1, 2 => 2, 3 => 3, 4 => 4 } if($tpl_id == 225 && $key eq "int07"); - while (my ($key, $value) = each %{ $s_hash }) { - push @s_valxx, "$key:$value";#[2:unlocked] + $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{ diff --git a/copri4/main/src/scripts/sms_message.pl b/copri4/main/src/scripts/sms_message.pl index 9c7e517..f3efd06 100755 --- a/copri4/main/src/scripts/sms_message.pl +++ b/copri4/main/src/scripts/sms_message.pl @@ -3,8 +3,13 @@ # SPDX-License-Identifier: AGPL-3.0-or-later # Copyright (c) Rainer Gümpelein, TeilRad GmbH # +#SMS message if 24h,48h,72h occupied +#sudo su www-data -c "./src/scripts/sms_message.pl shareedms-fr01 '24h_occupied' '' ''" +# +#SMS message locking_progress after 45sec #sudo su www-data -c "./src/scripts/sms_message.pl shareeapp-operator locking_progress '0179xxxx372' $pos_id" # +# use vars qw($syshost); BEGIN { @@ -16,6 +21,10 @@ use lib "/var/www/copri-bike/$syshost/src"; use strict; use warnings; use POSIX; +use DateTime; +use DateTime::Format::Pg; +use Data::Dumper; + use Mod::DBtank; use Mod::SMSTransport; @@ -23,11 +32,70 @@ my $dbt = new DBtank; my $smstrans = new SMSTransport; my $todo = $ARGV[1] || die 'todo not defined'; -my $phone = $ARGV[2] || die 'phone not defined'; -my $pos_id = $ARGV[3] || die 'no booking id available'; +my $phone = $ARGV[2] || ""; +my $pos_id = $ARGV[3] || ""; my $dbh = ""; -if($todo eq "locking_progress"){ +#operator contact + my $pref_cc = { + table => "contentuser", + fetch => "one", + template_id => "197", + c_id => 1, + }; +my $record_cc = { c_id => 0 }; +$record_cc = $dbt->fetch_record($dbh,$pref_cc); +my $hotline = ""; +$record_cc->{txt07} =~ s/\s//g; +$hotline = "Hotline $record_cc->{txt01} $record_cc->{txt07}"; + + +#SMS message if 24h,48h,72h occupied +if($todo eq "24h_occupied"){ + #select booking pos if state=occupied and start_time > 24h + my $search = { + table => "contenttranspos", + int10 => 3, + start_time_interval => "(now() - interval '1 day')", + }; + + my $dt1 = DateTime->now(time_zone => "Europe/Berlin"); + + my $cttpos = { c_id => 0 }; + $cttpos = $dbt->collect_transpos($dbh,$search); + + foreach my $pid (sort { $cttpos->{$b}->{end_time} cmp $cttpos->{$a}->{end_time} } keys(%$cttpos)){ + if($cttpos->{$pid}->{int10} == 3){ + my $dt2 = ""; + $dt2 = DateTime::Format::Pg->parse_datetime($cttpos->{$pid}->{start_time}); + my $dt2_24h_occupied = $dt2->add( days => 1 ); + $dt2 = DateTime::Format::Pg->parse_datetime($cttpos->{$pid}->{start_time}); + my $dt2_48h_occupied = $dt2->add( days => 2 ); + $dt2 = DateTime::Format::Pg->parse_datetime($cttpos->{$pid}->{start_time}); + my $dt2_72h_occupied = $dt2->add( days => 3 ); + #print $dt1 . ">=" . $dt2_72h_occupied . "|" . $dt1 . ">=" . $dt2_48h_occupied . "|" . $dt1 . ">=" . $dt2_24h_occupied . "\n"; + if($dt2){ + if($dt1 >= $dt2_72h_occupied){ + $todo = "72h_occupied"; + $smstrans->sms_message($dt1 >= $dt2_72h_occupied,$todo,$hotline,$cttpos->{$pid}->{phone},$cttpos->{$pid}->{ct_name}); + print $dt1 . ">=" . $dt2_72h_occupied . "|$todo,$hotline,$cttpos->{$pid}->{phone},$cttpos->{$pid}->{ct_name}\n"; + }elsif($dt1 >= $dt2_48h_occupied){ + $todo = "48h_occupied"; + $smstrans->sms_message($todo,$hotline,$cttpos->{$pid}->{phone},$cttpos->{$pid}->{ct_name}); + print $dt1 . ">=" . $dt2_48h_occupied . "|$todo,$hotline,$cttpos->{$pid}->{phone},$cttpos->{$pid}->{ct_name}\n"; + }elsif($dt1 >= $dt2_24h_occupied){ + $todo = "24h_occupied"; + $smstrans->sms_message($todo,$hotline,$cttpos->{$pid}->{phone},$cttpos->{$pid}->{ct_name}); + print $dt1 . ">=" . $dt2_24h_occupied . "|$todo,$hotline,$cttpos->{$pid}->{phone},$cttpos->{$pid}->{ct_name}\n"; + } + } + sleep 1; + } + } +}#end + +#SMS message locking_progress after 45sec +if($todo eq "locking_progress" && $phone && $pos_id){ sleep 45; #select booking pos if lock_state=locking still set my $booking_pos = { @@ -39,7 +107,6 @@ if($todo eq "locking_progress"){ my $booking = { c_id => 0 }; $booking = $dbt->fetch_tablerecord($dbh,$booking_pos); if($booking->{int20} == 3){ - $smstrans->sms_message($phone,$booking->{ct_name}); + $smstrans->sms_message($todo,$hotline,$phone,$booking->{ct_name}); } - -} +}#end diff --git a/copri4/shareeapp-operator/src/Tpl/Contact.pm b/copri4/shareeapp-operator/src/Tpl/Contact.pm index d7ec90e..c76d53a 100755 --- a/copri4/shareeapp-operator/src/Tpl/Contact.pm +++ b/copri4/shareeapp-operator/src/Tpl/Contact.pm @@ -60,6 +60,7 @@ sub tpl(){ } my $project = "all"; + $project = "Freiburg" if($varenv->{syshost} eq "shareeweb-sharee"); $project = "Bayern" if($varenv->{syshost} eq "shareeweb-bayern"); $project = "Konstanz" if($varenv->{syshost} eq "shareeweb-konstanz");