sharee.bike/copri4/main/src/Mod/Buttons.pm

552 lines
19 KiB
Perl
Raw Normal View History

2021-12-30 12:05:56 +01:00
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 = (
2022-11-09 15:17:55 +01:00
'set_gps' => 'Position',
2022-11-02 20:14:57 +01:00
'operator_accounting' => '2. Abrechnung generieren',
2021-12-30 12:05:56 +01:00
'service_done' => 'Wartungsprotokoll für ausgewähltes Rad einfügen/bearbeiten',
'post_email' => 'submit',
'barcode' => 'Barcode Label drucken',
'buchen' => 'buchen',
'send_invoice_again' => 'senden',
'email_generate' => 'eMail generieren',
2021-12-30 12:05:56 +01:00
'new_contenttver' => 'Neues Arbeitsprofil',
'new_content' => 'NEUER Datensatz',
2023-01-17 20:43:36 +01:00
'new_contentcms' => 'NEUER Datensatz',
2021-12-30 12:05:56 +01:00
'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',
2022-05-09 12:45:01 +02:00
'save_ctuser' => 'Save',
2021-12-30 12:05:56 +01:00
'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',
2022-03-17 20:28:28 +01:00
'print_pdf' => ' PDF ',
2021-12-30 12:05:56 +01:00
'set_relation' => 'Formular',
'set_workflow' => 'Workflow',
2022-03-18 14:51:25 +01:00
'set_workflow2invoice' => 'Rechnung generieren',
'set_workflow2storno' => 'Storno generieren',
2022-10-31 08:11:53 +01:00
'set_accounting2invoice' => 'Rechnung generieren',
2021-12-30 12:05:56 +01:00
'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 = "<a title='$lang_name' href='$lang_href'><img src='$icon' border='0' width='18' height='12' alt='$lang_name' /></a>\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 = "<a class='headnav' style='margin:1em 0 0 1em' title='$main_id' href='$lang_href'>$lang_name</a>\n";
return $langicon;
}
# Head Main Menue Button
sub head_button(){
my $self = shift;
my ($node_path,$node_name,$style) = @_;
my $button = "<div style='font-size:0.80em;float:left;$style'><a style='margin:0 0.5em;' class='linknav' href='$node_path'>$node_name</a></div>\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 = "<li><a style='$style $txt_color' title='' href='$node_path'>$node_name</a></li>\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 = "<a id='id_$main_id' style='$mstyle $txt_color' title='$main_id' href='$node_path'>$node_name</a>|\n";
#my $button = "<a id='id_$main_id' style='$style $txt_color' title='$main_id' href='javascript:mainbrowser(\"$node_path\")'>$node_name</a>|";
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 $button = "<li><a onmousedown='WhichButton(event,\"$url\");' class='$class' style='$style' title='$debug' href='$node_path'>$node_name</a></li>";
2021-12-30 12:05:56 +01:00
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 = "<img src='$icon' style='$icon_style' />" if($icon) || "";
my $button = "<li><a onmousedown='WhichButton(event,\"$url\");' class='$class' style='$style' title='$title' href='$node_path'>$image $node->{node_name}</a></li>";
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 = "<img src='$icon' style='$icon_style' />" if($icon) || "";
my $button;
if($script){
$button = "<a class='$class' style='$style' title='$debug' onclick='$script(\"$node_path\",\"$mtop\",\"$mleft\")'>$image $node_name</a>";
}else{
$button = "<a class='$class' style='$style' title='$debug' href='$node_path'>$image $node_name</a>";
}
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 = "<a onmouseover=\"this.innerHTML = '$node_name_int'\" onmouseout=\"this.innerHTML = '$node_name'\" class='$class' style='$style' title='$debug' href='$node_path'>$node_name</a>";
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 = "<li><a class='$class' style='$style' title='$debug' href='$node_path' target='$target'>$node_name</a></li>\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, "<option style='$ostyle' selected value='$id'>$value</option>\n";
}
else {
push @selopt, "<option style='$ostyle' value='$id'>$id</option>\n";
}
}
my $selret;
if($style =~ /background-color/){
$selret = "<select style='$style;' onchange='this.style.backgroundColor = this.options[this.selectedIndex].style.backgroundColor;' name='$colname'>@selopt</select>\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, "<option selected value=\"$id\">$value</option>\n";
}else{
push @selopt, "<option value=\"$id\">$value</option>\n";
}
}
my $selret = "<select class='eselect' style='width:$width' size=1 name='$tbl_columne' id='$tbl_columne'>@selopt</select>\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 eq $id){
2021-12-30 12:05:56 +01:00
push @selopt, "<option style='$des_style' selected value='$id'>$value</option>\n";
}else{
push @selopt, "<option style='$des_style' value='$id'>$value</option>\n";
}
}
my $selret = "<select class='$class' style='background-color:white;$style' name='$column'>@selopt</select>\n";
2021-12-30 12:05:56 +01:00
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/<br>";
if($sel && $id && (("$sel" eq "$id") || ("$sel" =~ /$id|$opt/))){
push @selopt, "<option selected value=\"$id\">$value</option>\n";
}else{
push @selopt, "<option value=\"$id\">$value</option>\n";
}
}
my $selret = "<select multiple class=\"eselect_multiple\" style=\"width:$width\" size=$height name=\"$tbl_columne\" >@selopt</select>\n";
return $selret;
}
sub checkbox_style() {
my $self = shift;
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-color:grey;}
.sq_$dialog$sid_key :checked + label {content: '';position: absolute;width: 16px;height: 16px;background-color: #333333;}
//--></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 || "";
2021-12-30 12:05:56 +01:00
$checked = "checked" if($checked);
$required = "required" if($required);
my $checkb = "<input type='checkbox' style='border: 1px solid silver;' name='$check_name' value='$val' title='$title' $checked $required $autofocus>";
2021-12-30 12:05:56 +01:00
return $checkb;
}
#reverse checkbox
sub rev_checkbox(){
my $self = shift;
my ($val,$check_name,$checked,$title) = @_;
if(!$checked){
$checked = "checked";
}
my $checkb = "<input type='checkbox' style='border: 1px solid;' name='$check_name' value='$val' title='$title' $checked>";
return $checkb;
}
#radio (seems not working!!)
sub radiobox(){
my $self = shift;
my ($val,$check_name,$checked) = @_;
$checked = "checked" if($checked);
my $checkb = "<input type='radio' class='ebutton' name='$check_name' value='$val' $checked>";
return $checkb;
}
#radio
#$but->radiobox2("$key","$ctrel->{$key}","$a","$b","$c")
sub radiobox2(){
my $self = shift;
2022-05-13 10:38:03 +02:00
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 = "";
2021-12-30 12:05:56 +01:00
$a_checked = "checked" if(!$val);
$b_checked = "checked" if($val==1);
$c_checked = "checked" if($val==2);
2022-05-13 10:38:03 +02:00
my $checkb = "";
$checkb .= " $a_name <input type='radio' name='$key' value='0' $a_checked>" if($a_name);
$checkb .= " $b_name <input type='radio' name='$key' value='1' $b_checked>" if($b_name);
2021-12-30 12:05:56 +01:00
$checkb .= " $c_name <input type='radio' name='$key' value='2' $c_checked>" 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 <input type='radio' name='$key' value='1' $a_checked> $b_name <input type='radio' name='$key' value='0' $b_checked>";
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 = "<label><input type='radio' name='$key' value='$val' $checked>$boxname</label>";
return $radiobox;
}
# Submit Buttons
sub singlesubmit(){
my $self = shift;
my ($function,$b_name,$jscript) = @_;
my $button;
if($jscript){
$button = "<input type='submit' onClick='javascript:$jscript' class='ebutton' name='$function' value='$b_name'>";
}else{
$button = "<input type='submit' class='ebutton' name='$function' value='$b_name'>";
}
return $button;
}
# Submit Buttons with db based button
sub singlesubmit10(){
my $self = shift;
my ($function,$b_val,$b_name) = @_;
my $button = "<button type='submit' class='ebutton' name='$function' value='$b_val'>$b_name</button>";
return $button;
}
sub singlesubmit1(){
my $self = shift;
2022-10-11 07:00:25 +02:00
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);
2021-12-30 12:05:56 +01:00
}
2022-10-11 07:00:25 +02:00
my $button = "<button type='submit' class='$class' style='$style' name='$function' value='$button_key' title=''>$ib_view</button>";
2021-12-30 12:05:56 +01:00
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;
}
}
2022-03-17 20:28:28 +01:00
my $button = "<button class='ebutton' style='height:17px;'></button>";
2021-12-30 12:05:56 +01:00
if("$b_name" =~ /delete/){
2022-03-17 20:28:28 +01:00
$button = "<button type='submit' onClick=\"return confirm('Wirklich löschen?')\" class='ebutton' style='$style' name='$function' value='$ib_key'>$ib_value</button>";
2021-12-30 12:05:56 +01:00
}elsif($b_img){
$button = "<button type='submit' style='border: 1px solid silver;' name='$function' value='$ib_key' title='$title' ><img src='$b_img' style='$style' /></button>";
2021-12-30 12:05:56 +01:00
}elsif($b_name){
2022-03-17 20:28:28 +01:00
$button = "<button type='submit' class='ebutton' style='$style' name='$function' value='$ib_key'>$ib_value</button>";
2021-12-30 12:05:56 +01:00
}
return $button;
}
# without grafic
sub singlesubmit7(){
my $self = shift;
2023-02-10 12:04:30 +01:00
my $function = shift;
my $b_name = shift;
my $title = shift || "";
my $set_style = shift || "";
my $jscript = shift || "";
my $autofocus = shift || "";
my $b_img = "";;
2021-12-30 12:05:56 +01:00
$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/);
2023-01-27 06:55:30 +01:00
$b_img = "Text & State Save" if("$b_name" =~ /save_text/);
2021-12-30 12:05:56 +01:00
$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 = "<span style='width:25px;height=15px;'>&nbsp;</span>";
if($b_name){
if("$b_name" =~ /delete/){
2023-02-10 12:04:30 +01:00
$button = "<button type='submit' onClick=\"return confirm('Wirklich löschen?')\" class='ebutton' style='$set_style' name='$function' value='$b_name' title='$title'>$b_img</button>";
2021-12-30 12:05:56 +01:00
}elsif($jscript){
2023-02-10 12:04:30 +01:00
$button = "<button type='submit' onClick='javascript:$jscript' class='ebutton' style='$set_style' name='$function' value='$b_name' title='$title'>$b_img</button>";
2021-12-30 12:05:56 +01:00
}else{
2023-02-10 12:04:30 +01:00
$button = "<button type='submit' class='ebutton' style='$set_style' name='$function' value='$b_name' title='$title' $autofocus>$b_img</button>";
2021-12-30 12:05:56 +01:00
}
}
return $button;
}
# Grafic Submit Buttons
sub singlesubmit2glyph(){
my $self = shift;
my ($function,$b_name,$title,$set_style,$jscript) = @_;
my $a_key = "";
2021-12-30 12:05:56 +01:00
$a_key = "y" if("$b_name" =~ /save/);
my $b_img = "";
$b_img = "<span class='bi bi-check-circle' style='font-size:1.5em;'</span>" if("$b_name" =~ /save/);
$b_img = "<span class='bi bi-x-circle' style='font-size:1.5em;'</span>" if("$b_name" =~ /delete|remove/);
$b_img = "<span class='bi bi-file-earmark-plus-fill' style='font-size:1.5em;'</span>" if("$b_name" =~ /new/);
$b_img = "<span class='bi bi-file-earmark-text-fill' style='font-size:1.5em;'</span>" if("$b_name" =~ /open|client/);
2021-12-30 12:05:56 +01:00
my $button = "<span style='width:25px;height=15px;'>&nbsp;</span>";
if($b_name){
if("$b_name" =~ /delete/){
2021-12-30 12:05:56 +01:00
if($jscript){
$button = "<button type='submit' onClick=\"javascript:$jscript; return confirm('Wirklich löschen?')\" style='width:25px;height=15px; border: 0px solid;$set_style' name='$function' value='$b_name' title='$title'>$b_img</button>";
2021-12-30 12:05:56 +01:00
}else{
$button = "<button type='submit' onClick=\"return confirm('Wirklich löschen?')\" style='width:25px;height=15px; border: 0px solid;$set_style' name='$function' value='$b_name' title='$title'>$b_img</button>";
2021-12-30 12:05:56 +01:00
}
}else{
$button = "<button type='submit' style='border: 0px solid;$set_style' name='$function' value='$b_name' title='$title' accesskey='$a_key'>$b_img</button>";
2021-12-30 12:05:56 +01:00
}
}
return $button;
}
#Submit Buttons
2021-12-30 12:05:56 +01:00
sub singlesubmit2(){
my $self = shift;
my ($function,$b_name,$title,$set_style,$jscript) = @_;
my $a_key = "";
2021-12-30 12:05:56 +01:00
$a_key = "y" if("$b_name" =~ /save/);
my $button = "<span style='width:25px;height=15px;'>&nbsp;</span>";
if($b_name){
if("$b_name" =~ /delete/){
2021-12-30 12:05:56 +01:00
if($jscript){
$button = "<button type='submit' onClick=\"javascript:$jscript; return confirm('Wirklich löschen?')\" style='width:25px;height=15px; border: 0px solid;$set_style' name='$function' value='$b_name' title='$title'></button>";
2021-12-30 12:05:56 +01:00
}else{
$button = "<button type='submit' onClick=\"return confirm('Wirklich löschen?')\" style='width:25px;height=15px; border: 0px solid;$set_style' name='$function' value='$b_name' title='$title'></button>";
2021-12-30 12:05:56 +01:00
}
}else{
$button = "<button type='submit' style='width:25px;height=15px; border: 0px solid;$set_style' name='$function' value='$b_name' title='$title' accesskey='$a_key'></button>";
2021-12-30 12:05:56 +01:00
}
}
return $button;
}
1;