package Buttons;
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
#
use strict;
use warnings;
use Lib::Config;
use Data::Dumper;
sub new {
my $class = shift;
my $self = {};
bless($self,$class);
return $self;
}
my $cf = new Config;
my %varenv = $cf->envonline();
my $icon = "/icon";
#my standard internationalize submit buttons
sub ibuttons(){
my $self = shift;
my %ib = (
'set_gps' => 'Position',
'operator_accounting' => '2. Abrechnung generieren',
'service_done' => 'Wartungsprotokoll für ausgewähltes Rad einfügen/bearbeiten',
'post_email' => 'submit',
'barcode' => 'Barcode Label drucken',
'buchen' => 'buchen',
'send_invoice_again' => 'senden',
'new_contenttver' => 'Neues Arbeitsprofil',
'new_content' => 'NEUER Datensatz',
'new_contentcms' => 'NEUER Datensatz',
'new_adr' => 'Kunde anlegen',
'new_trans' => 'NEUE Transaktion',
'new_tver' => 'NEU',
'new_nel' => 'NEUE Nachricht',
'new_transdate' => 'NEUER Kalendereintrag',
'new_time' => 'NEUER Termin',
'new_dmsusers' => 'NEUER DMS Account',
'new_relation' => 'NEUES Menue anlegen',
'new_relation4sub' => 'NEUES Sub-Menue anlegen',
'save_content' => 'Speichern',
'save_ctuser' => 'Save',
'save_nel' => 'Nachricht speichern',
'context_copy_content' => 'Kopie im Kontext der internen Barcode Nummer',
'copy_content' => 'Kopie fuer neuen Datensatz',
'move_relation' => 'Menue verschieben',
'move_content' => 'Datensatz in anderen Ordner verschieben',
'save_adr' => 'Kunden speichern',
'save_text' => 'Text speichern',
'save_dmsusers' => 'DMS Account speichern',
'save_relation' => 'Menue speichern',
'remove_chk4rel' => 'löschen',
'delete_content' => 'löschen',
'delete_adr' => 'Kunden löschen',
'delete_nel' => 'Nachricht löschen',
'newsletter_mailman' => 'Nachricht senden',
'delete_dmsusers' => 'DMS Account löschen',
'delete_trans' => 'löschen',
'delete_relation' => 'Menue löschen',
'save_pos' => 'Datensatz speichern',
'delete_pos' => 'Datensatz löschen',
'save_name' => 'Kunden speichern',
'search' => 'suchen',
'search_product' => 'Search',
'search_calendar' => 'anzeigen',
'search_adr' => 'Kunden suchen',
'search_extrakt' => 'extrakt',
'change_login' => 'ID',
'print_pdf' => ' PDF ',
'set_relation' => 'Formular',
'set_workflow' => 'Workflow',
'set_workflow2invoice' => 'Rechnung generieren',
'set_workflow2storno' => 'Storno generieren',
'set_accounting2invoice' => 'Rechnung generieren',
'relate_content' => 'Content-Menu Relation',
'relate_dialog' => 'Relation herstellen',
'relate_dialog4menu' => 'Relation herstellen',
'save_media' => 'Foto speichern',
'delete_media' => 'Foto löschen',
'save_database' => 'Datenbank Sicherung',
'XLSout_contentadr' => 'XLS Export',
'more' => 'more',
'Login' => 'Login',
'login' => 'login'
);
return %ib;
}
my %ib = ibuttons();
# Language Icons
sub langicon_pic(){
my $self = shift;
my ($script,$lang_name,$lang,$view) = @_;
if($script =~ /(\/src\/index\.pl)/){
$script = $1
}else{
$script = "/src";
}
my $icon = "$icon/$lang.gif";
my $lang_href = "$script/$lang/$view";
my $langicon = " \n";
return $langicon;
}
sub langicon_txt(){
my $self = shift;
my ($script,$lang_name,$main_id,$lang,$view) = @_;
if($script =~ /(\/src\/index\.pl)/){
$script = $1
}else{
$script = "/src";
}
my $lang_href = "$script/$lang/$view";
my $langicon = "$lang_name \n";
return $langicon;
}
# Head Main Menue Button
sub head_button(){
my $self = shift;
my ($node_path,$node_name,$style) = @_;
my $button = "
\n";
return $button;
}
# Top Main Menue Button
sub top_button(){
my $self = shift;
my ($node_path,$node_name,$main_id,$style) = @_;
my $txt_color;
$txt_color = "color: black;" if($style =~ /white/);
my $button = "$node_name \n";
return $button;
}
# a link for Top2
sub a_button(){
my $self = shift;
my ($node_path,$node_name,$main_id,$mstyle) = @_;
my $txt_color;
#$txt_color = "color: black;" if($mstyle =~ /white/);
my $button = "$node_name |\n";
#my $button = "$node_name |";
return $button;
}
#with mousevent
sub event_button(){
my $self = shift;
my ($node_path,$node_name,$main_id,$class,$style,$owner,$url,$icon,$icon_style) = @_;
my $debug = $main_id if($owner && $owner eq $varenv{superu_id});
my $image = " " if($icon) || "";
my $button = "$image $node_name ";
return $button;
}
sub event_button2(){
my $self = shift;
my ($node_path,$node,$class,$style,$owner,$url,$icon,$icon_style) = @_;
$node->{change} =~ s/\.\d.*//;
my $title = "($node->{change})";
$title .= " | main_id: $node->{main_id}" if($owner && $owner eq $varenv{superu_id});
my $image = " " if($icon) || "";
my $button = "$image $node->{node_name} ";
return $button;
}
#just a without li
sub lo_button(){
my $self = shift;
my ($node_path,$node_name,$main_id,$class,$style,$owner,$script,$mtop,$mleft,$icon,$icon_style) = @_;
my $debug = $main_id if($owner && $owner eq $varenv{superu_id});
my $image = " " if($icon) || "";
my $button;
if($script){
$button = "$image $node_name ";
}else{
$button = "$image $node_name ";
}
return $button;
}
#with mousevent over/out
sub lo_button2(){
my $self = shift;
my ($node_path,$node_name,$node_name_int,$main_id,$class,$style,$owner) = @_;
my $debug = $main_id if($owner && $owner eq $varenv{superu_id});
my $button = "$node_name ";
return $button;
}
#mit li
sub lia_button(){
my $self = shift;
my ($node_path,$node_name,$main_id,$class,$style,$owner) = @_;
my $debug = $main_id if($owner && $owner eq $varenv{superu_id});
my $target = "_self";
$target = "_blank" if($node_path =~ /http/);
my $button = "$node_name \n";
return $button;
}
# select tag
sub selector_color() {
my $self = shift;
my $colname = shift;
my $style = shift;
my $value = shift;
my @selval = @_;
my @selopt = ();
foreach my $id (@selval) {
my $ostyle;
$ostyle = "background-color:$id" if($style =~ /background-color/);
if ($id eq $value) {
push @selopt, "$value \n";
}
else {
push @selopt, "$id \n";
}
}
my $selret;
if($style =~ /background-color/){
$selret = "@selopt \n";
}
return $selret;
}
# select tag
sub selector(){
my $self = shift;
my $tbl_columne = shift;
my $width = shift || "";
my $sel = shift || "";
my @selval = @_;
my @selopt = ();
foreach my $opt (@selval){
my $id = $opt;
my $value = $opt;
($id,$value) = split /:/,$opt if($opt =~ /\w+\:.*/);
if($sel eq $id){
push @selopt, "$value \n";
}else{
push @selopt, "$value \n";
}
}
my $selret = "@selopt \n";
return $selret;
}
# select tag with class
sub selector_class(){
my $self = shift;
my ($column,$class,$style,$sel,@selval) = @_;
my @selopt = ();
foreach my $opt (@selval){
my $des_style = "";
my $id = $opt;
my $value = $opt;
($id,$value) = split /:/,$opt if($opt =~ /\:/);
$des_style = "color:grey;" if(!$id);
if($sel && $sel eq $id){
push @selopt, "$value \n";
}else{
push @selopt, "$value \n";
}
}
my $selret = "@selopt \n";
return $selret;
}
# select tag by id and class onChange
sub selector_byidclass(){
my $self = shift;
my ($column,$byid,$class,$style,$sel,@selval) = @_;
my @selopt = ();
foreach my $opt (@selval){
my $id = $opt;
my $value = $opt;
($id,$value) = split /:/,$opt if($opt =~ /\w+\:.*/);
if($sel && $sel eq $id){
push @selopt, "$value \n";
}else{
push @selopt, "$value \n";
}
}
#my $selret = "@selopt \n";
my $selret = "@selopt \n";
return $selret;
}
# select onChange
sub userselector_onchange(){
my $self = shift;
my $key = shift;
my $selected = shift;
my $users_all = shift;
my $admin_name = shift || "";
my $class = shift || "";
my $style = shift || "";
my @selopt = ();
foreach my $c_id (sort { $users_all->{$a}->{txt08} cmp $users_all->{$b}->{txt08} } keys (%$users_all)){
#print $c_id . "|" . $users_all->{$c_id}->{txt08} . "\n";
$users_all->{$c_id}->{txt08} .= " (Ferien)" if($users_all->{$c_id}->{txt08} eq $admin_name);
if($selected eq $c_id){
push @selopt, "$users_all->{$c_id}->{txt08} \n";
}else{
push @selopt, "$users_all->{$c_id}->{txt08} \n";
}
}
my $selret = "\n@selopt \n";
return $selret;
}
# select2 tag
sub selector2(){
my $self = shift;
my $tbl_columne = shift;
my $width = shift;
my $height = shift;
my $sel = shift;
my @selval = @_;
my @selopt = ();
foreach my $opt (@selval){
my $id = $opt;
my $value = $opt;
($id,$value) = split /:/,$opt if($opt =~ /\d\:.*/);
#print "$sel eq $id || ($sel && $sel =~ /$id|$opt/ ";
if($sel && $id && (("$sel" eq "$id") || ("$sel" =~ /$id|$opt/))){
push @selopt, "$value \n";
}else{
push @selopt, "$value \n";
}
}
my $selret = "@selopt \n";
return $selret;
}
# select3 tag with id:value
sub selector3(){
my $self = shift;
my $tbl_columne = shift;
my $width = shift;
my $height = shift;
my $sel = shift;
my @selval = @_;
my @selopt = ();
foreach my $opt (@selval){
my $id = $opt;
my $value = $opt;
($id,$value) = split /:/,$opt if($opt =~ /\d\:.*/);
#print "$sel =~ /\w+/ && $sel =~ /$id|$value/) ";
if($sel && "$sel" =~ /$id|$value/){
push @selopt, "$value \n";
}else{
push @selopt, "$value \n";
}
}
my $multiple = "";
$multiple = "multiple" if($height > 1);
my $selret = "\n@selopt \n";
return $selret;
}
#with onchange event
sub selector_onchange(){
my $self = shift;
my $key = shift;
my $width = shift;
my $path = shift;
my $jscript = shift;
my $sel = shift;
my $todo = shift;
my @selval = @_;
my @selopt = ();
foreach my $opt (@selval){
my $id = $opt;
my $value = $opt;
($id,$value) = split /:/,$opt if($opt =~ /\d\:.*/);
my $rid = "$id";
$rid = "$path?change_login=$value" if($todo eq "change_login");
$rid = "$value?$path\&$key=$id" if($key =~ /set_main_id/);
if("$sel" eq "$id"){
push @selopt, "$value \n";
}else{
push @selopt, "$value \n";
}
}
my $selret = "@selopt \n";
return $selret;
}
sub checkbox_style() {
my $self = shift;
my ($sid_key,$dialog) = @_;
my $ck_style = "\n";
return $ck_style;
}
#checkbox
sub checkbox(){
my $self = shift;
my $val = shift;
my $check_name = shift;
my $checked = shift;
my $title = shift || "";
my $required = shift || "";
my $autofocus = shift || "";
$checked = "checked" if($checked);
$required = "required" if($required);
my $checkb = " ";
return $checkb;
}
#reverse checkbox
sub rev_checkbox(){
my $self = shift;
my ($val,$check_name,$checked,$title) = @_;
if(!$checked){
$checked = "checked";
}
my $checkb = " ";
return $checkb;
}
#radio (seems not working!!)
sub radiobox(){
my $self = shift;
my ($val,$check_name,$checked) = @_;
$checked = "checked" if($checked);
my $checkb = " ";
return $checkb;
}
#radio
#$but->radiobox2("$key","$ctrel->{$key}","$a","$b","$c")
sub radiobox2(){
my $self = shift;
my $key = shift;
my $val = shift;
my $a_name = shift || "";
my $b_name = shift || "";
my $c_name = shift || "";
my $a_checked = "";
my $b_checked = "";
my $c_checked = "";
$a_checked = "checked" if(!$val);
$b_checked = "checked" if($val==1);
$c_checked = "checked" if($val==2);
my $checkb = "";
$checkb .= " $a_name " if($a_name);
$checkb .= " $b_name " if($b_name);
$checkb .= " $c_name " if($c_name);
return $checkb;
}
#radio reverse
sub radiobox2reverse(){
my $self = shift;
my ($key,$val,$a_name,$b_name) = @_;
my $a_checked;
my $b_checked;
$a_checked = "checked" if($val);
$b_checked = "checked" if(!$val);
my $checkb = "$a_name $b_name ";
return $checkb;
}
#Returns one radiobox ... you need min two to get a radioboxe
sub radiobox_vertical(){
my $self = shift;
my ($key,$val,$checked,$boxname) = @_;
$checked = "checked" if($checked);
my $radiobox = " $boxname ";
return $radiobox;
}
# Submit Buttons
sub singlesubmit(){
my $self = shift;
my ($function,$b_name,$jscript) = @_;
my $button;
if($jscript){
$button = " ";
}else{
$button = " ";
}
return $button;
}
# Submit Buttons with db based button
sub singlesubmit10(){
my $self = shift;
my ($function,$b_val,$b_name) = @_;
my $button = "$b_name ";
return $button;
}
sub singlesubmit1(){
my $self = shift;
my $function = shift;
my $button_key = shift;
my $class = shift || "ebutton";
my $style = shift || "";
my $ib_view = $button_key;
while (my($key,$val) = each(%ib)) {
$ib_view = $val if($key eq $button_key);
}
my $button = "$ib_view ";
return $button;
}
sub singlesubmit3(){
my $self = shift;
my ($function,$b_name,$b_img,$style,$title) = @_;
my ($key,$val,$ib_key,$ib_value);
#my %ib = ibuttons_arch();
my %ib = ibuttons();
while (($key,$val) = each(%ib)) {
if($b_name eq $key){
$ib_key = $key;
$ib_value = $val;
}
}
my $button = " ";
if("$b_name" =~ /delete/){
$button = "$ib_value ";
}elsif($b_img){
$button = " ";
}elsif($b_name){
$button = "$ib_value ";
}
return $button;
}
# without grafic
sub singlesubmit7(){
my $self = shift;
my ($function,$b_name,$title,$set_style,$jscript,$ebutton) = @_;
$ebutton = "ebutton" if(!$ebutton);
my ($b_img,$a_key);
$b_img = "Barcode" if("$b_name" =~ /barcode/);
$b_img = "Copy" if("$b_name" =~ /copy/);
$b_img = "Relate" if("$b_name" =~ /relate/);
$b_img = "Move" if("$b_name" =~ /move_/);
$b_img = "Delete" if("$b_name" =~ /delete|remove/);
$b_img = "Delete" if("$b_name" =~ /delete_media/);
$b_img = "Save" if("$b_name" =~ /save|service_done|_contenttverpos/);
$a_key = "y" if("$b_name" =~ /save/);
$b_img = "Text Save" if("$b_name" =~ /save_text/);
$b_img = "Delete All" if("$b_name" =~ /delete_all/);
$b_img = "Search" if("$b_name" =~ /search/);
$b_img = "New" if("$b_name" =~ /^new/);
$b_img = "Open" if("$b_name" eq "open");
$b_img = "Close" if("$b_name" eq "close");
$b_img = "Print" if("$b_name" eq "print_sheet");
$b_img = "Change Login" if("$b_name" eq "change_login");
$b_img = "Senden" if("$b_name" =~ /send_newsletter/);
$b_img = "XLS Export" if("$b_name" =~ /XLSout/);
$b_img = "Save & Close" if("$b_name" =~ /_and_close/);
$b_img = "Save & Close & Print " if("$b_name" =~ /_print_and_close/);
$b_img = "Print" if("$b_name" =~ /_print_only/);
$b_img = "Kunde" if("$b_name" =~ /client/);
$b_img = "Artikel" if("$b_name" =~ /part/);
$b_img = "speichern & schließen" if("$b_name" =~ /save_tver_close/);
my $button = " ";
if($b_name){
if("$b_name" =~ /delete/){
$button = "$b_img ";
}elsif($jscript){
$button = "$b_img ";
}else{
$button = "$b_img ";
}
}
return $button;
}
# Grafic Submit Buttons
sub singlesubmit2glyph(){
my $self = shift;
my ($function,$b_name,$title,$set_style,$jscript) = @_;
my $a_key = "";
$a_key = "y" if("$b_name" =~ /save/);
my $b_img = "";
$b_img = "" if("$b_name" =~ /save/);
$b_img = "" if("$b_name" =~ /delete|remove/);
$b_img = "" if("$b_name" =~ /new/);
$b_img = "" if("$b_name" =~ /open|client/);
my $button = " ";
if($b_name){
if("$b_name" =~ /delete/){
if($jscript){
$button = "$b_img ";
}else{
$button = "$b_img ";
}
}else{
$button = "$b_img ";
}
}
return $button;
}
#Submit Buttons
sub singlesubmit2(){
my $self = shift;
my ($function,$b_name,$title,$set_style,$jscript) = @_;
my $a_key = "";
$a_key = "y" if("$b_name" =~ /save/);
my $button = " ";
if($b_name){
if("$b_name" =~ /delete/){
if($jscript){
$button = " ";
}else{
$button = " ";
}
}else{
$button = " ";
}
}
return $button;
}
1;