package Libenz; # #Deprecated module, better use Prelib.pm or Basework.pm # # SPDX-License-Identifier: AGPL-3.0-or-later # Copyright (c) Rainer Gümpelein, TeilRad GmbH # use strict; use warnings; use POSIX; use File::Path qw(make_path remove_tree); use File::Copy; use File::Copy::Recursive qw(fcopy rcopy dircopy fmove rmove dirmove); use Getopt::Long; use CGI; # only for debugging use CGI::Carp qw(fatalsToBrowser); use Calendar::Simple; use Date::Calc qw(:all); use Mod::Callib; use Mod::Libenzdb; use Mod::Buttons; use Lib::Config; use Digest::MD5 qw(md5 md5_hex); use Scalar::Util qw(looks_like_number); my $cf = new Config; my $cb = new Callib; my $but = new Buttons; my $db = new Libenzdb; my $q = new CGI; #my $pi = new Image::Magick; $q->import_names('R'); sub new { my $class = shift; my $self = {}; bless($self,$class); return $self; } my %varenv = $cf->envonline(); my $lang="de"; my $now_time = strftime "%Y-%m-%d %H:%M", localtime; my @months = $cb->monthmap(); my @days = $cb->daymap(); my $i_rows=0; my $u_rows=0; my $d_rows=0; my $nall; sub grep_filecontent(){ my $self = shift; my ($filename,$content,$pattern) = @_; my $match = ""; if (open(my $fh, '<:encoding(UTF-8)', $filename)) { while (my $row = <$fh>) { $row =~ s/\n//; $row =~ s/\r//; if($content && $row eq $content){ $match = $content; }elsif($pattern && $row =~ /$pattern/){ $match = $row; } } } return $match; } # calculates the distance between two latitude, longitude points sub geo_fencing { my $self = shift; my ($lat1, $lon1, $lat2, $lon2) = @_; my $pi = atan2(1,1) * 4; if (($lat1 == $lat2) && ($lon1 == $lon2)) { return 0; } else { my $theta = $lon1 - $lon2; my $dist = sin($lat1 * $pi / 180) * sin($lat2 * $pi / 180) + cos($lat1 * $pi / 180) * cos($lat2 * $pi / 180) * cos($theta * $pi / 180); $dist = atan2(sqrt(1 - $dist**2), $dist); $dist = $dist * 180 / $pi; $dist = $dist * 60 * 1.1515;#Miles $dist = $dist * 1.609344 * 1000;#Meters $dist = sprintf('%.0f',$dist); return ($dist); } } sub country_code(){ my $self = shift; my $country = { 'DE' => 'Deutschland', 'BE' => 'Belgien', 'BG' => 'Bulgarien', 'CH' => 'Schweiz', 'CZ' => 'Tschechische Republik', 'DK' => 'Dänemark', 'EE' => 'Estland', 'IE' => 'Irland', 'EL' => 'Griechenland', 'ES' => 'Spanien', 'FR' => 'Frankreich', 'HR' => 'Kroatien', 'IT' => 'Italien', 'CY' => 'Zypern', 'LV' => 'Lettland', 'LT' => 'Litauen', 'LU' => 'Luxemburg', 'HU' => 'Ungarn', 'MT' => 'Malta', 'NL' => 'Niederlande', 'AT' => 'Österreich', 'PL' => 'Polen', 'PT' => 'Portugal', 'RO' => 'Rumänien', 'SI' => 'Slowenien', 'SK' => 'Slowakei', 'FI' => 'Finnland', 'SE' => 'Schweden', 'GB' => 'Vereinigtes Königreich', }; return $country; } sub country_code_all(){ my $self = shift; my $country = { '--' => '----------------------', 'AF' => 'Afghanistan', 'AX' => 'Åland Islands', 'AL' => 'Albania', 'DZ' => 'Algeria', 'AS' => 'American Samoa', 'AD' => 'Andorra', 'AO' => 'Angola', 'AI' => 'Anguilla', 'AQ' => 'Antarctica', 'AG' => 'Antigua and Barbuda', 'AR' => 'Argentina', 'AM' => 'Armenia', 'AW' => 'Aruba', 'AU' => 'Australia', 'AT' => 'Austria', 'AZ' => 'Azerbaijan', 'BS' => 'Bahamas', 'BH' => 'Bahrain', 'BD' => 'Bangladesh', 'BB' => 'Barbados', 'BY' => 'Belarus', 'BE' => 'Belgium', 'BZ' => 'Belize', 'BJ' => 'Benin', 'BM' => 'Bermuda', 'BT' => 'Bhutan', 'BO' => 'Bolivia (Plurinational State of)', 'BQ' => 'Bonaire, Sint Eustatius and Saba', 'BA' => 'Bosnia and Herzegovina', 'BW' => 'Botswana', 'BV' => 'Bouvet Island', 'BR' => 'Brazil', 'IO' => 'British Indian Ocean Territory', 'BN' => 'Brunei Darussalam', 'BG' => 'Bulgaria', 'BF' => 'Burkina Faso', 'BI' => 'Burundi', 'CV' => 'Cabo Verde', 'KH' => 'Cambodia', 'CM' => 'Cameroon', 'CA' => 'Canada', 'KY' => 'Cayman Islands', 'CF' => 'Central African Republic', 'TD' => 'Chad', 'CL' => 'Chile', 'CN' => 'China', 'CX' => 'Christmas Island', 'CC' => 'Cocos (Keeling) Islands', 'CO' => 'Colombia', 'KM' => 'Comoros', 'CG' => 'Congo', 'CD' => 'Congo, Democratic Republic of the', 'CK' => 'Cook Islands', 'CR' => 'Costa Rica', 'CI' => 'Côte d\'Ivoire', 'HR' => 'Croatia', 'CU' => 'Cuba', 'CW' => 'Curaçao', 'CY' => 'Cyprus', 'CZ' => 'Czechia', 'DK' => 'Denmark', 'DJ' => 'Djibouti', 'DM' => 'Dominica', 'DO' => 'Dominican Republic', 'EC' => 'Ecuador', 'EG' => 'Egypt', 'SV' => 'El Salvador', 'GQ' => 'Equatorial Guinea', 'ER' => 'Eritrea', 'EE' => 'Estonia', 'SZ' => 'Eswatini', 'ET' => 'Ethiopia', 'FK' => 'Falkland Islands (Malvinas)', 'FO' => 'Faroe Islands', 'FJ' => 'Fiji', 'FI' => 'Finland', 'FR' => 'France', 'GF' => 'French Guiana', 'PF' => 'French Polynesia', 'TF' => 'French Southern Territories', 'GA' => 'Gabon', 'GM' => 'Gambia', 'GE' => 'Georgia', #'DE' => 'Germany', 'GH' => 'Ghana', 'GI' => 'Gibraltar', 'GR' => 'Greece', 'GL' => 'Greenland', 'GD' => 'Grenada', 'GP' => 'Guadeloupe', 'GU' => 'Guam', 'GT' => 'Guatemala', 'GG' => 'Guernsey', 'GN' => 'Guinea', 'GW' => 'Guinea-Bissau', 'GY' => 'Guyana', 'HT' => 'Haiti', 'HM' => 'Heard Island and McDonald Islands', 'VA' => 'Holy See', 'HN' => 'Honduras', 'HK' => 'Hong Kong', 'HU' => 'Hungary', 'IS' => 'Iceland', 'IN' => 'India', 'ID' => 'Indonesia', 'IR' => 'Iran (Islamic Republic of)', 'IQ' => 'Iraq', 'IE' => 'Ireland', 'IM' => 'Isle of Man', 'IL' => 'Israel', 'IT' => 'Italy', 'JM' => 'Jamaica', 'JP' => 'Japan', 'JE' => 'Jersey', 'JO' => 'Jordan', 'KZ' => 'Kazakhstan', 'KE' => 'Kenya', 'KI' => 'Kiribati', 'KP' => 'Korea (Democratic People\'s Republic of)', 'KR' => 'Korea, Republic of', 'KW' => 'Kuwait', 'KG' => 'Kyrgyzstan', 'LA' => 'Lao People\'s Democratic Republic', 'LV' => 'Latvia', 'LB' => 'Lebanon', 'LS' => 'Lesotho', 'LR' => 'Liberia', 'LY' => 'Libya', 'LI' => 'Liechtenstein', 'LT' => 'Lithuania', 'LU' => 'Luxembourg', 'MO' => 'Macao', 'MG' => 'Madagascar', 'MW' => 'Malawi', 'MY' => 'Malaysia', 'MV' => 'Maldives', 'ML' => 'Mali', 'MT' => 'Malta', 'MH' => 'Marshall Islands', 'MQ' => 'Martinique', 'MR' => 'Mauritania', 'MU' => 'Mauritius', 'YT' => 'Mayotte', 'MX' => 'Mexico', 'FM' => 'Micronesia (Federated States of)', 'MD' => 'Moldova, Republic of', 'MC' => 'Monaco', 'MN' => 'Mongolia', 'ME' => 'Montenegro', 'MS' => 'Montserrat', 'MA' => 'Morocco', 'MZ' => 'Mozambique', 'MM' => 'Myanmar', 'NA' => 'Namibia', 'NR' => 'Nauru', 'NP' => 'Nepal', 'NL' => 'Netherlands', 'NC' => 'New Caledonia', 'NZ' => 'New Zealand', 'NI' => 'Nicaragua', 'NE' => 'Niger', 'NG' => 'Nigeria', 'NU' => 'Niue', 'NF' => 'Norfolk Island', 'MK' => 'North Macedonia', 'MP' => 'Northern Mariana Islands', 'NO' => 'Norway', 'OM' => 'Oman', 'PK' => 'Pakistan', 'PW' => 'Palau', 'PS' => 'Palestine, State of', 'PA' => 'Panama', 'PG' => 'Papua New Guinea', 'PY' => 'Paraguay', 'PE' => 'Peru', 'PH' => 'Philippines', 'PN' => 'Pitcairn', 'PL' => 'Poland', 'PT' => 'Portugal', 'PR' => 'Puerto Rico', 'QA' => 'Qatar', 'RE' => 'Réunion', 'RO' => 'Romania', 'RU' => 'Russian Federation', 'RW' => 'Rwanda', 'BL' => 'Saint Barthélemy', 'SH' => 'Saint Helena, Ascension and Tristan da Cunha', 'KN' => 'Saint Kitts and Nevis', 'LC' => 'Saint Lucia', 'MF' => 'Saint Martin (French part)', 'PM' => 'Saint Pierre and Miquelon', 'VC' => 'Saint Vincent and the Grenadines', 'WS' => 'Samoa', 'SM' => 'San Marino', 'ST' => 'Sao Tome and Principe', 'SA' => 'Saudi Arabia', 'SN' => 'Senegal', 'RS' => 'Serbia', 'SC' => 'Seychelles', 'SL' => 'Sierra Leone', 'SG' => 'Singapore', 'SX' => 'Sint Maarten (Dutch part)', 'SK' => 'Slovakia', 'SI' => 'Slovenia', 'SB' => 'Solomon Islands', 'SO' => 'Somalia', 'ZA' => 'South Africa', 'GS' => 'South Georgia and the South Sandwich Islands', 'SS' => 'South Sudan', 'ES' => 'Spain', 'LK' => 'Sri Lanka', 'SD' => 'Sudan', 'SR' => 'Suriname', 'SJ' => 'Svalbard and Jan Mayen', 'SE' => 'Sweden', 'CH' => 'Switzerland', 'SY' => 'Syrian Arab Republic', 'TW' => 'Taiwan, Province of China', 'TJ' => 'Tajikistan', 'TZ' => 'Tanzania, United Republic of', 'TH' => 'Thailand', 'TL' => 'Timor-Leste', 'TG' => 'Togo', 'TK' => 'Tokelau', 'TO' => 'Tonga', 'TT' => 'Trinidad and Tobago', 'TN' => 'Tunisia', 'TR' => 'Turkey', 'TM' => 'Turkmenistan', 'TC' => 'Turks and Caicos Islands', 'TV' => 'Tuvalu', 'UG' => 'Uganda', 'UA' => 'Ukraine', 'AE' => 'United Arab Emirates', 'GB' => 'United Kingdom of Great Britain and Northern Ireland', 'US' => 'United States of America', 'UM' => 'United States Minor Outlying Islands', 'UY' => 'Uruguay', 'UZ' => 'Uzbekistan', 'VU' => 'Vanuatu', 'VE' => 'Venezuela (Bolivarian Republic of)', 'VN' => 'Viet Nam', 'VG' => 'Virgin Islands (British)', 'VI' => 'Virgin Islands (U.S.)', 'WF' => 'Wallis and Futuna', 'EH' => 'Western Sahara', 'YE' => 'Yemen', 'ZM' => 'Zambia', 'ZW' => 'Zimbabwe', }; return $country; } #read directory sub read_dirfiles(){ my $self = shift; my ($dir,$extensions,$dirOfile,$not) = @_; my @dirfiles; if( -d "$dir" || -l "$dir"){ opendir(DIR, "$dir") or die "could not open $dir $!"; foreach(sort(readdir(DIR))){ if($dir =~ /INBOX/){ if($_ =~ /^$extensions/){ push(@dirfiles,$_) if(-f "$dir/$_" && $dirOfile eq "file"); push(@dirfiles,$_) if(-d "$dir/$_" && $dirOfile eq "dir"); } } elsif($not){ if(uc($_) !~ /$extensions/){ push(@dirfiles,$_) if(-f "$dir/$_" && $dirOfile eq "file"); push(@dirfiles,$_) if(-d "$dir/$_" && $dirOfile eq "dir"); } }else{ if(uc($_) =~ /$extensions/ || $_ =~ /$extensions/){ push(@dirfiles,$_) if(-f "$dir/$_" && $dirOfile eq "file"); push(@dirfiles,$_) if(-d "$dir/$_" && $dirOfile eq "dir"); } } } closedir DIR; }else{ print "\ndirectory: $dir does not exist\n $!\n"; } return @dirfiles; } #Quersumme sub quersum(){ my $self = shift; my ($kecks) = @_; my $laenge = length($kecks); my $quersum = 0; for(my $i=0; $i<$laenge; $i++) { my $signs = substr($kecks, $i, 1); $quersum = $quersum + int(ord($signs)); } return $quersum; } #Calfkt to get a scalable line of days per month sub month_line(){ my $self = shift; my ($users) = @_; #my $users = $db->select_users($u_id); my $hh;my $mm; my $day = strftime "%d", localtime; my $mon = strftime "%m", localtime; my $year = strftime "%Y", localtime; my $day_today = $day; my $mon_today = $mon; my $year_today = $year; ($year,$mon,$day,$hh,$mm) = &split_date("",$users->{cal_start}) if($users->{cal_start}); #print "$year,$mon,$day,$hh,$mm"; my $month_days = Days_in_Month($year,$mon); my $factor = 100 / $month_days; $factor = sprintf('%.3f',$factor); my @month = calendar($mon, $year); my $raster_mmpx = $factor . "%"; #bsp.: 100% / 31days my $day4month; my $bg; my @week; my $i=0; my $j=0; #month, week loop foreach (@month) { $i=0; $j++; #print map { $_ ? sprintf "%2d ", $_ : ' x ' } @$_; #day-of-week loop foreach(@$_){ if($_){ $_ = "0$_" if($_ < "10"); $week[$j] .= "$_,"; #print $q->th({-nowrap=>1},"$days[$i] $_"); if("$_" eq "$day_today" && "$mon" eq "$mon_today"){ $bg="#009899"; }else{ $bg="silver"; } $day4month .= "