package APIdialog; # # # SPDX-License-Identifier: AGPL-3.0-or-later # Copyright (c) Rainer Gümpelein, TeilRad GmbH # use strict; use warnings; use POSIX; use CGI::Carp qw(fatalsToBrowser); use CGI ':standard'; use JSON; #use Test::JSON; use Scalar::Util qw(looks_like_number); use Lib::Config; use Mod::Buttons; use Mod::Libenz; use Mod::DBtank; use Mod::APIfunc; use Data::Dumper; sub new { my $class = shift; my $self = {}; bless($self,$class); return $self; } #Template sub tpl(){ my $node_meta = shift; my $users_dms = shift; my $u_group = shift; my $return = shift; my $q = new CGI; my $json = JSON->new->allow_nonref; my $cf = new Config; my $lb = new Libenz; my $dbt = new DBtank; my $apif = new APIfunc; my $but = new Buttons; my $dbh = "";#$dbt->dbconnect(); my %varenv = $cf->envonline(); my %ib = $but->ibuttons(); my $tpl = $dbt->get_tpl($dbh,$node_meta->{template_id}); my $tpl_order = $tpl->{tpl_order}; #$tpl_order =~ s/barcode=Rad/barcode=Rad,txt09=Wartungsarbeiten=area/; #$tpl_order =~ s/int04=Station/int04=Station,txt09=Wartungsarbeiten=area/ if($tpl->{tpl_id} == 403); $tpl_order = "barcode=Rad,txt09=Wartungsprotokoll=area"; $tpl_order = "int04=Station,txt09=Wartungsprotokoll=area" if($tpl->{tpl_id} == 403); my @tpl_order = split /,/,$tpl_order; my $edit="rel_edit"; my $save_key = "service_done"; my $ctrel = {}; if(ref($return) ne "SCALAR" && $return =~ /shareejson/){ my $tj = $json->pretty->decode($return); foreach my $obj (keys (%{$tj->{shareejson}})){ if($obj eq "service_id_done" && looks_like_number($tj->{shareejson}->{$obj})){ my $c_id = $tj->{shareejson}->{$obj}; my $fetch = { table => "contentpos", fetch => "one", c_id => "$c_id", }; $ctrel = $dbt->fetch_tablerecord($dbh,$fetch); } } }else{ print $q->div($return),"\n"; return; } my $u_name; my $channel_map = $dbt->channel_map(); my $mapref = {}; my $ct_users = $dbt->users_map($dbh,$mapref);#get serviceAPP and DMS users from contentadr foreach my $id (sort { $channel_map->{$a} cmp $channel_map->{$b} } keys (%$channel_map)){ if($id == $ctrel->{owner}){ $u_name = $channel_map->{$id}; } } if(!$u_name){ foreach my $ctu_id (keys (%$ct_users)){ if($ct_users->{$ctu_id}->{c_id} == $ctrel->{owner}){ $u_name = $ct_users->{$ctu_id}->{txt01}; } } } $ctrel->{mtime} = $lb->time4de($ctrel->{mtime},"1") if($ctrel->{mtime}); print $q->hidden(-name=>'mode', -value=>"manager",-override=>1),"\n"; print $q->hidden(-name=>'detail_search', -value=>"1",-override=>1),"\n"; print $q->hidden(-name=>'owner', -value=>"$users_dms->{u_id}",-override=>1),"\n"; print $q->hidden(-name=>'s_barcode', -value=>"$ctrel->{barcode}",-override=>1),"\n" if($ctrel->{barcode}); print $q->hidden(-name=>'s_int04', -value=>"$ctrel->{int04}",-override=>1),"\n" if($ctrel->{int04}); print $q->hidden(-name=>'service_id', -value=>"$ctrel->{c_id}",-override=>1),"\n"; print $q->hidden(-name=>'main_id', -value=>"$node_meta->{main_id}",-override=>1),"\n"; print $q->hidden(-name=>'template_id', -value=>"$node_meta->{template_id}",-override=>1),"\n"; print "