2 |
|
|
3 |
use strict; |
use strict; |
4 |
|
|
5 |
|
my $ic_mail='biljana.gombar@pliva.hr,antonio.gulam@pliva.hr'; |
6 |
|
my $mreze_mail='davorin.koprivnjak@pliva.hr'; |
7 |
|
|
8 |
my $debug=0; |
my $debug=0; |
9 |
|
|
10 |
use DBI; |
use DBI; |
11 |
use POSIX qw(strftime); |
use POSIX qw(strftime); |
12 |
|
|
13 |
$debug++ if ($ARGV[0] eq "-d"); |
$debug++ if (defined $ARGV[0] && $ARGV[0] eq "-d"); |
14 |
|
|
15 |
print STDERR "Debug mod: output je u /tmp/debug*\n" if ($debug); |
print STDERR "Debug mod: output je u /tmp/debug*\n" if ($debug); |
16 |
|
|
17 |
my $currdate = strftime "%d.%m.%Y %H:%M:%S", localtime; |
my $currdate = strftime "%Y-%m-%d %H:%M:%S", localtime; |
18 |
|
|
19 |
my $html_file=$currdate; |
my $html_file=$currdate; |
20 |
$html_file=~s/ /_/g; |
$html_file=~s/ /_/g; |
21 |
$html_file="izvjestaji/$html_file.html"; |
$html_file="izvjestaji/$html_file.html"; |
22 |
|
my $html_date=$currdate; |
23 |
|
$html_date=~s/ /%20/g; |
24 |
|
|
25 |
if (! $debug) { |
if (! $debug) { |
26 |
open(HTML,"> $html_file") || die "html: $!"; |
open(HTML,"> $html_file") || die "html: $!"; |
27 |
open(MAIL,"|/usr/lib/sendmail biljana.gombar\@pliva.hr,izvjestaji\@support.pliva.hr") || die "sendmail: $!"; |
open(MAIL,"|/usr/lib/sendmail $ic_mail,$mreze_mail,izvjestaji\@support.pliva.hr") || die "sendmail: $!"; |
28 |
} else { |
} else { |
29 |
open(HTML,"> /tmp/debug.html") || die "html: $!"; |
open(HTML,"> /tmp/debug.html") || die "html: $!"; |
30 |
open(MAIL,"> /tmp/debug.mail") || die "sendmail: $!"; |
open(MAIL,"> /tmp/debug.mail") || die "sendmail: $!"; |
55 |
$db_user="user=$db_user;"; |
$db_user="user=$db_user;"; |
56 |
} |
} |
57 |
|
|
58 |
|
my $dbh = DBI->connect("DBI:Pg:dbname=informatika;${host}${db_user}","","") || die "can't connect"; |
59 |
my $dbh = DBI->connect("DBI:Pg:dbname=informatika;${host}${db_user}","","") || die $DBI::errstr; |
# die $DBI::errstr; |
60 |
$dbh->do("set datestyle = 'german'") || die $dbh->errstr(); |
$dbh->do("set datestyle = 'german'") || die $dbh->errstr(); |
61 |
|
|
62 |
my $sth = $dbh->prepare("select id from last_print order by id desc limit 1,1"); |
my $sth = $dbh->prepare("select id from last_print order by id desc limit 1,1"); |
81 |
Datum i vrijeme generiranja izvještaja: $currdate |
Datum i vrijeme generiranja izvještaja: $currdate |
82 |
|
|
83 |
Izvještaj za štampanje se nalazi na |
Izvještaj za štampanje se nalazi na |
84 |
http://support.pliva.hr/$html_file |
http://support.pliva.hr/ic.php?datum=$html_date |
85 |
sa potpunim podacima o umrežavanju, lokaciji računala i osobe |
sa potpunim podacima o umrežavanju, lokaciji računala i osobe |
86 |
|
|
87 |
"; |
"; |
88 |
print HTML " |
print HTML " |
89 |
<br>Datum i vrijeme generiranja izvještaja: $currdate<p>"; |
<br>Datum i vrijeme generiranja izvještaja: $currdate<p>"; |
90 |
|
|
91 |
$sth = $dbh->prepare(" |
my $sql=" |
92 |
select osobe.id,ime,prezime,tel,lokacije.naziv, |
select osobe.id,ime,prezime,tel,lokacije.naziv, |
93 |
org_jed.naziv,org_pod_jed.pod_naziv, |
org_jed.naziv,org_pod_jed.pod_naziv, |
94 |
lok_racunala,objekt,kat,soba,z_rac,umrezavanje, |
lok_racunala,objekt,kat,soba,z_rac,umrezavanje, |
100 |
and podesavanje=true |
and podesavanje=true |
101 |
and kontakt_osobe.id=kontakt_osoba_id |
and kontakt_osobe.id=kontakt_osoba_id |
102 |
order by lokacije.naziv,org_jed.naziv |
order by lokacije.naziv,org_jed.naziv |
103 |
") || die $dbh->errstr(); |
"; |
104 |
|
|
105 |
|
die "nema osoba za izvještaj" if (! @osoba_id_za_print); |
106 |
|
|
107 |
|
$sth = $dbh->prepare($sql) || die $dbh->errstr(); |
108 |
$sth->execute() || die $sth->errstr(); |
$sth->execute() || die $sth->errstr(); |
109 |
|
|
110 |
my $rbr=1; |
my $rbr=1; |
156 |
} |
} |
157 |
} |
} |
158 |
|
|
|
$sth->finish; |
|
159 |
|
|
160 |
print HTML ' |
print HTML ' |
161 |
</table> |
</table> |
165 |
close(HTML); |
close(HTML); |
166 |
close(MAIL); |
close(MAIL); |
167 |
|
|
|
$dbh->disconnect; |
|
|
|
|
168 |
foreach my $email_ko (keys %mail4ko) { |
foreach my $email_ko (keys %mail4ko) { |
169 |
if (! $debug) { |
if (! $debug) { |
170 |
open(MAIL,"|/usr/lib/sendmail $email_ko") || die "sendmail: $!"; |
open(MAIL,"|/usr/lib/sendmail $email_ko") || die "sendmail: $!"; |
189 |
close(MAIL); |
close(MAIL); |
190 |
} |
} |
191 |
|
|
192 |
print "Printanje zahtjeva za print za IC:\n./print.pl ",join(",",@za_ic),"\n"; |
#print "Printanje zahtjeva za print za IC:\n./print.pl ",join(",",@za_ic),"\n"; |
193 |
|
foreach my $id (@za_ic) { |
194 |
|
if (! $debug) { |
195 |
|
$dbh->do("insert into izvjestaji (datum,osoba_id) |
196 |
|
values ('$currdate',$id)") || die $dbh->errstr(); |
197 |
|
} |
198 |
|
} |
199 |
|
|
200 |
|
$sth->finish; undef $sth; |
201 |
|
$dbh->disconnect; |
202 |
|
|