sharee.bike/copri4/main/src/Tpl/AttributMatrix.pm

206 lines
7.5 KiB
Perl
Raw Normal View History

2021-12-30 12:05:56 +01:00
package AttributMatrix;
#
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
use strict;
use warnings;
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 $mode = shift;
my $return = shift;
my $q = new CGI;
my $cf = new Config;
my $lb = new Libenz;
my $db = new Libenzdb;
my $but = new Buttons;
my $dbt = new DBtank;
my %varenv = $cf->envonline();
my $script = $q->script_name();
my $path_info = $q->path_info();
my $path = $path_info;
if("$varenv{metahost}"){
$path = "$script" . "$path_info";
$script="";
}
my $dbh = "";
my $lang = "de";
my %ib = $but->ibuttons_arch();
my @viewsel = split /\//,$1 if($path =~ /^\/(.*)/);
my $tpl_master = $db->get_tpl("400");
my @tpl_masterorder = ();
my $node = {};
if($users_dms->{int08} == 2){
print<<EOF
<script>
\$(function() {
function postValues() {
var data = \$("input[type='checkbox'], input[type='text'], input[type='hidden']").serialize();
\$.ajax({
url: '$varenv{wwwhost}/ajax_post',
type: 'POST',
async: true,
cache: false,
data: data,
});
}
\$("input[type='checkbox']").on( "click", postValues );
\$("input[type='text']").on( "change", postValues );
});
</script>
EOF
;
}
if($users_dms->{int08} >= 1){
@tpl_masterorder = split /,/,$tpl_master->{tpl_order};
my $pref = { template_id1 => 401,
template_id2 => 499,
fetch => "all",
keyfield => "main_id",
};
$node = $dbt->fetch_rel4tpl4nd($dbh,$pref);
}else{
$return = "failure::Abbruch. Keine Zugriffsberechtigung";
}
sub checkbox_style2() {
my ($sid_key,$dialog) = @_;
my $ck_style = "<style type='text/css'><!--
.sq_$dialog$sid_key {margin:auto;position: relative;width: 16px;height: 16px;}
.sq_$dialog$sid_key label {cursor: pointer;position: absolute;width: 16px;height: 16px;background:#cccccc;top: 0%;left: 0%;}
.sq_$dialog$sid_key :checked + label {content: '';position: absolute;width: 16px;height: 16px;background: #333333;top: 0%;left: 0%;}
//--></style>\n";
return $ck_style;
}
print "<div id='Content4list'>\n";
print $q->div({-class=>"copri_header",-style=>"background-color:#cccccc;"},"$path",$q->span("(shareetool Datenfeld Matrix)"));
print $q->start_form();
print $q->hidden(-name=>'mode', -override=>1, -value=>"supervisor");
#table header
print $q->start_table({-border=>'0', -width=>'100%',-align=>'center', -cellpadding=>'0', -cellspacing=>'0'});
print $q->Tr();
if($users_dms->{int08} == 2){
#print $q->th({-style=>'text-align:right;padding:1px 3px;font-size:1em;'},"Datenfeld", $but->singlesubmit2("rel_edit","new_attrtpl_int","$ib{new_attrtpl_int}","background-color:silver;"), $but->singlesubmit2("rel_edit","new_attrtpl_txt","$ib{new_attrtpl_txt}","background-color:silver;")),"\n";
print $q->th({-style=>'text-align:right;padding:1px 3px;font-size:1em;'},"Datenfeld", $but->singlesubmit2glyph("rel_edit","new_attrtpl_int","$ib{new_attrtpl_int}","background-color:silver;")),"\n";
}else{
print $q->th({-style=>'text-align:right;padding:1px 3px;font-size:1em;'},""),"\n";
}
#foreach my $id (sort {$node->{$a}->{n_sort} <=> $node->{$b}->{n_sort}} keys (%$node)){
foreach my $id (sort {$node->{$a}->{node_name} cmp $node->{$b}->{node_name}} keys (%$node)){
if($node->{$id}->{template_id}){
if($node->{$id}->{main_id} == $node_meta->{main_id}){
print $q->hidden(-name=>'template_id',-override=>'1', -value=>"$node->{$id}->{template_id}");
print $q->th({-class=>'thmatrix',-nowrap=>1,-colspan=>2}, $q->b("$node->{$id}->{node_name}")),"\n";
}else{
if($users_dms->{int08} == 2){
my $uri_path = $dbt->recurse_node($dbh,$node->{$id}->{main_id});
print $q->th({-class=>'thmatrix',-nowrap=>1,-colspan=>2}, $q->a({-class=>"sortnav",-href=>"/$uri_path/supervisor",-title=>'aktivieren'}, "$node->{$id}->{node_name}")),"\n";
}else{
print $q->th({-class=>'thmatrix',-nowrap=>1,-colspan=>2},"$node->{$id}->{node_name}"),"\n";
}
}
}
}
#table content
my $j=0;
my $set_style;
my $checked="";
#tpl_id=400
foreach (@tpl_masterorder){
$j++;
$set_style = "background-color:#fcfdfb;";
$set_style = "background-color:#f4f1ee;" if($j %= 2);
print $q->Tr();
my ($m_key,$m_des,$m_size) = split /=/,$_;
if($m_key !~ /img|time|c_id|barcode|int04|owner/){#static
print $q->td({-class=>'tdtxtw', -style=>"$set_style"},$q->a({-class=>'sortnav',-href=>"/$viewsel[0]/$viewsel[1]/$viewsel[2]/supervisor?node2edit=edit_template\&tpl_id=$tpl_master->{tpl_id}\&key=$m_key", -title=>"edit ($j)"},"$m_des")),"\n";
}else{
print $q->td({-class=>'tdtxtw', -style=>"$set_style"},$q->a({-class=>'sortnav',-href=>"#", -title=>"static"},"$m_des")),"\n";
}
foreach my $id (sort {$node->{$a}->{node_name} cmp $node->{$b}->{node_name}} keys (%$node)){
my $cat_off="";
my $m_style="margin:auto;width:16px;height:16px;background-color:#cccccc;";
my $interval="";
#tpl_id > 400 and depends on node
if($node->{$id}->{tpl_order} =~ /$m_key=[a-z0-9-_ ]+=[a-z0-9-_]+=(\d+)/i){
$interval = $1;
}
my $service_type="";
if($node->{$id}->{tpl_order} =~ /$m_key=[a-z0-9-_ ]+=[a-z0-9-_]+=\d+=(\d+)/i){
$service_type = $1;
}
if($node->{$id}->{main_id} == $node_meta->{main_id}){
my $ck_style = &checkbox_style2($m_key,"attr");
print "$ck_style";
$checked="";
$checked="checked" if($node->{$id}->{tpl_order} =~ /$m_key/);
}else{
$cat_off=1;
$m_style="margin:auto;width:16px;height:16px;background-color:#717171;" if($node->{$id}->{tpl_order} =~ /$m_key/);
}
#my @tpl_node = split /,/,$node->{$id}->{tpl_order};
foreach (@tpl_masterorder){
my ($key,$des,$size) = split /=/,$_;
if($m_key eq $key){
if($cat_off){
my $itext = "";
my $ytext = "";
if($interval){
$itext = "$interval Tage Intervall";
$ytext = "";
$ytext = " | weich=1" if($service_type eq 1);
}
$ytext = " | hart=2" if($service_type eq 2);
print $q->td({-class=>'tdtxtc', -style=>"$set_style"},$q->div({-style=>"$m_style"},"")),"\n";
print $q->td({-class=>'tdtxtc', -style=>"$set_style text-align:left"},$q->div({-style=>""},"$itext $ytext")),"\n";
}else{
#print $q->td({-class=>'tdtxtc', -style=>"$set_style"},$q->div({ -class => "sq_attr$key" },"<input type='checkbox' id='sq_attr$key' name='matrix_template' value='$key=$des=$size' $checked><label for='sq_attr$key'></label>")),"\n";
print $q->td({-class=>'tdtxtc', -style=>"$set_style"},$q->div({ -class => "sq_attr$key" },"<input type='checkbox' id='sq_attr$key' name='matrix_template' value='$key=$des=$size' $checked><label for='sq_attr$key'></label>")),"\n";
print $q->td({-class=>'tdtxtc', -style=>"$set_style text-align:left;"}, $q->textfield(-class=>'etxt',-size=>'1',-name=>"interval_$key", -override=>'1',-default=>"$interval"), "Tage Intervall | Typ ", $q->textfield(-class=>'etxt',-size=>'1',-name=>"servicetype_$key", -override=>'1',-default=>"$service_type")),"\n";
}
}
}
}
}
print $q->end_table;
print $q->end_form;
print "</div>\n";
return $return;
}
1;