package MandantConf;
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
#
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use CGI ':standard';
use Lib::Config;
use Mod::Buttons;
use Mod::Libenz;
use Mod::Libenzdb;
use Mod::DBtank;
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 $cf = new Config;
my $lb = new Libenz;
my $db = new Libenzdb;
my $dbt = new DBtank;
my $but = new Buttons;
my %ib = $but->ibuttons();
my %varenv = $cf->envonline();
my $script = $q->script_name();
my $path_info = $q->path_info();
my $path = $path_info;
#with meta_host,
if("$varenv{metahost}"){
$path = "$script" . "$path_info";
$script="";
}
$path =~ s/\/user|\/manager|\/admin//;
my $lang = "de";
my $dbh = "";
my $dbh_primary = $dbt->dbconnect_extern("sharee_primary");
my $users_dms_primary = { u_id => 0 };
$users_dms_primary = $dbt->select_users($dbh_primary,$users_dms->{u_id},"and int02 >= 1");
my $rel = {};
my $ct = {};
if($node_meta->{ct_table} eq "contentuser"){
#Firma alias Kunden-Faktura and Operator-Faktura config
if(($node_meta->{template_id} =~ /196|201/) && $users_dms_primary->{int02} >= 1){
$rel = $db->get_rel4tpl($node_meta->{main_id},$lang,"","$node_meta->{template_id}","","",">0");
$ct = $db->get_content1("contentuser",$rel->{content_id});
}elsif($node_meta->{template_id} == 197 && $users_dms->{int08} >= 1){
$rel = $db->get_rel4tpl($node_meta->{main_id},$lang,"","197","","",">0");
$ct = $db->get_content1("contentuser",$rel->{content_id});
}else{
$return = "failure::Abbruch. Keine Zugriffsberechtigung";
}
}
my $tpl = $db->get_tpl($rel->{template_id});
my @tpl_order = split /,/,$tpl->{tpl_order};
my $u_name = $dbt->sys_username($dbh,$ct->{owner});
$ct->{mtime} = $lb->time4de($ct->{mtime},"1");
print "